@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.
2 lines (1 loc) • 1.53 kB
JavaScript
;const u=require("react/jsx-runtime"),r=require("react"),j=require("d3");function g(n){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const e in n)if(e!=="default"){const i=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:()=>n[e]})}}return t.default=n,Object.freeze(t)}const p=g(j);class m extends r.Component{constructor(t){super(t),this.state={},this.divRef=r.createRef(),this.createProjection=this.createProjection.bind(this)}createProjection(){const{editing:t,height:e,width:i,scale:o=200,center:s=[0,0],projectionName:a}=this.props,c=p[a]().fitSize([i,e]).scale(o).center(s).translate([i/2,e/2]);return{path:p.geoPath().projection(c),projection:c}}componentDidMount(){const{svg:t}=this.props,{path:e,projection:i}=this.createProjection();this.setState({path:e,projection:i})}componentDidUpdate(t,e,i){if(t.height!==this.props.height||t.width!==this.props.width||t.projectionName!==this.props.projectionName){const{path:o,projection:s}=this.createProjection();this.setState({path:o,projection:s})}}render(){const{editing:t,backgroundColor:e,height:i,width:o,scale:s=190,center:a=[0,0],initialPosition:c,settings:h}=this.props,d=r.Children.toArray(this.props.children);return u.jsx("div",{className:"projected",width:o,height:i,style:{margin:"auto",backgroundColor:e,height:`${i}px`,width:`${o}px`},children:r.Children.map(d,l=>r.cloneElement(l,{...this.state,initialPosition:c,editing:t,height:i,width:o,settings:h}))})}}module.exports=m;