@@ -157,7 +157,7 @@ export const ChartColors = (props) => {
157157
158158 useEffect ( ( ) => {
159159 let nextUseColors = useColors ;
160- if ( app != "csv" ) {
160+ if ( app !== "csv" ) {
161161 // All conditions for coloring by measures
162162 if ( ( dimension2 == "none" && colorBy === "index" && swap ) ||
163163 ( dimension1 == "none" && dimension2 == "none" ) ) { //Multi measure colored by first dimension but swapped (Colored by Measure) or dimensionless bar charts
@@ -198,13 +198,26 @@ export const ChartColors = (props) => {
198198
199199 const updateColor = ( value , color , colorByMode = null ) => {
200200
201- const newColors = Object . assign ( { } , manualColors )
201+ const newColors = {
202+ ...manualColors ,
203+ [ app ] : {
204+ ...manualColors [ app ] ,
205+ }
206+ }
202207 if ( colorByMode ) {
203- // For CSV colors, nest by colorBy mode
204- if ( ! newColors [ app ] [ colorByMode ] ) {
205- newColors [ app ] [ colorByMode ] = { }
208+ // For CSV colors, nest by colorBy mode.
209+ // If the key exists as a flat (legacy) entry, remove it to avoid duplicates.
210+ const appColors = newColors [ app ] ;
211+ const baseApp = typeof appColors [ value ] === "string"
212+ ? ( ( { [ value ] : _removed , ...rest } ) => rest ) ( appColors )
213+ : appColors ;
214+ newColors [ app ] = {
215+ ...baseApp ,
216+ [ colorByMode ] : {
217+ ...( baseApp [ colorByMode ] || { } ) ,
218+ [ value ] : color
219+ }
206220 }
207- newColors [ app ] [ colorByMode ] [ value ] = color
208221 } else {
209222 // For non-CSV colors, use flat structure
210223 newColors [ app ] [ value ] = color
@@ -399,7 +412,7 @@ export const ChartColors = (props) => {
399412 return null
400413 }
401414
402- const csvColors = ( ) => {
415+ const csvColors = ( ) => {
403416 const data = Papa . parse ( csv , { header : true , dynamicTyping : true } ) ;
404417 const values = [ ] ;
405418
@@ -416,11 +429,12 @@ export const ChartColors = (props) => {
416429
417430 if ( manualColors [ app ] && values ) {
418431 return values . map ( v => {
419- // Get the current colorBy mode's color storage, creating it if needed
432+ // Get the current colorBy mode's color storage, falling back to flat structure for legacy data
420433 const colorByColors = manualColors [ app ] [ colorBy ] || { } ;
434+ const color = colorByColors [ v ] !== undefined ? colorByColors [ v ] : manualColors [ app ] [ v ] ;
421435 return < PanelColorSettings
422436 colorSettings = { [ {
423- value : colorByColors [ v ] ,
437+ value : color ,
424438
425439 onChange : ( color ) => {
426440 if ( color ) {
@@ -517,7 +531,7 @@ export const ChartColors = (props) => {
517531 { /* CSV CHART*/ }
518532
519533 { app == "csv" && < PanelBody initialOpen = { false } title = { __ ( "Set Colors" ) } >
520- { csvColors ( colorBy ) }
534+ { csvColors ( ) }
521535 </ PanelBody > }
522536
523537
0 commit comments