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.

77 lines (76 loc) 2.82 kB
import { jsxs as I, jsx as z } from "react/jsx-runtime"; import { Fragment as B } from "react"; import { line as L } from "d3-shape"; import * as O from "d3"; import { formatContent as R } from "./Tooltip.js"; import { injectIntl as W } from "react-intl"; const X = (r, m, t, S, c, g, j, w) => W((l) => { const { intl: A } = l; let o = S === "grouped"; if (r) { const { bars: y, xScale: u, yScale: x, innerWidth: M, innerHeight: E } = l; let s = /* @__PURE__ */ new Set(), d = [], n = 0; y && y.length > 0 ? (s = new Set(l.bars.map((e) => e.data.indexValue)), d = r.data.filter((e) => Array.from(s).find((p) => p == e[0])), n = t === "horizontal" ? l.bars[0].height : l.bars[0].width) : (o = !1, r.data && (r.data.forEach((e) => { e && s.add(e[0]); }), d = r.data, n = t === "horizontal" ? E / s.size : M / s.size)); let a, h; t === "horizontal" ? (h = 1, a = 0) : (h = 0, a = 1); const b = L(); b.x((e) => t === "horizontal" ? u(e[h]) : u(e[h]) + n * (o ? c.length : 1) / 2).y((e) => t === "horizontal" ? x(e[a]) + n * (o ? c.length : 1) / 2 : x(e[a])); const i = O.select("#root").append("div").attr("class", "chart tooltip").style("transition", "all 1s ease-out;").style("background-color", m).style("position", "absolute").style("visibility", "hidden"); return /* @__PURE__ */ I(B, { children: [ /* @__PURE__ */ z( "path", { d: b(d), fill: "none", "stroke-width": "4", stroke: `${m}`, style: { pointerEvents: "none" } } ), d.map((e) => { const v = t === "horizontal" ? n * (o ? c.length : 1) / 2 : 0, p = t === "horizontal" ? 0 : n * (o ? c.length : 1) / 2; return /* @__PURE__ */ z( "circle", { onMouseOver: (f) => { i.style("visibility", "visible"); }, onMouseMove: (f) => { g && g.trim().length > 0 && (i.html( R( g, { x: e[0], y: e[1], title: j, measure: w }, A ) ), i.style( "top", f.pageY - i.node().getBoundingClientRect().height + "px" ).style( "left", f.pageX - i.node().getBoundingClientRect().width + "px" )); }, onMouseOut: (f) => i.style("visibility", "hidden"), cx: u(e[h]) + p, cy: x(e[a]) + v, r: 7, fill: m, style: { pointerEvents: "all", cursor: "pointer" } }, e.index ); }) ] }); } else return null; }); export { X as default };