Skip to content

Commit

Permalink
feat(templates): use lines to render smooth template (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
shcheklein authored May 15, 2023
1 parent fef2941 commit a4099d3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
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

0 comments on commit a4099d3

Please sign in to comment.