Keep dashboard category identity separate from shortened labels
This commit is contained in:
parent
0b676ddc7c
commit
774546a2c4
2 changed files with 15 additions and 4 deletions
|
|
@ -272,10 +272,10 @@ def get_dimension_descriptor(df: pd.DataFrame, column: str) -> Dict[str, Any]:
|
|||
except (TypeError, ValueError):
|
||||
MAX_LENGTH = 40
|
||||
unique_values = unique(values, key=freeze)
|
||||
value_mapping = {str(v)[:MAX_LENGTH]: i for i, v in enumerate(unique_values)}
|
||||
value_mapping = {freeze(v): i for i, v in enumerate(unique_values)}
|
||||
|
||||
dimension["values"] = [value_mapping[str(v)[:MAX_LENGTH]] for v in values]
|
||||
dimension["values"] = [value_mapping[freeze(v)] for v in values]
|
||||
dimension["tickvals"] = list(value_mapping.values())
|
||||
dimension["ticktext"] = [k[:MAX_LENGTH] for k in value_mapping.keys()]
|
||||
dimension["ticktext"] = [str(value)[:MAX_LENGTH] for value in unique_values]
|
||||
|
||||
return dimension
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
from typing import Any
|
||||
|
||||
import pandas as pd
|
||||
import pytest
|
||||
|
||||
from great_ai.deploy.routes.dashboard.create_dash_app import get_dimension_descriptor
|
||||
from great_ai.deploy.routes.dashboard.get_filter_from_datatable import (
|
||||
get_filter_from_datatable,
|
||||
)
|
||||
|
|
@ -30,3 +31,13 @@ def test_dashboard_filter_grammar(expression: str, operator: str, value: Any) ->
|
|||
)
|
||||
def test_incomplete_filters_are_ignored(expression: str) -> None:
|
||||
assert get_filter_from_datatable(expression) is None
|
||||
|
||||
|
||||
def test_long_category_labels_keep_distinct_coordinates() -> None:
|
||||
prefix = "a" * 40
|
||||
dimension = get_dimension_descriptor(
|
||||
pd.DataFrame({"category": [prefix + "1", prefix + "2"]}), "category"
|
||||
)
|
||||
assert dimension["values"] == [0, 1]
|
||||
assert dimension["tickvals"] == [0, 1]
|
||||
assert dimension["ticktext"] == [prefix, prefix]
|
||||
|
|
|
|||
Loading…
Reference in a new issue