@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.
61 lines (60 loc) • 2.24 kB
JavaScript
import { jsx as i } from "react/jsx-runtime";
import "react";
import h from "react-markdown";
import v from "remark-gfm";
import x from "rehype-raw";
import f from "string-template";
const N = /(\+?\%)[\(]([A-z0-9,.,-]+)\)/gi, F = /(\+?\#)[\(]([A-z0-9,.,-]+)\)/gi, _ = /(\+?\#C)[\(]([A-z0-9,.,-]+)\)/gi, u = (o, e, n, a, r, d) => {
if (!r || !r.formatNumber)
return e;
let t, m = e;
for (; (t = o.exec(e)) !== null; ) {
const l = t[2], c = t[1], g = ((p, y = 2) => r.formatNumber(a ? p / 100 : p, {
maximumFractionDigits: y,
...n,
signDisplay: c && c.startsWith("+") ? "never" : "auto"
})).apply(void 0, l.split(","));
m = m.replaceAll(t[0], g);
}
return m;
}, A = (o, e, n, a) => {
if (!o || !e)
return "";
e.field && e[`_${e.field}`] && (e._value = e[`_${e.field}`]), !e.field && e.category && (e.field = e.category);
let r = a ? f(o, e) : f(o, e).replace(/(?:\r\n|\r|\n)/g, "<br>");
return r = u(N, r, { style: "percent" }, !0, n), r = u(F, r, { style: "decimal" }, !1, n), r = u(
_,
r,
{ notation: "compact" },
!1,
n
), r;
}, D = ({ tooltip: o, d: e, intl: n, tooltipEnableMarkdown: a }) => {
if (!e || !o)
return /* @__PURE__ */ i("div", {});
const r = e.datum || e.point || e, { color: d, data: t } = r || {}, m = e.value || (e.datum ? e.datum.value : null) || (e.point ? e.point.data.y : null);
if (t) {
let l;
t.variables ? l = typeof t.variables[e.id] == "object" ? t.variables[e.id] : t.variables : l = t;
const c = {
field: e.point ? e.point.serieId : e.id || "",
...l,
value: m
};
t.measureFieldName && t.variables && (c.populationValue = t.variables[t.measureFieldName + "Population"]);
const s = A(o, c, n, a);
return s ? a ? /* @__PURE__ */ i("div", { className: "chart tooltip", children: /* @__PURE__ */ i(
h,
{
children: s,
remarkPlugins: [v],
rehypePlugins: [x]
}
) }) : /* @__PURE__ */ i("div", { className: "chart tooltip", children: /* @__PURE__ */ i("div", { dangerouslySetInnerHTML: { __html: s } }) }) : /* @__PURE__ */ i("div", {});
} else
return /* @__PURE__ */ i("div", {});
};
export {
D as default,
A as formatContent
};