@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) • 5.03 kB
JavaScript
"use strict";const e=require("react/jsx-runtime"),S=require("react"),I=require("prop-types"),P=require("papaparse"),L=({breaks:i,isPoint:n})=>i.length>0&&e.jsx("div",{className:"legend-breaks",children:i.map((l,d)=>l.type!=="graterThan"?e.jsxs("div",{className:"break",children:[e.jsx("div",{className:`break-item ${n?"point":""}`,style:{backgroundColor:l.color,border:`1px solid ${l.borderColor}`}}),e.jsxs("div",{className:"break-label",children:[" < ",l.end]})]}):e.jsxs("div",{className:"break",children:[e.jsx("div",{className:`break-item ${I.symbol}`,style:{backgroundColor:l.color,border:`1px solid ${l.borderColor}`}}),e.jsxs("div",{className:"break-label",children:[" > ",l.end]})]}))}),q=i=>{const{name:n,breaks:l,pointStyleBy:d,dimension2:o,pointDimensionStyles:r={},markFillColor:s,markBorderColor:c,measures:t,visible:b,id:g,onItemClick:v,customMeasuresLabels:j}=i;let m=t[0];return j&&(m=j[t[0]]),[...new Set(Object.keys(r).map(x=>x.split("_")[0]))],e.jsx("div",{className:"legend",children:e.jsxs("div",{children:[e.jsxs("div",{className:"legend-item",children:[e.jsx("div",{className:"legend-color legend-check",onClick:x=>v(g),style:{backgroundColor:s,borderColor:c},children:b!=!1&&e.jsx(e.Fragment,{children:"✓"})}),e.jsxs("div",{className:"legend-label",children:[n," (",m,")"]})]}),b!=!1&&e.jsx(L,{breaks:l,symbol:"arrow"})]})})},w=i=>{const{id:n,name:l,breaks:d,pointStyleBy:o,dimension2:r,pointDimensionStyles:s={},markFillColor:c,markBorderColor:t,measures:b,visible:g,onItemClick:v,customMeasuresLabels:j,allCategories:m}=i;let x=b[0];j&&(x=j[b[0]]);const N=r&&m?m.filter(a=>a.type.toUpperCase()==r.toUpperCase()):[],k=(N.length>0?N[0].items:[]).map(a=>a.value),y=o==="dimension"?r:x;return e.jsx("div",{className:"legend",children:e.jsxs("div",{children:[e.jsxs("div",{className:"legend-item",children:[e.jsx("div",{className:"legend-color legend-check",onClick:a=>v(n),style:{backgroundColor:c,borderColor:t},children:g!=!1&&e.jsx(e.Fragment,{children:"✓"})}),e.jsxs("div",{className:"legend-label",children:[l," "]})]}),e.jsx("div",{className:"legend",children:e.jsx("div",{className:"legend-item",children:e.jsx("div",{className:"legend-label",children:y})})}),o==="dimension"&&g!=!1&&e.jsx("div",{className:"legend-breaks",children:k.map(a=>e.jsxs("div",{className:"break",children:[e.jsx("div",{className:"break-item",style:{backgroundColor:s[a+"_color"]||c,border:`1px solid ${s[a+"_border"]||t}`}}),e.jsx("div",{className:"break-label",children:a})]}))}),o==="measure"&&g!=!1&&e.jsx("div",{className:"legend-breaks",children:d.map((a,$)=>e.jsxs("div",{className:"break",children:[e.jsx("div",{className:"break-item",style:{backgroundColor:a.color,border:`1px solid ${a.borderColor}`}}),e.jsxs("div",{className:"break-label",children:[" < ",a.end]})]}))})]})})},R=i=>{const{fillColor:n,borderColor:l,name:d,visible:o,id:r,onItemClick:s}=i;return e.jsx("div",{className:"legend",children:e.jsxs("div",{className:"legend-item",children:[e.jsx("div",{className:"legend-color legend-check",onClick:c=>s(r),style:{backgroundColor:n,borderColor:l},children:o!=!1&&e.jsx(e.Fragment,{children:"✓"})}),e.jsx("div",{className:"legend-label",children:d})]})})},_=i=>{const{markFillColor:n,fillColor:l,markSizeScale:d,markBorderColor:o,useCentroidPoint:r,name:s,useBreaks:c,breaks:t,usePattern:b,patternsData:g,patternDiscriminator:v,patternDiscriminatorLabel:j,measures:m,borderColor:x,data:N,app:C,customMeasuresLabels:k,divRef:y,id:a,patternWidth:$=.35,patternHeight:T=.25,group:D,csv:B,visible:p,onItemClick:F}=i;let u="";if(C!="csv"&&k)u=k[m[0]];else{const h=P.parse(B,{header:!0,dynamicTyping:!0});u=h.meta.fields.length>0?h.meta.fields[1]:""}const f=h=>h?h.toString().replace(/ /g,"_").toLocaleLowerCase():"";return e.jsx("div",{className:`legend layer_${f(a)}`,id:f(`${D} ${s} ${a}`),children:e.jsxs("div",{children:[e.jsxs("div",{className:"legend-item",children:[e.jsx("div",{className:"legend-color legend-check",onClick:h=>F(a),style:{backgroundColor:l,borderColor:x},children:p!=!1&&e.jsx(e.Fragment,{children:"✓"})}),e.jsxs("div",{className:"legend-label",children:[s," ",!r&&e.jsxs("span",{children:["(",u,")"]})]})]}),r&&!c&&p!=!1&&e.jsx("div",{className:"legend-breaks",children:e.jsxs("div",{className:"break",children:[e.jsx("div",{className:"break-item point",style:{backgroundColor:n,border:`1px solid ${o}`}}),u]})}),c&&p!=!1&&e.jsxs("div",{children:[r&&e.jsx("div",{className:"legend-breaks",children:e.jsx("div",{className:"break-item",children:u})}),e.jsx(L,{symbol:r?"point":"square",breaks:t,visible:p})]})]})})},M=i=>{const n=S.useRef(null),{layers:l=[],onItemClick:d,patternsData:o,group:r}=i;return e.jsx("div",{className:"legends",ref:n,children:l&&l.map(s=>e.jsxs("div",{children:[s.type=="base"&&e.jsx(R,{...s,group:r,onItemClick:d}),s.type=="data"&&e.jsx(_,{group:r,patternsData:o?o[s.id]:null,divRef:n,...s,onItemClick:d}),s.type=="dataPoints"&&e.jsx(w,{group:r,...s,onItemClick:d}),s.type=="flow"&&e.jsx(q,{group:r,...s,onItemClick:d})]}))})};module.exports=M;