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) 2.8 kB
"use strict";const i=require("react/jsx-runtime"),v=require("react"),b=require("semantic-ui-react"),T=require("../data/DataProvider.js"),U=require("../data/DataConsumer.js"),A=require("@devgateway/wp-react-lib"),L=require("react-redux"),O=p=>{const{editing:r=!1,unique:n,intl:a,childContent:t,"data-csv":c="","data-no-data-message":l="No data matches your selection","data-view-mode":e="info","data-height":s,"data-dimension1":d,"data-app":u,"data-measures":N={},"data-format":C="{}","data-group":q,"data-filters":F=[],"data-value-type":M}=p,R=a.locale,S=v.useRef(null),w=o=>r?o:decodeURIComponent(o),f=o=>{try{return JSON.parse(w(o))}catch{console.error("error parsing value:"+o)}return null},m=f(C),I=m?{style:m.style==="compacted"?"decimal":m.style,notation:m.style==="compacted"?"compact":"standard",currency:m.currency,minimumFractionDigits:parseInt(m.minimumFractionDigits),maximumFractionDigits:parseInt(m.maximumFractionDigits)}:{notation:"standard",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2},[P,z]=v.useState(e),E=r?e:P,g=r?s-80:s-40,D={},y=f(F)||{};y&&y.forEach&&y.forEach(o=>{o.value!=null&&o.value.filter(x=>x!=null&&x.toString().trim()!="").length>0&&(D[o.param]=o.value)});let j=!1;const h=[];return d!="none"&&h.push(d),u!="csv"&&(!h.length||!f(N)[0])&&(j=!0),i.jsx("div",{ref:S,children:i.jsxs(b.Container,{className:"chart container data-label",style:{height:s+"px"},fluid:!0,children:[i.jsx(T,{style:{height:`${g}px`},params:D,app:u,group:q,csv:c,editing:r,store:[u,n,...h],source:h.join("/"),children:i.jsx(b.Container,{style:{height:`${g}px`},className:"body data-label-body",fluid:!0,children:!j&&i.jsx(U,{children:i.jsx($,{locale:R,dimensions:[...h],valueType:M,intl:a,app:u,format:I,measure:f(N)[0]||null})})})}),i.jsx("br",{}),t&&E=="info"&&i.jsx(b.Container,{fluid:!0,style:{height:g+"px"},className:"body data-label-body",children:i.jsx(A.PostContent,{post:{content:{rendered:t}}})})]})})},$=p=>{const{valueType:r,measure:n,data:a,format:t,intl:c}=p;let l="N/A";if(r==="first"){const e=a.children[0][n];l=c.formatNumber(t.style==="percent"?e/100:e,{...t})}else if(r==="total"){const e=a[n];l=c.formatNumber(t.style==="percent"?e/100:e,{...t})}else if(r==="min"&&!isNaN(a[n])){const e=Math.min(...a.children.map(s=>s[n]));l=c.formatNumber(t.style==="percent"?e/100:e,{...t})}else if(r==="max"&&!isNaN(a[n])){const e=Math.max(...a.children.map(s=>s[n]));l=c.formatNumber(t.style==="percent"?e/100:e,{...t})}else if(r==="avg"&&!isNaN(a[n])){const e=a.children.map(d=>d[n]),s=e.reduce((d,u)=>d+u,0)/e.length;l=c.formatNumber(t.style==="percent"?s/100:s,{...t})}return i.jsx("div",{children:l})},H=(p,r)=>{const{"data-app":n,"data-group":a}=r,t=p.getIn(["data","measures",n,a]);return t?{injectedMeasures:t}:{}},J={},k=L.connect(H,J)(O);module.exports=k;