Aleem89 commented on code in PR #45648:
URL: https://github.com/apache/superset/pull/45648#discussion_r4408519791
##########
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts:
##########
@@ -146,11 +148,75 @@ import { safeParseEChartOptions } from
'../utils/safeEChartOptionsParser';
import { mergeCustomEChartOptions } from '../utils/mergeCustomEChartOptions';
type LegendSeriesVisual = {
- itemStyle?: { color?: unknown };
- lineStyle?: { color?: unknown };
+ itemStyle?: { color?: unknown; opacity?: unknown };
+ lineStyle?: {
+ color?: unknown;
+ opacity?: unknown;
+ type?: unknown;
+ width?: unknown;
+ };
name?: string | number;
+ symbol?: unknown;
+ type?: string;
};
+// ECharts draws a circle for `none` and falls back to the series default when
unset.
+function normalizeLegendSymbol(symbol: unknown, fallback: string): string {
+ if (symbol === 'none') {
+ return 'circle';
+ }
+ return typeof symbol === 'string' ? symbol : fallback;
+}
+
+// The legend inherits the series opacity; a fully transparent line (a forecast
+// confidence band) still gets a visible icon.
+function normalizeLegendOpacity(opacity: unknown): number {
+ return typeof opacity === 'number' && opacity > 0 && opacity < 1
+ ? opacity
+ : 1;
+}
+
+/**
+ * The icon the ECharts legend would draw for a series: its line in the series'
+ * dash style with its symbol, the symbol alone for scatter, a box otherwise.
+ * The legend line is 2px like ECharts' `lineStyle.width: 'auto'`, or hidden
+ * when the series hides its own line.
+ */
+export function getLegendSeriesIcon(
+ series: SeriesOption | undefined,
+): TimeseriesLegendIcon {
+ const visual = series as LegendSeriesVisual | undefined;
+ if (visual?.type === 'scatter') {
+ return {
+ shape: 'symbol',
+ opacity: normalizeLegendOpacity(visual.itemStyle?.opacity),
+ symbol: normalizeLegendSymbol(visual.symbol, 'circle'),
+ };
+ }
+ if (visual?.type !== 'line') {
+ return {
+ shape: 'box',
+ opacity: normalizeLegendOpacity(visual?.itemStyle?.opacity),
+ };
+ }
+ const { opacity, type, width } = visual.lineStyle ?? {};
Review Comment:
Nice catch, hadn't considered that case. Fixed in 81bbbe9 so the symbol gets
its own opacity from itemStyle. The symbol now correctly disappears w/ rich
tooltip and markers off just like it does w/ the Scroll legend.
--
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]