UNPKG

@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.

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