-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
fix: repeated color in the same chart #23762
Changes from 7 commits
443f913
fea753a
2d0f564
8c7fc74
bd4679d
844bee8
2c6e38f
14636cd
f978b1f
d5d68b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,12 +76,14 @@ class CategoricalColorScale extends ExtensibleFunction { | |
getColor(value?: string, sliceId?: number) { | ||
const cleanedValue = stringifyAndTrim(value); | ||
const sharedLabelColor = getSharedLabelColor(); | ||
const sharedColorMap = sharedLabelColor.getColorMap(); | ||
const sharedColor = sharedColorMap.get(cleanedValue); | ||
|
||
// priority: parentForcedColors > forcedColors > labelColors | ||
let color = | ||
this.parentForcedColors?.[cleanedValue] || | ||
this.forcedColors?.[cleanedValue] || | ||
sharedLabelColor.getColorMap().get(cleanedValue); | ||
sharedColor; | ||
|
||
if (isFeatureEnabled(FeatureFlag.USE_ANALAGOUS_COLORS)) { | ||
const multiple = Math.floor( | ||
|
@@ -96,7 +98,22 @@ class CategoricalColorScale extends ExtensibleFunction { | |
const newColor = this.scale(cleanedValue); | ||
if (!color) { | ||
color = newColor; | ||
// make sure we don't overwrite the origin colors | ||
if (!isFeatureEnabled(FeatureFlag.USE_ANALAGOUS_COLORS)) { | ||
const updatedRange = [...this.originColors]; | ||
// remove the color option from shared color | ||
sharedColorMap.forEach((value, key) => { | ||
if (key !== cleanedValue) { | ||
const index = updatedRange.indexOf(value); | ||
updatedRange.splice(index, 1); | ||
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. It looks like this may be removing items from a list. Can you use the filter function here instead? |
||
} | ||
}); | ||
|
||
this.range(updatedRange.length > 0 ? updatedRange : this.originColors); | ||
color = this.scale(cleanedValue); | ||
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. Calling this again will move to the next color in the scale again unnecessarily |
||
} | ||
} | ||
|
||
sharedLabelColor.addSlice(cleanedValue, color, sliceId); | ||
|
||
return color; | ||
|
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.
This is moving the scale to the next color in order