datajunction-ui
Version:
DataJunction UI
679 lines (678 loc) • 17.7 kB
JavaScript
import * as s from "react";
import { isValidElement as Ie, cloneElement as Ee, PureComponent as Oe, useMemo as De, Component as Se, useRef as R, useState as we, useCallback as U, forwardRef as Le } from "react";
import { az as V, aq as J, aI as O, cG as je, cq as B, bH as Ce, bF as ke, aK as Ne, bi as k, y as G, aE as $, bR as ee, bQ as Ke, bL as te, bY as ae, bZ as Te, be as _e, aR as Y, a6 as Re, a$ as re, bC as Be, cE as We, cs as ze, cA as Ve, G as Ge, bf as ne, b1 as ie, aU as H, c as $e, bc as L, h as Fe, ck as Me, ax as qe } from "./index-n79cxNwC.js";
import { b as Ue, e as Ye, g as He, G as Xe, d as Qe, S as Ze, u as Je, L as et, C as tt } from "./BarChart-JyKNSAsC.js";
function W() {
return W = Object.assign ? Object.assign.bind() : function(e) {
for (var t = 1; t < arguments.length; t++) {
var a = arguments[t];
for (var r in a) ({}).hasOwnProperty.call(a, r) && (e[r] = a[r]);
}
return e;
}, W.apply(null, arguments);
}
var oe = (e) => {
var {
cx: t,
cy: a,
r,
className: n
} = e, i = V("recharts-dot", n);
return t === +t && a === +a && r === +r ? /* @__PURE__ */ s.createElement("circle", W({}, O(e, !1), J(e), {
className: i,
cx: t,
cy: a,
r
})) : null;
};
function X(e, t) {
var a = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var r = Object.getOwnPropertySymbols(e);
t && (r = r.filter(function(n) {
return Object.getOwnPropertyDescriptor(e, n).enumerable;
})), a.push.apply(a, r);
}
return a;
}
function Q(e) {
for (var t = 1; t < arguments.length; t++) {
var a = arguments[t] != null ? arguments[t] : {};
t % 2 ? X(Object(a), !0).forEach(function(r) {
at(e, r, a[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(a)) : X(Object(a)).forEach(function(r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(a, r));
});
}
return e;
}
function at(e, t, a) {
return (t = rt(t)) in e ? Object.defineProperty(e, t, { value: a, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = a, e;
}
function rt(e) {
var t = nt(e, "string");
return typeof t == "symbol" ? t : t + "";
}
function nt(e, t) {
if (typeof e != "object" || !e) return e;
var a = e[Symbol.toPrimitive];
if (a !== void 0) {
var r = a.call(e, t);
if (typeof r != "object") return r;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (t === "string" ? String : Number)(e);
}
var it = (e) => {
var {
point: t,
childIndex: a,
mainColor: r,
activeDot: n,
dataKey: i
} = e;
if (n === !1 || t.x == null || t.y == null)
return null;
var o = Q(Q({
index: a,
dataKey: i,
cx: t.x,
cy: t.y,
r: 4,
fill: r ?? "none",
strokeWidth: 2,
stroke: "#fff",
payload: t.payload,
value: t.value
}, O(n, !1)), J(n)), l;
return /* @__PURE__ */ Ie(n) ? l = /* @__PURE__ */ Ee(n, o) : typeof n == "function" ? l = n(o) : l = /* @__PURE__ */ s.createElement(oe, o), /* @__PURE__ */ s.createElement(G, {
className: "recharts-active-dot"
}, l);
};
function ot(e) {
var {
points: t,
mainColor: a,
activeDot: r,
itemDataKey: n
} = e, i = je(), o = B(Ce), l = B(ke);
if (!o)
return null;
var c, u = i.dataKey;
if (u && !i.allowDuplicatedCategory) {
var f = typeof u == "function" ? (d) => u(d.payload) : "payload.".concat(u);
c = Ne(t, f, l);
} else
c = t == null ? void 0 : t[Number(o)];
return k(c) ? null : it({
point: c,
childIndex: Number(o),
mainColor: a,
dataKey: n,
activeDot: r
});
}
var se = (e, t, a, r) => te(e, "xAxis", t, r), le = (e, t, a, r) => ae(e, "xAxis", t, r), ce = (e, t, a, r) => te(e, "yAxis", a, r), ue = (e, t, a, r) => ae(e, "yAxis", a, r), st = $([ee, se, ce, le, ue], (e, t, a, r, n) => _e(e, "xAxis") ? Y(t, r, !1) : Y(a, n, !1)), lt = (e, t, a, r, n) => n, ct = $([Te, lt], (e, t) => {
if (e.some((a) => a.type === "line" && t.dataKey === a.dataKey && t.data === a.data))
return t;
}), ut = $([ee, se, ce, le, ue, ct, st, Ke], (e, t, a, r, n, i, o, l) => {
var {
chartData: c,
dataStartIndex: u,
dataEndIndex: f
} = l;
if (!(i == null || t == null || a == null || r == null || n == null || r.length === 0 || n.length === 0 || o == null)) {
var {
dataKey: d,
data: p
} = i, v;
if (p != null && p.length > 0 ? v = p : v = c == null ? void 0 : c.slice(u, f + 1), v != null)
return Lt({
layout: e,
xAxis: t,
yAxis: a,
xAxisTicks: r,
yAxisTicks: n,
dataKey: d,
bandSize: o,
displayedData: v
});
}
}), dt = ["type", "layout", "connectNulls", "needClip"], pt = ["activeDot", "animateNewValues", "animationBegin", "animationDuration", "animationEasing", "connectNulls", "dot", "hide", "isAnimationActive", "label", "legendType", "xAxisId", "yAxisId"];
function de(e, t) {
if (e == null) return {};
var a, r, n = ft(e, t);
if (Object.getOwnPropertySymbols) {
var i = Object.getOwnPropertySymbols(e);
for (r = 0; r < i.length; r++) a = i[r], t.indexOf(a) === -1 && {}.propertyIsEnumerable.call(e, a) && (n[a] = e[a]);
}
return n;
}
function ft(e, t) {
if (e == null) return {};
var a = {};
for (var r in e) if ({}.hasOwnProperty.call(e, r)) {
if (t.indexOf(r) !== -1) continue;
a[r] = e[r];
}
return a;
}
function Z(e, t) {
var a = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var r = Object.getOwnPropertySymbols(e);
t && (r = r.filter(function(n) {
return Object.getOwnPropertyDescriptor(e, n).enumerable;
})), a.push.apply(a, r);
}
return a;
}
function y(e) {
for (var t = 1; t < arguments.length; t++) {
var a = arguments[t] != null ? arguments[t] : {};
t % 2 ? Z(Object(a), !0).forEach(function(r) {
N(e, r, a[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(a)) : Z(Object(a)).forEach(function(r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(a, r));
});
}
return e;
}
function N(e, t, a) {
return (t = vt(t)) in e ? Object.defineProperty(e, t, { value: a, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = a, e;
}
function vt(e) {
var t = mt(e, "string");
return typeof t == "symbol" ? t : t + "";
}
function mt(e, t) {
if (typeof e != "object" || !e) return e;
var a = e[Symbol.toPrimitive];
if (a !== void 0) {
var r = a.call(e, t);
if (typeof r != "object") return r;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (t === "string" ? String : Number)(e);
}
function D() {
return D = Object.assign ? Object.assign.bind() : function(e) {
for (var t = 1; t < arguments.length; t++) {
var a = arguments[t];
for (var r in a) ({}).hasOwnProperty.call(a, r) && (e[r] = a[r]);
}
return e;
}, D.apply(null, arguments);
}
var yt = (e) => {
var {
dataKey: t,
name: a,
stroke: r,
legendType: n,
hide: i
} = e;
return [{
inactive: i,
dataKey: t,
type: n,
color: r,
value: re(a, t),
payload: e
}];
};
function ht(e) {
var {
dataKey: t,
data: a,
stroke: r,
strokeWidth: n,
fill: i,
name: o,
hide: l,
unit: c
} = e;
return {
dataDefinedOnItem: a,
positions: void 0,
settings: {
stroke: r,
strokeWidth: n,
fill: i,
dataKey: t,
nameKey: void 0,
name: re(o, t),
hide: l,
type: e.tooltipType,
color: e.stroke,
unit: c
}
};
}
var pe = (e, t) => "".concat(t, "px ").concat(e - t, "px");
function gt(e, t) {
for (var a = e.length % 2 !== 0 ? [...e, 0] : e, r = [], n = 0; n < t; ++n)
r = [...r, ...a];
return r;
}
var xt = (e, t, a) => {
var r = a.reduce((d, p) => d + p);
if (!r)
return pe(t, e);
for (var n = Math.floor(e / r), i = e % r, o = t - e, l = [], c = 0, u = 0; c < a.length; u += a[c], ++c)
if (u + a[c] > i) {
l = [...a.slice(0, c), i - u];
break;
}
var f = l.length % 2 === 0 ? [0, o] : [o];
return [...gt(a, n), ...l, ...f].map((d) => "".concat(d, "px")).join(", ");
};
function bt(e, t) {
var a;
if (/* @__PURE__ */ s.isValidElement(e))
a = /* @__PURE__ */ s.cloneElement(e, t);
else if (typeof e == "function")
a = e(t);
else {
var r = V("recharts-line-dot", typeof e != "boolean" ? e.className : "");
a = /* @__PURE__ */ s.createElement(oe, D({}, t, {
className: r
}));
}
return a;
}
function Pt(e, t) {
return e == null ? !1 : t ? !0 : e.length === 1;
}
function At(e) {
var {
clipPathId: t,
points: a,
props: r
} = e, {
dot: n,
dataKey: i,
needClip: o
} = r;
if (!Pt(a, n))
return null;
var l = ne(n), c = O(r, !1), u = O(n, !0), f = a.map((p, v) => {
var h = y(y(y({
key: "dot-".concat(v),
r: 3
}, c), u), {}, {
index: v,
cx: p.x,
cy: p.y,
dataKey: i,
value: p.value,
payload: p.payload,
points: a
});
return bt(n, h);
}), d = {
clipPath: o ? "url(#clipPath-".concat(l ? "" : "dots-").concat(t, ")") : null
};
return /* @__PURE__ */ s.createElement(G, D({
className: "recharts-line-dots",
key: "dots"
}, d), f);
}
function z(e) {
var {
clipPathId: t,
pathRef: a,
points: r,
strokeDasharray: n,
props: i,
showLabels: o
} = e, {
type: l,
layout: c,
connectNulls: u,
needClip: f
} = i, d = de(i, dt), p = y(y({}, O(d, !0)), {}, {
fill: "none",
className: "recharts-line-curve",
clipPath: f ? "url(#clipPath-".concat(t, ")") : null,
points: r,
type: l,
layout: c,
connectNulls: u,
strokeDasharray: n ?? i.strokeDasharray
});
return /* @__PURE__ */ s.createElement(s.Fragment, null, (r == null ? void 0 : r.length) > 1 && /* @__PURE__ */ s.createElement(Fe, D({}, p, {
pathRef: a
})), /* @__PURE__ */ s.createElement(At, {
points: r,
clipPathId: t,
props: i
}), o && et.renderCallByParent(i, r));
}
function It(e) {
try {
return e && e.getTotalLength && e.getTotalLength() || 0;
} catch {
return 0;
}
}
function Et(e) {
var {
clipPathId: t,
props: a,
pathRef: r,
previousPointsRef: n,
longestAnimatedLengthRef: i
} = e, {
points: o,
strokeDasharray: l,
isAnimationActive: c,
animationBegin: u,
animationDuration: f,
animationEasing: d,
animateNewValues: p,
width: v,
height: h,
onAnimationEnd: P,
onAnimationStart: g
} = a, b = n.current, S = Je(a, "recharts-line-"), [E, x] = we(!1), w = U(() => {
typeof P == "function" && P(), x(!1);
}, [P]), K = U(() => {
typeof g == "function" && g(), x(!0);
}, [g]), A = It(r.current), j = i.current;
return /* @__PURE__ */ s.createElement($e, {
begin: u,
duration: f,
isActive: c,
easing: d,
from: {
t: 0
},
to: {
t: 1
},
onAnimationEnd: w,
onAnimationStart: K,
key: S
}, (T) => {
var {
t: I
} = T, me = L(j, A + j), _ = Math.min(me(I), A), C;
if (l) {
var ye = "".concat(l).split(/[,\s]+/gim).map((m) => parseFloat(m));
C = xt(_, A, ye);
} else
C = pe(A, _);
if (b) {
var he = b.length / o.length, F = I === 1 ? o : o.map((m, ge) => {
var M = Math.floor(ge * he);
if (b[M]) {
var q = b[M], xe = L(q.x, m.x), be = L(q.y, m.y);
return y(y({}, m), {}, {
x: xe(I),
y: be(I)
});
}
if (p) {
var Pe = L(v * 2, m.x), Ae = L(h / 2, m.y);
return y(y({}, m), {}, {
x: Pe(I),
y: Ae(I)
});
}
return y(y({}, m), {}, {
x: m.x,
y: m.y
});
});
return n.current = F, /* @__PURE__ */ s.createElement(z, {
props: a,
points: F,
clipPathId: t,
pathRef: r,
showLabels: !E,
strokeDasharray: C
});
}
return I > 0 && A > 0 && (n.current = o, i.current = _), /* @__PURE__ */ s.createElement(z, {
props: a,
points: o,
clipPathId: t,
pathRef: r,
showLabels: !E,
strokeDasharray: C
});
});
}
function Ot(e) {
var {
clipPathId: t,
props: a
} = e, {
points: r,
isAnimationActive: n
} = a, i = R(null), o = R(0), l = R(null), c = i.current;
return n && r && r.length && c !== r ? /* @__PURE__ */ s.createElement(Et, {
props: a,
clipPathId: t,
previousPointsRef: i,
longestAnimatedLengthRef: o,
pathRef: l
}) : /* @__PURE__ */ s.createElement(z, {
props: a,
points: r,
clipPathId: t,
pathRef: l,
showLabels: !0
});
}
var Dt = (e, t) => ({
x: e.x,
y: e.y,
value: e.value,
// @ts-expect-error getValueByDataKey does not validate the output type
errorVal: ie(e.payload, t)
});
class St extends Se {
constructor() {
super(...arguments), N(this, "id", Me("recharts-line-"));
}
render() {
var t, {
hide: a,
dot: r,
points: n,
className: i,
xAxisId: o,
yAxisId: l,
top: c,
left: u,
width: f,
height: d,
id: p,
needClip: v,
layout: h
} = this.props;
if (a)
return null;
var P = V("recharts-line", i), g = k(p) ? this.id : p, {
r: b = 3,
strokeWidth: S = 2
} = (t = O(r, !1)) !== null && t !== void 0 ? t : {
r: 3,
strokeWidth: 2
}, E = ne(r), x = b * 2 + S;
return /* @__PURE__ */ s.createElement(s.Fragment, null, /* @__PURE__ */ s.createElement(G, {
className: P
}, v && /* @__PURE__ */ s.createElement("defs", null, /* @__PURE__ */ s.createElement(Xe, {
clipPathId: g,
xAxisId: o,
yAxisId: l
}), !E && /* @__PURE__ */ s.createElement("clipPath", {
id: "clipPath-dots-".concat(g)
}, /* @__PURE__ */ s.createElement("rect", {
x: u - x / 2,
y: c - x / 2,
width: f + x,
height: d + x
}))), /* @__PURE__ */ s.createElement(Ot, {
props: this.props,
clipPathId: g
}), /* @__PURE__ */ s.createElement(Qe, {
direction: h === "horizontal" ? "y" : "x"
}, /* @__PURE__ */ s.createElement(Ze, {
xAxisId: o,
yAxisId: l,
data: n,
dataPointFormatter: Dt,
errorBarOffset: 0
}, this.props.children))), /* @__PURE__ */ s.createElement(ot, {
activeDot: this.props.activeDot,
points: n,
mainColor: this.props.stroke,
itemDataKey: this.props.dataKey
}));
}
}
var fe = {
activeDot: !0,
animateNewValues: !0,
animationBegin: 0,
animationDuration: 1500,
animationEasing: "ease",
connectNulls: !1,
dot: !0,
fill: "#fff",
hide: !1,
isAnimationActive: !Ge.isSsr,
label: !1,
legendType: "line",
stroke: "#3182bd",
strokeWidth: 1,
xAxisId: 0,
yAxisId: 0
};
function wt(e) {
var t = Be(e, fe), {
activeDot: a,
animateNewValues: r,
animationBegin: n,
animationDuration: i,
animationEasing: o,
connectNulls: l,
dot: c,
hide: u,
isAnimationActive: f,
label: d,
legendType: p,
xAxisId: v,
yAxisId: h
} = t, P = de(t, pt), {
needClip: g
} = He(v, h), {
height: b,
width: S,
left: E,
top: x
} = We(), w = ze(), K = Ve(), A = De(() => ({
dataKey: e.dataKey,
data: e.data
}), [e.dataKey, e.data]), j = B((T) => ut(T, v, h, K, A));
return w !== "horizontal" && w !== "vertical" ? null : /* @__PURE__ */ s.createElement(St, D({}, P, {
connectNulls: l,
dot: c,
activeDot: a,
animateNewValues: r,
animationBegin: n,
animationDuration: i,
animationEasing: o,
isAnimationActive: f,
hide: u,
label: d,
legendType: p,
xAxisId: v,
yAxisId: h,
points: j,
layout: w,
height: b,
width: S,
left: E,
top: x,
needClip: g
}));
}
function Lt(e) {
var {
layout: t,
xAxis: a,
yAxis: r,
xAxisTicks: n,
yAxisTicks: i,
dataKey: o,
bandSize: l,
displayedData: c
} = e;
return c.map((u, f) => {
var d = ie(u, o);
return t === "horizontal" ? {
x: H({
axis: a,
ticks: n,
bandSize: l,
entry: u,
index: f
}),
y: k(d) ? null : r.scale(d),
value: d,
payload: u
} : {
x: k(d) ? null : a.scale(d),
y: H({
axis: r,
ticks: i,
bandSize: l,
entry: u,
index: f
}),
value: d,
payload: u
};
});
}
class ve extends Oe {
render() {
return /* @__PURE__ */ s.createElement(Ue, {
type: "line",
data: this.props.data,
xAxisId: this.props.xAxisId,
yAxisId: this.props.yAxisId,
zAxisId: 0,
dataKey: this.props.dataKey,
stackId: void 0,
hide: this.props.hide,
barSize: void 0
}, /* @__PURE__ */ s.createElement(Ye, {
legendPayload: yt(this.props)
}), /* @__PURE__ */ s.createElement(Re, {
fn: ht,
args: this.props
}), /* @__PURE__ */ s.createElement(wt, this.props));
}
}
N(ve, "displayName", "Line");
N(ve, "defaultProps", fe);
var jt = ["axis"], Kt = /* @__PURE__ */ Le((e, t) => /* @__PURE__ */ s.createElement(tt, {
chartName: "LineChart",
defaultTooltipEventType: "axis",
validateTooltipEventTypes: jt,
tooltipPayloadSearcher: qe,
categoricalChartProps: e,
ref: t
}));
export {
ot as A,
oe as D,
ve as L,
Kt as a
};
//# sourceMappingURL=LineChart-B9ulwx-b.js.map