Skip to content

Commit 3434ea8

Browse files
feat: make value bold and formatted
1 parent 83797f6 commit 3434ea8

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

src/chart/bar/BarChart.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { convertRecordObjectToString, recordToNative } from '../ChartUtils';
88
import { themeNivo, themeNivoCanvas } from '../Utils';
99
import { extensionEnabled } from '../../utils/ReportUtils';
1010
import { getPageNumbersAndNamesList, getRule, performActionOnElement } from '../../extensions/advancedcharts/Utils';
11-
import { getOriginalRecordForNivoClickEvent, getRecordByCategory } from './util';
11+
import { formatToolTipValue, getOriginalRecordForNivoClickEvent, getRecordByCategory } from './util';
1212
import { BarChartTooltip } from './BarChartTooltip';
1313

1414
const NeoBarChart = (props: ChartProps) => {
@@ -42,7 +42,7 @@ const NeoBarChart = (props: ChartProps) => {
4242
const enableLabel = settings.barValues ? settings.barValues : false;
4343
const positionLabel = settings.positionLabel ? settings.positionLabel : 'off';
4444
// New configurable tooltip property (name of field to show on hover instead of default value)
45-
const {tooltipField} = settings;
45+
const { tooltipField } = settings;
4646

4747
// New value toggle related settings (primary vs alternate numeric field)
4848
const { alternateValueField } = settings; // optional second numeric field name
@@ -415,17 +415,22 @@ const NeoBarChart = (props: ChartProps) => {
415415
// Find the original record by matching category and group (not value, since value changes with toggle)
416416
const record = getRecordByCategory(bar, records, selection, bar);
417417
// Priority1: Display tooltipField value if available, otherwise fall back to bar.value
418-
let content = `${bar.id} - ${bar.indexValue}: ${bar.value}`;
418+
// Format bar.value if it's an array
419+
let content = `${bar.id} - ${bar.indexValue}: <strong>${formatToolTipValue(bar.value)}</strong>`;
419420
if (tooltipField && record && record[tooltipField] !== undefined) {
420-
content = `${tooltipField}: ${record[tooltipField]}`;
421+
content = `${tooltipField}: <strong>${formatToolTipValue(record[tooltipField])}</strong>`;
421422
} else if (record) {
422423
// Priority 2: Show field based on current mode (alternate or primary)
423424
if (valueFieldMode === 'alternate' && alternateValueField && record[alternateValueField] !== undefined) {
424425
// Alternate mode: show alternate field
425-
content = `${alternateValueField} - ${bar.indexValue}: ${record[alternateValueField]}`;
426+
content = `${alternateValueField} - ${bar.indexValue}: <strong>${formatToolTipValue(
427+
record[alternateValueField]
428+
)}</strong>`;
426429
} else if (selection?.value && record[selection.value] !== undefined) {
427430
// Primary mode: show primary field
428-
content = `${selection.value} - ${bar.indexValue}: ${record[selection.value]}`;
431+
content = `${selection.value} - ${bar.indexValue}: <strong>${formatToolTipValue(
432+
record[selection.value]
433+
)}</strong>`;
429434
}
430435
}
431436
const isDarkMode = props.theme === 'dark';

src/chart/bar/BarChartTooltip.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const BarChartTooltip = ({ content, isDarkMode, barColor }) => {
4444
return (
4545
<div style={tooltipStyle}>
4646
<span style={colorBoxStyle} />
47-
<span>{content}</span>
47+
<span dangerouslySetInnerHTML={{ __html: content }} />
4848
</div>
4949
);
5050
};

src/chart/bar/util.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,27 @@ export function getRecordByCategory(e, records, selection, bar) {
7878
break;
7979
}
8080
} else if (recordCategory == category) {
81-
// Build dictionary of all fields from this record
82-
const dict: Record<string, any> = {};
83-
r.keys.forEach((key) => {
84-
if (typeof key === 'string') {
85-
dict[key] = recordToNative(r.get(key));
86-
}
87-
});
88-
record = dict;
89-
break;
90-
}
81+
// Build dictionary of all fields from this record
82+
const dict: Record<string, any> = {};
83+
r.keys.forEach((key) => {
84+
if (typeof key === 'string') {
85+
dict[key] = recordToNative(r.get(key));
86+
}
87+
});
88+
record = dict;
89+
break;
90+
}
9191
} catch (e) {
9292
// Skip records that don't have required fields
9393
continue;
9494
}
9595
}
9696
return record;
9797
}
98+
99+
export const formatToolTipValue = (value: any): string => {
100+
if (Array.isArray(value)) {
101+
return value.join(', ');
102+
}
103+
return String(value);
104+
};

0 commit comments

Comments
 (0)