| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.useChartName = exports.selectTooltipPayloadConfigurations = exports.selectTooltipPayload = exports.selectTooltipInteractionState = exports.selectTooltipDataKey = exports.selectOrderedTooltipTicks = exports.selectIsTooltipActive = exports.selectCoordinateForDefaultIndex = exports.selectActiveLabel = exports.selectActiveIndex = exports.selectActiveCoordinate = exports.combineActiveProps = void 0;
|
|---|
| 7 | var _reselect = require("reselect");
|
|---|
| 8 | var _sortBy = _interopRequireDefault(require("es-toolkit/compat/sortBy"));
|
|---|
| 9 | var _hooks = require("../hooks");
|
|---|
| 10 | var _ChartUtils = require("../../util/ChartUtils");
|
|---|
| 11 | var _dataSelectors = require("./dataSelectors");
|
|---|
| 12 | var _tooltipSelectors = require("./tooltipSelectors");
|
|---|
| 13 | var _axisSelectors = require("./axisSelectors");
|
|---|
| 14 | var _rootPropsSelectors = require("./rootPropsSelectors");
|
|---|
| 15 | var _chartLayoutContext = require("../../context/chartLayoutContext");
|
|---|
| 16 | var _selectChartOffsetInternal = require("./selectChartOffsetInternal");
|
|---|
| 17 | var _containerSelectors = require("./containerSelectors");
|
|---|
| 18 | var _combineActiveLabel = require("./combiners/combineActiveLabel");
|
|---|
| 19 | var _combineTooltipInteractionState = require("./combiners/combineTooltipInteractionState");
|
|---|
| 20 | var _combineActiveTooltipIndex = require("./combiners/combineActiveTooltipIndex");
|
|---|
| 21 | var _combineCoordinateForDefaultIndex = require("./combiners/combineCoordinateForDefaultIndex");
|
|---|
| 22 | var _combineTooltipPayloadConfigurations = require("./combiners/combineTooltipPayloadConfigurations");
|
|---|
| 23 | var _selectTooltipPayloadSearcher = require("./selectTooltipPayloadSearcher");
|
|---|
| 24 | var _selectTooltipState = require("./selectTooltipState");
|
|---|
| 25 | var _combineTooltipPayload = require("./combiners/combineTooltipPayload");
|
|---|
| 26 | var _getActiveCoordinate = require("../../util/getActiveCoordinate");
|
|---|
| 27 | var _PolarUtils = require("../../util/PolarUtils");
|
|---|
| 28 | function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|---|
| 29 | var useChartName = () => {
|
|---|
| 30 | return (0, _hooks.useAppSelector)(_rootPropsSelectors.selectChartName);
|
|---|
| 31 | };
|
|---|
| 32 | exports.useChartName = useChartName;
|
|---|
| 33 | var pickTooltipEventType = (_state, tooltipEventType) => tooltipEventType;
|
|---|
| 34 | var pickTrigger = (_state, _tooltipEventType, trigger) => trigger;
|
|---|
| 35 | var pickDefaultIndex = (_state, _tooltipEventType, _trigger, defaultIndex) => defaultIndex;
|
|---|
| 36 | var selectOrderedTooltipTicks = exports.selectOrderedTooltipTicks = (0, _reselect.createSelector)(_tooltipSelectors.selectTooltipAxisTicks, ticks => (0, _sortBy.default)(ticks, o => o.coordinate));
|
|---|
| 37 | var selectTooltipInteractionState = exports.selectTooltipInteractionState = (0, _reselect.createSelector)([_selectTooltipState.selectTooltipState, pickTooltipEventType, pickTrigger, pickDefaultIndex], _combineTooltipInteractionState.combineTooltipInteractionState);
|
|---|
| 38 | var selectActiveIndex = exports.selectActiveIndex = (0, _reselect.createSelector)([selectTooltipInteractionState, _tooltipSelectors.selectTooltipDisplayedData, _axisSelectors.selectTooltipAxisDataKey, _tooltipSelectors.selectTooltipAxisDomain], _combineActiveTooltipIndex.combineActiveTooltipIndex);
|
|---|
| 39 | var selectTooltipDataKey = (state, tooltipEventType, trigger) => {
|
|---|
| 40 | if (tooltipEventType == null) {
|
|---|
| 41 | return undefined;
|
|---|
| 42 | }
|
|---|
| 43 | var tooltipState = (0, _selectTooltipState.selectTooltipState)(state);
|
|---|
| 44 | if (tooltipEventType === 'axis') {
|
|---|
| 45 | if (trigger === 'hover') {
|
|---|
| 46 | return tooltipState.axisInteraction.hover.dataKey;
|
|---|
| 47 | }
|
|---|
| 48 | return tooltipState.axisInteraction.click.dataKey;
|
|---|
| 49 | }
|
|---|
| 50 | if (trigger === 'hover') {
|
|---|
| 51 | return tooltipState.itemInteraction.hover.dataKey;
|
|---|
| 52 | }
|
|---|
| 53 | return tooltipState.itemInteraction.click.dataKey;
|
|---|
| 54 | };
|
|---|
| 55 | exports.selectTooltipDataKey = selectTooltipDataKey;
|
|---|
| 56 | var selectTooltipPayloadConfigurations = exports.selectTooltipPayloadConfigurations = (0, _reselect.createSelector)([_selectTooltipState.selectTooltipState, pickTooltipEventType, pickTrigger, pickDefaultIndex], _combineTooltipPayloadConfigurations.combineTooltipPayloadConfigurations);
|
|---|
| 57 | var selectCoordinateForDefaultIndex = exports.selectCoordinateForDefaultIndex = (0, _reselect.createSelector)([_containerSelectors.selectChartWidth, _containerSelectors.selectChartHeight, _chartLayoutContext.selectChartLayout, _selectChartOffsetInternal.selectChartOffsetInternal, _tooltipSelectors.selectTooltipAxisTicks, pickDefaultIndex, selectTooltipPayloadConfigurations], _combineCoordinateForDefaultIndex.combineCoordinateForDefaultIndex);
|
|---|
| 58 | var selectActiveCoordinate = exports.selectActiveCoordinate = (0, _reselect.createSelector)([selectTooltipInteractionState, selectCoordinateForDefaultIndex], (tooltipInteractionState, defaultIndexCoordinate) => {
|
|---|
| 59 | var _tooltipInteractionSt;
|
|---|
| 60 | return (_tooltipInteractionSt = tooltipInteractionState.coordinate) !== null && _tooltipInteractionSt !== void 0 ? _tooltipInteractionSt : defaultIndexCoordinate;
|
|---|
| 61 | });
|
|---|
| 62 | var selectActiveLabel = exports.selectActiveLabel = (0, _reselect.createSelector)([_tooltipSelectors.selectTooltipAxisTicks, selectActiveIndex], _combineActiveLabel.combineActiveLabel);
|
|---|
| 63 | var selectTooltipPayload = exports.selectTooltipPayload = (0, _reselect.createSelector)([selectTooltipPayloadConfigurations, selectActiveIndex, _dataSelectors.selectChartDataWithIndexes, _axisSelectors.selectTooltipAxisDataKey, selectActiveLabel, _selectTooltipPayloadSearcher.selectTooltipPayloadSearcher, pickTooltipEventType], _combineTooltipPayload.combineTooltipPayload);
|
|---|
| 64 | var selectIsTooltipActive = exports.selectIsTooltipActive = (0, _reselect.createSelector)([selectTooltipInteractionState, selectActiveIndex], (tooltipInteractionState, activeIndex) => {
|
|---|
| 65 | return {
|
|---|
| 66 | isActive: tooltipInteractionState.active && activeIndex != null,
|
|---|
| 67 | activeIndex
|
|---|
| 68 | };
|
|---|
| 69 | });
|
|---|
| 70 | var combineActiveCartesianProps = (chartEvent, layout, tooltipAxisType, tooltipAxisRange, tooltipTicks, orderedTooltipTicks, offset) => {
|
|---|
| 71 | if (!chartEvent || !tooltipAxisType || !tooltipAxisRange || !tooltipTicks) {
|
|---|
| 72 | return undefined;
|
|---|
| 73 | }
|
|---|
| 74 | if (!(0, _getActiveCoordinate.isInCartesianRange)(chartEvent, offset)) {
|
|---|
| 75 | return undefined;
|
|---|
| 76 | }
|
|---|
| 77 | var pos = (0, _ChartUtils.calculateCartesianTooltipPos)(chartEvent, layout);
|
|---|
| 78 | var activeIndex = (0, _getActiveCoordinate.calculateActiveTickIndex)(pos, orderedTooltipTicks, tooltipTicks, tooltipAxisType, tooltipAxisRange);
|
|---|
| 79 | var activeCoordinate = (0, _getActiveCoordinate.getActiveCartesianCoordinate)(layout, tooltipTicks, activeIndex, chartEvent);
|
|---|
| 80 | return {
|
|---|
| 81 | activeIndex: String(activeIndex),
|
|---|
| 82 | activeCoordinate
|
|---|
| 83 | };
|
|---|
| 84 | };
|
|---|
| 85 | var combineActivePolarProps = (chartEvent, layout, polarViewBox, tooltipAxisType, tooltipAxisRange, tooltipTicks, orderedTooltipTicks) => {
|
|---|
| 86 | if (!chartEvent || !tooltipAxisType || !tooltipAxisRange || !tooltipTicks || !polarViewBox) {
|
|---|
| 87 | return undefined;
|
|---|
| 88 | }
|
|---|
| 89 | var rangeObj = (0, _PolarUtils.inRangeOfSector)(chartEvent, polarViewBox);
|
|---|
| 90 | if (!rangeObj) {
|
|---|
| 91 | return undefined;
|
|---|
| 92 | }
|
|---|
| 93 | var pos = (0, _ChartUtils.calculatePolarTooltipPos)(rangeObj, layout);
|
|---|
| 94 | var activeIndex = (0, _getActiveCoordinate.calculateActiveTickIndex)(pos, orderedTooltipTicks, tooltipTicks, tooltipAxisType, tooltipAxisRange);
|
|---|
| 95 | var activeCoordinate = (0, _getActiveCoordinate.getActivePolarCoordinate)(layout, tooltipTicks, activeIndex, rangeObj);
|
|---|
| 96 | return {
|
|---|
| 97 | activeIndex: String(activeIndex),
|
|---|
| 98 | activeCoordinate
|
|---|
| 99 | };
|
|---|
| 100 | };
|
|---|
| 101 | var combineActiveProps = (chartEvent, layout, polarViewBox, tooltipAxisType, tooltipAxisRange, tooltipTicks, orderedTooltipTicks, offset) => {
|
|---|
| 102 | if (!chartEvent || !layout || !tooltipAxisType || !tooltipAxisRange || !tooltipTicks) {
|
|---|
| 103 | return undefined;
|
|---|
| 104 | }
|
|---|
| 105 | if (layout === 'horizontal' || layout === 'vertical') {
|
|---|
| 106 | return combineActiveCartesianProps(chartEvent, layout, tooltipAxisType, tooltipAxisRange, tooltipTicks, orderedTooltipTicks, offset);
|
|---|
| 107 | }
|
|---|
| 108 | return combineActivePolarProps(chartEvent, layout, polarViewBox, tooltipAxisType, tooltipAxisRange, tooltipTicks, orderedTooltipTicks);
|
|---|
| 109 | };
|
|---|
| 110 | exports.combineActiveProps = combineActiveProps; |
|---|