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.

56 lines (55 loc) 2.01 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 = (i, t, o, a, e, r) => { let l, n = t; for (; (l = i.exec(t)) !== null; ) { const s = l[2], m = l[1], d = ((u, g = 2) => e.formatNumber(a ? u / 100 : u, { maximumFractionDigits: g, ...o, signDisplay: m && m.startsWith("+") ? "never" : "auto" })).apply(void 0, s.split(",")); n = n.replaceAll(l[0], d); } return n; }, v = (i, t, o, a) => { t.field && t[`_${t.field}`] && (t._value = t[`_${t.field}`]), !t.field && t.category && (t.field = t.category); let e = a ? f(i, t) : f(i, 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; }, D = ({ tooltip: i, d: t, intl: o, tooltipEnableMarkdown: a }) => { const { color: e, data: r } = t.datum || t.point || t, l = t.value || (t.datum ? t.datum.value : null) || (t.point ? t.point.data.y : null); if (r) { let n; r.variables ? n = typeof r.variables[t.id] == "object" ? r.variables[t.id] : r.variables : n = r; const s = { field: t.point ? t.point.serieId : t.id, ...n, value: l }; r.measureFieldName && (s.populationValue = r.variables[r.measureFieldName + "Population"]); const m = v(i, s, o, a); return a ? /* @__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 { D as default, v as formatContent };