Skip to content

Update default templates #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 50 additions & 29 deletions src/dvc_render/vega_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class BarHorizontalSortedTemplate(Template):
"width": 300,
"height": 300,
"mark": {"type": "bar"},
"params": [{"bind": "scales", "name": "grid", "select": "interval"}],
"encoding": {
"x": {
"field": Template.anchor("x"),
Expand Down Expand Up @@ -175,6 +176,7 @@ class BarHorizontalTemplate(Template):
"width": 300,
"height": 300,
"mark": {"type": "bar"},
"params": [{"bind": "scales", "name": "grid", "select": "interval"}],
"encoding": {
"x": {
"field": Template.anchor("x"),
Expand Down Expand Up @@ -502,15 +504,17 @@ class SmoothLinearTemplate(Template):
},
},
],
"encoding": {
"x": {
"field": Template.anchor("x"),
"type": "quantitative",
"title": Template.anchor("x_label"),
},
},
"layer": [
{
"mark": "line",
"encoding": {
"x": {
"field": Template.anchor("x"),
"type": "quantitative",
"title": Template.anchor("x_label"),
},
"y": {
"field": Template.anchor("y"),
"type": "quantitative",
Expand All @@ -521,19 +525,14 @@ class SmoothLinearTemplate(Template):
"field": "rev",
"type": "nominal",
},
"tooltip": [
{
"field": Template.anchor("x"),
"title": Template.anchor("x_label"),
"type": "quantitative",
},
{
"field": Template.anchor("y"),
"title": Template.anchor("y_label"),
"type": "quantitative",
},
],
},
"layer": [
{"mark": "line"},
{
"transform": [{"filter": {"param": "hover", "empty": False}}],
"mark": "point",
},
],
"transform": [
{
"loess": Template.anchor("y"),
Expand All @@ -544,6 +543,7 @@ class SmoothLinearTemplate(Template):
],
},
{
"params": [{"bind": "scales", "name": "grid", "select": "interval"}],
"mark": {"type": "line", "opacity": 0.2},
"encoding": {
"x": {
Expand All @@ -558,18 +558,6 @@ class SmoothLinearTemplate(Template):
"scale": {"zero": False},
},
"color": {"field": "rev", "type": "nominal"},
"tooltip": [
{
"field": Template.anchor("x"),
"title": Template.anchor("x_label"),
"type": "quantitative",
},
{
"field": Template.anchor("y"),
"title": Template.anchor("y_label"),
"type": "quantitative",
},
],
},
},
{
Expand All @@ -595,6 +583,38 @@ class SmoothLinearTemplate(Template):
"color": {"field": "rev", "type": "nominal"},
},
},
{
"transform": [
{
"calculate": "datum.rev + '::' + datum.filename + '::' + datum.field", # noqa: E501
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fields have to be present in the data in order to implement the new tooltips. I am not sure if these or dvc_data_version_info are present in the Studio/DVC data. Will need to investigate.

Copy link
Contributor Author

@mattseddon mattseddon Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is also too long and giving pylint the shits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From iterative/dvc#9931 (comment) seems like we want to add an actual ID field instead of calculating this.

"as": "tooltip_group",
},
{
"pivot": "tooltip_group",
"value": Template.anchor("y"),
"groupby": [Template.anchor("x")],
},
],
"mark": {"type": "rule", "tooltip": {"content": "data"}},
"encoding": {
"opacity": {
"condition": {"value": 0.3, "param": "hover", "empty": False},
"value": 0,
}
},
"params": [
{
"name": "hover",
"select": {
"type": "point",
"fields": [Template.anchor("x")],
"nearest": True,
"on": "mouseover",
"clear": "mouseout",
},
}
],
},
],
}

Expand All @@ -616,6 +636,7 @@ class SimpleLinearTemplate(Template):
"type": "line",
"tooltip": {"content": "data"},
},
"params": [{"bind": "scales", "name": "grid", "select": "interval"}],
"encoding": {
"x": {
"field": Template.anchor("x"),
Expand Down
4 changes: 2 additions & 2 deletions tests/test_vega.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_default_template_mark():

plot_content = VegaRenderer(datapoints, "foo").get_filled_template(as_string=False)

assert plot_content["layer"][0]["mark"] == "line"
assert plot_content["layer"][0]["layer"][0]["mark"] == "line"

assert plot_content["layer"][1]["mark"] == {"type": "line", "opacity": 0.2}

Expand Down Expand Up @@ -78,7 +78,7 @@ def test_choose_axes():
"second_val": 300,
},
]
assert plot_content["layer"][0]["encoding"]["x"]["field"] == "first_val"
assert plot_content["encoding"]["x"]["field"] == "first_val"
assert plot_content["layer"][0]["encoding"]["y"]["field"] == "second_val"


Expand Down