@devgateway/dvz-ui-react
Version:
A modular, embeddable React component library for data visualization and UI, built with TypeScript. Provides reusable components for charts, maps, dashboards, and more, with built-in support for internationalization and Redux integration.
35 lines (34 loc) • 1.74 kB
JavaScript
import { jsx as c } from "react/jsx-runtime";
import "react";
import g from "react-markdown";
import h from "remark-gfm";
import y from "rehype-raw";
import f from "string-template";
const x = /(\+?\%)[\(]([A-z0-9,.,-]+)\)/gi, F = /(\+?\#)[\(]([A-z0-9,.,-]+)\)/gi, N = /(\+?\#C)[\(]([A-z0-9,.,-]+)\)/gi, p = (o, t, a, n, e, r) => {
let i, s = t;
for (; (i = o.exec(t)) !== null; ) {
const m = i[2], l = i[1], v = ((u, d = 2) => e.formatNumber(n ? u / 100 : u, {
maximumFractionDigits: d,
...a,
signDisplay: l && l.startsWith("+") ? "never" : "auto"
})).apply(void 0, m.split(","));
s = s.replaceAll(i[0], v);
}
return s;
}, b = (o, t, a, n) => {
let e = n ? f(o, t) : f(o, t).replace(/(?:\r\n|\r|\n)/g, "<br>");
return e = p(x, e, { style: "percent" }, !0, a), e = p(F, e, { style: "decimal" }, !1, a), e = p(N, e, { notation: "compact" }, !1, a), e;
}, E = ({ tooltip: o, d: t, intl: a, tooltipEnableMarkdown: n }) => {
const { color: e, data: r } = t.datum || t.point || t, i = t.value || (t.datum ? t.datum.value : null) || (t.point ? t.point.data.y : null);
if (r) {
const s = r.variables ? r.variables[t.id] || r.variables : r, m = { field: t.point ? t.point.serieId : t.id, ...s, value: i };
r.measureFieldName && (m.populationValue = r.variables[r.measureFieldName + "Population"]);
const l = b(o, m, a, n);
return n ? /* @__PURE__ */ c(g, { children: l, remarkPlugins: [h], rehypePlugins: [y], className: "chart tooltip" }) : /* @__PURE__ */ c("div", { className: "chart tooltip", children: /* @__PURE__ */ c("div", { dangerouslySetInnerHTML: { __html: l } }) });
} else
return /* @__PURE__ */ c("div", {});
};
export {
E as default,
b as formatContent
};