UNPKG

datajunction-ui

Version:
361 lines (360 loc) 10.5 kB
import * as i from "react"; import { PureComponent as D, useEffect as L } from "react"; import { createPortal as _ } from "react-dom"; import { az as A, ar as C, ab as W, cq as I, bT as B, bk as H, cB as $, cC as F, cx as q, cu as K, cr as M, cp as k, c8 as R, c9 as E, b0 as T } from "./index-n79cxNwC.js"; import { f as U } from "./BarChart-JyKNSAsC.js"; function b() { return b = Object.assign ? Object.assign.bind() : function(e) { for (var t = 1; t < arguments.length; t++) { var r = arguments[t]; for (var n in r) ({}).hasOwnProperty.call(r, n) && (e[n] = r[n]); } return e; }, b.apply(null, arguments); } function x(e, t) { var r = Object.keys(e); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); t && (n = n.filter(function(a) { return Object.getOwnPropertyDescriptor(e, a).enumerable; })), r.push.apply(r, n); } return r; } function V(e) { for (var t = 1; t < arguments.length; t++) { var r = arguments[t] != null ? arguments[t] : {}; t % 2 ? x(Object(r), !0).forEach(function(n) { O(e, n, r[n]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : x(Object(r)).forEach(function(n) { Object.defineProperty(e, n, Object.getOwnPropertyDescriptor(r, n)); }); } return e; } function O(e, t, r) { return (t = Z(t)) in e ? Object.defineProperty(e, t, { value: r, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = r, e; } function Z(e) { var t = G(e, "string"); return typeof t == "symbol" ? t : t + ""; } function G(e, t) { if (typeof e != "object" || !e) return e; var r = e[Symbol.toPrimitive]; if (r !== void 0) { var n = r.call(e, t); if (typeof n != "object") return n; throw new TypeError("@@toPrimitive must return a primitive value."); } return (t === "string" ? String : Number)(e); } var f = 32; class w extends D { /** * Render the path of icon * @param data Data of each legend item * @param iconType if defined, it will always render this icon. If undefined then it uses icon from data.type * @return Path element */ renderIcon(t, r) { var { inactiveColor: n } = this.props, a = f / 2, l = f / 6, s = f / 3, c = t.inactive ? n : t.color, u = r ?? t.type; if (u === "none") return null; if (u === "plainline") return /* @__PURE__ */ i.createElement("line", { strokeWidth: 4, fill: "none", stroke: c, strokeDasharray: t.payload.strokeDasharray, x1: 0, y1: a, x2: f, y2: a, className: "recharts-legend-icon" }); if (u === "line") return /* @__PURE__ */ i.createElement("path", { strokeWidth: 4, fill: "none", stroke: c, d: "M0,".concat(a, "h").concat(s, ` A`).concat(l, ",").concat(l, ",0,1,1,").concat(2 * s, ",").concat(a, ` H`).concat(f, "M").concat(2 * s, ",").concat(a, ` A`).concat(l, ",").concat(l, ",0,1,1,").concat(s, ",").concat(a), className: "recharts-legend-icon" }); if (u === "rect") return /* @__PURE__ */ i.createElement("path", { stroke: "none", fill: c, d: "M0,".concat(f / 8, "h").concat(f, "v").concat(f * 3 / 4, "h").concat(-f, "z"), className: "recharts-legend-icon" }); if (/* @__PURE__ */ i.isValidElement(t.legendIcon)) { var d = V({}, t); return delete d.legendIcon, /* @__PURE__ */ i.cloneElement(t.legendIcon, d); } return /* @__PURE__ */ i.createElement(U, { fill: c, cx: a, cy: a, size: f, sizeType: "diameter", type: u }); } /** * Draw items of legend * @return Items */ renderItems() { var { payload: t, iconSize: r, layout: n, formatter: a, inactiveColor: l, iconType: s } = this.props, c = { x: 0, y: 0, width: f, height: f }, u = { display: n === "horizontal" ? "inline-block" : "block", marginRight: 10 }, d = { display: "inline-block", verticalAlign: "middle", marginRight: 4 }; return t.map((o, h) => { var p = o.formatter || a, g = A({ "recharts-legend-item": !0, ["legend-item-".concat(h)]: !0, inactive: o.inactive }); if (o.type === "none") return null; var y = o.inactive ? l : o.color, v = p ? p(o.value, o, h) : o.value; return /* @__PURE__ */ i.createElement("li", b({ className: g, style: u, key: "legend-item-".concat(h) }, C(this.props, o, h)), /* @__PURE__ */ i.createElement(W, { width: r, height: r, viewBox: c, style: d, "aria-label": "".concat(v, " legend icon") }, this.renderIcon(o, s)), /* @__PURE__ */ i.createElement("span", { className: "recharts-legend-item-text", style: { color: y } }, v)); }); } render() { var { payload: t, layout: r, align: n } = this.props; if (!t || !t.length) return null; var a = { padding: 0, margin: 0, textAlign: r === "horizontal" ? n : "left" }; return /* @__PURE__ */ i.createElement("ul", { className: "recharts-default-legend", style: a }, this.renderItems()); } } O(w, "displayName", "Legend"); O(w, "defaultProps", { align: "center", iconSize: 14, inactiveColor: "#ccc", layout: "horizontal", verticalAlign: "middle" }); function J() { return I(B); } var Q = ["contextPayload"]; function P() { return P = Object.assign ? Object.assign.bind() : function(e) { for (var t = 1; t < arguments.length; t++) { var r = arguments[t]; for (var n in r) ({}).hasOwnProperty.call(r, n) && (e[n] = r[n]); } return e; }, P.apply(null, arguments); } function z(e, t) { var r = Object.keys(e); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); t && (n = n.filter(function(a) { return Object.getOwnPropertyDescriptor(e, a).enumerable; })), r.push.apply(r, n); } return r; } function m(e) { for (var t = 1; t < arguments.length; t++) { var r = arguments[t] != null ? arguments[t] : {}; t % 2 ? z(Object(r), !0).forEach(function(n) { j(e, n, r[n]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : z(Object(r)).forEach(function(n) { Object.defineProperty(e, n, Object.getOwnPropertyDescriptor(r, n)); }); } return e; } function j(e, t, r) { return (t = X(t)) in e ? Object.defineProperty(e, t, { value: r, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = r, e; } function X(e) { var t = Y(e, "string"); return typeof t == "symbol" ? t : t + ""; } function Y(e, t) { if (typeof e != "object" || !e) return e; var r = e[Symbol.toPrimitive]; if (r !== void 0) { var n = r.call(e, t); if (typeof n != "object") return n; throw new TypeError("@@toPrimitive must return a primitive value."); } return (t === "string" ? String : Number)(e); } function ee(e, t) { if (e == null) return {}; var r, n, a = te(e, t); if (Object.getOwnPropertySymbols) { var l = Object.getOwnPropertySymbols(e); for (n = 0; n < l.length; n++) r = l[n], t.indexOf(r) === -1 && {}.propertyIsEnumerable.call(e, r) && (a[r] = e[r]); } return a; } function te(e, t) { if (e == null) return {}; var r = {}; for (var n in e) if ({}.hasOwnProperty.call(e, n)) { if (t.indexOf(n) !== -1) continue; r[n] = e[n]; } return r; } function re(e) { return e.value; } function ne(e) { var { contextPayload: t } = e, r = ee(e, Q), n = T(t, e.payloadUniqBy, re), a = m(m({}, r), {}, { payload: n }); return /* @__PURE__ */ i.isValidElement(e.content) ? /* @__PURE__ */ i.cloneElement(e.content, a) : typeof e.content == "function" ? /* @__PURE__ */ i.createElement(e.content, a) : /* @__PURE__ */ i.createElement(w, a); } function ae(e, t, r, n, a, l) { var { layout: s, align: c, verticalAlign: u } = t, d, o; return (!e || (e.left === void 0 || e.left === null) && (e.right === void 0 || e.right === null)) && (c === "center" && s === "vertical" ? d = { left: ((n || 0) - l.width) / 2 } : d = c === "right" ? { right: r && r.right || 0 } : { left: r && r.left || 0 }), (!e || (e.top === void 0 || e.top === null) && (e.bottom === void 0 || e.bottom === null)) && (u === "middle" ? o = { top: ((a || 0) - l.height) / 2 } : o = u === "bottom" ? { bottom: r && r.bottom || 0 } : { top: r && r.top || 0 }), m(m({}, d), o); } function ie(e) { var t = k(); return L(() => { t(R(e)); }, [t, e]), null; } function oe(e) { var t = k(); return L(() => (t(E(e)), () => { t(E({ width: 0, height: 0 })); }), [t, e]), null; } function le(e) { var t = J(), r = $(), n = F(), { width: a, height: l, wrapperStyle: s, portal: c } = e, [u, d] = q([t]), o = K(), h = M(), p = o - (n.left || 0) - (n.right || 0), g = S.getWidthOrHeight(e.layout, l, a, p), y = c ? s : m(m({ position: "absolute", width: (g == null ? void 0 : g.width) || a || "auto", height: (g == null ? void 0 : g.height) || l || "auto" }, ae(s, e, n, o, h, u)), s), v = c ?? r; if (v == null) return null; var N = /* @__PURE__ */ i.createElement("div", { className: "recharts-legend-wrapper", style: y, ref: d }, /* @__PURE__ */ i.createElement(ie, { layout: e.layout, align: e.align, verticalAlign: e.verticalAlign, itemSorter: e.itemSorter }), /* @__PURE__ */ i.createElement(oe, { width: u.width, height: u.height }), /* @__PURE__ */ i.createElement(ne, P({}, e, g, { margin: n, chartWidth: o, chartHeight: h, contextPayload: t }))); return /* @__PURE__ */ _(N, v); } class S extends D { static getWidthOrHeight(t, r, n, a) { return t === "vertical" && H(r) ? { height: r } : t === "horizontal" ? { width: n || a } : null; } render() { return /* @__PURE__ */ i.createElement(le, this.props); } } j(S, "displayName", "Legend"); j(S, "defaultProps", { align: "center", iconSize: 14, itemSorter: "value", layout: "horizontal", verticalAlign: "bottom" }); export { S as L }; //# sourceMappingURL=Legend-CTc9jmzF.js.map