@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.
151 lines (150 loc) • 5.04 kB
JavaScript
import { jsx as o, jsxs as A } from "react/jsx-runtime";
import { useRef as V, useState as q } from "react";
import { Container as H } from "semantic-ui-react";
import J from "../data/DataProvider.js";
import $ from "../data/DataConsumer.js";
import "@devgateway/wp-react-lib";
import { connect as k } from "react-redux";
import { alphaSort as B } from "../utils/common.js";
import G from "string-template";
const K = (f) => {
const {
editing: c = !1,
unique: g,
intl: u,
childContent: h,
"data-csv": m = "",
"data-dvz-proxy-dataset-id": b,
"data-no-data-message": T = "No data matches your selection",
"data-view-mode": v = "info",
"data-height": F,
"data-app": x,
"data-measures": C = "{}",
"data-format": z = "{}",
"data-group": y,
"data-filters": N = "[]",
"data-text-color": e = "#000000",
"data-big-number-font-size": i = 20,
"data-label-font-size": a = 20,
"data-percent-font-size": d = 20,
"data-label": p = "",
"data-dimension1": r,
"data-show-percentage-change": S = "false",
"data-wait-for-filters": D = "false",
"data-no-data-text": w = "-"
} = f, I = u.locale, j = V(null), s = (n) => c ? n : decodeURIComponent(n), l = (n) => {
try {
return JSON.parse(s(n));
} catch {
console.error("error parsing value:" + n);
}
return null;
}, t = l(z), E = t ? {
style: t.style === "compacted" ? "decimal" : t.style,
notation: t.style === "compacted" ? "compact" : "standard",
currency: t.currency,
minimumFractionDigits: parseInt(t.minimumFractionDigits),
maximumFractionDigits: parseInt(t.maximumFractionDigits)
} : {
notation: "standard",
currency: "USD",
minimumFractionDigits: 2,
maximumFractionDigits: 2
}, [X, Y] = q(v), O = c ? F - 80 : F - 40, P = {}, M = l(N) || {};
M && M.forEach && M.forEach((n) => {
n.value != null && n.value.filter((U) => U != null && U.toString().trim() != "").length > 0 && (P[n.param] = n.value);
}), b && (P.dvzProxyDatasetId = b);
const R = [];
return r != "none" && R.push(r), /* @__PURE__ */ o("div", { ref: j, children: /* @__PURE__ */ o(H, { className: "chart container big-number-trend-container", style: { height: F + "px" }, fluid: !0, children: /* @__PURE__ */ o(
J,
{
style: { height: `${O}px` },
params: P,
app: x,
group: y,
csv: m,
editing: c,
waitForFilters: D === "true",
store: [x, g, ...R],
source: R.join("/"),
children: /* @__PURE__ */ o($, { children: /* @__PURE__ */ o(
L,
{
editing: c,
locale: I,
intl: u,
app: x,
format: E,
dimension1: r,
measure: l(C)[0] || null,
label: p,
bigNumberFontSize: i,
textColor: e,
labelFontSize: a,
percentFontSize: d,
showPercentageChange: S == "true" || S == !0,
noDataText: w
}
) })
}
) }) });
}, L = (f) => {
const {
editing: c,
app: g,
measure: u,
dimension1: h,
data: m,
format: b,
label: T,
textColor: v,
bigNumberFontSize: F,
percentFontSize: x,
labelFontSize: C,
showPercentageChange: z,
intl: y,
noDataText: N
} = f;
let e = [], i, a;
if (g == "csv") {
const { data: s, meta: { fields: l } } = m;
i = l[0], a = l[1], e = m.data.map((t) => ({
value: t[i],
[a]: t[a],
[i]: t[i]
}));
} else
e = !m.children || m.children.length == 0 ? [] : m.children, a = u, i = h, e = e.map((s) => ({
value: s.value,
[a]: s[a],
[i]: s.value
}));
let d = null, p = null, r, S, D;
e.length > 0 && (e = e.sort((s, l) => B(!1, y.locale, s.value, l.value)), d = e[e.length - 1][a], e.length > 1 && (p = e[e.length - 2][a]), D = y.formatNumber(b.style === "percent" ? d / 100 : d, { ...b }), p && (r = (d - p) / p, S = y.formatNumber(r, { style: "percent", minimumFractionDigits: 2, maximumFractionDigits: 2 }))), d == null && (D = N);
const w = {
color: decodeURIComponent(v),
fontSize: F + "px"
}, I = {
color: decodeURIComponent(v),
fontSize: x + "px"
}, j = {
color: decodeURIComponent(v),
fontSize: C + "px"
};
return /* @__PURE__ */ A("div", { className: "trend", children: [
/* @__PURE__ */ o("div", { className: "label", style: j, children: G(T, e[e.length - 1]) }),
/* @__PURE__ */ A("div", { className: "number-and-icon", children: [
/* @__PURE__ */ o("span", { className: "number", style: w, children: D }),
r && /* @__PURE__ */ o("img", { src: r > 0 ? "/trend-up.svg" : "/trend-down.svg", alt: "Arrow", className: "icon" })
] }),
z && r && /* @__PURE__ */ o("div", { className: "percentage", style: I, children: S })
] });
}, Q = (f, c) => {
const { "data-app": g, "data-group": u } = c, h = f.getIn(["data", "measures", g, u]);
return h ? {
injectedMeasures: h
} : {};
}, W = {}, se = k(Q, W)(K);
export {
se as default
};