UNPKG

recharts

Version:
52 lines (51 loc) 2.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.combineTooltipPayloadConfigurations = void 0; var combineTooltipPayloadConfigurations = (tooltipState, tooltipEventType, trigger, defaultIndex) => { // if tooltip reacts to axis interaction, then we display all items at the same time. if (tooltipEventType === 'axis') { return tooltipState.tooltipItemPayloads; } /* * By now we already know that tooltipEventType is 'item', so we can only search in itemInteractions. * item means that only the hovered or clicked item will be present in the tooltip. */ if (tooltipState.tooltipItemPayloads.length === 0) { // No point filtering if the payload is empty return []; } var filterByGraphicalItemId; if (trigger === 'hover') { filterByGraphicalItemId = tooltipState.itemInteraction.hover.graphicalItemId; } else { filterByGraphicalItemId = tooltipState.itemInteraction.click.graphicalItemId; } if (tooltipState.syncInteraction.active && filterByGraphicalItemId == null) { /* * When a tooltip is synchronised from another chart, the local itemInteraction * has no graphicalItemId because the user hasn't hovered over this chart. * In that case we show all tooltip items so the receiving chart can display * its own data at the synced index — matching the behaviour of axis-type tooltips. */ return tooltipState.tooltipItemPayloads; } if (filterByGraphicalItemId == null && (defaultIndex != null || tooltipState.keyboardInteraction.active)) { /* * So when we use `defaultIndex` - we don't have a dataKey to filter by because user did not hover over anything yet. * In that case let's display the first item in the tooltip; after all, this is `item` interaction case, * so we should display only one item at a time instead of all. */ var firstItemPayload = tooltipState.tooltipItemPayloads[0]; if (firstItemPayload != null) { return [firstItemPayload]; } return []; } return tooltipState.tooltipItemPayloads.filter(tpc => { var _tpc$settings; return ((_tpc$settings = tpc.settings) === null || _tpc$settings === void 0 ? void 0 : _tpc$settings.graphicalItemId) === filterByGraphicalItemId; }); }; exports.combineTooltipPayloadConfigurations = combineTooltipPayloadConfigurations;