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


##########
superset/mcp_service/chart/preview_utils.py:
##########
@@ -1809,7 +1815,1060 @@ def generate_xy_vega_lite_preview(
             spec["transform"] = [
                 {"fold": series_columns, "as": [series_field, value_field]}
             ]
-            encoding["y"] = {"field": value_field, "type": "quantitative"}
+            # Vega-Lite stacks bar and area marks colored by a nominal field
+            # by default; follow the chart's saved ``stack`` control instead.
+            encoding["y"] = {
+                "field": value_field,
+                "type": "quantitative",
+                "stack": _xy_vega_lite_stack(form_data.get("stack")),
+            }
             encoding["color"] = {"field": series_field, "type": "nominal"}
+            if (
+                spec.get("mark") == "bar"
+                and encoding["y"]["stack"] is None
+                and "x" in encoding
+            ):
+                # Unstacked bars sit side by side like Explore's grouped bars.
+                # Offset channels need a discrete band x scale, so temporal
+                # values stay date-formatted through a full-precision time 
unit.
+                x_encoding = encoding["x"]
+                if x_encoding.get("type") == "temporal":
+                    x_encoding["timeUnit"] = "yearmonthdatehoursminutesseconds"

Review Comment:
   Confirmed: `yearmonthdatehoursminutesseconds` drops milliseconds, so 
sub-second rows shared a band. Fixed in 
44f32eafd26c892f303cf6b0b667e69c52eec7fe by switching to 
`yearmonthdatehoursminutessecondsmilliseconds`, which keeps each timestamp in 
its own band like Explore. Updated the comment and the pinning test, and added 
`test_wide_preview_unstacked_bars_keep_sub_second_timestamps_distinct` (fails 
on the old unit, passes now).



-- 
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