aminghadersohi commented on code in PR #43770:
URL: https://github.com/apache/superset/pull/43770#discussion_r4224297719


##########
superset/mcp_service/chart/preview_utils.py:
##########
@@ -1398,6 +2412,101 @@ def fallback_vega_lite_preview(
     return None
 
 
+def generate_xy_pivot_vega_lite_preview(
+    data: list[dict[str, Any]], form_data: dict[str, Any], *, mark: str
+) -> VegaLitePreview | None:
+    """Render flattened timeseries pivot columns without dropping grouped 
series.
+
+    Folding escaped field paths resolves literal output keys without splitting
+    category values that contain escaped commas. The legend retains each
+    complete metric/category label.
+    Long-form results continue through the generic renderer.
+    """
+    from superset.mcp_service.chart.chart_helpers import _as_list
+    from superset.utils.pandas_postprocessing.utils import (
+        escape_separator,
+        FLAT_COLUMN_SEPARATOR,
+    )
+
+    if not data:
+        return None
+    dimensions = [
+        label
+        for column in _as_list(form_data.get("groupby"))
+        if (label := _form_column_label(column))
+    ]
+    if not dimensions or any(label in data[0] for label in dimensions):
+        return None
+    x_axis = _form_column_label(form_data.get("x_axis")) or "__timestamp"
+    if x_axis not in data[0]:
+        return None
+    metric_labels = [
+        escape_separator(label)
+        for metric in _as_list(form_data.get("metrics"))
+        if (label := metric_result_label(metric))
+    ]
+    fields = [
+        field
+        for field in data[0]
+        if field != x_axis
+        and any(
+            field.startswith(label + FLAT_COLUMN_SEPARATOR)

Review Comment:
   Confirmed: with `truncate_metric: true` and one metric the rename step 
leaves `{event_date, East, West}` and field discovery found nothing. Fixed in 
f19daaf51a99f657d599f3f02dd0944d9546624a: when no metric-prefixed field 
matches, there is a single metric, and `truncate_metric` is set, every 
non-x-axis column is folded as a category series. New 
`test_xy_preview_renders_truncated_metric_series` runs the real post-processing 
chain and asserts the fold covers `East` and `West`; it fails without the fix.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to