-
Notifications
You must be signed in to change notification settings - Fork 16.6k
New Feature : Add an option - Color by X axis to Bar Charts , when no… #37531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
madhushreeag
wants to merge
1
commit into
apache:master
Choose a base branch
from
madhushreeag:madhu/feat/bar-chart-color-by-x-axis
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -167,6 +167,7 @@ export default function transformProps( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| seriesType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showLegend, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showValue, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showColorByXAxis, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sliceId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sortSeriesType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sortSeriesAscending, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -356,6 +357,7 @@ export default function transformProps( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| timeCompare: array, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| timeShiftColor, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| theme, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showColorByXAxis, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (transformedSeries) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -373,6 +375,53 @@ export default function transformProps( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Add x-axis color legend when showColorByXAxis is enabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (showColorByXAxis && groupBy.length === 0 && series.length > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Hide original series from legend | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| series.forEach(s => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| s.legendHoverLink = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Get x-axis values from the first series | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const firstSeries = series[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (firstSeries && Array.isArray(firstSeries.data)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const xAxisValues: (string | number)[] = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Extract x-axis values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (firstSeries.data as any[]).forEach(point => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let xValue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (point && typeof point === 'object' && 'value' in point) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const val = point.value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| xValue = Array.isArray(val) ? val[0] : val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (Array.isArray(point)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| xValue = point[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| xValue = point; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| xAxisValues.push(xValue); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Create hidden series for legend (using 'line' type to not affect bar width) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| xAxisValues.forEach(xValue => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const colorKey = String(xValue); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| series.push({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: String(xValue), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'line', // Use line type to not affect bar positioning | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: [], // Empty - doesn't render | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| itemStyle: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| color: colorScale(colorKey, sliceId), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lineStyle: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| color: colorScale(colorKey, sliceId), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| silent: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| legendHoverLink: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showSymbol: false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (stack === StackControlsValue.Stream) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const baselineSeries = getBaselineSeriesForStream( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| series.map(entry => entry.data) as [string | number, number][][], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -513,14 +562,34 @@ export default function transformProps( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isHorizontal, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const legendData = rawSeries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .filter( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| entry => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extractForecastSeriesContext(entry.name || '').type === | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ForecastSeriesEnum.Observation, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .map(entry => entry.name || '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .concat(extractAnnotationLabels(annotationLayers)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const legendData = showColorByXAxis && groupBy.length === 0 && series.length > 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? // When showColorByXAxis is enabled, show only x-axis values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const firstSeries = series[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (firstSeries && Array.isArray(firstSeries.data)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return (firstSeries.data as any[]).map(point => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (point && typeof point === 'object' && 'value' in point) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const val = point.value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return String(Array.isArray(val) ? val[0] : val); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (Array.isArray(point)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return String(point[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return String(point); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+566
to
+580
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Logic/robustness: Severity Level: Major
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? // When showColorByXAxis is enabled, show only x-axis values | |
| (() => { | |
| const firstSeries = series[0]; | |
| if (firstSeries && Array.isArray(firstSeries.data)) { | |
| return (firstSeries.data as any[]).map(point => { | |
| if (point && typeof point === 'object' && 'value' in point) { | |
| const val = point.value; | |
| return String(Array.isArray(val) ? val[0] : val); | |
| } else if (Array.isArray(point)) { | |
| return String(point[0]); | |
| } else { | |
| return String(point); | |
| } | |
| }); | |
| } | |
| ? // When showColorByXAxis is enabled, show only x-axis values (filtered + deduped) | |
| (() => { | |
| const firstSeries = series[0]; | |
| if (firstSeries && Array.isArray(firstSeries.data)) { | |
| const names = (firstSeries.data as any[]).map(point => { | |
| if (point && typeof point === 'object' && 'value' in point) { | |
| const val = point.value; | |
| return String(Array.isArray(val) ? val[0] : val); | |
| } else if (Array.isArray(point)) { | |
| return String(point[0]); | |
| } else { | |
| return String(point); | |
| } | |
| }) | |
| // filter out empty/invalid entries and deduplicate | |
| .filter(name => name !== '' && name !== 'undefined' && name !== 'null'); | |
| return Array.from(new Set(names)); |
Steps of Reproduction ✅
1. Call transformProps in plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
with formData.showColorByXAxis = true and no groupBy (groupBy.length === 0). The
legendData computation is at lines ~565-592.
2. If the first rendered series (series[0]) contains points where the x value is
null/undefined/empty, the mapping at lines 569-578 will convert those to the strings
"null" or "undefined" or empty strings, and include them in the returned array.
3. If the firstSeries.data contains duplicate x values, the current map returns duplicates
(no deduplication). These values are later fed to echartOptions.legend.data (see legend
configuration at lines ~771-792), producing duplicate or meaningless legend entries in the
chart UI.
4. Reproduce in UI: render a Timeseries chart with showColorByXAxis enabled and a dataset
where firstSeries.data includes duplicate or empty x values; verify duplicate/empty legend
items appear. Fixing by filtering out empty values and deduplicating (as suggested) yields
stable, meaningful legend items.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
**Line:** 566:580
**Comment:**
*Logic Error: Logic/robustness: `legendData` is built from `firstSeries.data` and can include duplicate or empty/undefined entries; filter out empty/undefined names and deduplicate them so legend items are stable and meaningful.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Performance & correctness: when creating hidden legend series you append one series per x-axis data point without deduplicating, which can create duplicate legend entries and a large number of unnecessary series; deduplicate x-axis values first before pushing hidden series. [performance]
Severity Level: Major⚠️
Steps of Reproduction ✅
Prompt for AI Agent 🤖