mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
plots: shorten names in the legend (#8900)
* plots: shorten field names * plots: handle missing field names * plots: make compatible with py3.8 * plots: fix for missing data * plots: add test for field shortening * plots: strip separators regardless of os * plots: don't shorten field name * plots: drop test for shortening field name
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
|
||||
|
||||
from funcy import first, last
|
||||
@@ -221,7 +222,13 @@ class VegaConverter(Converter):
|
||||
)
|
||||
|
||||
all_datapoints = []
|
||||
all_y_fields = {y_field for _, y_field in ys}
|
||||
if ys:
|
||||
all_y_files, all_y_fields = list(zip(*ys))
|
||||
all_y_fields = set(all_y_fields)
|
||||
all_y_files = set(all_y_files)
|
||||
else:
|
||||
all_y_files = set()
|
||||
all_y_fields = set()
|
||||
|
||||
# override to unified y field name if there are different y fields
|
||||
if len(all_y_fields) > 1:
|
||||
@@ -229,6 +236,12 @@ class VegaConverter(Converter):
|
||||
else:
|
||||
props_update["y"] = first(all_y_fields)
|
||||
|
||||
# get common prefix to drop from file names
|
||||
if len(all_y_files) > 1:
|
||||
common_prefix_len = len(os.path.commonpath(all_y_files))
|
||||
else:
|
||||
common_prefix_len = 0
|
||||
|
||||
for i, (y_file, y_field) in enumerate(ys):
|
||||
if num_xs > 1:
|
||||
x_file, x_field = xs[i]
|
||||
@@ -258,12 +271,13 @@ class VegaConverter(Converter):
|
||||
"They have to have same length."
|
||||
)
|
||||
|
||||
y_file_short = y_file[common_prefix_len:].strip("/\\")
|
||||
_update_all(
|
||||
datapoints,
|
||||
update_dict={
|
||||
VERSION_FIELD: {
|
||||
"revision": revision,
|
||||
FILENAME_FIELD: y_file,
|
||||
FILENAME_FIELD: y_file_short,
|
||||
"field": y_field,
|
||||
}
|
||||
},
|
||||
|
||||
@@ -379,6 +379,40 @@ def test_finding_lists(dictionary, expected_result):
|
||||
},
|
||||
id="multi_source_y_single_x",
|
||||
),
|
||||
pytest.param(
|
||||
{
|
||||
"dir/f": {"metric": [{"v": 1, "v2": 0.1}]},
|
||||
"dir/f2": {"metric": [{"v": 1, "v2": 0.1}]},
|
||||
},
|
||||
{"y": {"dir/f": ["v2"], "dir/f2": ["v2"]}, "x": "v"},
|
||||
[
|
||||
{
|
||||
"v": 1,
|
||||
"v2": 0.1,
|
||||
VERSION_FIELD: {
|
||||
"revision": "r",
|
||||
"filename": "f",
|
||||
"field": "v2",
|
||||
},
|
||||
},
|
||||
{
|
||||
"v": 1,
|
||||
"v2": 0.1,
|
||||
VERSION_FIELD: {
|
||||
"revision": "r",
|
||||
"filename": "f2",
|
||||
"field": "v2",
|
||||
},
|
||||
},
|
||||
],
|
||||
{
|
||||
"x": "v",
|
||||
"y": "v2",
|
||||
"x_label": "v",
|
||||
"y_label": "v2",
|
||||
},
|
||||
id="multi_file_y_same_prefix",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_convert(
|
||||
|
||||
Reference in New Issue
Block a user