Skip to content

Commit a5284c2

Browse files
committed
add rev_order anchor for Studio
1 parent e42805b commit a5284c2

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/dvc_render/vega.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def get_partial_filled_template(self):
132132
split_anchors=[
133133
"color",
134134
"data",
135+
"rev_order",
135136
"shape",
136137
"stroke_dash",
137138
"tooltip",
@@ -208,6 +209,7 @@ def _process_optional_anchors(self, split_anchors: List[str]):
208209
"group_by_y",
209210
"group_by",
210211
"pivot_field",
212+
"rev_order",
211213
"row",
212214
"shape",
213215
"stroke_dash",
@@ -221,6 +223,7 @@ def _process_optional_anchors(self, split_anchors: List[str]):
221223

222224
self._fill_color(split_anchors, optional_anchors)
223225
self._fill_zoom_and_pan(split_anchors, optional_anchors)
226+
self._fill_rev_order(split_anchors, optional_anchors)
224227

225228
y_definitions = self.properties.get("anchors_y_definitions", [])
226229
is_single_source = len(y_definitions) <= 1
@@ -245,17 +248,25 @@ def _fill_color(self, split_anchors: List[str], optional_anchors: List[str]):
245248

246249
def _fill_zoom_and_pan(self, split_anchors: List[str], optional_anchors: List[str]):
247250
name = "zoom_and_pan"
248-
encoding = {"name": "grid", "select": "interval", "bind": "scales"}
249-
if "zoom_and_pan" not in optional_anchors:
251+
if name not in optional_anchors:
250252
return
251253

252-
optional_anchors.remove("zoom_and_pan")
254+
optional_anchors.remove(name)
253255

254-
if name in split_anchors:
255-
self._set_split_content(name, encoding)
256+
self._fill_split_anchor(
257+
split_anchors,
258+
name,
259+
{"name": "grid", "select": "interval", "bind": "scales"},
260+
)
261+
262+
def _fill_rev_order(self, split_anchors: List[str], optional_anchors: List[str]):
263+
name = "rev_order"
264+
if name not in optional_anchors:
256265
return
257266

258-
self.template.fill_anchor(name, encoding)
267+
optional_anchors.remove(name)
268+
269+
self._fill_split_anchor(split_anchors, name, self.get_revs())
259270

260271
def _process_single_source_plot(
261272
self, split_anchors: List[str], optional_anchors: List[str]
@@ -421,6 +432,9 @@ def _fill_optional_anchor_mapping(
421432

422433
encoding = self._get_optional_anchor_mapping(field, name, domain)
423434

435+
self._fill_split_anchor(split_anchors, name, encoding)
436+
437+
def _fill_split_anchor(self, split_anchors: List[str], name: str, encoding: Any):
424438
if name in split_anchors:
425439
self._set_split_content(name, encoding)
426440
return

src/dvc_render/vega_templates.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ class ConfusionTemplate(Template):
200200
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
201201
"data": {"values": Template.anchor("data")},
202202
"title": Template.anchor("title"),
203-
"facet": {"column": {"field": "rev"}, "row": Template.anchor("row")},
203+
"facet": {
204+
"column": {"field": "rev", "sort": Template.anchor("rev_order")},
205+
"row": Template.anchor("row"),
206+
},
204207
"spec": {
205208
"transform": [
206209
{
@@ -310,7 +313,10 @@ class NormalizedConfusionTemplate(Template):
310313
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
311314
"data": {"values": Template.anchor("data")},
312315
"title": Template.anchor("title"),
313-
"facet": {"column": {"field": "rev"}, "row": Template.anchor("row")},
316+
"facet": {
317+
"column": {"field": "rev", "sort": Template.anchor("rev_order")},
318+
"row": Template.anchor("row"),
319+
},
314320
"spec": {
315321
"transform": [
316322
{

0 commit comments

Comments
 (0)