@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.
50 lines (49 loc) • 1.69 kB
JavaScript
import { jsx as g } from "react/jsx-runtime";
import a from "react";
import * as o from "d3";
class u extends a.Component {
constructor(t) {
super(t), this.svgRef = a.createRef(), this.dragged = this.dragged.bind(this);
}
componentDidUpdate(t, s, r) {
if (t.projection !== this.props.projection) {
const n = o.geoPath().projection(this.props.projection);
this.setState({ projection: this.props.projection, path: n });
}
const { rotationEnabled: i } = this.props, e = o.select(this.svgRef.current).datum({
x: 0,
y: 0
});
i ? e.call(o.drag().on("drag", this.dragged)) : e.on(".drag", null);
}
componentDidMount() {
const { rotationEnabled: t } = this.props, s = o.select(this.svgRef.current).datum({
x: 0,
y: 0
});
t && s.call(o.drag().on("drag", this.dragged));
}
dragged(t, s) {
const r = {
x: 0,
y: 0
}, { projection: i, width: e, height: n } = this.props, c = o.scaleLinear().domain([-e, e]).range([-180, 180]), h = o.scaleLinear().domain([-n, n]).range([90, -90]), p = {
x: c(s.x = t.x),
y: h(s.y = t.y)
};
i.rotate([r.x + p.x, r.y + p.y]);
const d = o.geoPath().projection(i);
this.setState({ projection: i, path: d });
}
render() {
const { projection: t, width: s, height: r, path: i } = this.props;
return /* @__PURE__ */ g("svg", { viewBox: `0 0 ${s} ${r}`, className: "map", height: r, width: "100%", ref: this.svgRef, children: t && this.props.children ? this.props.children.map((e) => a.cloneElement(e, {
...this.props,
svg: this.svgRef.current,
...this.state
})) : null });
}
}
export {
u as default
};