Skip to content
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

feat(templates): use lines to render smooth template #131

Merged
merged 1 commit into from
May 15, 2023
Merged
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
48 changes: 46 additions & 2 deletions src/dvc_render/vega_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,18 @@ 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",
},
],
},
"transform": [
{
Expand All @@ -523,18 +535,50 @@ class SmoothLinearTemplate(Template):
},
],
},
{
"mark": {"type": "line", "opacity": 0.2},
"encoding": {
"x": {
"field": Template.anchor("x"),
"type": "quantitative",
"title": Template.anchor("x_label"),
},
"y": {
"field": Template.anchor("y"),
"type": "quantitative",
"title": Template.anchor("y_label"),
"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",
},
],
},
},
{
"mark": {
"type": "point",
"tooltip": {"content": "data"},
"type": "circle",
"size": 10,
"tooltip": {"content": "encoding"},
},
"encoding": {
"x": {
"aggregate": "max",
"field": Template.anchor("x"),
"type": "quantitative",
"title": Template.anchor("x_label"),
},
"y": {
"aggregate": {"argmax": Template.anchor("x")},
"field": Template.anchor("y"),
"type": "quantitative",
"title": Template.anchor("y_label"),
Expand Down
9 changes: 6 additions & 3 deletions tests/test_vega.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ def test_default_template_mark():

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

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

assert plot_content["layer"][2]["mark"] == {
"type": "circle",
"size": 10,
"tooltip": {"content": "encoding"},
}


Expand Down