laif-ds
Version:
Design System di Laif con componenti React basati su principi di Atomic Design
149 lines (148 loc) • 6.48 kB
JavaScript
"use client";
import { createSelector as i } from "../../../../reselect/dist/reselect.js";
import H from "../../../../../_virtual/sortBy.js";
import { useAppSelector as $ } from "../hooks.js";
import { getTooltipEntry as P, getValueByDataKey as v } from "../../util/ChartUtils.js";
import { findEntryInArray as q } from "../../util/DataUtils.js";
import { selectChartDataWithIndexes as z } from "./dataSelectors.js";
import { selectTooltipAxis as B, selectTooltipDisplayedData as G, selectTooltipAxisTicks as s } from "./tooltipSelectors.js";
import { selectChartName as J } from "./rootPropsSelectors.js";
import { selectChartLayout as M } from "../../context/chartLayoutContext.js";
import { selectChartOffset as Q } from "./selectChartOffset.js";
import { selectChartWidth as R, selectChartHeight as U } from "./containerSelectors.js";
import { combineActiveLabel as X } from "./combiners/combineActiveLabel.js";
import { combineTooltipInteractionState as Y } from "./combiners/combineTooltipInteractionState.js";
import { combineActiveTooltipIndex as Z } from "./combiners/combineActiveTooltipIndex.js";
import { combineCoordinateForDefaultIndex as V } from "./combiners/combineCoordinateForDefaultIndex.js";
import { combineTooltipPayloadConfigurations as ee } from "./combiners/combineTooltipPayloadConfigurations.js";
import { selectTooltipPayloadSearcher as S } from "./selectTooltipPayloadSearcher.js";
import { selectTooltipState as m } from "./selectTooltipState.js";
function K(e, t) {
var r = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var a = Object.getOwnPropertySymbols(e);
t && (a = a.filter(function(c) {
return Object.getOwnPropertyDescriptor(e, c).enumerable;
})), r.push.apply(r, a);
}
return r;
}
function D(e) {
for (var t = 1; t < arguments.length; t++) {
var r = arguments[t] != null ? arguments[t] : {};
t % 2 ? K(Object(r), !0).forEach(function(a) {
te(e, a, r[a]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : K(Object(r)).forEach(function(a) {
Object.defineProperty(e, a, Object.getOwnPropertyDescriptor(r, a));
});
}
return e;
}
function te(e, t, r) {
return (t = re(t)) in e ? Object.defineProperty(e, t, { value: r, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = r, e;
}
function re(e) {
var t = ae(e, "string");
return typeof t == "symbol" ? t : t + "";
}
function ae(e, t) {
if (typeof e != "object" || !e) return e;
var r = e[Symbol.toPrimitive];
if (r !== void 0) {
var a = r.call(e, t);
if (typeof a != "object") return a;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (t === "string" ? String : Number)(e);
}
var Ie = () => $(J), y = (e, t) => t, j = (e, t, r) => r, b = (e, t, r, a) => a;
function oe(e, t, r) {
return Array.isArray(e) && e && t + r !== 0 ? e.slice(t, r + 1) : e;
}
i(s, (e) => H(e, (t) => t.coordinate));
var h = i([m, y, j, b], Y), I = i([h, G], Z), Ce = (e, t, r) => {
if (t != null) {
var a = m(e);
return t === "axis" ? r === "hover" ? a.axisInteraction.hover.dataKey : a.axisInteraction.click.dataKey : r === "hover" ? a.itemInteraction.hover.dataKey : a.itemInteraction.click.dataKey;
}
}, C = i([m, y, j, b], ee), ie = i([R, U, M, Q, s, b, C, S], V), we = i([h, ie], (e, t) => {
var r;
return (r = e.coordinate) !== null && r !== void 0 ? r : t;
}), ne = i(s, I, X);
function le(e, t) {
return e ?? t;
}
var ce = (e, t, r, a, c, g, w) => {
if (!(t == null || g == null)) {
var {
chartData: E,
computedData: _,
dataStartIndex: A,
dataEndIndex: k
} = r, x = [];
return e.reduce((u, N) => {
var d, {
dataDefinedOnItem: F,
settings: o
} = N, L = le(F, E), f = oe(L, A, k), T = (d = o?.dataKey) !== null && d !== void 0 ? d : a?.dataKey, O = o?.nameKey, n;
if (a != null && a.dataKey && !(a != null && a.allowDuplicatedCategory) && Array.isArray(f) && /*
* If the tooltipEventType is 'axis', we should search for the dataKey in the sliced data
* because thanks to allowDuplicatedCategory=false, the order of elements in the array
* no longer matches the order of elements in the original data
* and so we need to search by the active dataKey + label rather than by index.
*
* On the other hand the tooltipEventType 'item' should always search by index
* because we get the index from interacting over the individual elements
* which is always accurate, irrespective of the allowDuplicatedCategory setting.
*/
w === "axis" ? n = q(f, a.dataKey, c) : n = g(f, t, _, O), Array.isArray(n))
n.forEach((l) => {
var W = D(D({}, o), {}, {
name: l.name,
unit: l.unit,
// color and fill are erased to keep 100% the identical behaviour to recharts 2.x - but there's nothing stopping us from returning them here. It's technically a breaking change.
color: void 0,
// color and fill are erased to keep 100% the identical behaviour to recharts 2.x - but there's nothing stopping us from returning them here. It's technically a breaking change.
fill: void 0
});
u.push(P({
tooltipEntrySettings: W,
dataKey: l.dataKey,
payload: l.payload,
// @ts-expect-error getValueByDataKey does not validate the output type
value: v(l.payload, l.dataKey),
name: l.name
}));
});
else {
var p;
u.push(P({
tooltipEntrySettings: o,
dataKey: T,
payload: n,
// @ts-expect-error getValueByDataKey does not validate the output type
value: v(n, T),
// @ts-expect-error getValueByDataKey does not validate the output type
name: (p = v(n, O)) !== null && p !== void 0 ? p : o?.name
}));
}
return u;
}, x);
}
}, Ee = i([C, I, z, B, ne, S, y], ce), _e = i([h], (e) => ({
isActive: e.active,
activeIndex: e.index
}));
export {
ce as combineTooltipPayload,
we as selectActiveCoordinate,
I as selectActiveIndex,
ne as selectActiveLabel,
ie as selectCoordinateForDefaultIndex,
_e as selectIsTooltipActive,
Ce as selectTooltipDataKey,
h as selectTooltipInteractionState,
Ee as selectTooltipPayload,
C as selectTooltipPayloadConfigurations,
Ie as useChartName
};