@@ -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,9 @@ export const ChartColors = (props) => {
399412 return null
400413 }
401414
402- const csvColors = ( ) => {
415+ const csvColors = ( colorByParams ) => {
416+ console . log ( "color by params..." , colorByParams )
417+ console . log ( "csv colors..." , manualColors , colorBy )
403418 const data = Papa . parse ( csv , { header : true , dynamicTyping : true } ) ;
404419 const values = [ ] ;
405420
@@ -416,11 +431,12 @@ export const ChartColors = (props) => {
416431
417432 if ( manualColors [ app ] && values ) {
418433 return values . map ( v => {
419- // Get the current colorBy mode's color storage, creating it if needed
434+ // Get the current colorBy mode's color storage, falling back to flat structure for legacy data
420435 const colorByColors = manualColors [ app ] [ colorBy ] || { } ;
436+ const color = colorByColors [ v ] !== undefined ? colorByColors [ v ] : manualColors [ app ] [ v ] ;
421437 return < PanelColorSettings
422438 colorSettings = { [ {
423- value : colorByColors [ v ] ,
439+ value : color ,
424440
425441 onChange : ( color ) => {
426442 if ( color ) {
0 commit comments