You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "msyavuz (via GitHub)" <gi...@apache.org> on 2026/08/11 17:58:11 UTC
[PR] feat(dashboard-v2): theme a building block's chart [superset]
msyavuz opened a new pull request, #43070:
URL: https://github.com/apache/superset/pull/43070
### SUMMARY
Targets `dashboard-v2`, on top of the containers work merged in #43065.
A Dashboard v2 block draws its ECharts option on a bare canvas, bypassing `SuperChart`/`ChartPlugin` — so nothing applied the theme to it. Three consequences, fixed here:
1. **A chart ignored the theme.** It rendered ECharts' stock near-black text and default blue palette whatever theme was active. `getEchartsTheme` moves out of `Echart.tsx`'s inline closure into `utils/echartsTheme.ts` so something other than that one component can reach it, and `ChartBlock` merges it *under* the authored option — an explicit choice in the spec still wins. Axis styling applies only when the option declares an axis, so it no longer draws a cartesian grid onto a pie.
2. **A block had no way to know what the theme means.** The only affordance was `getCategoricalColors()`, so each contributed block re-derived the rest from raw antd tokens — every extension its own mapping, all destined to drift. `dashboard.getChartTheme()` states it once, semantically (background, text, axis, tooltip, accent, categorical + sequential colours); a renderer maps those few fields and merges its own spec over the result. It also exposes Superset's sequential schemes, which nothing was exposing at all, so any continuous colour fell back to the library's default blues.
`getColor(label)` colours a series by name through the scale that remembers what it gave a label — the same one v1 charts use. By position, a category is one colour in a chart that lists it second and another in a chart that lists it fifth, which is what makes a set of blocks read as unrelated charts rather than one dashboard.
3. **A themed deployment didn't reach a canvas.** The card used `colorBgContainer`/`colorBorderSecondary`/`borderRadiusLG` — close to v1's dashboard tile but not it. v1 reads three `dashboardTile*` override points, so a deployment that themes its tiles had no effect here at all. Same tokens now, same fallbacks.
Also adds per-series-type theming, which a global `textStyle` cannot reach: v1 is theme-correct because ~40 `transformProps` files each know which of *their* chart's elements are themeable, and a generic option has no `viz_type` to look that up by. It does carry `series[].type`, so the same thing is derived from the option — which is what stops an AI-authored pie drawing a white halo around every label (zrender's `useDefaultFill` stroke when no label colour is set).
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — the visible change is charts matching the active theme rather than ECharts' defaults; no layout or chrome changes beyond the card's token source.
### TESTING INSTRUCTIONS
1. Open a v2 dashboard and add an `echarts` block with a `dataBinding` and a bar or pie option that sets no colours.
2. Confirm text, axes, legend and tooltip follow the active theme, and that the series takes a colour from the active categorical scheme rather than ECharts' blue.
3. Add a second chart whose series has the same name; confirm both draw it in the same colour.
4. Switch light/dark and confirm both follow without a reload.
5. Set `colorScheme` on the root node; confirm charts pick up that palette.
6. With a theme defining `dashboardTileBg`/`dashboardTileBorder`/`dashboardTileBorderRadius`, confirm a block's card matches a v1 dashboard tile.
7. `npm run test -- src/core/dashboard` — `chartTheme`, `echartsSeriesDefaults` and `resolveBindings` suites.
### ADDITIONAL INFORMATION
- [ ] Has associated issue: No
- [ ] Required feature flags: None
- [x] Changes UI — charts inside v2 building blocks follow the theme; the block card reads v1's `dashboardTile*` tokens
- [ ] Includes DB Migration: No — frontend only
- [x] Introduces new feature or API — `dashboard.getChartTheme()` on the extension API; `getEchartsTheme`/`mergeEchartsThemeOverrides` newly exported from `plugin-chart-echarts`
- [ ] Removes existing feature or API: No — `getCategoricalColors()` stays, though `getChartTheme().categoricalColors` supersedes 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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(dashboard-v2): theme a building block's chart [superset]
Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #43070:
URL: https://github.com/apache/superset/pull/43070#discussion_r3760364404
##########
superset-frontend/packages/superset-core/src/dashboard/index.ts:
##########
@@ -240,3 +240,85 @@ export interface QueryDataResult {
export declare function fetchQueryData(
binding: DataBindingSpec,
): Promise<QueryDataResult>;
+
+/**
+ * The categorical series colors of the active color scheme, in order.
+ *
+ * A building block that draws its own chart has to colour its series itself,
+ * and an extension can't reach `CategoricalColorNamespace` — it isn't part of
+ * this API. Without this, every renderer falls back to its own library's stock
+ * palette (ECharts' blues, Vega-Lite's `category10`), so two blocks on one
+ * dashboard disagree about what "the first series" looks like.
+ */
+export declare function getCategoricalColors(): string[];
Review Comment:
These are part of the `theme` package like @rusackas's https://github.com/apache/superset/pull/39226. We can address the comments in that PR and merge it or just copy the relevant parts for the prototype into the `theme` folder.
##########
superset-frontend/src/core/dashboard/blocks/ChartBlock.tsx:
##########
@@ -56,7 +56,13 @@ import { useTheme } from '@apache-superset/core/theme';
import { Flex, Loading, Typography } from '@superset-ui/core/components';
import { provider, useDashboardRevision } from '../store';
import { fetchQueryData } from '../chartData';
+import {
+ getEchartsTheme,
+ mergeEchartsThemeOverrides,
+} from '@superset-ui/plugin-chart-echarts';
Review Comment:
Our plan is to delete/replace the plugin-chart-echarts with a generic ECharts component (ChartBlock is the name for now) so these should actually be exposed here. I think this will depend on @villebro's effort as an ECharts block will need to expose its "schema" which contains theme properties.
##########
superset-frontend/src/core/dashboard/echartsSeriesDefaults.ts:
##########
@@ -0,0 +1,201 @@
+/**
+ * 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.
+ */
+
+/**
+ * @fileoverview Theming that a global `textStyle` cannot reach.
+ *
+ * v1 charts are theme-correct because each of ~40 `transformProps` files knows
+ * which of *its* chart's elements are themeable — pie sets
+ * `label.color = theme.colorText`, and so on. A generic option has no
+ * `viz_type` to look that up by, which is why an AI-authored pie renders with a
+ * white halo around every label: with no explicit label colour, zrender falls
+ * back to drawing its own contrasting stroke (`zrender/graphic/Text.js`, the
+ * `useDefaultFill` branch), on the assumption that text over an arbitrary mark
+ * needs one.
+ *
+ * The fix does not need a `viz_type`. The option already says what it is —
+ * `series[].type` — so per-chart-type theming can be derived from the option
+ * itself, the same way `getEchartsTheme` already keys axis styling off whether
+ * the option declares an axis.
+ *
+ * The same pass is where a series gets its colour by name rather than by
+ * position. ECharts colours by index off the palette, so a category is one
+ * colour in a chart that lists it second and another in a chart that lists it
+ * fifth — on one dashboard, the same "EMEA" in three blocks in three colours.
+ * `theme.getColor` is the shared label→colour memory, so asking it here makes
+ * a canvas agree with itself and with the v1 charts beside it.
+ *
+ * Applied *after* the theme merge rather than as another merge source, because
+ * `mergeEchartsThemeOverrides` replaces a destination array whenever a source
+ * has one — so any `series` the theme layer contributed would be discarded the
+ * moment the authored `series: [...]` merged over it, whatever the ordering.
+ * Filling only absent keys afterwards gives the same precedence a merge would
+ * have: whatever the author set explicitly is left alone.
+ */
+
+import type { ChartTheme } from './chartTheme';
Review Comment:
Same here. This looks specific to ChartBlock (ECharts version).
##########
superset-frontend/src/core/dashboard/chartTheme.ts:
##########
@@ -0,0 +1,152 @@
+/**
+ * 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.
+ */
+
+/**
+ * @fileoverview What the active theme means for a chart, stated without
+ * reference to any charting library.
+ *
+ * Blocks draw with whatever renderer they like — ECharts, Vega-Lite, plain SVG —
+ * and each library ships its own palette and its own near-black text. Left to
+ * itself, every block therefore looks like its library rather than like
+ * Superset, and two blocks on one dashboard disagree about what "the first
+ * series" is. The only affordance a contributed block had here was
+ * `getCategoricalColors()`, so each one hand-rolled the rest from raw tokens:
+ * three extensions, three different mappings, all destined to drift.
+ *
+ * The fix is that theme compatibility should be the default a block starts from
+ * rather than something its author remembers to implement. So the host states
+ * the theme once, semantically, and each renderer maps those few fields onto its
+ * own config — a mapping that is a handful of lines, unlike re-deriving what a
+ * theme means. A block that genuinely wants different colours still says so: its
+ * own spec is merged *over* this, never under it.
+ *
+ * Superset's sequential schemes are included because nothing was exposing them
+ * at all, so any continuous colour a block drew — a heatmap, a `visualMap`, a
+ * choropleth — fell back to its library's default ramp. That is the most
+ * visible mismatch of the lot, and the least excusable, since Superset has had
+ * the schemes all along.
+ */
+
+import {
+ CategoricalColorNamespace,
+ getSequentialSchemeRegistry,
+} from '@superset-ui/core';
+import type { useTheme } from '@apache-superset/core/theme';
+
+type Theme = ReturnType<typeof useTheme>;
+
+export interface ChartTheme {
Review Comment:
Doesn't the ChartTheme structure depends on the chart library used? In other words, should this be inside ChartBlock?
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(dashboard-v2): theme a building block's chart [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on code in PR #43070:
URL: https://github.com/apache/superset/pull/43070#discussion_r4028163955
##########
superset-frontend/src/core/dashboard/resolveBindings.ts:
##########
@@ -32,7 +43,10 @@ interface BindMarker {
source: 'metric' | 'dimension' | 'theme' | 'records';
/** `metric`/`dimension` — the row field to pull one column's values from. */
alias?: string;
- /** `theme` — the theme token to substitute. */
+ /**
+ * `theme` — the chart theme field to substitute, as a dotted path:
+ * `accent`, `text.mutedColor`, `axis.gridColor`.
+ */
token?: string;
/**
Review Comment:
This landed in 7c236dc94e9, the legacy lookup is `hasOwnProperty`-gated now so `constructor`/`toString` fall through to the error instead of resolving.
##########
superset-frontend/plugins/plugin-chart-echarts/src/utils/echartsTheme.ts:
##########
@@ -0,0 +1,84 @@
+/**
+ * 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 type { SupersetTheme } from '@apache-superset/core/theme';
+
+/**
+ * Derives the ECharts styling implied by the active theme's tokens — text,
+ * legend, tooltip, axis-pointer, and (when the chart declares them) axis
+ * colors.
+ *
+ * Lives here rather than inside `Echart.tsx` because that component isn't the
+ * only renderer: the Dashboard v2 building blocks draw AI-authored options on
+ * a bare `echarts.init` canvas, bypassing `SuperChart`/`ChartPlugin` entirely,
+ * and without this they render ECharts' stock near-black text regardless of
+ * the theme.
+ *
+ * Returns only what the theme implies — merge it *under* the chart's own
+ * options (see `mergeEchartsThemeOverrides`) so anything the chart sets
+ * explicitly still wins.
+ */
+export function getEchartsTheme(theme: SupersetTheme, options?: any) {
+ const echartsTheme = {
+ textStyle: {
+ color: theme.colorText,
+ fontFamily: theme.fontFamily,
+ },
+ title: {
+ textStyle: { color: theme.colorText },
+ },
+ legend: {
+ textStyle: { color: theme.colorTextSecondary },
+ pageTextStyle: {
+ color: theme.colorTextSecondary,
+ },
+ pageIconColor: theme.colorTextSecondary,
+ pageIconInactiveColor: theme.colorTextDisabled,
+ inactiveColor: theme.colorTextDisabled,
+ },
+ tooltip: {
+ backgroundColor: theme.colorBgContainer,
+ textStyle: { color: theme.colorText },
+ },
+ axisPointer: {
+ lineStyle: { color: theme.colorPrimary },
+ label: { color: theme.colorText },
+ },
+ } as any;
+
+ // Only styled when the chart actually declares an axis — an axis block on a
+ // pie or gauge option would otherwise draw a cartesian grid that isn't there.
+ const axisTheme = {
+ axisLine: { lineStyle: { color: theme.colorSplit } },
+ axisLabel: { color: theme.colorTextSecondary },
+ splitLine: { lineStyle: { color: theme.colorSplit } },
+ minorSplitLine: {
+ lineStyle: { color: theme.colorBorderSecondary },
+ },
+ };
+ if (options?.xAxis) {
+ echartsTheme.xAxis = axisTheme;
+ }
+ if (options?.yAxis) {
+ echartsTheme.yAxis = axisTheme;
+ }
Review Comment:
Same commit (7c236dc94e9) fixed this one too, the axis default now matches the authored shape, array gets one default per axis instead of a single object overwriting the array.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(dashboard-v2): theme a building block's chart [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on code in PR #43070:
URL: https://github.com/apache/superset/pull/43070#discussion_r4028165674
##########
superset-frontend/src/core/dashboard/blocks/ChartBlock.tsx:
##########
@@ -223,20 +229,52 @@ export default function ChartBlock({ nodeId }: { nodeId: string }) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [bindingKey]);
+ const colorScheme = provider.getRoot().props?.colorScheme;
+ const chartTheme = useMemo(
+ () =>
+ getChartTheme(
+ theme,
+ typeof colorScheme === 'string' ? colorScheme : undefined,
Review Comment:
This one's fixed too, same 7c236dc94e9 commit, now in ChartWidget.tsx (renamed from ChartBlock along the way). Empty string normalizes to undefined before it hits the scheme registry.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(dashboard-v2): theme a building block's chart [superset]
Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #43070:
URL: https://github.com/apache/superset/pull/43070#issuecomment-5256630386
### <span aria-hidden="true">✅</span> Deploy Preview for *superset-docs-preview* ready!
| Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | 1d1af6489bbfd0927cf9b84004da6e6c1bba8351 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6a7b5be974dc030008ffc1bc |
|<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-43070--superset-docs-preview.netlify.app](https://deploy-preview-43070--superset-docs-preview.netlify.app) |
|<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br /><br /><br />_Use your smartphone camera to open QR code link._</details> |
|<span aria-hidden="true">🤖</span> Make changes | [Run an agent on this branch](https://app.netlify.com/projects/superset-docs-preview/agent-runs#DctLDoMgFADAu7x1ibRatb2Bx3gfkCYiBNBEjXcvu9nMBTEFHwt8AR5ACVd21T4fuG9nYw2WRjA7CphE7S_FDlNRxRn_W-daxMQlHJPU1ONAbzKfoRPWrdZ6tJafxHD_AQ) |
---
<!-- [superset-docs-preview Preview](https://deploy-preview-43070--superset-docs-preview.netlify.app) -->
_To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(dashboard-v2): theme a building block's chart [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on code in PR #43070:
URL: https://github.com/apache/superset/pull/43070#discussion_r4028161540
##########
superset-frontend/src/core/dashboard/chartTheme.ts:
##########
@@ -0,0 +1,152 @@
+/**
+ * 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.
+ */
+
+/**
+ * @fileoverview What the active theme means for a chart, stated without
+ * reference to any charting library.
+ *
+ * Blocks draw with whatever renderer they like — ECharts, Vega-Lite, plain SVG —
+ * and each library ships its own palette and its own near-black text. Left to
+ * itself, every block therefore looks like its library rather than like
+ * Superset, and two blocks on one dashboard disagree about what "the first
+ * series" is. The only affordance a contributed block had here was
+ * `getCategoricalColors()`, so each one hand-rolled the rest from raw tokens:
+ * three extensions, three different mappings, all destined to drift.
+ *
+ * The fix is that theme compatibility should be the default a block starts from
+ * rather than something its author remembers to implement. So the host states
+ * the theme once, semantically, and each renderer maps those few fields onto its
+ * own config — a mapping that is a handful of lines, unlike re-deriving what a
+ * theme means. A block that genuinely wants different colours still says so: its
+ * own spec is merged *over* this, never under it.
+ *
+ * Superset's sequential schemes are included because nothing was exposing them
+ * at all, so any continuous colour a block drew — a heatmap, a `visualMap`, a
+ * choropleth — fell back to its library's default ramp. That is the most
+ * visible mismatch of the lot, and the least excusable, since Superset has had
+ * the schemes all along.
+ */
+
+import {
+ CategoricalColorNamespace,
+ getSequentialSchemeRegistry,
+} from '@superset-ui/core';
+import type { useTheme } from '@apache-superset/core/theme';
+
+type Theme = ReturnType<typeof useTheme>;
+
+export interface ChartTheme {
+ /** Transparent, so a chart sits on the block surface rather than over it. */
+ background: string;
+ text: {
+ color: string;
+ /** Text that labels rather than states — axis ticks, legend entries. */
+ mutedColor: string;
+ /** Text that is present but inactive — a toggled-off legend entry. */
+ disabledColor: string;
+ fontFamily: string;
+ fontSize: number;
+ };
+ axis: {
+ lineColor: string;
+ labelColor: string;
+ gridColor: string;
+ /** Minor gridlines, where a renderer draws them. */
+ minorGridColor: string;
+ };
+ tooltip: {
+ background: string;
+ color: string;
+ };
+ /** Accent for hover markers, crosshairs, selection. */
+ accent: string;
+ /** The active categorical scheme, in order. One colour per series. */
+ categoricalColors: string[];
+ /**
+ * The colour for a named series or category.
+ *
+ * By position, "EMEA" is the second colour in a chart that lists it second
+ * and the fifth in one that does not, so the same category comes out a
+ * different colour in every block it appears in — the thing that most makes
+ * a set of blocks read as unrelated charts rather than as one dashboard.
+ * Superset already solves this: the scale remembers what it gave a label and
+ * gives it the same one again, which is also how the v1 charts beside a
+ * canvas resolve theirs.
+ */
+ getColor: (label: string) => string;
+ /**
+ * The active sequential scheme, light to dark — for a continuous measure
+ * (heatmap cells, a colour ramp), where a categorical palette is wrong.
+ */
+ sequentialColors: string[];
+}
+
+/**
+ * The default sequential scheme's colours, or an empty list if none is
+ * registered. Empty rather than a hardcoded fallback ramp: a renderer that gets
+ * nothing keeps its own default, which is a better outcome than inventing a
+ * Superset-looking ramp that no Superset chart actually uses.
+ */
+function getSequentialColors(): string[] {
+ try {
+ return getSequentialSchemeRegistry().get()?.colors ?? [];
+ } catch {
+ return [];
+ }
+}
+
+/**
+ * Reads live rather than being captured once: the active colour scheme and the
+ * light/dark theme can both change after any given module was imported.
+ *
+ * `scheme` is the canvas's own choice of categorical palette, stored on its
+ * root node; omitted, the deployment's default is used. Passed through to the
+ * scale rather than resolved here so that the label→colour memory is the
+ * shared one — a canvas and the v1 charts around it agree on what colour
+ * "EMEA" is.
+ */
+export function getChartTheme(theme: Theme, scheme?: string): ChartTheme {
+ const scale = CategoricalColorNamespace.getScale(scheme);
+ return {
+ background: 'transparent',
+ text: {
+ color: theme.colorText,
+ mutedColor: theme.colorTextSecondary,
+ disabledColor: theme.colorTextDisabled,
+ fontFamily: theme.fontFamily,
+ fontSize: theme.fontSize,
+ },
+ axis: {
+ lineColor: theme.colorSplit,
+ labelColor: theme.colorTextSecondary,
+ gridColor: theme.colorSplit,
+ minorGridColor: theme.colorBorderSecondary,
+ },
+ tooltip: {
+ background: theme.colorBgContainer,
+ color: theme.colorText,
+ },
+ accent: theme.colorPrimary,
+ categoricalColors: scale.colors,
+ getColor: (label: string) => scale.getColor(label),
+ sequentialColors: getSequentialColors(),
Review Comment:
Agreed, this looks real. `getScale()` here never gets a `sliceId`, so `getColor` skips `addSlice` and the shared dashboard label map never gets written to from these blocks. Two blocks listing the same label in a different series order would end up with different colors.
##########
superset-frontend/src/core/dashboard/widgets/ChartWidget.tsx:
##########
@@ -223,20 +229,52 @@ export default function ChartBlock({ nodeId }: { nodeId: string }) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [bindingKey]);
+ const colorScheme = provider.getRoot().props?.colorScheme;
+ const chartTheme = useMemo(
+ () =>
+ getChartTheme(
+ theme,
+ typeof colorScheme === 'string' ? colorScheme : undefined,
+ ),
+ [theme, colorScheme],
+ );
const option = useMemo(() => {
if (!rows) return undefined;
const resolved = resolveBindings(
(node?.props?.echartsOptions as Record<string, unknown>) ?? {},
- { rows, theme },
+ { rows, chartTheme, theme },
);
// The chart's name is drawn by the block's header, which reads it from
// this same option (see `blockLabel`). Leaving it here too would print it
// twice, at two sizes, in two places — and the header's copy is the one
// that sits where every other block's name sits.
const withoutTitle = { ...resolved };
delete withoutTitle.title;
- return withoutTitle;
- }, [node?.props?.echartsOptions, rows, theme]);
+
+ // Everything an AI-authored option doesn't say for itself comes from the
+ // theme: text/axis/legend/tooltip colors, the categorical palette, and
+ // whatever chart overrides the theme carries. Merged *under* the option
+ // (rightmost source wins in `mergeEchartsThemeOverrides`), so an explicit
+ // choice in the spec still takes precedence.
+ const merged = mergeEchartsThemeOverrides(
+ {
+ ...getEchartsTheme(theme, withoutTitle),
+ // The fallback for a series with no name of its own. A named one is
+ // coloured by that name in `applySeriesDefaults`, so it never reaches
+ // this list.
+ color: chartTheme.categoricalColors,
+ backgroundColor: 'transparent',
+ },
+ withoutTitle,
+ theme.echartsOptionsOverrides ?? {},
Review Comment:
Agreed. `Echart.tsx` keys off `vizType` for `echartsOptionsOverridesByChartType`, but this only ever merges the global `echartsOptionsOverrides`. A deployment with chart-type overrides configured would silently not get them here.
##########
superset-frontend/src/core/dashboard/index.ts:
##########
@@ -53,4 +69,10 @@ export const dashboard: typeof dashboardApi = {
updateProps: provider.updateProps.bind(provider),
onDidLayoutChange: provider.onDidLayoutChange,
fetchQueryData,
+ // Both read per call rather than captured once: the canvas's scheme, the
+ // deployment's default and the light/dark theme can each change after this
+ // module is imported.
+ getCategoricalColors: () =>
+ CategoricalColorNamespace.getScale(canvasColorScheme()).colors,
+ getChartTheme: () => getChartTheme(themeObject.theme, canvasColorScheme()),
Review Comment:
Pretty sure this isn't two sources in practice. `themeObject.theme` and `useTheme()` both come off the same `Theme` instance in Theme.tsx, `setConfig` sets `this.theme` and calls `updateProviders` with that same object in the same breath, which is what feeds the emotion `ThemeProvider` state. They shouldn't be able to disagree.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(dashboard-v2): theme a building block's chart [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #43070:
URL: https://github.com/apache/superset/pull/43070#discussion_r4028166381
##########
superset-frontend/src/core/dashboard/index.ts:
##########
@@ -53,4 +69,10 @@ export const dashboard: typeof dashboardApi = {
updateProps: provider.updateProps.bind(provider),
onDidLayoutChange: provider.onDidLayoutChange,
fetchQueryData,
+ // Both read per call rather than captured once: the canvas's scheme, the
+ // deployment's default and the light/dark theme can each change after this
+ // module is imported.
+ getCategoricalColors: () =>
+ CategoricalColorNamespace.getScale(canvasColorScheme()).colors,
+ getChartTheme: () => getChartTheme(themeObject.theme, canvasColorScheme()),
Review Comment:
✅ **Customized review instruction saved!**
**Instruction:**
> Do not flag a theme-source mismatch between `themeObject.theme` and `useTheme()` in the dashboard API; both are intentionally derived from the same `Theme` instance and updated together.
**Applied to:**
- `superset-frontend/src/core/dashboard/index.ts`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI Settings](https://app.codeant.ai/org/settings/learnings)*
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(dashboard-v2): theme a building block's chart [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43070:
URL: https://github.com/apache/superset/pull/43070#issuecomment-5256609515
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(dashboard-v2): theme a building block's chart [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #43070:
URL: https://github.com/apache/superset/pull/43070#issuecomment-5346843019
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/43070?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:warning: Please [upload](https://docs.codecov.com/docs/codecov-uploader) report for BASE (`dashboard-v2@df3c616`). [Learn more](https://docs.codecov.io/docs/error-reference?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#section-missing-base-commit) about missing BASE report.
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## dashboard-v2 #43070 +/- ##
===============================================
Coverage ? 55.99%
===============================================
Files ? 2804
Lines ? 157980
Branches ? 36091
===============================================
Hits ? 88466
Misses ? 68687
Partials ? 827
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/43070/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [presto](https://app.codecov.io/gh/apache/superset/pull/43070/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `40.35% <ø> (?)` | |
| [python](https://app.codecov.io/gh/apache/superset/pull/43070/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `40.35% <ø> (?)` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/43070?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(dashboard-v2): theme a building block's chart [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #43070:
URL: https://github.com/apache/superset/pull/43070#discussion_r3760277639
##########
superset-frontend/src/core/dashboard/chartTheme.ts:
##########
@@ -0,0 +1,152 @@
+/**
+ * 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.
+ */
+
+/**
+ * @fileoverview What the active theme means for a chart, stated without
+ * reference to any charting library.
+ *
+ * Blocks draw with whatever renderer they like — ECharts, Vega-Lite, plain SVG —
+ * and each library ships its own palette and its own near-black text. Left to
+ * itself, every block therefore looks like its library rather than like
+ * Superset, and two blocks on one dashboard disagree about what "the first
+ * series" is. The only affordance a contributed block had here was
+ * `getCategoricalColors()`, so each one hand-rolled the rest from raw tokens:
+ * three extensions, three different mappings, all destined to drift.
+ *
+ * The fix is that theme compatibility should be the default a block starts from
+ * rather than something its author remembers to implement. So the host states
+ * the theme once, semantically, and each renderer maps those few fields onto its
+ * own config — a mapping that is a handful of lines, unlike re-deriving what a
+ * theme means. A block that genuinely wants different colours still says so: its
+ * own spec is merged *over* this, never under it.
+ *
+ * Superset's sequential schemes are included because nothing was exposing them
+ * at all, so any continuous colour a block drew — a heatmap, a `visualMap`, a
+ * choropleth — fell back to its library's default ramp. That is the most
+ * visible mismatch of the lot, and the least excusable, since Superset has had
+ * the schemes all along.
+ */
+
+import {
+ CategoricalColorNamespace,
+ getSequentialSchemeRegistry,
+} from '@superset-ui/core';
+import type { useTheme } from '@apache-superset/core/theme';
+
+type Theme = ReturnType<typeof useTheme>;
+
+export interface ChartTheme {
+ /** Transparent, so a chart sits on the block surface rather than over it. */
+ background: string;
+ text: {
+ color: string;
+ /** Text that labels rather than states — axis ticks, legend entries. */
+ mutedColor: string;
+ /** Text that is present but inactive — a toggled-off legend entry. */
+ disabledColor: string;
+ fontFamily: string;
+ fontSize: number;
+ };
+ axis: {
+ lineColor: string;
+ labelColor: string;
+ gridColor: string;
+ /** Minor gridlines, where a renderer draws them. */
+ minorGridColor: string;
+ };
+ tooltip: {
+ background: string;
+ color: string;
+ };
+ /** Accent for hover markers, crosshairs, selection. */
+ accent: string;
+ /** The active categorical scheme, in order. One colour per series. */
+ categoricalColors: string[];
+ /**
+ * The colour for a named series or category.
+ *
+ * By position, "EMEA" is the second colour in a chart that lists it second
+ * and the fifth in one that does not, so the same category comes out a
+ * different colour in every block it appears in — the thing that most makes
+ * a set of blocks read as unrelated charts rather than as one dashboard.
+ * Superset already solves this: the scale remembers what it gave a label and
+ * gives it the same one again, which is also how the v1 charts beside a
+ * canvas resolve theirs.
+ */
+ getColor: (label: string) => string;
+ /**
+ * The active sequential scheme, light to dark — for a continuous measure
+ * (heatmap cells, a colour ramp), where a categorical palette is wrong.
+ */
+ sequentialColors: string[];
+}
+
+/**
+ * The default sequential scheme's colours, or an empty list if none is
+ * registered. Empty rather than a hardcoded fallback ramp: a renderer that gets
+ * nothing keeps its own default, which is a better outcome than inventing a
+ * Superset-looking ramp that no Superset chart actually uses.
+ */
+function getSequentialColors(): string[] {
+ try {
+ return getSequentialSchemeRegistry().get()?.colors ?? [];
+ } catch {
+ return [];
+ }
+}
+
+/**
+ * Reads live rather than being captured once: the active colour scheme and the
+ * light/dark theme can both change after any given module was imported.
+ *
+ * `scheme` is the canvas's own choice of categorical palette, stored on its
+ * root node; omitted, the deployment's default is used. Passed through to the
+ * scale rather than resolved here so that the label→colour memory is the
+ * shared one — a canvas and the v1 charts around it agree on what colour
+ * "EMEA" is.
+ */
+export function getChartTheme(theme: Theme, scheme?: string): ChartTheme {
+ const scale = CategoricalColorNamespace.getScale(scheme);
+ return {
+ background: 'transparent',
+ text: {
+ color: theme.colorText,
+ mutedColor: theme.colorTextSecondary,
+ disabledColor: theme.colorTextDisabled,
+ fontFamily: theme.fontFamily,
+ fontSize: theme.fontSize,
+ },
+ axis: {
+ lineColor: theme.colorSplit,
+ labelColor: theme.colorTextSecondary,
+ gridColor: theme.colorSplit,
+ minorGridColor: theme.colorBorderSecondary,
+ },
+ tooltip: {
+ background: theme.colorBgContainer,
+ color: theme.colorText,
+ },
+ accent: theme.colorPrimary,
+ categoricalColors: scale.colors,
+ getColor: (label: string) => scale.getColor(label),
+ sequentialColors: getSequentialColors(),
Review Comment:
**Suggestion:** The scale is created without a slice identifier, so calls to `scale.getColor(label)` record the mapping only in that scale's private `chartLabelsColorMap`; `CategoricalColorScale` adds labels to the shared dashboard map only when a truthy `sliceId` is supplied. Because `getChartTheme` creates a fresh scale for every block, the same label can receive different colors depending on each block's series order, contradicting the documented cross-block consistency. Use the shared namespace color API or otherwise provide a stable dashboard-level mapping rather than creating independent unregistered scales. [cache]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Repeated categories receive inconsistent colors across dashboard blocks.
- ⚠️ ECharts series colors vary with authored series order.
- ⚠️ Cross-block visual comparison becomes misleading for shared labels.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=601860f40de6419a84ad5a61cf95a0ff&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=601860f40de6419a84ad5a61cf95a0ff&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/src/core/dashboard/chartTheme.ts
**Line:** 125:148
**Comment:**
*Cache: The scale is created without a slice identifier, so calls to `scale.getColor(label)` record the mapping only in that scale's private `chartLabelsColorMap`; `CategoricalColorScale` adds labels to the shared dashboard map only when a truthy `sliceId` is supplied. Because `getChartTheme` creates a fresh scale for every block, the same label can receive different colors depending on each block's series order, contradicting the documented cross-block consistency. Use the shared namespace color API or otherwise provide a stable dashboard-level mapping rather than creating independent unregistered scales.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43070&comment_hash=2121a1e60e928b46fb7f1b86c14063df69b3bce904b2e9621c564ca1333bc690&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43070&comment_hash=2121a1e60e928b46fb7f1b86c14063df69b3bce904b2e9621c564ca1333bc690&reaction=dislike'>👎</a>
##########
superset-frontend/src/core/dashboard/index.ts:
##########
@@ -53,4 +69,10 @@ export const dashboard: typeof dashboardApi = {
updateProps: provider.updateProps.bind(provider),
onDidLayoutChange: provider.onDidLayoutChange,
fetchQueryData,
+ // Both read per call rather than captured once: the canvas's scheme, the
+ // deployment's default and the light/dark theme can each change after this
+ // module is imported.
+ getCategoricalColors: () =>
+ CategoricalColorNamespace.getScale(canvasColorScheme()).colors,
+ getChartTheme: () => getChartTheme(themeObject.theme, canvasColorScheme()),
Review Comment:
**Suggestion:** The public API derives its theme from the module-level `themeObject`, while mounted dashboard blocks derive it from React's `useTheme()` context. When the application uses a different `ThemeController` or provider theme, `dashboard.getChartTheme()` and the rendered block can return different colors and typography after a theme change. Resolve the API through the same active theme source used by the provider, or ensure the provider updates this exact `themeObject`. [api mismatch]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Dashboard-specific themes can disagree with block API values.
- ⚠️ Extensions may render inconsistent chart colors and typography.
- ⚠️ Theme changes can produce mismatched canvas and block styling.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=e574e168cde142aea364876b93788efd&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=e574e168cde142aea364876b93788efd&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/src/core/dashboard/index.ts
**Line:** 77:77
**Comment:**
*Api Mismatch: The public API derives its theme from the module-level `themeObject`, while mounted dashboard blocks derive it from React's `useTheme()` context. When the application uses a different `ThemeController` or provider theme, `dashboard.getChartTheme()` and the rendered block can return different colors and typography after a theme change. Resolve the API through the same active theme source used by the provider, or ensure the provider updates this exact `themeObject`.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43070&comment_hash=2b90522cfea35993a52d41d9498229b58517650bd02c04d69b73ebc8f844f239&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43070&comment_hash=2b90522cfea35993a52d41d9498229b58517650bd02c04d69b73ebc8f844f239&reaction=dislike'>👎</a>
##########
superset-frontend/src/core/dashboard/resolveBindings.ts:
##########
@@ -32,7 +43,10 @@ interface BindMarker {
source: 'metric' | 'dimension' | 'theme' | 'records';
/** `metric`/`dimension` — the row field to pull one column's values from. */
alias?: string;
- /** `theme` — the theme token to substitute. */
+ /**
+ * `theme` — the chart theme field to substitute, as a dotted path:
+ * `accent`, `text.mutedColor`, `axis.gridColor`.
+ */
token?: string;
/**
Review Comment:
**Suggestion:** The legacy fallback reads the raw theme through normal property access, so tokens such as `constructor` or `toString` resolve inherited `Object.prototype` members instead of throwing the documented “not a chart theme field” error. This can inject functions or prototype objects into authored chart options. Restrict both legacy and dotted-path lookups to own properties. [api mismatch]
<details>
<summary><b>Severity Level:</b> Minor 🧹</summary>
```mdx
- ⚠️ Invalid theme binds bypass the documented validation error.
- ⚠️ ECharts options can receive inherited functions or objects.
- ⚠️ Malformed authored charts may fail during rendering.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=2d4c6027be4f4da58cc3c8a94ec426ef&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=2d4c6027be4f4da58cc3c8a94ec426ef&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/src/core/dashboard/resolveBindings.ts
**Line:** 51:54
**Comment:**
*Api Mismatch: The legacy fallback reads the raw theme through normal property access, so tokens such as `constructor` or `toString` resolve inherited `Object.prototype` members instead of throwing the documented “not a chart theme field” error. This can inject functions or prototype objects into authored chart options. Restrict both legacy and dotted-path lookups to own properties.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43070&comment_hash=d691475dbb1236e019bb365eb921db7d7804f16ec77b2ed330c0a7dfa6c33798&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43070&comment_hash=d691475dbb1236e019bb365eb921db7d7804f16ec77b2ed330c0a7dfa6c33798&reaction=dislike'>👎</a>
##########
superset-frontend/src/core/dashboard/blocks/ChartBlock.tsx:
##########
@@ -223,20 +229,52 @@ export default function ChartBlock({ nodeId }: { nodeId: string }) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [bindingKey]);
+ const colorScheme = provider.getRoot().props?.colorScheme;
+ const chartTheme = useMemo(
+ () =>
+ getChartTheme(
+ theme,
+ typeof colorScheme === 'string' ? colorScheme : undefined,
Review Comment:
**Suggestion:** An empty string is passed as a color-scheme name instead of being normalized to `undefined`. The shared dashboard implementation explicitly treats an empty root `colorScheme` as unset and uses the deployment default, whereas `CategoricalColorNamespace` looks up the empty key and returns an empty palette. A saved or edited block with `colorScheme: ''` can therefore lose its categorical colors and produce undefined color assignments. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Saved blocks can lose categorical chart colors.
- ⚠️ Named series receive undefined item colors.
- ⚠️ Empty schemes bypass the deployment default palette.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=ab2da6aa3e4849f490cd2374be0f406a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=ab2da6aa3e4849f490cd2374be0f406a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/src/core/dashboard/blocks/ChartBlock.tsx
**Line:** 235:237
**Comment:**
*Logic Error: An empty string is passed as a color-scheme name instead of being normalized to `undefined`. The shared dashboard implementation explicitly treats an empty root `colorScheme` as unset and uses the deployment default, whereas `CategoricalColorNamespace` looks up the empty key and returns an empty palette. A saved or edited block with `colorScheme: ''` can therefore lose its categorical colors and produce undefined color assignments.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43070&comment_hash=b98c561c34b445b3f4096bfa715eed27ed4aba4c5c0cb2ee22979d1e9129e56b&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43070&comment_hash=b98c561c34b445b3f4096bfa715eed27ed4aba4c5c0cb2ee22979d1e9129e56b&reaction=dislike'>👎</a>
##########
superset-frontend/src/core/dashboard/blocks/ChartBlock.tsx:
##########
@@ -223,20 +229,52 @@ export default function ChartBlock({ nodeId }: { nodeId: string }) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [bindingKey]);
+ const colorScheme = provider.getRoot().props?.colorScheme;
+ const chartTheme = useMemo(
+ () =>
+ getChartTheme(
+ theme,
+ typeof colorScheme === 'string' ? colorScheme : undefined,
+ ),
+ [theme, colorScheme],
+ );
const option = useMemo(() => {
if (!rows) return undefined;
const resolved = resolveBindings(
(node?.props?.echartsOptions as Record<string, unknown>) ?? {},
- { rows, theme },
+ { rows, chartTheme, theme },
);
// The chart's name is drawn by the block's header, which reads it from
// this same option (see `blockLabel`). Leaving it here too would print it
// twice, at two sizes, in two places — and the header's copy is the one
// that sits where every other block's name sits.
const withoutTitle = { ...resolved };
delete withoutTitle.title;
- return withoutTitle;
- }, [node?.props?.echartsOptions, rows, theme]);
+
+ // Everything an AI-authored option doesn't say for itself comes from the
+ // theme: text/axis/legend/tooltip colors, the categorical palette, and
+ // whatever chart overrides the theme carries. Merged *under* the option
+ // (rightmost source wins in `mergeEchartsThemeOverrides`), so an explicit
+ // choice in the spec still takes precedence.
+ const merged = mergeEchartsThemeOverrides(
+ {
+ ...getEchartsTheme(theme, withoutTitle),
+ // The fallback for a series with no name of its own. A named one is
+ // coloured by that name in `applySeriesDefaults`, so it never reaches
+ // this list.
+ color: chartTheme.categoricalColors,
+ backgroundColor: 'transparent',
+ },
+ withoutTitle,
+ theme.echartsOptionsOverrides ?? {},
Review Comment:
**Suggestion:** The v2 renderer applies only global ECharts overrides and never selects `echartsOptionsOverridesByChartType`, unlike `Echart.tsx`. Deployments that configure chart-specific overrides will therefore render regular charts and building-block charts differently, even when both use the same theme configuration. The renderer needs a chart-type mapping or an explicit documented policy for resolving the option's series type to the configured override. [api mismatch]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Chart-type overrides apply only to v1 charts.
- ⚠️ Dashboard v2 blocks ignore configured series styling.
- ⚠️ Themed deployments render equivalent charts inconsistently.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=97d47c41d3304f178cba24648ee870c4&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=97d47c41d3304f178cba24648ee870c4&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/src/core/dashboard/blocks/ChartBlock.tsx
**Line:** 268:269
**Comment:**
*Api Mismatch: The v2 renderer applies only global ECharts overrides and never selects `echartsOptionsOverridesByChartType`, unlike `Echart.tsx`. Deployments that configure chart-specific overrides will therefore render regular charts and building-block charts differently, even when both use the same theme configuration. The renderer needs a chart-type mapping or an explicit documented policy for resolving the option's series type to the configured override.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43070&comment_hash=226dfee4cca5fa84d5cef341ec5c0ea4ecfdcd9e0ce033320f007aea75a72ff4&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43070&comment_hash=226dfee4cca5fa84d5cef341ec5c0ea4ecfdcd9e0ce033320f007aea75a72ff4&reaction=dislike'>👎</a>
##########
superset-frontend/plugins/plugin-chart-echarts/src/utils/echartsTheme.ts:
##########
@@ -0,0 +1,84 @@
+/**
+ * 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 type { SupersetTheme } from '@apache-superset/core/theme';
+
+/**
+ * Derives the ECharts styling implied by the active theme's tokens — text,
+ * legend, tooltip, axis-pointer, and (when the chart declares them) axis
+ * colors.
+ *
+ * Lives here rather than inside `Echart.tsx` because that component isn't the
+ * only renderer: the Dashboard v2 building blocks draw AI-authored options on
+ * a bare `echarts.init` canvas, bypassing `SuperChart`/`ChartPlugin` entirely,
+ * and without this they render ECharts' stock near-black text regardless of
+ * the theme.
+ *
+ * Returns only what the theme implies — merge it *under* the chart's own
+ * options (see `mergeEchartsThemeOverrides`) so anything the chart sets
+ * explicitly still wins.
+ */
+export function getEchartsTheme(theme: SupersetTheme, options?: any) {
+ const echartsTheme = {
+ textStyle: {
+ color: theme.colorText,
+ fontFamily: theme.fontFamily,
+ },
+ title: {
+ textStyle: { color: theme.colorText },
+ },
+ legend: {
+ textStyle: { color: theme.colorTextSecondary },
+ pageTextStyle: {
+ color: theme.colorTextSecondary,
+ },
+ pageIconColor: theme.colorTextSecondary,
+ pageIconInactiveColor: theme.colorTextDisabled,
+ inactiveColor: theme.colorTextDisabled,
+ },
+ tooltip: {
+ backgroundColor: theme.colorBgContainer,
+ textStyle: { color: theme.colorText },
+ },
+ axisPointer: {
+ lineStyle: { color: theme.colorPrimary },
+ label: { color: theme.colorText },
+ },
+ } as any;
+
+ // Only styled when the chart actually declares an axis — an axis block on a
+ // pie or gauge option would otherwise draw a cartesian grid that isn't there.
+ const axisTheme = {
+ axisLine: { lineStyle: { color: theme.colorSplit } },
+ axisLabel: { color: theme.colorTextSecondary },
+ splitLine: { lineStyle: { color: theme.colorSplit } },
+ minorSplitLine: {
+ lineStyle: { color: theme.colorBorderSecondary },
+ },
+ };
+ if (options?.xAxis) {
+ echartsTheme.xAxis = axisTheme;
+ }
+ if (options?.yAxis) {
+ echartsTheme.yAxis = axisTheme;
+ }
Review Comment:
**Suggestion:** When `xAxis` or `yAxis` is authored in ECharts' valid array form, this helper still returns a single object axis override. `mergeEchartsThemeOverrides` replaces that object with the authored array, so none of the theme's axis line, label, or grid styling reaches any array axis. Convert the theme override to an array-compatible per-axis default before merging. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Multi-axis building blocks lose themed axis styling.
- ⚠️ Axis labels and grid lines use ECharts defaults.
- ⚠️ Dashboard charts can look inconsistent across axis forms.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=fcfb1c9a84674d3889afb431d91f0fc6&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=fcfb1c9a84674d3889afb431d91f0fc6&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/plugins/plugin-chart-echarts/src/utils/echartsTheme.ts
**Line:** 74:79
**Comment:**
*Logic Error: When `xAxis` or `yAxis` is authored in ECharts' valid array form, this helper still returns a single object axis override. `mergeEchartsThemeOverrides` replaces that object with the authored array, so none of the theme's axis line, label, or grid styling reaches any array axis. Convert the theme override to an array-compatible per-axis default before merging.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43070&comment_hash=4731accdb628671161d46fca555123b1460772ca36258100468dc62fa1bb6485&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43070&comment_hash=4731accdb628671161d46fca555123b1460772ca36258100468dc62fa1bb6485&reaction=dislike'>👎</a>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(dashboard-v2): theme a building block's chart [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43070:
URL: https://github.com/apache/superset/pull/43070#issuecomment-5256660218
<!-- Bito Reply -->
The flagged issue is correct. In `superset-frontend/src/core/dashboard/chartTheme.ts`, `getChartTheme` creates a new `CategoricalColorScale` instance without a `sliceId` for every block. Because `CategoricalColorScale` only registers labels in the shared dashboard-level map when a `sliceId` is provided, these independent scales do not share color mappings, leading to inconsistent colors for the same labels across different dashboard blocks.
To resolve this, you should ensure that the scale is associated with a stable dashboard-level identifier. Since `getChartTheme` is intended to be used across the dashboard, you can pass a consistent identifier (such as a dashboard-level namespace or a shared `sliceId` if applicable) to `CategoricalColorNamespace.getScale(scheme)` to ensure the scale instance is shared or correctly scoped.
Would you like me to fetch all other comments on this PR to validate and implement fixes for them as well?
**superset-frontend/src/core/dashboard/chartTheme.ts**
```
export function getChartTheme(theme: Theme, scheme?: string): ChartTheme {
// Use a consistent dashboard-level identifier instead of an unregistered scale
const scale = CategoricalColorNamespace.getScale(scheme, 'dashboard-shared-namespace');
return {
// ... rest of the implementation
getColor: (label: string) => scale.getColor(label),
// ...
};
}
```
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org