| 1 | export var combineTooltipPayloadConfigurations = (tooltipState, tooltipEventType, trigger, defaultIndex) => {
|
|---|
| 2 | // if tooltip reacts to axis interaction, then we display all items at the same time.
|
|---|
| 3 | if (tooltipEventType === 'axis') {
|
|---|
| 4 | return tooltipState.tooltipItemPayloads;
|
|---|
| 5 | }
|
|---|
| 6 | /*
|
|---|
| 7 | * By now we already know that tooltipEventType is 'item', so we can only search in itemInteractions.
|
|---|
| 8 | * item means that only the hovered or clicked item will be present in the tooltip.
|
|---|
| 9 | */
|
|---|
| 10 | if (tooltipState.tooltipItemPayloads.length === 0) {
|
|---|
| 11 | // No point filtering if the payload is empty
|
|---|
| 12 | return [];
|
|---|
| 13 | }
|
|---|
| 14 | var filterByGraphicalItemId;
|
|---|
| 15 | if (trigger === 'hover') {
|
|---|
| 16 | filterByGraphicalItemId = tooltipState.itemInteraction.hover.graphicalItemId;
|
|---|
| 17 | } else {
|
|---|
| 18 | filterByGraphicalItemId = tooltipState.itemInteraction.click.graphicalItemId;
|
|---|
| 19 | }
|
|---|
| 20 | if (filterByGraphicalItemId == null && defaultIndex != null) {
|
|---|
| 21 | /*
|
|---|
| 22 | * So when we use `defaultIndex` - we don't have a dataKey to filter by because user did not hover over anything yet.
|
|---|
| 23 | * In that case let's display the first item in the tooltip; after all, this is `item` interaction case,
|
|---|
| 24 | * so we should display only one item at a time instead of all.
|
|---|
| 25 | */
|
|---|
| 26 | var firstItemPayload = tooltipState.tooltipItemPayloads[0];
|
|---|
| 27 | if (firstItemPayload != null) {
|
|---|
| 28 | return [firstItemPayload];
|
|---|
| 29 | }
|
|---|
| 30 | return [];
|
|---|
| 31 | }
|
|---|
| 32 | return tooltipState.tooltipItemPayloads.filter(tpc => {
|
|---|
| 33 | var _tpc$settings;
|
|---|
| 34 | return ((_tpc$settings = tpc.settings) === null || _tpc$settings === void 0 ? void 0 : _tpc$settings.graphicalItemId) === filterByGraphicalItemId;
|
|---|
| 35 | });
|
|---|
| 36 | }; |
|---|