Skip to content

Commit

Permalink
add mean transform to linear plot tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Jan 22, 2024
1 parent 012111f commit 2422b5f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/dvc_render/vega_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ class SmoothLinearTemplate(Template):
{"calculate": Template.anchor("pivot_field"), "as": "pivot_field"},
{
"pivot": "pivot_field",
"op": "mean",
"value": Template.anchor("y"),
"groupby": [Template.anchor("x")],
},
Expand Down
54 changes: 54 additions & 0 deletions tests/test_vega.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,60 @@ def test_no_revs_with_datapoints():
}


# https://github.com/iterative/studio/issues/8851
def test_linear_tooltip_groupby():
datapoints = [
{
"filename": "roc.json",
"fpr": 0.00399400898652022,
"tpr": 0.193158953722334,
"rev": "main",
"threshold": 0.84,
},
{
"filename": "roc.json",
"fpr": 0.00399400898652022,
"tpr": 0.2012072434607646,
"rev": "main",
"threshold": 0.829854797979798,
},
{
"filename": "roc.json",
"fpr": 0.00399400898652022,
"tpr": 0.20724346076458752,
"rev": "main",
"threshold": 0.8266666666666667,
},
{
"filename": "roc.json",
"fpr": 0.00399400898652022,
"tpr": 0.21327967806841047,
"rev": "main",
"threshold": 0.8133333333333334,
},
{
"filename": "roc.json",
"fpr": 0.00399400898652022,
"tpr": 0.2193158953722334,
"rev": "main",
"threshold": 0.8066666666666666,
},
]

props = {
"anchors_y_definitions": [{"filename": "test", "field": "fpr"}],
"revs_with_datapoints": ["main"],
"template": "linear",
"x": "fpr",
"y": "tpr",
}

renderer = VegaRenderer(datapoints, "foo", **props)
plot_content = renderer.get_filled_template()

assert plot_content["layer"][3]["transform"][1]["op"] == "mean"


@pytest.mark.parametrize(
(
"anchors_y_definitions",
Expand Down

0 comments on commit 2422b5f

Please sign in to comment.