| 1 | function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|---|
| 2 | function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|---|
| 3 | function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|---|
| 4 | function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|---|
| 5 | function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|---|
| 6 | import { noInteraction } from '../../tooltipSlice';
|
|---|
| 7 | function chooseAppropriateMouseInteraction(tooltipState, tooltipEventType, trigger) {
|
|---|
| 8 | if (tooltipEventType === 'axis') {
|
|---|
| 9 | if (trigger === 'click') {
|
|---|
| 10 | return tooltipState.axisInteraction.click;
|
|---|
| 11 | }
|
|---|
| 12 | return tooltipState.axisInteraction.hover;
|
|---|
| 13 | }
|
|---|
| 14 | if (trigger === 'click') {
|
|---|
| 15 | return tooltipState.itemInteraction.click;
|
|---|
| 16 | }
|
|---|
| 17 | return tooltipState.itemInteraction.hover;
|
|---|
| 18 | }
|
|---|
| 19 | function hasBeenActivePreviously(tooltipInteractionState) {
|
|---|
| 20 | return tooltipInteractionState.index != null;
|
|---|
| 21 | }
|
|---|
| 22 | export var combineTooltipInteractionState = (tooltipState, tooltipEventType, trigger, defaultIndex) => {
|
|---|
| 23 | if (tooltipEventType == null) {
|
|---|
| 24 | return noInteraction;
|
|---|
| 25 | }
|
|---|
| 26 | var appropriateMouseInteraction = chooseAppropriateMouseInteraction(tooltipState, tooltipEventType, trigger);
|
|---|
| 27 | if (appropriateMouseInteraction == null) {
|
|---|
| 28 | return noInteraction;
|
|---|
| 29 | }
|
|---|
| 30 | if (appropriateMouseInteraction.active) {
|
|---|
| 31 | return appropriateMouseInteraction;
|
|---|
| 32 | }
|
|---|
| 33 | if (tooltipState.keyboardInteraction.active) {
|
|---|
| 34 | return tooltipState.keyboardInteraction;
|
|---|
| 35 | }
|
|---|
| 36 | if (tooltipState.syncInteraction.active && tooltipState.syncInteraction.index != null) {
|
|---|
| 37 | return tooltipState.syncInteraction;
|
|---|
| 38 | }
|
|---|
| 39 | var activeFromProps = tooltipState.settings.active === true;
|
|---|
| 40 | if (hasBeenActivePreviously(appropriateMouseInteraction)) {
|
|---|
| 41 | if (activeFromProps) {
|
|---|
| 42 | return _objectSpread(_objectSpread({}, appropriateMouseInteraction), {}, {
|
|---|
| 43 | active: true
|
|---|
| 44 | });
|
|---|
| 45 | }
|
|---|
| 46 | } else if (defaultIndex != null) {
|
|---|
| 47 | return {
|
|---|
| 48 | active: true,
|
|---|
| 49 | coordinate: undefined,
|
|---|
| 50 | dataKey: undefined,
|
|---|
| 51 | index: defaultIndex,
|
|---|
| 52 | graphicalItemId: undefined
|
|---|
| 53 | };
|
|---|
| 54 | }
|
|---|
| 55 | return _objectSpread(_objectSpread({}, noInteraction), {}, {
|
|---|
| 56 | coordinate: appropriateMouseInteraction.coordinate
|
|---|
| 57 | });
|
|---|
| 58 | }; |
|---|