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.

2 lines (1 loc) 7.8 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),E=require("react");require("prop-types");const G=require("papaparse"),V=require("react-intl"),z=require("../data/DataProvider.js"),F=require("../data/DataConsumer.js"),A=require("./GradientColors.js"),O=({breaks:i,isPoint:n,numberFormat:c,intl:o})=>i.length>0&&e.jsx("div",{className:"legend-breaks",children:i.map((l,r)=>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:[" < ",o.formatNumber(l.end,c)]})]}):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:[" > ",o.formatNumber(l.end,c)]})]}))}),H=i=>{const{name:n,breaks:c,pointStyleBy:o,dimension2:l,pointDimensionStyles:r={},markFillColor:d,markBorderColor:u,measures:s,visible:p,format:m,intl:y,id:v,onItemClick:C,customMeasuresLabels:k}=i,g={style:m.style==="compacted"?"decimal":m.style,notation:m.style==="compacted"?"compact":"standard",currency:m.currency,minimumFractionDigits:parseInt(m.minimumFractionDigits),maximumFractionDigits:parseInt(m.maximumFractionDigits)};let x=s[0];return k&&(x=k[s[0]]),[...new Set(Object.keys(r).map(b=>b.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:b=>C(v),style:{backgroundColor:d,borderColor:u},children:p!=!1&&e.jsx(e.Fragment,{children:"✓"})}),e.jsxs("div",{className:"legend-label",children:[n," (",x,")"]})]}),p!=!1&&e.jsx(O,{breaks:c,symbol:"arrow",numberFormat:g,intl:y})]})})},J=i=>{const{id:n,name:c,breaks:o,intl:l,pointStyleBy:r,format:d,dimension2:u,pointDimensionStyles:s={},markFillColor:p,markBorderColor:m,measures:y,visible:v,onItemClick:C,customMeasuresLabels:k,allCategories:g,showDim2OnLegends:x,dim2LegendLabel:b,type:f,d2Click:N,selectedItem:L}=i,h={style:d.style==="compacted"?"decimal":d.style,notation:d.style==="compacted"?"compact":"standard",currency:d.currency,minimumFractionDigits:parseInt(d.minimumFractionDigits),maximumFractionDigits:parseInt(d.maximumFractionDigits)};let I=y[0];k&&(I=k[y[0]]);const $=u&&g?g.filter(a=>a.type.toUpperCase()==u.toUpperCase()):[],j=($.length>0?$[0].items:[]).map(a=>a.value),S=r==="dimension"||x?u:I;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=>C(n),style:r==="measure"||x?{}:{backgroundColor:p,borderColor:m},children:v!=!1&&e.jsx(e.Fragment,{children:"✓"})}),e.jsxs("div",{className:"legend-label",children:[c," "]})]}),r==="measure"&&v!=!1&&e.jsx("div",{className:"legend-breaks",children:o.map((a,q)=>e.jsxs("div",{className:"break",children:[e.jsx("div",{className:"break-item",style:{backgroundColor:a.color,border:`1px solid ${a.borderColor}`,borderRadius:f=="dataPoints"?"50%":"0"}}),e.jsxs("div",{className:"break-label",children:[" < ",l.formatNumber(a.end,h)]})]}))}),v!=!1&&x!=!1&&e.jsx("div",{className:"legend",children:e.jsx("div",{className:"legend-item",children:e.jsx("div",{className:"legend-label",children:b||S})})}),v!=!1&&x!=!1&&e.jsx("div",{className:"legend-breaks",children:j.map(a=>e.jsxs("div",{className:"break",children:[r==="measure"?e.jsx("span",{className:"break-item dim2-item"}):e.jsx("div",{className:"break-item",style:{backgroundColor:s[a+"_color"]||p,border:`1px solid ${s[a+"_border"]||m}`,borderRadius:f=="dataPoints"?"50%":"0"}}),e.jsx("div",{className:"break-label",onClick:q=>N(a),children:L==a?e.jsx("b",{children:a}):a})]}))})]})})},W=i=>{const{fillColor:n,borderColor:c,name:o,visible:l,id:r,onItemClick:d}=i;return e.jsx("div",{className:"legend",children:e.jsxs("div",{className:"legend-item",children:[e.jsx("div",{className:"legend-color legend-check",onClick:u=>d(r),style:{backgroundColor:n,borderColor:c},children:l!=!1&&e.jsx(e.Fragment,{children:"✓"})}),e.jsx("div",{className:"legend-label",children:o})]})})},K=i=>{const{markFillColor:n,fillColor:c,markSizeScale:o,markBorderColor:l,useCentroidPoint:r,name:d,useBreaks:u,useGradients:s,breaks:p,intl:m,usePattern:y,patternsData:v,patternDiscriminator:C,patternDiscriminatorLabel:k,measures:g,borderColor:x,data:b,app:f,customMeasuresLabels:N,divRef:L,id:h,patternWidth:I=.35,patternHeight:$=.25,group:B,format:j,csv:S,visible:a,onItemClick:q,gradientScheme:T,gradientReverse:U,toggleColorLayer:_,colorLayerVisible:P=!0}=i;let D="";const R={style:j.style==="compacted"?"decimal":j.style,notation:j.style==="compacted"?"compact":"standard",currency:j.currency,minimumFractionDigits:parseInt(j.minimumFractionDigits),maximumFractionDigits:parseInt(j.maximumFractionDigits)},M=new A.default({data:b.children,measure:g[0],defaultFillColor:n,gradientScheme:T,gradientReverse:U});if(f!="csv"&&N)D=N[g[0]];else{const t=G.parse(S,{header:!0,dynamicTyping:!0});D=t.meta.fields.length>0?t.meta.fields[1]:""}const w=t=>t?t.toString().replace(/ /g,"_").toLocaleLowerCase():"";if(L.current){const t=L.current.querySelector(`.legend.layer_${w(h)} svg`);t&&(t.style.display=a===!1?"none":"block")}return e.jsx("div",{className:`legend layer_${w(h)}`,id:w(`${B} ${d} ${h}`),children:e.jsxs("div",{children:[e.jsxs("div",{className:"legend-item",children:[e.jsx("div",{className:"legend-color legend-check",onClick:t=>q(h),style:{backgroundColor:c,borderColor:x},children:a!=!1&&e.jsx(e.Fragment,{children:"✓"})}),e.jsx("div",{className:"legend-label",children:d})]}),r&&!u&&a!=!1&&e.jsx("div",{className:"legend-breaks",children:e.jsxs("div",{className:"break",children:[e.jsx("div",{className:`break-item point ${P?"checked":""}`,onClick:t=>_(h),style:{backgroundColor:n,border:`1px solid ${l}`}}),D]})}),u&&a!=!1&&e.jsxs("div",{children:[e.jsx("div",{className:"legend-breaks",children:e.jsxs("div",{className:"legend-section-title",onClick:t=>_(h),children:[e.jsx("div",{className:`legend-section-title-checkbox ${P?"checked":""}`}),e.jsx("span",{className:"measure-label",children:D})]})}),P&&e.jsx(O,{isPoint:r,numberFormat:R,breaks:p,visible:a,intl:m})]}),s&&a!=!1&&e.jsxs("div",{children:[e.jsx("div",{className:"gradient-label",style:{float:"right"},children:m.formatNumber(Math.max(...b.children.map(t=>t[g[0]])),R)}),e.jsx("div",{className:"gradient-label",style:{float:"left"},children:m.formatNumber(Math.min(...b.children.map(t=>t[g[0]])),R)}),e.jsx("div",{style:{background:`linear-gradient(to right, ${M.getStartColor()}, ${M.getEndColor()})`,width:"200px",height:"10px"}})]})]})})},Q=i=>{const n=E.useRef(null),{layers:c=[],onItemClick:o,patternsData:l,group:r,intl:d,toggleColorLayer:u}=i;return e.jsx("div",{className:"legends",ref:n,children:c&&c.map(s=>e.jsx(z.default,{editing:s.editing,params:s.params,app:s.app,csv:decodeURIComponent(s.csv),group:r,ignoreErrors:!0,isSvg:!0,store:[s.app,s.unique,s.id],source:s.apiJoinAttribute+(s.patternDiscriminator!="none"?"/"+s.patternDiscriminator:""),children:e.jsxs("div",{children:[s.type=="base"&&e.jsx(F.default,{children:e.jsx(W,{...s,group:r,onItemClick:o})}),s.type=="data"&&e.jsx(F.default,{children:e.jsx(K,{group:r,patternsData:l?l[s.id]:null,divRef:n,...s,intl:i.intl,onItemClick:o,toggleColorLayer:u})}),s.type=="dataPoints"&&e.jsx(F.default,{children:e.jsx(J,{selectedItem:i.selectedItem,d2Click:i.d2Click,intl:i.intl,group:r,...s,onItemClick:o})}),s.type=="flow"&&e.jsx(F.default,{children:e.jsx(H,{group:r,...s,onItemClick:o,intl:i.intl})})]})}))})},X=V.injectIntl(Q);exports.default=X;