@@ -41,6 +41,14 @@ const NeoBarChart = (props: ChartProps) => {
4141 const enableLabel = settings . barValues ? settings . barValues : false ;
4242 const positionLabel = settings . positionLabel ? settings . positionLabel : 'off' ;
4343
44+ // New value toggle related settings (primary vs alternate numeric field)
45+ const { alternateValueField } = settings ; // optional second numeric field name
46+ const valueFieldModeSetting = settings . valueFieldMode ? settings . valueFieldMode : 'primary' ;
47+ const [ localValueFieldMode ] = React . useState < string > ( valueFieldModeSetting ) ;
48+ const valueFieldMode = settings . valueFieldMode ? valueFieldModeSetting : localValueFieldMode ;
49+ const currentValueField =
50+ valueFieldMode === 'alternate' && alternateValueField ? alternateValueField : selection ?. value ;
51+
4452 // TODO: we should make all these defaults be loaded from the config file.
4553 const layout = settings . layout ? settings . layout : 'vertical' ;
4654 const colorScheme = settings . colors ? settings . colors : 'set2' ;
@@ -66,9 +74,10 @@ const NeoBarChart = (props: ChartProps) => {
6674 }
6775 const index = convertRecordObjectToString ( row . get ( selection . index ) ) ;
6876 const idx = data . findIndex ( ( item ) => item . index === index ) ;
69-
77+ // Keep key name stable even when toggling value field
7078 const key = selection . key !== '(none)' ? recordToNative ( row . get ( selection . key ) ) : selection . value ;
71- const rawValue = recordToNative ( row . get ( selection . value ) ) ;
79+ // Retrieve value from currentValueField (primary or alternate)
80+ const rawValue = recordToNative ( row . get ( currentValueField ) ) ;
7281 const value = rawValue !== null ? rawValue : 0.0000001 ;
7382 if ( isNaN ( value ) ) {
7483 return data ;
@@ -99,7 +108,7 @@ const NeoBarChart = (props: ChartProps) => {
99108 } ) ;
100109 setKeys ( Object . keys ( newKeys ) ) ;
101110 setData ( newData ) ;
102- } , [ selection ] ) ;
111+ } , [ selection , currentValueField , records ] ) ;
103112
104113 if ( ! selection || props . records == null || props . records . length == 0 || props . records [ 0 ] . keys == null ) {
105114 return < NoDrawableDataErrorMessage /> ;
@@ -176,8 +185,13 @@ const NeoBarChart = (props: ChartProps) => {
176185 return chartColorsByScheme [ colorIndex ] ;
177186 }
178187 dict [ selection . index ] = bar . indexValue ;
179- dict [ selection . value ] = bar . value ;
180- dict [ selection . key ] = bar . id ;
188+ // Populate current numeric field for styling rules
189+ if ( currentValueField ) {
190+ dict [ currentValueField ] = bar . value ;
191+ }
192+ if ( selection . key ) {
193+ dict [ selection . key ] = bar . id ;
194+ }
181195 const validRuleIndex = evaluateRulesOnDict ( dict , styleRules , [ 'bar color' ] ) ;
182196 if ( validRuleIndex !== - 1 ) {
183197 return styleRules [ validRuleIndex ] . customizationValue ;
@@ -387,7 +401,7 @@ const NeoBarChart = (props: ChartProps) => {
387401 < BarChartComponent
388402 theme = { canvas ? themeNivoCanvas ( props . theme ) : themeNivo }
389403 data = { data }
390- key = { `${ selection . index } ___${ selection . value } ` }
404+ key = { `${ selection . index } ___${ currentValueField } ` }
391405 layout = { layout }
392406 groupMode = { groupMode == 'stacked' ? 'stacked' : 'grouped' }
393407 enableLabel = { enableLabel }
0 commit comments