Skip to content

Commit e42805b

Browse files
committed
add tooltip anchor for Studio
1 parent 1c4428a commit e42805b

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/dvc_render/vega.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def get_partial_filled_template(self):
134134
"data",
135135
"shape",
136136
"stroke_dash",
137+
"tooltip",
137138
"title",
138139
"x_label",
139140
"y_label",
@@ -210,6 +211,7 @@ def _process_optional_anchors(self, split_anchors: List[str]):
210211
"row",
211212
"shape",
212213
"stroke_dash",
214+
"tooltip",
213215
"zoom_and_pan",
214216
]
215217
if self.template.has_anchor(anchor)
@@ -262,6 +264,7 @@ def _process_single_source_plot(
262264
self._fill_optional_anchor(
263265
split_anchors, optional_anchors, "pivot_field", "datum.rev"
264266
)
267+
self._fill_tooltip(split_anchors, optional_anchors)
265268
for anchor in optional_anchors:
266269
self.template.fill_anchor(anchor, {})
267270

@@ -327,8 +330,7 @@ def _fill_optional_multi_source_anchors(
327330
split_anchors, optional_anchors, "row", {"field": concat_field}
328331
)
329332

330-
if not optional_anchors:
331-
return
333+
self._fill_tooltip(split_anchors, optional_anchors, [concat_field])
332334

333335
for anchor in ["stroke_dash", "shape"]:
334336
self._fill_optional_anchor_mapping(
@@ -357,6 +359,26 @@ def _fill_group_by(
357359
[*grouped_keys, self.properties.get("y")],
358360
)
359361

362+
def _fill_tooltip(
363+
self,
364+
split_anchors: List[str],
365+
optional_anchors: List[str],
366+
additional_fields: Optional[List[str]] = None,
367+
):
368+
if not additional_fields:
369+
additional_fields = []
370+
self._fill_optional_anchor(
371+
split_anchors,
372+
optional_anchors,
373+
"tooltip",
374+
[
375+
{"field": "rev"},
376+
{"field": self.properties.get("x")},
377+
{"field": self.properties.get("y")},
378+
*[{"field": field} for field in additional_fields],
379+
],
380+
)
381+
360382
def _fill_optional_anchor(
361383
self,
362384
split_anchors: List[str],

src/dvc_render/vega_templates.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ class ScatterTemplate(Template):
442442
},
443443
"color": Template.anchor("color"),
444444
"shape": Template.anchor("shape"),
445+
"tooltip": Template.anchor("tooltip"),
445446
},
446447
}
447448

@@ -471,6 +472,7 @@ class ScatterJitterTemplate(Template):
471472
},
472473
"color": Template.anchor("color"),
473474
"shape": Template.anchor("shape"),
475+
"tooltip": Template.anchor("tooltip"),
474476
"xOffset": {"field": "randomX", "type": "quantitative"},
475477
"yOffset": {"field": "randomY", "type": "quantitative"},
476478
},
@@ -641,6 +643,7 @@ class SimpleLinearTemplate(Template):
641643
},
642644
"color": Template.anchor("color"),
643645
"strokeDash": Template.anchor("stroke_dash"),
646+
"tooltip": Template.anchor("tooltip"),
644647
},
645648
}
646649

0 commit comments

Comments
 (0)