gabotorresruiz commented on code in PR #43314:
URL: https://github.com/apache/superset/pull/43314#discussion_r3917975465


##########
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/TimeseriesLegend.tsx:
##########
@@ -0,0 +1,192 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { memo } from 'react';
+import { styled } from '@apache-superset/core/theme';
+import { t } from '@apache-superset/core/translation';
+import type { TimeseriesCustomLegend } from './types';
+
+const LegendViewport = styled.div<{ maxHeight: number }>`
+  ${({ maxHeight, theme }) => `
+    box-sizing: border-box;
+    color: ${theme.colorText};
+    font-size: ${theme.fontSizeSM}px;
+    max-height: ${maxHeight}px;
+    overflow-x: hidden;
+    overflow-y: auto;
+    padding: ${theme.sizeUnit}px ${theme.sizeUnit * 2}px;
+    width: 100%;
+  `}
+`;
+
+const SelectorRow = styled.div`
+  ${({ theme }) => `
+    align-items: center;
+    background: ${theme.colorBgContainer};
+    display: flex;
+    gap: ${theme.sizeUnit}px;
+    justify-content: flex-end;
+    padding-bottom: ${theme.sizeUnit}px;
+    position: sticky;
+    top: 0;
+    z-index: 1;
+  `}
+`;
+
+const SelectorButton = styled.button`
+  ${({ theme }) => `
+    background: transparent;
+    border: 1px solid ${theme.colorBorder};
+    border-radius: ${theme.borderRadius}px;
+    color: ${theme.colorText};
+    cursor: pointer;
+    font: inherit;
+    padding: 0 ${theme.sizeUnit}px;
+
+    &:hover {
+      color: ${theme.colorPrimary};
+    }
+  `}
+`;
+
+const ItemList = styled.ul`
+  ${({ theme }) => `
+    align-items: flex-start;
+    display: flex;
+    flex-wrap: wrap;
+    gap: ${theme.sizeUnit * 2}px;
+    list-style: none;
+    margin: 0;
+    padding: 0;
+  `}
+`;
+
+const LegendItem = styled.li`
+  min-width: 0;
+`;
+
+const ItemButton = styled.button<{ selected: boolean }>`
+  ${({ selected, theme }) => `
+    align-items: flex-start;
+    appearance: none;
+    background: none;
+    border: none;
+    color: ${selected ? theme.colorText : theme.colorTextDisabled};
+    cursor: pointer;
+    display: inline-flex;
+    font: inherit;
+    gap: ${theme.sizeUnit}px;
+    max-width: 100%;
+    padding: 0;
+    text-align: left;
+
+    &:disabled {
+      cursor: default;
+    }
+  `}
+`;
+
+const Swatch = styled.span<{ color: string; selected: boolean }>`
+  ${({ color, selected }) => `
+    background: ${selected ? color : 'transparent'};
+    border: 1px solid ${color};
+    box-sizing: border-box;
+    flex: 0 0 auto;
+    height: 12px;
+    margin-top: 2px;
+    width: 12px;
+  `}
+`;
+
+const Label = styled.span`
+  overflow-wrap: anywhere;
+  white-space: pre-line;
+`;
+
+const RowBreak = styled.li`
+  flex-basis: 100%;
+  height: 0;
+`;
+
+export type TimeseriesLegendProps = TimeseriesCustomLegend & {
+  maxHeight: number;
+  onAll: () => void;
+  onInverse: () => void;
+  onToggle: (name: string) => void;
+};
+
+function TimeseriesLegend({
+  items,
+  maxHeight,
+  onAll,
+  onInverse,
+  onToggle,
+  showSelectors,
+}: TimeseriesLegendProps) {
+  if (items.length === 0 || maxHeight <= 0) {
+    return null;
+  }
+
+  return (
+    <LegendViewport data-test="timeseries-custom-legend" maxHeight={maxHeight}>
+      {showSelectors && (
+        <SelectorRow>
+          <SelectorButton type="button" onClick={onAll}>
+            {t('All')}
+          </SelectorButton>
+          <SelectorButton type="button" onClick={onInverse}>
+            {t('Inverse')}
+          </SelectorButton>
+        </SelectorRow>
+      )}
+      <ItemList>
+        {items.map((item, index) =>
+          item.name === '' || item.name === '\n' ? (
+            <RowBreak
+              // ECharts treats these exact values as row-break sentinels.
+              key={`row-break-${item.name}-${index}`}
+            />
+          ) : (
+            <LegendItem key={item.name}>
+              <ItemButton

Review Comment:
   Not a blocker: the native ECharts legend highlights the hovered series by 
default (this file relies on that when it sets `legendHoverLink = false` for 
the color-by-x-axis proxies), but the HTML legend only wires click. Hovering a 
legend item no longer emphasizes its series, which is noticeable on dense 
charts. Since you already have `dispatchLegendAction`, this looks like a cheap 
add:
   
   ```tsx
   onMouseEnter={() => onHover?.(item.name)}
   onMouseLeave={() => onHover?.(null)}
   ```
   
   with the handler dispatching `highlight`/`downplay` by seriesName. Fine as a 
follow-up if you'd rather keep this scoped.



##########
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts:
##########
@@ -1378,6 +1471,9 @@ export default function transformProps(
     grid: {
       ...defaultGrid,
       ...padding,
+      // Compact charts prioritize a viable coordinate system over keeping
+      // axis labels inside an already constrained grid rectangle.
+      containLabel: !usesCompactLayout,

Review Comment:
   Question, not necessarily a blocker: this flips `containLabel` off for every 
chart at or below `compactChartHeight`, even with no legend involved and even 
when the grid reservations fit. So every small dashboard cell now renders axis 
labels un-contained, where they can overlap the plot or clip at the canvas 
edge. The SSR tests pin the grid rectangle but not label behavior. Are we 
certain we want this for all compact charts, rather than only when the 
reservations actually exceed the budget? Or is there a rendering problem with 
`containLabel: true` at these heights that motivated it?



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