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