@@ -8,7 +8,8 @@ import { convertRecordObjectToString, recordToNative } from '../ChartUtils';
88import { themeNivo , themeNivoCanvas } from '../Utils' ;
99import { extensionEnabled } from '../../utils/ReportUtils' ;
1010import { getPageNumbersAndNamesList , getRule , performActionOnElement } from '../../extensions/advancedcharts/Utils' ;
11- import { getOriginalRecordForNivoClickEvent } from './util' ;
11+ import { formatToolTipValue , getOriginalRecordForNivoClickEvent , getRecordByCategory } from './util' ;
12+ import { BarChartTooltip } from './BarChartTooltip' ;
1213
1314const NeoBarChart = ( props : ChartProps ) => {
1415 const { records, selection } = props ;
@@ -40,6 +41,8 @@ const NeoBarChart = (props: ChartProps) => {
4041 const labelSkipHeight = settings . labelSkipHeight ? settings . labelSkipHeight : 0 ;
4142 const enableLabel = settings . barValues ? settings . barValues : false ;
4243 const positionLabel = settings . positionLabel ? settings . positionLabel : 'off' ;
44+ // New configurable tooltip property (name of field to show on hover instead of default value)
45+ const { tooltipField } = settings ;
4346
4447 // New value toggle related settings (primary vs alternate numeric field)
4548 const { alternateValueField } = settings ; // optional second numeric field name
@@ -395,6 +398,46 @@ const NeoBarChart = (props: ChartProps) => {
395398 overflowY : 'auto' ,
396399 } ;
397400
401+ const handleToolTipRendering =
402+ settings . tooltipField || settings . alternateValueField
403+ ? (
404+ bar : {
405+ id : string | number ;
406+ value : number ;
407+ formattedValue : string ;
408+ index : number ;
409+ indexValue : string | number ;
410+ data : object ;
411+ } ,
412+ _color : string ,
413+ _label : string
414+ ) => {
415+ // Find the original record by matching category and group (not value, since value changes with toggle)
416+ const record = getRecordByCategory ( bar , records , selection , bar ) ;
417+ // Priority1: Display tooltipField value if available, otherwise fall back to bar.value
418+ // Format bar.value if it's an array
419+ let content = `${ bar . id } - ${ bar . indexValue } : <strong>${ formatToolTipValue ( bar . value ) } </strong>` ;
420+ if ( tooltipField && record && record [ tooltipField ] !== undefined ) {
421+ content = `${ tooltipField } : <strong>${ formatToolTipValue ( record [ tooltipField ] ) } </strong>` ;
422+ } else if ( record ) {
423+ // Priority 2: Show field based on current mode (alternate or primary)
424+ if ( valueFieldMode === 'alternate' && alternateValueField && record [ alternateValueField ] !== undefined ) {
425+ // Alternate mode: show alternate field
426+ content = `${ alternateValueField } - ${ bar . indexValue } : <strong>${ formatToolTipValue (
427+ record [ alternateValueField ]
428+ ) } </strong>`;
429+ } else if ( selection ?. value && record [ selection . value ] !== undefined ) {
430+ // Primary mode: show primary field
431+ content = `${ selection . value } - ${ bar . indexValue } : <strong>${ formatToolTipValue (
432+ record [ selection . value ]
433+ ) } </strong>`;
434+ }
435+ }
436+ const isDarkMode = props . theme === 'dark' ;
437+ return < BarChartTooltip content = { content } isDarkMode = { isDarkMode } barColor = { bar . color } /> ;
438+ }
439+ : undefined ;
440+
398441 const chart = (
399442 < div style = { barChartStyle } >
400443 < div style = { scrollableWrapperStyle } >
@@ -427,6 +470,7 @@ const NeoBarChart = (props: ChartProps) => {
427470 tickPadding : 5 ,
428471 tickRotation : 0 ,
429472 } }
473+ tooltip = { handleToolTipRendering }
430474 labelSkipWidth = { labelSkipWidth }
431475 labelSkipHeight = { labelSkipHeight }
432476 labelTextColor = { { from : 'color' , modifiers : [ [ 'darker' , 1.6 ] ] } }
0 commit comments