Skip to content

Commit ee0cb70

Browse files
committed
fix: supply datum to tooltip.formatSecondary arguments
1 parent 6d99763 commit ee0cb70

File tree

1 file changed

+39
-33
lines changed

1 file changed

+39
-33
lines changed

src/components/TooltipRenderer.tsx

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import React from 'react'
1+
import React from 'react';
22
//
33
//
44
import {
55
groupingSeries,
66
groupingPrimary,
77
groupingSecondary,
8-
} from '../utils/Constants'
8+
} from '../utils/Constants';
99

10-
const showCount = 10
10+
const showCount = 10;
1111

1212
function getSecondaryFormatter(datum, formatSecondary) {
1313
return (
1414
formatSecondary ||
1515
datum.secondaryAxis.format ||
1616
(val => (Math.floor(val) < val ? Math.round(val * 100) / 100 : val))
17-
)
17+
);
1818
}
1919

2020
export default function TooltipRenderer(props) {
@@ -28,69 +28,69 @@ export default function TooltipRenderer(props) {
2828
getStyle,
2929
dark,
3030
tooltip,
31-
} = props
31+
} = props;
3232

3333
if (!datum) {
34-
return null
34+
return null;
3535
}
3636

3737
const resolvedFormatTertiary =
3838
formatTertiary ||
39-
(val => (Math.floor(val) < val ? Math.round(val * 100) / 100 : val))
39+
(val => (Math.floor(val) < val ? Math.round(val * 100) / 100 : val));
4040

4141
const sortedGroupDatums = [...datum.group].sort((a, b) => {
4242
if (
4343
(!primaryAxis.stacked && grouping === groupingSeries) ||
4444
grouping === groupingSecondary
4545
) {
4646
if (a.primaryCoord > b.primaryCoord) {
47-
return -1
47+
return -1;
4848
} else if (a.primaryCoord < b.primaryCoord) {
49-
return 1
49+
return 1;
5050
}
5151
} else if (!secondaryAxis.stacked) {
5252
if (a.secondaryCoord > b.secondaryCoord) {
53-
return -1
53+
return -1;
5454
} else if (a.secondaryCoord < b.secondaryCoord) {
55-
return 1
55+
return 1;
5656
}
5757
}
58-
return a.seriesIndex > b.seriesIndex ? 1 : -1
59-
})
58+
return a.seriesIndex > b.seriesIndex ? 1 : -1;
59+
});
6060

6161
if (grouping === groupingPrimary) {
62-
sortedGroupDatums.reverse()
62+
sortedGroupDatums.reverse();
6363
}
6464

6565
if (secondaryAxis.invert) {
66-
sortedGroupDatums.reverse()
66+
sortedGroupDatums.reverse();
6767
}
6868

6969
if (tooltip.invert) {
70-
sortedGroupDatums.reverse()
70+
sortedGroupDatums.reverse();
7171
}
7272

73-
const resolvedShowCount = showCount % 2 === 0 ? showCount : showCount + 1
74-
const length = sortedGroupDatums.length
73+
const resolvedShowCount = showCount % 2 === 0 ? showCount : showCount + 1;
74+
const length = sortedGroupDatums.length;
7575

7676
// Get the focused series' index
77-
const activeIndex = sortedGroupDatums.findIndex(d => d === datum)
77+
const activeIndex = sortedGroupDatums.findIndex(d => d === datum);
7878
// Get the start by going back half of the showCount
79-
let start = activeIndex > -1 ? activeIndex - resolvedShowCount / 2 : 0
79+
let start = activeIndex > -1 ? activeIndex - resolvedShowCount / 2 : 0;
8080
// Make sure it's at least 0
81-
start = Math.max(start, 0)
81+
start = Math.max(start, 0);
8282
// Use the start and add the showCount to get the end
83-
let end = activeIndex > -1 ? start + resolvedShowCount : length
83+
let end = activeIndex > -1 ? start + resolvedShowCount : length;
8484
// Don't let the end go passed the length
85-
end = Math.min(end, length)
85+
end = Math.min(end, length);
8686
// Double check we aren't clipping the start
87-
start = Math.max(end - resolvedShowCount, 0)
87+
start = Math.max(end - resolvedShowCount, 0);
8888
// Slice the datums by start and end
89-
const visibleSortedGroupDatums = sortedGroupDatums.slice(start, end)
89+
const visibleSortedGroupDatums = sortedGroupDatums.slice(start, end);
9090
// Detect if we have previous items
91-
const hasPrevious = start > 0
91+
const hasPrevious = start > 0;
9292
// Or next items
93-
const hasNext = end < length
93+
const hasNext = end < length;
9494

9595
return (
9696
<div>
@@ -126,11 +126,11 @@ export default function TooltipRenderer(props) {
126126
</tr>
127127
) : null}
128128
{visibleSortedGroupDatums.map((sortedDatum, i) => {
129-
const active = sortedDatum === datum
129+
const active = sortedDatum === datum;
130130
const resolvedSecondaryFormat = getSecondaryFormatter(
131131
sortedDatum,
132132
formatSecondary
133-
)
133+
);
134134

135135
return (
136136
<tr
@@ -169,7 +169,10 @@ export default function TooltipRenderer(props) {
169169
textAlign: 'right',
170170
}}
171171
>
172-
{resolvedSecondaryFormat(sortedDatum.secondary)}
172+
{resolvedSecondaryFormat(
173+
sortedDatum.secondary,
174+
sortedDatum
175+
)}
173176
{sortedDatum.r
174177
? ` (${resolvedFormatTertiary(sortedDatum.r)})`
175178
: null}
@@ -197,15 +200,18 @@ export default function TooltipRenderer(props) {
197200
textAlign: 'right',
198201
}}
199202
>
200-
{resolvedSecondaryFormat(sortedDatum.secondary)}
203+
{resolvedSecondaryFormat(
204+
sortedDatum.secondary,
205+
sortedDatum
206+
)}
201207
{sortedDatum.r
202208
? ` (${resolvedFormatTertiary(sortedDatum.r)})`
203209
: null}
204210
</td>
205211
</React.Fragment>
206212
)}
207213
</tr>
208-
)
214+
);
209215
})}
210216
{hasNext ? (
211217
<tr
@@ -255,5 +261,5 @@ export default function TooltipRenderer(props) {
255261
</tbody>
256262
</table>
257263
</div>
258-
)
264+
);
259265
}

0 commit comments

Comments
 (0)