@automattic/charts 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.7.0] - 2025-01-31
9
+ ### Added
10
+ - Automatic margin for axis labels [#41325]
11
+ - Charts: adds tests and fixes to bar chart component [#41296]
12
+ - Charts: adds tests for line chart component [#41174]
13
+ - Line chart: draw x-axis and ticks [#41346]
14
+ - Line chart: use natural curve [#41293]
15
+ - Y axis non-zero start for line chart [#41291]
16
+
17
+ ### Changed
18
+ - Introduce `children` PieChart property [#41289]
19
+ - Only use area line for line chart [#41292]
20
+ - Updated package dependencies. [#41286]
21
+
8
22
  ## [0.6.0] - 2025-01-23
9
23
  ### Changed
10
24
  - size props renamed to width for semi circle chart [#41270]
@@ -75,6 +89,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
75
89
  - Fixed lints following ESLint rule changes for TS [#40584]
76
90
  - Fixing a bug in Chart storybook data. [#40640]
77
91
 
92
+ [0.7.0]: https://github.com/Automattic/charts/compare/v0.6.0...v0.7.0
78
93
  [0.6.0]: https://github.com/Automattic/charts/compare/v0.5.0...v0.6.0
79
94
  [0.5.0]: https://github.com/Automattic/charts/compare/v0.4.0...v0.5.0
80
95
  [0.4.0]: https://github.com/Automattic/charts/compare/v0.3.0...v0.4.0
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("react/jsx-runtime"),t=require("@visx/axis"),i=require("@visx/event"),a=require("@visx/group"),r=require("@visx/scale"),l=require("@visx/shape"),o=require("@visx/tooltip"),s=require("clsx"),n=require("react"),d=require("../../providers/theme/theme-provider.js"),h=require("../grid-control/grid-control.js"),c=require("../legend/base-legend.js"),p=require("../shared/with-responsive.js"),u=require("../tooltip/base-tooltip.js"),x=require("./bar-chart.module.scss.js");const m=({data:p,margin:m={top:20,right:20,bottom:40,left:40},withTooltips:v=!1,showLegend:g=!1,legendOrientation:b="horizontal",className:j,gridVisibility:q="x",width:f,height:w=400})=>{const y=d.useChartTheme(),{tooltipOpen:L,tooltipLeft:T,tooltipTop:B,tooltipData:M,hideTooltip:N,showTooltip:C}=o.useTooltip(),S=n.useCallback(((e,t,a,r,l)=>{const o=i.localPoint(e);o&&C({tooltipData:{value:t,xLabel:a,yLabel:r,seriesIndex:l},tooltipLeft:o.x,tooltipTop:o.y-10})}),[C]),k=n.useCallback((()=>{N()}),[N]);if(!p?.length)return e.jsx("div",{className:s("bar-chart-empty",x["bat-chart-empty"]),children:"Empty..."});const A=m,D=f-A.left-A.right,G=w-A.top-A.bottom,O=p[0].data?.map((e=>e?.label||"")),V=r.scaleBand({range:[0,D],domain:O,padding:.2}),$=r.scaleBand({range:[0,V.bandwidth()],domain:p.map(((e,t)=>t.toString())),padding:.1}),z=r.scaleLinear({range:[G,0],domain:[0,Math.max(...p.map((e=>Math.max(...e.data.map((e=>e?.value||0))))))]}),E=p.map(((e,t)=>({label:e.label,value:"",color:y.colors[t%y.colors.length]})));return e.jsxs("div",{className:s("bar-chart",j,x["bar-chart"]),children:[e.jsx("svg",{width:f,height:w,children:e.jsxs(a.Group,{left:A.left,top:A.top,children:[e.jsx(h,{width:D,height:G,xScale:V,yScale:z,gridVisibility:q}),p.map(((t,i)=>e.jsx(a.Group,{children:t.data.map((a=>{const r=V(a?.label||"");if(void 0===r)return null;const o=$.bandwidth(),s=r+($(i.toString())??0);return e.jsx(l.Bar,{x:s,y:z(a.value),width:o,height:G-(z(a.value)??0),fill:y.colors[i%y.colors.length],onMouseMove:v?e=>S(e,a.value,a?.label||"",t.label,i):void 0,onMouseLeave:v?k:void 0},`bar-${i}-${a.label}`)}))},i))),e.jsx(t.AxisLeft,{scale:z}),e.jsx(t.AxisBottom,{scale:V,top:G})]})}),v&&L&&M&&e.jsx(u.BaseTooltip,{top:B||0,left:T||0,children:e.jsxs("div",{children:[e.jsx("div",{children:M.yLabel}),e.jsxs("div",{children:[M.xLabel,": ",M.value]})]})}),g&&e.jsx(c.BaseLegend,{items:E,orientation:b,className:x["bar-chart-legend"]})]})};m.displayName="BarChart";var v=p.withResponsive(m);module.exports=v;
1
+ "use strict";var e=require("react/jsx-runtime"),a=require("@visx/axis"),t=require("@visx/event"),i=require("@visx/group"),r=require("@visx/scale"),l=require("@visx/shape"),o=require("@visx/tooltip"),s=require("clsx"),d=require("react"),n=require("../../providers/theme/theme-provider.js"),h=require("../grid-control/grid-control.js"),c=require("../legend/base-legend.js"),p=require("../shared/with-responsive.js"),u=require("../tooltip/base-tooltip.js"),v=require("./bar-chart.module.scss.js");const x=({data:p,margin:x={top:20,right:20,bottom:40,left:40},withTooltips:m=!1,showLegend:b=!1,legendOrientation:g="horizontal",className:j,gridVisibility:q="x",width:f,height:w=400})=>{const L=n.useChartTheme(),{tooltipOpen:N,tooltipLeft:y,tooltipTop:T,tooltipData:B,hideTooltip:M,showTooltip:S}=o.useTooltip(),C=d.useCallback(((e,a,i,r,l)=>{const o=t.localPoint(e);o&&S({tooltipData:{value:a,xLabel:i,yLabel:r,seriesIndex:l},tooltipLeft:o.x,tooltipTop:o.y-10})}),[S]);if(!p?.length)return e.jsx("div",{className:s(v["bar-chart-empty"]),children:"No data available"});if(p.some((e=>e.data.some((e=>null===e.value||void 0===e.value||isNaN(e.value)||!e.label||e.date&&isNaN(e.date.getTime()))))))return e.jsx("div",{className:s(v["bar-chart-error"]),children:"Invalid data"});const A=x,D=f-A.left-A.right,G=w-A.top-A.bottom,I=p[0].data?.map((e=>e?.label||"")),O=r.scaleBand({range:[0,D],domain:I,padding:.2}),V=r.scaleBand({range:[0,O.bandwidth()],domain:p.map(((e,a)=>a.toString())),padding:.1}),$=r.scaleLinear({range:[G,0],domain:[0,Math.max(...p.map((e=>Math.max(...e.data.map((e=>e?.value||0))))))]}),_=p.map(((e,a)=>({label:e.label,value:"",color:L.colors[a%L.colors.length]})));return e.jsxs("div",{className:s("bar-chart",v["bar-chart"],j),"data-testid":"bar-chart",role:"img","aria-label":"bar chart",children:[e.jsx("svg",{width:f,height:w,children:e.jsxs(i.Group,{left:A.left,top:A.top,children:[e.jsx(h,{width:D,height:G,xScale:O,yScale:$,gridVisibility:q}),p.map(((a,t)=>e.jsx(i.Group,{children:a.data.map((i=>{const r=O(i?.label||"");if(void 0===r)return null;const o=V.bandwidth(),s=r+(V(t.toString())??0);return e.jsx(l.Bar,{x:s,y:$(i.value),width:o,height:G-($(i.value)??0),fill:L.colors[t%L.colors.length],onMouseMove:m?e=>C(e,i.value,i?.label||"",a.label,t):void 0,onMouseLeave:m?M:void 0},`bar-${t}-${i.label}`)}))},t))),e.jsx(a.AxisLeft,{scale:$}),e.jsx(a.AxisBottom,{scale:O,top:G})]})}),m&&N&&B&&e.jsx(u.BaseTooltip,{top:T||0,left:y||0,children:e.jsxs("div",{children:[e.jsx("div",{children:B.yLabel}),e.jsxs("div",{children:[B.xLabel,": ",B.value]})]})}),b&&e.jsx(c.BaseLegend,{items:_,orientation:g,className:v["bar-chart__legend"]})]})};x.displayName="BarChart";var m=p.withResponsive(x);module.exports=m;
2
2
  //# sourceMappingURL=bar-chart.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bar-chart.js","sources":["/@automattic/charts/../../../../src/components/bar-chart/bar-chart.tsx"],"sourcesContent":[null],"names":["BarChart","data","margin","top","right","bottom","left","withTooltips","showLegend","legendOrientation","className","gridVisibility","width","height","theme","useChartTheme","tooltipOpen","tooltipLeft","tooltipTop","tooltipData","hideTooltip","showTooltip","useTooltip","handleMouseMove","useCallback","event","value","xLabel","yLabel","seriesIndex","coords","localPoint","x","y","handleMouseLeave","length","_jsx","clsx","styles","margins","xMax","yMax","labels","map","d","label","xScale","scaleBand","range","domain","padding","innerScale","bandwidth","_","i","toString","yScale","scaleLinear","Math","max","series","legendItems","group","index","color","colors","_jsxs","jsxs","children","Group","GridControl","jsx","xPos","undefined","barWidth","barX","Bar","fill","onMouseMove","onMouseLeave","AxisLeft","scale","AxisBottom","BaseTooltip","Legend","BaseLegend","items","orientation","displayName","withResponsive"],"mappings":"8eAyBA,MAAMA,EAAgC,EACrCC,OACAC,SAAS,CAAEC,IAAK,GAAIC,MAAO,GAAIC,OAAQ,GAAIC,KAAM,IACjDC,gBAAe,EACfC,cAAa,EACbC,oBAAoB,aACpBC,YACAC,iBAAiB,IACjBC,QACAC,SAAS,QAET,MAAMC,EAAQC,EAAAA,iBACRC,YAAEA,EAAWC,YAAEA,EAAWC,WAAEA,EAAUC,YAAEA,EAAWC,YAAEA,EAAWC,YAAEA,GACvEC,EAAAA,aAEKC,EAAkBC,EAAAA,aACvB,CACCC,EACAC,EACAC,EACAC,EACAC,KAEA,MAAMC,EAASC,aAAYN,GACpBK,GAEPT,EAAa,CACZF,YAAa,CAAEO,QAAOC,SAAQC,SAAQC,eACtCZ,YAAaa,EAAOE,EACpBd,WAAYY,EAAOG,EAAI,IACrB,GAEJ,CAAEZ,IAGGa,EAAmBV,EAAAA,aAAa,KACrCJ,GAAa,GACX,CAAEA,IAEL,IAAOnB,GAAMkC,OACZ,OAAOC,MAAK,MAAA,CAAA1B,UAAY2B,EAAM,kBAAmBC,EAAQ,0CAG1D,MAAMC,EAAUrC,EACVsC,EAAO5B,EAAQ2B,EAAQjC,KAAOiC,EAAQnC,MACtCqC,EAAO5B,EAAS0B,EAAQpC,IAAMoC,EAAQlC,OAGtCqC,EAASzC,EAAM,GAAIA,MAAM0C,KAAKC,GAAKA,GAAGC,OAAS,KAG/CC,EAASC,EAAAA,UAAqB,CACnCC,MAAO,CAAE,EAAGR,GACZS,OAAQP,EACRQ,QAAS,KAGJC,EAAaJ,EAAAA,UAAW,CAC7BC,MAAO,CAAE,EAAGF,EAAOM,aACnBH,OAAQhD,EAAK0C,KAAK,CAAEU,EAAGC,IAAOA,EAAEC,aAChCL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Of,MAAOhB,QAUZ4C,EAClDM,aAAexE,EAAe2B,OAAmBuC,GAP3C,OAAQ5C,KAAiBe,EAAEC,QASjC,KAtBShB,KA0BdO,MAAC4C,EAAQA,SAAA,CAACC,MAAQzB,IAClBpB,EAAAmC,IAACW,aAAW,CAAAD,MAAQnC,EAAS3C,IAAMsC,SAInClC,GAAgBS,GAAeG,GAChCiB,EAAAA,IAAC+C,EAAAA,YAAY,CAAAhF,IAAMe,GAAc,EAAIZ,KAAOW,GAAe,WAC1DiD,EACCC,KAAA,MAAA,CAAAC,SAAA,CAAAhC,EAAAA,IAAA,MAAA,CAAAgC,SAAOjD,EAAYS,SACnBsC,EAAAC,KAAA,MAAA,CAAAC,SAAA,CACGjD,EAAYQ,YAAYR,EAAYO,cAMxClB,GACD4B,EAAAmC,IAACa,EAAMC,WACN,CAAAC,MAAQzB,EACR0B,YAAc9E,EACdC,UAAY4B,EAAQ,wBAItB,EAGHtC,EAASwF,YAAc,WACvB,IAAeC,EAAAA,EAAAA,eAAiCzF"}
1
+ {"version":3,"file":"bar-chart.js","sources":["/@automattic/charts/../../../../src/components/bar-chart/bar-chart.tsx"],"sourcesContent":[null],"names":["BarChart","data","margin","top","right","bottom","left","withTooltips","showLegend","legendOrientation","className","gridVisibility","width","height","theme","useChartTheme","tooltipOpen","tooltipLeft","tooltipTop","tooltipData","hideTooltip","showTooltip","useTooltip","handleMouseMove","useCallback","event","value","xLabel","yLabel","seriesIndex","coords","localPoint","x","y","length","_jsx","clsx","styles","children","some","series","d","undefined","isNaN","label","date","getTime","margins","xMax","yMax","labels","map","xScale","scaleBand","range","domain","padding","innerScale","bandwidth","_","i","toString","yScale","scaleLinear","Math","max","legendItems","group","index","color","colors","_jsxs","role","jsxs","Group","GridControl","xPos","barWidth","barX","jsx","Bar","fill","onMouseMove","onMouseLeave","AxisLeft","scale","AxisBottom","BaseTooltip","Legend","BaseLegend","items","orientation","displayName","withResponsive"],"mappings":"8eAyBA,MAAMA,EAAgC,EACrCC,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AAS,GAAIJ,EAAOI,MAAOf,QAUZa,EAClDyC,aAAe5E,EAAea,OAAcsB,GAPtC,OAAQb,KAAiBY,EAAEG,QASjC,KAtBSf,KA0BdM,MAACiD,EAAQA,SAAA,CAACC,MAAQvB,IAClB3B,EAAA4C,IAACO,aAAW,CAAAD,MAAQjC,EAASjD,IAAM8C,SAInC1C,GAAgBS,GAAeG,GAChCgB,EAAAA,IAACoD,EAAAA,YAAY,CAAApF,IAAMe,GAAc,EAAIZ,KAAOW,GAAe,WAC1DsD,EACCE,KAAA,MAAA,CAAAnC,SAAA,CAAAH,EAAAA,IAAA,MAAA,CAAAG,SAAOnB,EAAYS,SACnB2C,EAAAE,KAAA,MAAA,CAAAnC,SAAA,CACGnB,EAAYQ,YAAYR,EAAYO,cAMxClB,GACD2B,EAAA4C,IAACS,EAAMC,WACN,CAAAC,MAAQxB,EACRyB,YAAclF,EACdC,UAAY2B,EAAQ,yBAItB,EAGHrC,EAAS4F,YAAc,WACvB,IAAeC,EAAAA,EAAAA,eAAiC7F"}
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("react/jsx-runtime"),t=require("@visx/gradient"),r=require("@visx/xychart"),a=require("clsx");require("react");var i=require("../../providers/theme/theme-provider.js"),s=require("../legend/base-legend.js"),o=require("../shared/with-responsive.js"),l=require("./line-chart.module.scss.js");const n=({tooltipData:t})=>{const r=t?.nearestDatum?.datum;if(!r)return null;const a=Object.entries(t?.datumByKey||{}).map((([e,{datum:t}])=>({key:e,value:t.value}))).sort(((e,t)=>t.value-e.value));return e.jsxs("div",{className:l["line-chart__tooltip"],children:[e.jsx("div",{className:l["line-chart__tooltip-date"],children:r.date.toLocaleDateString()}),a.map((t=>e.jsxs("div",{className:l["line-chart__tooltip-row"],children:[e.jsxs("span",{className:l["line-chart__tooltip-label"],children:[t.key,":"]}),e.jsx("span",{className:l["line-chart__tooltip-value"],children:t.value})]},t.key)))]})},c=e=>new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"});var d=o.withResponsive((({data:o,width:d,height:h,margin:m={top:20,right:20,bottom:40,left:40},className:u,withTooltips:p=!0,showLegend:g=!1,legendOrientation:x="horizontal",withGradientFill:j=!1,options:v={}})=>{const y=i.useChartTheme();if(!o?.length)return e.jsx("div",{className:a("line-chart-empty",l["line-chart-empty"]),children:"Empty..."});const k=o.map(((e,t)=>({label:e.label,value:"",color:y.colors[t%y.colors.length]}))),b={xAccessor:e=>e.date,yAccessor:e=>e.value},T=r.buildChartTheme({backgroundColor:y.backgroundColor,colors:y.colors,gridStyles:y.gridStyles,tickLength:y?.tickLength||0,gridColor:y?.gridColor||"",gridColorDark:y?.gridColorDark||""});return e.jsxs("div",{className:a("line-chart",l["line-chart"],u),children:[e.jsxs(r.XYChart,{theme:T,width:d,height:h,margin:m,xScale:{type:"time"},yScale:{type:"linear",nice:!0},children:[e.jsx(r.AnimatedGrid,{columns:!1,numTicks:4}),e.jsx(r.AnimatedAxis,{orientation:"bottom",numTicks:5,tickFormat:c,...v?.axis?.x}),e.jsx(r.AnimatedAxis,{orientation:"left",numTicks:4,...v?.axis?.y}),o.map(((a,i)=>{const s=a.options?.stroke??T.colors[i%T.colors.length];return e.jsxs(e.Fragment,{children:[e.jsx(t.LinearGradient,{id:`area-gradient-${i+1}`,from:s,to:"white",toOpacity:.1,...a.options?.gradient}),e.jsx(r.AnimatedLineSeries,{dataKey:a?.label,data:a.data,...b,stroke:s,strokeWidth:2},a?.label),j&&e.jsx(r.AnimatedAreaSeries,{dataKey:a?.label,data:a.data,...b,stroke:s,strokeWidth:0,fill:`url(#area-gradient-${i+1})`,renderLine:!1},a?.label)]})})),p&&e.jsx(r.Tooltip,{snapTooltipToDatumX:!0,snapTooltipToDatumY:!0,showSeriesGlyphs:!0,renderTooltip:n})]}),g&&e.jsx(s.BaseLegend,{items:k,orientation:x,className:l["line-chart-legend"]})]})}));module.exports=d;
1
+ "use strict";var e=require("react/jsx-runtime"),t=require("@visx/curve"),a=require("@visx/gradient"),i=require("@visx/xychart"),r=require("clsx"),s=require("react"),l=require("../../providers/theme/theme-provider.js"),o=require("../legend/base-legend.js"),n=require("../shared/with-responsive.js"),c=require("./line-chart.module.scss.js");const d=({tooltipData:t})=>{const a=t?.nearestDatum?.datum;if(!a)return null;const i=Object.entries(t?.datumByKey||{}).map((([e,{datum:t}])=>({key:e,value:t.value}))).sort(((e,t)=>t.value-e.value));return e.jsxs("div",{className:c["line-chart__tooltip"],children:[e.jsx("div",{className:c["line-chart__tooltip-date"],children:a.date.toLocaleDateString()}),i.map((t=>e.jsxs("div",{className:c["line-chart__tooltip-row"],children:[e.jsxs("span",{className:c["line-chart__tooltip-label"],children:[t.key,":"]}),e.jsx("span",{className:c["line-chart__tooltip-value"],children:t.value})]},t.key)))]})},h=e=>new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"});var u=n.withResponsive((({data:n,width:u,height:m,className:p,margin:x,withTooltips:v=!0,showLegend:g=!1,legendOrientation:j="horizontal",withGradientFill:y=!1,options:N={}})=>{const b=l.useChartTheme(),T=s.useMemo((()=>{const e=n?.map((e=>e.options?.stroke??"")).filter(Boolean)??[];return i.buildChartTheme({...b,colors:[...e,...b.colors]})}),[b,n]);x=s.useMemo((()=>{let e={top:0,right:0,bottom:40,left:40};return"right"===N.axis?.y?.orientation&&(e={...e,right:40,left:0}),"top"===N.axis?.x?.orientation&&(e={...e,top:40,bottom:0}),{...e,...x}}),[x,N]);const w=(e=>e?.length?e.some((e=>e.data.some((e=>isNaN(e.value)||null===e.value||void 0===e.value||isNaN(e.date.getTime())))))?"Invalid data":null:"No data available")(n);if(w)return e.jsx("div",{className:r("line-chart",c["line-chart"]),children:w});const q=n.map(((e,t)=>({label:e.label,value:"",color:b.colors[t%b.colors.length]}))),_={xAccessor:e=>e.date,yAccessor:e=>e.value};return e.jsxs("div",{className:r("line-chart",c["line-chart"],p),"data-testid":"line-chart",role:"img","aria-label":"line chart",children:[e.jsxs(i.XYChart,{theme:T,width:u,height:m,margin:x,xScale:{type:"time",...N?.xScale},yScale:{type:"linear",nice:!0,zero:!1,...N?.yScale},children:[e.jsx(i.AnimatedGrid,{columns:!1,numTicks:4}),e.jsx(i.AnimatedAxis,{orientation:"bottom",numTicks:5,tickFormat:h,...N?.axis?.x}),e.jsx(i.AnimatedAxis,{orientation:"left",numTicks:4,...N?.axis?.y}),n.map(((r,s)=>{const l=r.options?.stroke??T.colors[s%T.colors.length];return e.jsxs("g",{children:[y&&e.jsx(a.LinearGradient,{id:`area-gradient-${s+1}`,from:l,to:"white",toOpacity:.1,...r.options?.gradient,"data-testid":"line-gradient"}),e.jsx(i.AnimatedAreaSeries,{dataKey:r?.label,data:r.data,..._,fill:y?`url(#area-gradient-${s+1})`:void 0,renderLine:!0,curve:t.curveNatural},r?.label)]},r?.label||s)})),v&&e.jsx(i.Tooltip,{snapTooltipToDatumX:!0,snapTooltipToDatumY:!0,showSeriesGlyphs:!0,renderTooltip:d})]}),g&&e.jsx(o.BaseLegend,{items:q,orientation:j,className:c["line-chart-legend"]})]})}));module.exports=u;
2
2
  //# sourceMappingURL=line-chart.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"line-chart.js","sources":["/@automattic/charts/../../../../src/components/line-chart/line-chart.tsx"],"sourcesContent":[null],"names":["renderTooltip","tooltipData","nearestDatum","datum","tooltipPoints","Object","entries","datumByKey","map","key","value","sort","a","b","_jsxs","jsxs","className","styles","children","_jsx","date","toLocaleDateString","point","formatDateTick","Date","undefined","month","day","withResponsive","data","width","height","margin","top","right","bottom","left","withTooltips","showLegend","legendOrientation","withGradientFill","options","providerTheme","useChartTheme","length","clsx","legendItems","group","index","label","color","colors","accessors","xAccessor","d","yAccessor","theme","buildChartTheme","backgroundColor","gridStyles","tickLength","gridColor","gridColorDark","XYChart","xScale","type","yScale","nice","jsx","AnimatedGrid","columns","numTicks","AnimatedAxis","orientation","tickFormat","axis","x","y","seriesData","stroke","_Fragment","LinearGradient","id","from","to","toOpacity","gradient","AnimatedLineSeries","dataKey","strokeWidth","AnimatedAre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AAOiD,EAAWjD,QACbuB,EACL2B,OAASA,EACTU,YAAc,GALRX,GAAY7B,OASjBT,GACDrB,EAAAiD,IAACsB,EAAkBA,mBAAA,CAElBF,QAAUV,GAAY7B,MACtBpB,KAAOiD,EAAWjD,QACbuB,EACL2B,OAASA,EACTU,YAAc,EACdE,KAAO,sBAAuB3C,EAAQ,KACtC4C,YAAa,GAPPd,GAAY7B,SAWpB,IAGDZ,GACDlB,EAAAA,IAAC0E,EAAAA,SACAC,qBAAmB,EACnBC,qBACA,EAAAC,oBACAhG,cAAgBA,OAKjBsC,GACDnB,EAAAA,IAAC8E,EAAAA,WACA,CAAAC,MAAQpD,EACR2B,YAAclC,EACdvB,UAAYC,EAAQ,yBAItB"}
1
+ {"version":3,"file":"line-chart.js","sources":["/@automattic/charts/../../../../src/components/line-chart/line-chart.tsx"],"sourcesContent":[null],"names":["renderTooltip","tooltipData","nearestDatum","datum","tooltipPoints","Object","entries","datumByKey","map","key","value","sort","a","b","_jsxs","jsxs","className","styles","children","_jsx","date","toLocaleDateString","point","formatDateTick","Date","undefined","month","day","withResponsive","data","width","height","margin","withTooltips","showLegend","legendOrientation","withGradientFill","options","providerTheme","useChartTheme","theme","useMemo","seriesColors","series","stroke","filter","Boolean","buildChartTheme","colors","defaultMargin","top","right","bottom","left","axis","y","orientation","x","error","length","some","isNaN","getTime","validateData","clsx","legendItems","group","index","label","color","accessors","xAccessor","d","yAccessor","role","XYChart","xScale","type","yScale","nice","zero","AnimatedGrid","columns","numTicks","jsx","AnimatedAxis","tickFormat","seriesData","LinearGradient","id","from","to","toOpacity","gradient","AnimatedAreaSeries","dataKey","fill","renderLine","curve","curveNatural","Tooltip","snapTooltipToDatumX","snapTooltipToDatumY","showSeriesGlyphs","Legend","items"],"mappings":"mVAiCA,MAAMA,EAAgB,EACrBC,kBAUA,MAAMC,EAAeD,GAAaC,cAAcC,MAChD,IAAOD,EAAe,OAAO,KAE7B,MAAME,EAAgCC,OAAOC,QAASL,GAAaM,YAAc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C,IAElE1B,EAAKrB,KAAK,CAAE+E,EAAYpB,KACzB,MAAMvB,EAAS2C,EAAWlD,SAASO,QAAUJ,EAAMQ,OAAQmB,EAAQ3B,EAAMQ,OAAOW,QAChF,OACC7C,EACGC,KAAA,IAAA,CAAAG,SAAA,CAAAkB,GACDjB,EAAAA,IAACqE,EAAcA,eACd,CAAAC,GAAK,iBAAkBtB,EAAQ,IAC/BuB,KAAO9C,EACP+C,GAAG,QACHC,UAAY,MACPL,EAAWlD,SAASwD,uBACb,kBAGd1E,EAAAiE,IAACU,qBAEA,CAAAC,QAAUR,GAAYnB,MACtBvC,KAAO0D,EAAW1D,QACbyC,EACL0B,KAAO5D,EAAmB,sBAAuB+B,EAAQ,UAAQ1C,EACjEwE,YAAa,EACbC,MAAQC,EAAAA,cANFZ,GAAYnB,SAZXmB,GAAYnB,OAASD,EAqB7B,IAGDlC,GACDd,EAAAA,IAACiF,EAAAA,SACAC,qBAAmB,EACnBC,qBACA,EAAAC,oBACAvG,cAAgBA,OAKjBkC,GACDf,EAAAA,IAACqF,EAAAA,WACA,CAAAC,MAAQxC,EACRT,YAAcrB,EACdnB,UAAYC,EAAQ,yBAItB"}
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("react/jsx-runtime"),a=require("@visx/group"),s=require("@visx/shape"),t=require("clsx");require("react");var r=require("../../hooks/use-chart-mouse-handler.js"),i=require("../../providers/theme/theme-provider.js"),l=require("../../providers/theme/themes.js"),o=require("../legend/base-legend.js"),n=require("../shared/with-responsive.js"),d=require("../tooltip/base-tooltip.js"),c=require("./pie-chart.module.scss.js");const u=({data:n,withTooltips:u=!1,className:h,showLegend:p,legendOrientation:m,size:v,thickness:g=1,padding:x=20,gapScale:j=0,cornerScale:f=0})=>{const q=i.useChartTheme(),{onMouseMove:M,onMouseLeave:b,tooltipOpen:w,tooltipData:N,tooltipLeft:T,tooltipTop:V}=r({withTooltips:u}),{isValid:A,message:B}=(e=>{if(!e.length)return{isValid:!1,message:"No data available"};if(e.some((e=>e.percentage<0||e.value<0)))return{isValid:!1,message:"Invalid data: Negative values are not allowed"};const a=e.reduce(((e,a)=>e+a.percentage),0);return Math.abs(a-100)>.01?{isValid:!1,message:"Invalid percentage total: Must equal 100"}:{isValid:!0,message:""}})(n);if(!A)return e.jsx("div",{className:t("pie-chart",c["pie-chart"],h),children:e.jsx("div",{className:c["error-message"],children:B})});const L=v,R=v,k=Math.min(L,R)/2,y=L/2,C=R/2,S=j*(2*Math.PI/n.length),I=k-x,P=I*(1-g),$=(I-P)/2,z=f?Math.min(f*I,$):0,O=n.map(((e,a)=>({...e,index:a}))),D={value:e=>e.value,fill:e=>e?.color||q.colors[e.index]},E=n.map(((e,a)=>({label:e.label,value:e.value.toString(),color:q.colors[a%q.colors.length]})));return e.jsxs("div",{className:t("pie-chart",c["pie-chart"],h),children:[e.jsx("svg",{viewBox:`0 0 ${v} ${v}`,preserveAspectRatio:"xMidYMid meet",width:v,height:v,children:e.jsx(a.Group,{top:C,left:y,children:e.jsx(s.Pie,{data:O,pieValue:D.value,outerRadius:I,innerRadius:P,padAngle:S,cornerRadius:z,children:a=>a.arcs.map(((s,t)=>{const[r,i]=a.path.centroid(s),o=s.endAngle-s.startAngle>=.25,n=e=>M(e,s.data),d={d:a.path(s)||"",fill:D.fill(s.data)};return u&&(d.onMouseMove=n,d.onMouseLeave=b),e.jsxs("g",{children:[e.jsx("path",{...d}),o&&e.jsx("text",{x:r,y:i,dy:".33em",fill:q.labelBackgroundColor||l.defaultTheme.labelBackgroundColor,fontSize:12,textAnchor:"middle",pointerEvents:"none",children:s.data.label})]},`arc-${t}`)}))})})}),p&&e.jsx(o.BaseLegend,{items:E,orientation:m,className:c["pie-chart-legend"]}),u&&w&&N&&e.jsx(d.BaseTooltip,{data:N,top:V||0,left:T||0,style:{transform:"translate(-50%, -100%)"}})]})};u.displayName="PieChart";var h=n.withResponsive(u);module.exports=h;
1
+ "use strict";var e=require("react/jsx-runtime"),a=require("@visx/group"),s=require("@visx/shape"),r=require("clsx");require("react");var t=require("../../hooks/use-chart-mouse-handler.js"),i=require("../../providers/theme/theme-provider.js"),l=require("../../providers/theme/themes.js"),o=require("../legend/base-legend.js"),n=require("../shared/with-responsive.js"),d=require("../tooltip/base-tooltip.js"),c=require("./pie-chart.module.scss.js");const u=({data:n,withTooltips:u=!1,className:h,showLegend:p,legendOrientation:m,size:v,thickness:g=1,padding:x=20,gapScale:j=0,cornerScale:f=0,children:q=null})=>{const M=i.useChartTheme(),{onMouseMove:b,onMouseLeave:w,tooltipOpen:N,tooltipData:T,tooltipLeft:V,tooltipTop:A}=t({withTooltips:u}),{isValid:B,message:L}=(e=>{if(!e.length)return{isValid:!1,message:"No data available"};if(e.some((e=>e.percentage<0||e.value<0)))return{isValid:!1,message:"Invalid data: Negative values are not allowed"};const a=e.reduce(((e,a)=>e+a.percentage),0);return Math.abs(a-100)>.01?{isValid:!1,message:"Invalid percentage total: Must equal 100"}:{isValid:!0,message:""}})(n);if(!B)return e.jsx("div",{className:r("pie-chart",c["pie-chart"],h),children:e.jsx("div",{className:c["error-message"],children:L})});const R=v,k=v,y=Math.min(R,k)/2,C=R/2,S=k/2,I=j*(2*Math.PI/n.length),P=y-x,$=P*(1-g),z=(P-$)/2,O=f?Math.min(f*P,z):0,D=n.map(((e,a)=>({...e,index:a}))),E={value:e=>e.value,fill:e=>e?.color||M.colors[e.index]},G=n.map(((e,a)=>({label:e.label,value:e.value.toString(),color:M.colors[a%M.colors.length]})));return e.jsxs("div",{className:r("pie-chart",c["pie-chart"],h),children:[e.jsx("svg",{viewBox:`0 0 ${v} ${v}`,preserveAspectRatio:"xMidYMid meet",width:v,height:v,children:e.jsxs(a.Group,{top:S,left:C,children:[e.jsx(s.Pie,{data:D,pieValue:E.value,outerRadius:P,innerRadius:$,padAngle:I,cornerRadius:O,children:a=>a.arcs.map(((s,r)=>{const[t,i]=a.path.centroid(s),o=s.endAngle-s.startAngle>=.25,n=e=>b(e,s.data),d={d:a.path(s)||"",fill:E.fill(s.data)};return u&&(d.onMouseMove=n,d.onMouseLeave=w),e.jsxs("g",{children:[e.jsx("path",{...d}),o&&e.jsx("text",{x:t,y:i,dy:".33em",fill:M.labelBackgroundColor||l.defaultTheme.labelBackgroundColor,fontSize:12,textAnchor:"middle",pointerEvents:"none",children:s.data.label})]},`arc-${r}`)}))}),q]})}),p&&e.jsx(o.BaseLegend,{items:G,orientation:m,className:c["pie-chart-legend"]}),u&&N&&T&&e.jsx(d.BaseTooltip,{data:T,top:A||0,left:V||0,style:{transform:"translate(-50%, -100%)"}})]})};u.displayName="PieChart";var h=n.withResponsive(u);module.exports=h;
2
2
  //# sourceMappingURL=pie-chart.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pie-chart.js","sources":["/@automattic/charts/../../../../src/components/pie-chart/pie-chart.tsx"],"sourcesContent":[null],"names":["PieChart","data","withTooltips","className","showLegend","legendOrientation","size","thickness","padding","gapScale","cornerScale","providerTheme","useChartTheme","onMouseMove","onMouseLeave","tooltipOpen","tooltipData","tooltipLeft","tooltipTop","useChartMouseHandler","isValid","message","length","some","item","percentage","value","totalPercentage","reduce","sum","Math","abs","validateData","_jsx","jsx","clsx","styles","children","width","height","radius","min","centerX","centerY","padAngle","PI","outerRadius","innerRadius","maxCornerRadius","cornerRadius","dataWithIndex","map","d","index","accessors","fill","color","colors","legendItems","label","toString","_jsxs","viewBox","preserveAspectRatio","Group","top","left","Pie","pieValue","pie","arcs","arc","centroidX","centroidY","path","centroid","hasSpaceForLabel","endAngle","startAngle","handleMouseMove","event","pathProps","jsxs","x","y","dy","labelBackgroundColor","defaultTheme","fontSize","textAnchor","pointerEvents","Legend","items","orientation","BaseTooltip","style","transform","displayName","withResponsive"],"mappings":"+bAyDA,MA2BMA,EAAW,EAChBC,OACAC,gBAAe,EACfC,YACAC,aACAC,oBACAC,OACAC,YAAY,EACZC,UAAU,GACVC,WAAW,EACXC,cAAc,MAEd,MAAMC,EAAgBC,EAAAA,iBAChBC,YAAEA,EAAWC,aAAEA,E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sBAIpBlC,GAAgBa,GAAeC,GAChCiB,MAAC6D,EAAWA,YAAA,CACX7F,KAAOe,EACPiD,IAAM/C,GAAc,EACpBgD,KAAOjD,GAAe,EACtB8E,MAAQ,CACPC,UAAW,8BAKd,EAGHhG,EAASiG,YAAc,WACvB,IAAeC,EAAAA,EAAAA,eAAiClG"}
1
+ {"version":3,"file":"pie-chart.js","sources":["/@automattic/charts/../../../../src/components/pie-chart/pie-chart.tsx"],"sourcesContent":[null],"names":["PieChart","data","withTooltips","className","showLegend","legendOrientation","size","thickness","padding","gapScale","cornerScale","children","providerTheme","useChartTheme","onMouseMove","onMouseLeave","tooltipOpen","tooltipData","tooltipLeft","tooltipTop","useChartMouseHandler","isValid","message","length","some","item","percentage","value","totalPercentage","reduce","sum","Math","abs","validateData","_jsx","jsx","clsx","styles","width","height","radius","min","centerX","centerY","padAngle","PI","outerRadius","innerRadius","maxCornerRadius","cornerRadius","dataWithIndex","map","d","index","accessors","fill","color","colors","legendItems","label","toString","_jsxs","viewBox","preserveAspectRatio","Group","top","left","Pie","pieValue","pie","arcs","arc","centroidX","centroidY","path","centroid","hasSpaceForLabel","endAngle","startAngle","handleMouseMove","event","pathProps","jsxs","x","y","dy","labelBackgroundColor","defaultTheme","fontSize","textAnchor","pointerEvents","Legend","BaseLegend","items","orientation","BaseTooltip","style","transform","displayName","withResponsive"],"mappings":"+bA8DA,MA2BMA,EAAW,EAChBC,OACAC,gBAAe,EACfC,YACAC,aACAC,oBACAC,OACAC,YAAY,EACZC,UAAU,GACVC,WAAW,EACXC,cAAc,EACdC,WAAW,SAEX,MAAMC,EAAgBC,EAAAA,iBAChBC,YAAEA,EAAWC,aAAEA,EAAYC,YAAEA,EAAWC,YAAEA,EAAWC,YAAEA,EAAWC,WAAEA,GACzEC,EAAsB,CACrBlB,kBAGImB,QAAEA,EAAOC,QAAEA,GA9CG,CAAErB,IACtB,IAAOA,EAAKsB,OACX,MAAO,CAAEF,SAAS,EAAOC,QAAS,qBAKnC,GA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ACvB,IAAeC,EAAAA,EAAAA,eAAiCnG"}
@@ -1,2 +1,2 @@
1
- "use strict";exports.defaultTheme={backgroundColor:"#FFFFFF",labelBackgroundColor:"#FFFFFF",colors:["#98C8DF","#006DAB","#A6DC80","#1F9828","#FF8C8F"],gridStyles:{stroke:"#787C82",strokeWidth:1},tickLength:0,gridColor:"",gridColorDark:""};
1
+ "use strict";exports.defaultTheme={backgroundColor:"#FFFFFF",labelBackgroundColor:"#FFFFFF",colors:["#98C8DF","#006DAB","#A6DC80","#1F9828","#FF8C8F"],gridStyles:{stroke:"#DCDCDE",strokeWidth:1},tickLength:4,gridColor:"",gridColorDark:"",xTickLineStyles:{stroke:"black"},xAxisLineStyles:{stroke:"#DCDCDE",strokeWidth:1}};
2
2
  //# sourceMappingURL=themes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"themes.js","sources":["/@automattic/charts/../../../../src/providers/theme/themes.ts"],"sourcesContent":[null],"names":["backgroundColor","labelBackgroundColor","colors","gridStyles","stroke","strokeWidth","tickLength","gridColor","gridColorDark"],"mappings":"kCAKiC,CAChCA,gBAAiB,UACjBC,qBAAsB,UACtBC,OAAQ,CAAE,UAAW,UAAW,UAAW,UAAW,WACtDC,WAAY,CACXC,OAAQ,UACRC,YAAa,GAEdC,WAAY,EACZC,UAAW,GACXC,cAAe"}
1
+ {"version":3,"file":"themes.js","sources":["/@automattic/charts/../../../../src/providers/theme/themes.ts"],"sourcesContent":[null],"names":["backgroundColor","labelBackgroundColor","colors","gridStyles","stroke","strokeWidth","tickLength","gridColor","gridColorDark","xTickLineStyles","xAxisLineStyles"],"mappings":"kCAKiC,CAChCA,gBAAiB,UACjBC,qBAAsB,UACtBC,OAAQ,CAAE,UAAW,UAAW,UAAW,UAAW,WACtDC,WAAY,CACXC,OAAQ,UACRC,YAAa,GAEdC,WAAY,EACZC,UAAW,GACXC,cAAe,GACfC,gBAAiB,CAAEL,OAAQ,SAC3BM,gBAAiB,CAAEN,OAAQ,UAAWC,YAAa"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { Orientation } from '@visx/axis';
3
+ import { ScaleType, scaleOrdinal } from '@visx/scale';
4
+ import { LineStyles } from '@visx/xychart';
3
5
  import { CSSProperties, ComponentType, ReactNode, FC } from 'react';
4
- import { scaleOrdinal } from '@visx/scale';
5
6
 
6
7
  type ValueOf<T> = T[keyof T];
7
8
  declare type OrientationType = ValueOf<typeof Orientation>;
@@ -11,8 +12,8 @@ type DataPoint = {
11
12
  };
12
13
  type DataPointDate = {
13
14
  date: Date;
15
+ value: number | null;
14
16
  label?: string;
15
- value: number;
16
17
  };
17
18
  type SeriesData = {
18
19
  group?: string;
@@ -67,6 +68,10 @@ type ChartTheme = {
67
68
  gridColor: string;
68
69
  /** Color of the grid lines in dark mode */
69
70
  gridColorDark: string;
71
+ /** Styles for x-axis tick lines */
72
+ xTickLineStyles?: LineStyles;
73
+ /** Styles for x-axis line */
74
+ xAxisLineStyles?: LineStyles;
70
75
  };
71
76
  declare type AxisOptions = {
72
77
  orientation?: OrientationType;
@@ -125,6 +130,13 @@ type BaseChartProps<T = DataPoint | DataPointDate> = {
125
130
  * More options for the chart.
126
131
  */
127
132
  options?: {
133
+ yScale?: {
134
+ type?: ScaleType;
135
+ zero?: boolean;
136
+ };
137
+ xScale?: {
138
+ type?: ScaleType;
139
+ };
128
140
  axis?: {
129
141
  x?: AxisOptions;
130
142
  y?: AxisOptions;
@@ -134,7 +146,7 @@ type BaseChartProps<T = DataPoint | DataPointDate> = {
134
146
 
135
147
  interface BarChartProps extends BaseChartProps<SeriesData[]> {
136
148
  }
137
- declare const _default$3: (props: Omit<BarChartProps, "width" | "height" | "size">) => react_jsx_runtime.JSX.Element;
149
+ declare const _default$3: (props: Omit<BarChartProps, "height" | "width" | "size">) => react_jsx_runtime.JSX.Element;
138
150
 
139
151
  interface LineChartProps extends BaseChartProps<SeriesData[]> {
140
152
  margin?: {
@@ -145,7 +157,7 @@ interface LineChartProps extends BaseChartProps<SeriesData[]> {
145
157
  };
146
158
  withGradientFill: boolean;
147
159
  }
148
- declare const _default$2: (props: Omit<LineChartProps, "width" | "height" | "size">) => react_jsx_runtime.JSX.Element;
160
+ declare const _default$2: (props: Omit<LineChartProps, "height" | "width" | "size">) => react_jsx_runtime.JSX.Element;
149
161
 
150
162
  type OmitBaseChartProps = Omit<BaseChartProps<DataPointPercentage[]>, 'width' | 'height'>;
151
163
  interface PieChartProps extends OmitBaseChartProps {
@@ -177,8 +189,12 @@ interface PieChartProps extends OmitBaseChartProps {
177
189
  * A value between 0 and 1, where 0 means no corner radius.
178
190
  */
179
191
  cornerScale?: number;
192
+ /**
193
+ * Use the children prop to render additional elements on the chart.
194
+ */
195
+ children?: React.ReactNode;
180
196
  }
181
- declare const _default$1: (props: Omit<PieChartProps, "width" | "height" | "size">) => react_jsx_runtime.JSX.Element;
197
+ declare const _default$1: (props: Omit<PieChartProps, "height" | "width" | "size">) => react_jsx_runtime.JSX.Element;
182
198
 
183
199
  interface PieSemiCircleChartProps extends BaseChartProps<DataPointPercentage[]> {
184
200
  /**
@@ -203,7 +219,7 @@ interface PieSemiCircleChartProps extends BaseChartProps<DataPointPercentage[]>
203
219
  */
204
220
  clockwise?: boolean;
205
221
  }
206
- declare const _default: (props: Omit<PieSemiCircleChartProps, "width" | "height" | "size">) => react_jsx_runtime.JSX.Element;
222
+ declare const _default: (props: Omit<PieSemiCircleChartProps, "height" | "width" | "size">) => react_jsx_runtime.JSX.Element;
207
223
 
208
224
  type TooltipData = {
209
225
  label: string;
@@ -1,2 +1,2 @@
1
- import{jsx as t,jsxs as o}from"react/jsx-runtime";import{AxisLeft as e,AxisBottom as i}from"@visx/axis";import{localPoint as a}from"@visx/event";import{Group as r}from"@visx/group";import{scaleBand as l,scaleLinear as s}from"@visx/scale";import{Bar as m}from"@visx/shape";import{useTooltip as p}from"@visx/tooltip";import n from"clsx";import{useCallback as d}from"react";import{useChartTheme as h}from"../../providers/theme/theme-provider.js";import c from"../grid-control/grid-control.js";import{BaseLegend as v}from"../legend/base-legend.js";import{withResponsive as g}from"../shared/with-responsive.js";import{BaseTooltip as b}from"../tooltip/base-tooltip.js";import f from"./bar-chart.module.scss.js";const x=({data:g,margin:x={top:20,right:20,bottom:40,left:40},withTooltips:u=!1,showLegend:y=!1,legendOrientation:w="horizontal",className:L,gridVisibility:j="x",width:M,height:N=400})=>{const T=h(),{tooltipOpen:S,tooltipLeft:D,tooltipTop:O,tooltipData:V,hideTooltip:$,showTooltip:z}=p(),B=d(((t,o,e,i,r)=>{const l=a(t);l&&z({tooltipData:{value:o,xLabel:e,yLabel:i,seriesIndex:r},tooltipLeft:l.x,tooltipTop:l.y-10})}),[z]),C=d((()=>{$()}),[$]);if(!g?.length)return t("div",{className:n("bar-chart-empty",f["bat-chart-empty"]),children:"Empty..."});const E=x,I=M-E.left-E.right,k=N-E.top-E.bottom,q=g[0].data?.map((t=>t?.label||"")),A=l({range:[0,I],domain:q,padding:.2}),F=l({range:[0,A.bandwidth()],domain:g.map(((t,o)=>o.toString())),padding:.1}),G=s({range:[k,0],domain:[0,Math.max(...g.map((t=>Math.max(...t.data.map((t=>t?.value||0))))))]}),H=g.map(((t,o)=>({label:t.label,value:"",color:T.colors[o%T.colors.length]})));return o("div",{className:n("bar-chart",L,f["bar-chart"]),children:[t("svg",{width:M,height:N,children:o(r,{left:E.left,top:E.top,children:[t(c,{width:I,height:k,xScale:A,yScale:G,gridVisibility:j}),g.map(((o,e)=>t(r,{children:o.data.map((i=>{const a=A(i?.label||"");if(void 0===a)return null;const r=F.bandwidth(),l=a+(F(e.toString())??0);return t(m,{x:l,y:G(i.value),width:r,height:k-(G(i.value)??0),fill:T.colors[e%T.colors.length],onMouseMove:u?t=>B(t,i.value,i?.label||"",o.label,e):void 0,onMouseLeave:u?C:void 0},`bar-${e}-${i.label}`)}))},e))),t(e,{scale:G}),t(i,{scale:A,top:k})]})}),u&&S&&V&&t(b,{top:O||0,left:D||0,children:o("div",{children:[t("div",{children:V.yLabel}),o("div",{children:[V.xLabel,": ",V.value]})]})}),y&&t(v,{items:H,orientation:w,className:f["bar-chart-legend"]})]})};x.displayName="BarChart";var u=g(x);export{u as default};
1
+ import{jsx as t,jsxs as a}from"react/jsx-runtime";import{AxisLeft as e,AxisBottom as o}from"@visx/axis";import{localPoint as i}from"@visx/event";import{Group as r}from"@visx/group";import{scaleBand as l,scaleLinear as s}from"@visx/scale";import{Bar as d}from"@visx/shape";import{useTooltip as m}from"@visx/tooltip";import n from"clsx";import{useCallback as p}from"react";import{useChartTheme as h}from"../../providers/theme/theme-provider.js";import c from"../grid-control/grid-control.js";import{BaseLegend as v}from"../legend/base-legend.js";import{withResponsive as b}from"../shared/with-responsive.js";import{BaseTooltip as g}from"../tooltip/base-tooltip.js";import f from"./bar-chart.module.scss.js";const u=({data:b,margin:u={top:20,right:20,bottom:40,left:40},withTooltips:x=!1,showLegend:N=!1,legendOrientation:w="horizontal",className:y,gridVisibility:L="x",width:j,height:T=400})=>{const M=h(),{tooltipOpen:S,tooltipLeft:D,tooltipTop:I,tooltipData:O,hideTooltip:V,showTooltip:$}=m(),_=p(((t,a,e,o,r)=>{const l=i(t);l&&$({tooltipData:{value:a,xLabel:e,yLabel:o,seriesIndex:r},tooltipLeft:l.x,tooltipTop:l.y-10})}),[$]);if(!b?.length)return t("div",{className:n(f["bar-chart-empty"]),children:"No data available"});if(b.some((t=>t.data.some((t=>null===t.value||void 0===t.value||isNaN(t.value)||!t.label||t.date&&isNaN(t.date.getTime()))))))return t("div",{className:n(f["bar-chart-error"]),children:"Invalid data"});const z=u,B=j-z.left-z.right,C=T-z.top-z.bottom,k=b[0].data?.map((t=>t?.label||"")),q=l({range:[0,B],domain:k,padding:.2}),A=l({range:[0,q.bandwidth()],domain:b.map(((t,a)=>a.toString())),padding:.1}),E=s({range:[C,0],domain:[0,Math.max(...b.map((t=>Math.max(...t.data.map((t=>t?.value||0))))))]}),F=b.map(((t,a)=>({label:t.label,value:"",color:M.colors[a%M.colors.length]})));return a("div",{className:n("bar-chart",f["bar-chart"],y),"data-testid":"bar-chart",role:"img","aria-label":"bar chart",children:[t("svg",{width:j,height:T,children:a(r,{left:z.left,top:z.top,children:[t(c,{width:B,height:C,xScale:q,yScale:E,gridVisibility:L}),b.map(((a,e)=>t(r,{children:a.data.map((o=>{const i=q(o?.label||"");if(void 0===i)return null;const r=A.bandwidth(),l=i+(A(e.toString())??0);return t(d,{x:l,y:E(o.value),width:r,height:C-(E(o.value)??0),fill:M.colors[e%M.colors.length],onMouseMove:x?t=>_(t,o.value,o?.label||"",a.label,e):void 0,onMouseLeave:x?V:void 0},`bar-${e}-${o.label}`)}))},e))),t(e,{scale:E}),t(o,{scale:q,top:C})]})}),x&&S&&O&&t(g,{top:I||0,left:D||0,children:a("div",{children:[t("div",{children:O.yLabel}),a("div",{children:[O.xLabel,": ",O.value]})]})}),N&&t(v,{items:F,orientation:w,className:f["bar-chart__legend"]})]})};u.displayName="BarChart";var x=b(u);export{x as default};
2
2
  //# sourceMappingURL=bar-chart.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bar-chart.js","sources":["../../../../src/components/bar-chart/bar-chart.tsx"],"sourcesContent":[null],"names":["BarChart","data","margin","top","right","bottom","left","withTooltips","showLegend","legendOrientation","className","gridVisibility","width","height","theme","useChartTheme","tooltipOpen","tooltipLeft","tooltipTop","tooltipData","hideTooltip","showTooltip","useTooltip","handleMouseMove","useCallback","event","value","xLabel","yLabel","seriesIndex","coords","localPoint","x","y","handleMouseLeave","length","_jsx","clsx","styles","margins","xMax","yMax","labels","map","d","label","xScale","scaleBand","range","domain","padding","innerScale","bandwidth","_","i","toString","yScale","scaleLinear","Math","max","series","legendItems","group","index","color","colors","_jsxs","children","Group","GridControl","xPos","undefined","barWidth","barX","Bar","fill","onMouseMove","onMouseLeave","AxisLeft","scale","AxisBottom","BaseTooltip","Legend","items","orientation","displayName","barChart","withResponsive"],"mappings":"isBAyBA,MAAMA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AOW,GAAe,WAC1DiD,EACC,MAAA,CAAAC,SAAA,CAAA/B,EAAA,MAAA,CAAA+B,SAAOhD,EAAYS,SACnBsC,EAAA,MAAA,CAAAC,SAAA,CACGhD,EAAYQ,YAAYR,EAAYO,cAMxClB,GACD4B,EAAC8C,EACA,CAAAC,MAAQtB,EACRuB,YAAc3E,EACdC,UAAY4B,EAAQ,wBAItB,EAGHtC,EAASqF,YAAc,WACvB,IAAeC,EAAAC,EAAiCvF"}
1
+ {"version":3,"file":"bar-chart.js","sources":["../../../../src/components/bar-chart/bar-chart.tsx"],"sourcesContent":[null],"names":["BarChart","data","margin","top","right","bottom","left","withTooltips","showLegend","legendOrientation","className","gridVisibility","width","height","theme","useChartTheme","tooltipOpen","tooltipLeft","tooltipTop","tooltipData","hideTooltip","showTooltip","useTooltip","handleMouseMove","useCallback","event","value","xLabel","yLabel","seriesIndex","coords","localPoint","x","y","length","_jsx","clsx","styles","children","some","series","d","undefined","isNaN","label","date","getTime","margins","xMax","yMax","labels","map","xScale","scaleBand","range","domain","padding","innerScale","bandwidth","_","i","toString","yScale","scaleLinear","Math","max","legendItems","group","index","color","colors","_jsxs","role","Group","GridControl","xPos","barWidth","barX","Bar","fill","onMouseMove","onMouseLeave","AxisLeft","scale","AxisBottom","BaseTooltip","Legend","items","orientation","displayName","barChart","withResponsive"],"mappings":"isBAyBA,MAAMA,EAAgC,EACrCC,OACAC,SAAS,CAAEC,IAAK,GAAIC,MAAO,GAAIC,OAAQ,GAAIC,KAAM,IACjDC,gBAAe,EACfC,cAAa,EACbC,oBAAoB,aACpBC,YACAC,iBAAiB,IACjBC,QACAC,SAAS,QAET,MAAMC,EAAQC,KACRC,YAAEA,EAAWC,YAAEA,EAAWC,WAAEA,EAAUC,YAAEA,EAAWC,YAAEA,EAAWC,YAAEA,GACvEC,IAEKC,EAAkBC,GACvB,CACCC,EACAC,EACAC,EACAC,EACAC,KAEA,MAAMC,EAASC,EAAYN,GACpBK,GACPT,EAAa,CACZF,YAA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,CAAAC,MAAQrB,EACRsB,YAAc/E,EACdC,UAAY2B,EAAQ,yBAItB,EAGHrC,EAASyF,YAAc,WACvB,IAAeC,EAAAC,EAAiC3F"}
@@ -1,2 +1,2 @@
1
- import{jsx as t,jsxs as e,Fragment as o}from"react/jsx-runtime";import{LinearGradient as r}from"@visx/gradient";import{buildChartTheme as a,XYChart as i,AnimatedGrid as l,AnimatedAxis as n,AnimatedLineSeries as s,AnimatedAreaSeries as c,Tooltip as d}from"@visx/xychart";import m from"clsx";import"react";import{useChartTheme as h}from"../../providers/theme/theme-provider.js";import{BaseLegend as p}from"../legend/base-legend.js";import{withResponsive as u}from"../shared/with-responsive.js";import g from"./line-chart.module.scss.js";const y=({tooltipData:o})=>{const r=o?.nearestDatum?.datum;if(!r)return null;const a=Object.entries(o?.datumByKey||{}).map((([t,{datum:e}])=>({key:t,value:e.value}))).sort(((t,e)=>e.value-t.value));return e("div",{className:g["line-chart__tooltip"],children:[t("div",{className:g["line-chart__tooltip-date"],children:r.date.toLocaleDateString()}),a.map((o=>e("div",{className:g["line-chart__tooltip-row"],children:[e("span",{className:g["line-chart__tooltip-label"],children:[o.key,":"]}),t("span",{className:g["line-chart__tooltip-value"],children:o.value})]},o.key)))]})},v=t=>new Date(t).toLocaleDateString(void 0,{month:"short",day:"numeric"});var k=u((({data:u,width:k,height:f,margin:b={top:20,right:20,bottom:40,left:40},className:x,withTooltips:w=!0,showLegend:_=!1,legendOrientation:D="horizontal",withGradientFill:N=!1,options:T={}})=>{const S=h();if(!u?.length)return t("div",{className:m("line-chart-empty",g["line-chart-empty"]),children:"Empty..."});const j=u.map(((t,e)=>({label:t.label,value:"",color:S.colors[e%S.colors.length]}))),C={xAccessor:t=>t.date,yAccessor:t=>t.value},L=a({backgroundColor:S.backgroundColor,colors:S.colors,gridStyles:S.gridStyles,tickLength:S?.tickLength||0,gridColor:S?.gridColor||"",gridColorDark:S?.gridColorDark||""});return e("div",{className:m("line-chart",g["line-chart"],x),children:[e(i,{theme:L,width:k,height:f,margin:b,xScale:{type:"time"},yScale:{type:"linear",nice:!0},children:[t(l,{columns:!1,numTicks:4}),t(n,{orientation:"bottom",numTicks:5,tickFormat:v,...T?.axis?.x}),t(n,{orientation:"left",numTicks:4,...T?.axis?.y}),u.map(((a,i)=>{const l=a.options?.stroke??L.colors[i%L.colors.length];return e(o,{children:[t(r,{id:`area-gradient-${i+1}`,from:l,to:"white",toOpacity:.1,...a.options?.gradient}),t(s,{dataKey:a?.label,data:a.data,...C,stroke:l,strokeWidth:2},a?.label),N&&t(c,{dataKey:a?.label,data:a.data,...C,stroke:l,strokeWidth:0,fill:`url(#area-gradient-${i+1})`,renderLine:!1},a?.label)]})})),w&&t(d,{snapTooltipToDatumX:!0,snapTooltipToDatumY:!0,showSeriesGlyphs:!0,renderTooltip:y})]}),_&&t(p,{items:j,orientation:D,className:g["line-chart-legend"]})]})}));export{k as default};
1
+ import{jsx as e,jsxs as t}from"react/jsx-runtime";import{curveNatural as a}from"@visx/curve";import{LinearGradient as i}from"@visx/gradient";import{buildChartTheme as o,XYChart as r,AnimatedGrid as l,AnimatedAxis as n,AnimatedAreaSeries as s,Tooltip as c}from"@visx/xychart";import m from"clsx";import{useMemo as d}from"react";import{useChartTheme as h}from"../../providers/theme/theme-provider.js";import{BaseLegend as p}from"../legend/base-legend.js";import{withResponsive as u}from"../shared/with-responsive.js";import v from"./line-chart.module.scss.js";const g=({tooltipData:a})=>{const i=a?.nearestDatum?.datum;if(!i)return null;const o=Object.entries(a?.datumByKey||{}).map((([e,{datum:t}])=>({key:e,value:t.value}))).sort(((e,t)=>t.value-e.value));return t("div",{className:v["line-chart__tooltip"],children:[e("div",{className:v["line-chart__tooltip-date"],children:i.date.toLocaleDateString()}),o.map((a=>t("div",{className:v["line-chart__tooltip-row"],children:[t("span",{className:v["line-chart__tooltip-label"],children:[a.key,":"]}),e("span",{className:v["line-chart__tooltip-value"],children:a.value})]},a.key)))]})},f=e=>new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"});var y=u((({data:u,width:y,height:x,className:N,margin:b,withTooltips:w=!0,showLegend:T=!1,legendOrientation:_="horizontal",withGradientFill:k=!1,options:D={}})=>{const S=h(),j=d((()=>{const e=u?.map((e=>e.options?.stroke??"")).filter(Boolean)??[];return o({...S,colors:[...e,...S.colors]})}),[S,u]);b=d((()=>{let e={top:0,right:0,bottom:40,left:40};return"right"===D.axis?.y?.orientation&&(e={...e,right:40,left:0}),"top"===D.axis?.x?.orientation&&(e={...e,top:40,bottom:0}),{...e,...b}}),[b,D]);const L=(e=>e?.length?e.some((e=>e.data.some((e=>isNaN(e.value)||null===e.value||void 0===e.value||isNaN(e.date.getTime())))))?"Invalid data":null:"No data available")(u);if(L)return e("div",{className:m("line-chart",v["line-chart"]),children:L});const O=u.map(((e,t)=>({label:e.label,value:"",color:S.colors[t%S.colors.length]}))),z={xAccessor:e=>e.date,yAccessor:e=>e.value};return t("div",{className:m("line-chart",v["line-chart"],N),"data-testid":"line-chart",role:"img","aria-label":"line chart",children:[t(r,{theme:j,width:y,height:x,margin:b,xScale:{type:"time",...D?.xScale},yScale:{type:"linear",nice:!0,zero:!1,...D?.yScale},children:[e(l,{columns:!1,numTicks:4}),e(n,{orientation:"bottom",numTicks:5,tickFormat:f,...D?.axis?.x}),e(n,{orientation:"left",numTicks:4,...D?.axis?.y}),u.map(((o,r)=>{const l=o.options?.stroke??j.colors[r%j.colors.length];return t("g",{children:[k&&e(i,{id:`area-gradient-${r+1}`,from:l,to:"white",toOpacity:.1,...o.options?.gradient,"data-testid":"line-gradient"}),e(s,{dataKey:o?.label,data:o.data,...z,fill:k?`url(#area-gradient-${r+1})`:void 0,renderLine:!0,curve:a},o?.label)]},o?.label||r)})),w&&e(c,{snapTooltipToDatumX:!0,snapTooltipToDatumY:!0,showSeriesGlyphs:!0,renderTooltip:g})]}),T&&e(p,{items:O,orientation:_,className:v["line-chart-legend"]})]})}));export{y as default};
2
2
  //# sourceMappingURL=line-chart.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"line-chart.js","sources":["../../../../src/components/line-chart/line-chart.tsx"],"sourcesContent":[null],"names":["renderTooltip","tooltipData","nearestDatum","datum","tooltipPoints","Object","entries","datumByKey","map","key","value","sort","a","b","_jsxs","className","styles","children","_jsx","date","toLocaleDateString","point","formatDateTick","Date","undefined","month","day","lineChart","withResponsive","data","width","height","margin","top","right","bottom","left","withTooltips","showLegend","legendOrientation","withGradientFill","options","providerTheme","useChartTheme","length","clsx","legendItems","group","index","label","color","colors","accessors","xAccessor","d","yAccessor","theme","buildChartTheme","backgroundColor","gridStyles","tickLength","gridColor","gridColorDark","XYChart","xScale","type","yScale","nice","AnimatedGrid","columns","numTicks","AnimatedAxis","orientation","tickFormat","axis","x","y","seriesData","stroke","_Fragment","LinearGradient","id","from","to","toOpacity","gradient","AnimatedLineSeries","dataKey","strokeWidth","AnimatedAreaSeries","fill","renderLine","Tooltip","snapTooltipToDatumX","snapTooltipToDatumY","showSeriesGlyphs","Legend","items"],"mappings":"uhBAiCA,MAAMA,EAAgB,EACrBC,kBAUA,MAAMC,EAAeD,GAAaC,cAAcC,MAChD,IAAOD,EAAe,OAAO,KAE7B,MAAME,EAAgCC,OAAOC,QAASL,GAAaM,YAAc,CAAA,GAC/EC,KAAK,EAAIC,GAAON,aAAiB,CACjCM,MACAC,MAAOP,EAAMO,UAEbC,MAAM,CAAEC,EAAGC,IAAOA,EAAEH,MAAQE,EAAEF,QAEhC,OACCI,EAAK,MAAA,CAAAC,UAAYC,EAAQ,uBACxBC,SAAA,CAAAC,EAAA,MAAA,CAAKH,UAAYC,EAAQ,4BACtBC,SAAAf,EAAaiB,KAAKC,uBAEnBhB,EAAcI,KAAKa,GACpBP,EAAA,MAAA,CAAuBC,UAAYC,EAAQ,2BAC1CC,SAAA,CAAAH,EAAA,OAAA,CAAMC,UAAYC,EAAQ,6BAA6BC,SAAA,CAAKI,EAAMZ,IAAa,OAC/ES,UAAMH,UAAYC,EAAQ,6BAA6BC,SAAKI,EAA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a,CAAAC,YAAY,OAAOF,SAAW,KAAS7B,GAASiC,MAAME,IAElE/C,EAAKrB,KAAK,CAAEqE,EAAY7B,KACzB,MAAM8B,EAASD,EAAWpC,SAASqC,QAAUtB,EAAML,OAAQH,EAAQQ,EAAML,OAAOP,QAEhF,OACC9B,EACCiE,EAAA,CAAA9D,SAAA,CAAAC,EAAC8D,EAAc,CACdC,GAAK,iBAAkBjC,EAAQ,IAC/BkC,KAAOJ,EACPK,GAAG,QACHC,UAAY,MACPP,EAAWpC,SAAS4C,WAE1BnE,EAACoE,EAEA,CAAAC,QAAUV,GAAY5B,MACtBpB,KAAOgD,EAAWhD,QACbuB,EACL0B,OAASA,EACTU,YAAc,GALRX,GAAY5B,OASjBT,GACDtB,EAACuE,EAAkB,CAElBF,QAAUV,GAAY5B,MACtBpB,KAAOgD,EAAWhD,QACbuB,EACL0B,OAASA,EACTU,YAAc,EACdE,KAAO,sBAAuB1C,EAAQ,KACtC2C,YAAa,GAPPd,GAAY5B,SAWpB,IAGDZ,GACDnB,EAAC0E,GACAC,qBAAmB,EACnBC,qBACA,EAAAC,oBACA/F,cAAgBA,OAKjBsC,GACDpB,EAAC8E,EACA,CAAAC,MAAQnD,EACR0B,YAAcjC,EACdxB,UAAYC,EAAQ,yBAItB"}
1
+ {"version":3,"file":"line-chart.js","sources":["../../../../src/components/line-chart/line-chart.tsx"],"sourcesContent":[null],"names":["renderTooltip","tooltipData","nearestDatum","datum","tooltipPoints","Object","entries","datumByKey","map","key","value","sort","a","b","_jsxs","className","styles","children","_jsx","date","toLocaleDateString","point","formatDateTick","Date","undefined","month","day","lineChart","withResponsive","data","width","height","margin","withTooltips","showLegend","legendOrientation","withGradientFill","options","providerTheme","useChartTheme","theme","useMemo","seriesColors","series","stroke","filter","Boolean","buildChartTheme","colors","defaultMargin","top","right","bottom","left","axis","y","orientation","x","error","length","some","isNaN","getTime","validateData","clsx","legendItems","group","index","label","color","accessors","xAccessor","d","yAccessor","role","XYChart","xScale","type","yScale","nice","zero","AnimatedGrid","columns","numTicks","AnimatedAxis","tickFormat","seriesData","LinearGradient","id","from","to","toOpacity","gradient","AnimatedAreaSeries","dataKey","fill","renderLine","curve","curveNatural","Tooltip","snapTooltipToDatumX","snapTooltipToDatumY","showSeriesGlyphs","Legend","items"],"mappings":"8iBAiCA,MAAMA,EAAgB,EACrBC,kBAUA,MAAMC,EAAeD,GAAaC,cAAcC,MAChD,IAAOD,EAAe,OAAO,KAE7B,MAAME,EAAgCC,OAAOC,QAASL,GAAaM,YAAc,CAAA,GAC/EC,KAAK,EAAIC,GAAON,aAAiB,CACjCM,MACAC,MAAOP,EAAMO,UAEbC,MAAM,CAAEC,EAAGC,IAAOA,EAAEH,MAAQE,EAAEF,QAEhC,OACCI,EAAK,MAAA,CAAAC,UAAYC,EAAQ,uBACxBC,SAAA,CAAAC,EAAA,MAAA,CAAKH,UAAYC,EAAQ,4BACtBC,SAAAf,EAAaiB,KAAKC,uBAEnBhB,EAAcI,KAAKa,GACpBP,EAAA,MAAA,CAAuBC,UAAYC,EAAQ,2BAC1CC,SAAA,CAAAH,EAAA,OAAA,CAAMC,UAAYC,EAAQ,6BAA6BC,SAAA,CAAKI,EAAMZ,IAAa,OAC/ES,UAAMH,UAAYC,EAAQ,6BAA6BC,SAAKI,EAAMX,UAFxDW,EAAMZ,SAMlB,EAGGa,EAAmBZ,GACX,IAAIa,KAAMb,GACXU,wBAAoBI,EAAW,CAC1CC,MAAO,QACPC,IAAK,YAmJP,IAAeC,EAAAC,GA9HyB,EACvCC,OACAC,QACAC,SACAhB,YACAiB,SACAC,gBAAe,EACfC,cAAa,EACbC,oBAAoB,aACpBC,oBAAmB,EACnBC,UAAU,CAAA,MAEV,MAAMC,EAAgBC,IAEhBC,EAAQC,GAAS,KACtB,MAAMC,EACLb,GAAMrB,KAAKmC,GAAUA,EAAON,SAASO,QAAU,KAAKC,OAAQC,UAAa,GAC1E,OAAOC,EAAiB,IACpBT,EACHU,OAAQ,IAAKN,KAAiBJ,E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A,CAExEC,EAAC+D,EAAa,CAAAC,SAAU,EAAQC,SAAW,IAC3CjE,EAACkE,EAAY,CACZ5B,YAAY,SACZ2B,SAAW,EACXE,WAAa/D,KACRe,GAASiB,MAAMG,IAErBvC,EAACkE,EAAa,CAAA5B,YAAY,OAAO2B,SAAW,KAAS9C,GAASiB,MAAMC,IAElE1B,EAAKrB,KAAK,CAAE8E,EAAYnB,KACzB,MAAMvB,EAAS0C,EAAWjD,SAASO,QAAUJ,EAAMQ,OAAQmB,EAAQ3B,EAAMQ,OAAOW,QAChF,OACC7C,EACG,IAAA,CAAAG,SAAA,CAAAmB,GACDlB,EAACqE,EACA,CAAAC,GAAK,iBAAkBrB,EAAQ,IAC/BsB,KAAO7C,EACP8C,GAAG,QACHC,UAAY,MACPL,EAAWjD,SAASuD,uBACb,kBAGd1E,EAAC2E,EAEA,CAAAC,QAAUR,GAAYlB,MACtBvC,KAAOyD,EAAWzD,QACbyC,EACLyB,KAAO3D,EAAmB,sBAAuB+B,EAAQ,UAAQ3C,EACjEwE,YAAa,EACbC,MAAQC,GANFZ,GAAYlB,SAZXkB,GAAYlB,OAASD,EAqB7B,IAGDlC,GACDf,EAACiF,GACAC,qBAAmB,EACnBC,qBACA,EAAAC,oBACAtG,cAAgBA,OAKjBkC,GACDhB,EAACqF,EACA,CAAAC,MAAQvC,EACRT,YAAcrB,EACdpB,UAAYC,EAAQ,yBAItB"}
@@ -1,2 +1,2 @@
1
- import{jsx as e,jsxs as a}from"react/jsx-runtime";import{Group as t}from"@visx/group";import{Pie as o}from"@visx/shape";import r from"clsx";import"react";import i from"../../hooks/use-chart-mouse-handler.js";import{useChartTheme as s}from"../../providers/theme/theme-provider.js";import{defaultTheme as l}from"../../providers/theme/themes.js";import{BaseLegend as n}from"../legend/base-legend.js";import{withResponsive as d}from"../shared/with-responsive.js";import{BaseTooltip as p}from"../tooltip/base-tooltip.js";import m from"./pie-chart.module.scss.js";const c=({data:d,withTooltips:c=!1,className:h,showLegend:u,legendOrientation:g,size:v,thickness:f=1,padding:M=20,gapScale:x=0,cornerScale:b=0})=>{const j=s(),{onMouseMove:N,onMouseLeave:w,tooltipOpen:V,tooltipData:A,tooltipLeft:k,tooltipTop:y}=i({withTooltips:c}),{isValid:L,message:R}=(e=>{if(!e.length)return{isValid:!1,message:"No data available"};if(e.some((e=>e.percentage<0||e.value<0)))return{isValid:!1,message:"Invalid data: Negative values are not allowed"};const a=e.reduce(((e,a)=>e+a.percentage),0);return Math.abs(a-100)>.01?{isValid:!1,message:"Invalid percentage total: Must equal 100"}:{isValid:!0,message:""}})(d);if(!L)return e("div",{className:r("pie-chart",m["pie-chart"],h),children:e("div",{className:m["error-message"],children:R})});const S=v,B=v,C=Math.min(S,B)/2,I=S/2,T=B/2,$=x*(2*Math.PI/d.length),z=C-M,O=z*(1-f),P=(z-O)/2,q=b?Math.min(b*z,P):0,D=d.map(((e,a)=>({...e,index:a}))),E={value:e=>e.value,fill:e=>e?.color||j.colors[e.index]},Y=d.map(((e,a)=>({label:e.label,value:e.value.toString(),color:j.colors[a%j.colors.length]})));return a("div",{className:r("pie-chart",m["pie-chart"],h),children:[e("svg",{viewBox:`0 0 ${v} ${v}`,preserveAspectRatio:"xMidYMid meet",width:v,height:v,children:e(t,{top:T,left:I,children:e(o,{data:D,pieValue:E.value,outerRadius:z,innerRadius:O,padAngle:$,cornerRadius:q,children:t=>t.arcs.map(((o,r)=>{const[i,s]=t.path.centroid(o),n=o.endAngle-o.startAngle>=.25,d=e=>N(e,o.data),p={d:t.path(o)||"",fill:E.fill(o.data)};return c&&(p.onMouseMove=d,p.onMouseLeave=w),a("g",{children:[e("path",{...p}),n&&e("text",{x:i,y:s,dy:".33em",fill:j.labelBackgroundColor||l.labelBackgroundColor,fontSize:12,textAnchor:"middle",pointerEvents:"none",children:o.data.label})]},`arc-${r}`)}))})})}),u&&e(n,{items:Y,orientation:g,className:m["pie-chart-legend"]}),c&&V&&A&&e(p,{data:A,top:y||0,left:k||0,style:{transform:"translate(-50%, -100%)"}})]})};c.displayName="PieChart";var h=d(c);export{h as default};
1
+ import{jsx as e,jsxs as a}from"react/jsx-runtime";import{Group as t}from"@visx/group";import{Pie as o}from"@visx/shape";import r from"clsx";import"react";import i from"../../hooks/use-chart-mouse-handler.js";import{useChartTheme as l}from"../../providers/theme/theme-provider.js";import{defaultTheme as s}from"../../providers/theme/themes.js";import{BaseLegend as n}from"../legend/base-legend.js";import{withResponsive as d}from"../shared/with-responsive.js";import{BaseTooltip as p}from"../tooltip/base-tooltip.js";import m from"./pie-chart.module.scss.js";const c=({data:d,withTooltips:c=!1,className:h,showLegend:u,legendOrientation:g,size:v,thickness:f=1,padding:M=20,gapScale:x=0,cornerScale:b=0,children:j=null})=>{const N=l(),{onMouseMove:w,onMouseLeave:V,tooltipOpen:A,tooltipData:k,tooltipLeft:y,tooltipTop:L}=i({withTooltips:c}),{isValid:R,message:S}=(e=>{if(!e.length)return{isValid:!1,message:"No data available"};if(e.some((e=>e.percentage<0||e.value<0)))return{isValid:!1,message:"Invalid data: Negative values are not allowed"};const a=e.reduce(((e,a)=>e+a.percentage),0);return Math.abs(a-100)>.01?{isValid:!1,message:"Invalid percentage total: Must equal 100"}:{isValid:!0,message:""}})(d);if(!R)return e("div",{className:r("pie-chart",m["pie-chart"],h),children:e("div",{className:m["error-message"],children:S})});const B=v,C=v,I=Math.min(B,C)/2,T=B/2,$=C/2,z=x*(2*Math.PI/d.length),O=I-M,P=O*(1-f),q=(O-P)/2,D=b?Math.min(b*O,q):0,E=d.map(((e,a)=>({...e,index:a}))),Y={value:e=>e.value,fill:e=>e?.color||N.colors[e.index]},F=d.map(((e,a)=>({label:e.label,value:e.value.toString(),color:N.colors[a%N.colors.length]})));return a("div",{className:r("pie-chart",m["pie-chart"],h),children:[e("svg",{viewBox:`0 0 ${v} ${v}`,preserveAspectRatio:"xMidYMid meet",width:v,height:v,children:a(t,{top:$,left:T,children:[e(o,{data:E,pieValue:Y.value,outerRadius:O,innerRadius:P,padAngle:z,cornerRadius:D,children:t=>t.arcs.map(((o,r)=>{const[i,l]=t.path.centroid(o),n=o.endAngle-o.startAngle>=.25,d=e=>w(e,o.data),p={d:t.path(o)||"",fill:Y.fill(o.data)};return c&&(p.onMouseMove=d,p.onMouseLeave=V),a("g",{children:[e("path",{...p}),n&&e("text",{x:i,y:l,dy:".33em",fill:N.labelBackgroundColor||s.labelBackgroundColor,fontSize:12,textAnchor:"middle",pointerEvents:"none",children:o.data.label})]},`arc-${r}`)}))}),j]})}),u&&e(n,{items:F,orientation:g,className:m["pie-chart-legend"]}),c&&A&&k&&e(p,{data:k,top:L||0,left:y||0,style:{transform:"translate(-50%, -100%)"}})]})};c.displayName="PieChart";var h=d(c);export{h as default};
2
2
  //# sourceMappingURL=pie-chart.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pie-chart.js","sources":["../../../../src/components/pie-chart/pie-chart.tsx"],"sourcesContent":[null],"names":["PieChart","data","withTooltips","className","showLegend","legendOrientation","size","thickness","padding","gapScale","cornerScale","providerTheme","useChartTheme","onMouseMove","onMouseLeave","tooltipOpen","tooltipData","tooltipLeft","tooltipTop","useChartMouseHandler","isValid","message","length","some","item","percentage","value","totalPercentage","reduce","sum","Math","abs","validateData","_jsx","clsx","styles","children","width","height","radius","min","centerX","centerY","padAngle","PI","outerRadius","innerRadius","maxCornerRadius","cornerRadius","dataWithIndex","map","d","index","accessors","fill","color","colors","legendItems","label","toString","_jsxs","viewBox","preserveAspectRatio","Group","top","left","Pie","pieValue","pie","arcs","arc","centroidX","centroidY","path","centroid","hasSpaceForLabel","endAngle","startAngle","handleMouseMove","event","pathProps","x","y","dy","labelBackgroundColor","defaultTheme","fontSize","textAnchor","pointerEvents","Legend","items","orientation","BaseTooltip","style","transform","displayName","pieChart","withResponsive"],"mappings":"8iBAyDA,MA2BMA,EAAW,EAChBC,OACAC,gBAAe,EACfC,YACAC,aACAC,oBACAC,OACAC,YAAY,EACZC,UAAU,GACVC,WAAW,EACXC,cAAc,MAEd,MAAMC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CiB,EAAC2D,EAAW,CACX3F,KAAOe,EACPgD,IAAM9C,GAAc,EACpB+C,KAAOhD,GAAe,EACtB4E,MAAQ,CACPC,UAAW,8BAKd,EAGH9F,EAAS+F,YAAc,WACvB,IAAeC,EAAAC,EAAiCjG"}
1
+ {"version":3,"file":"pie-chart.js","sources":["../../../../src/components/pie-chart/pie-chart.tsx"],"sourcesContent":[null],"names":["PieChart","data","withTooltips","className","showLegend","legendOrientation","size","thickness","padding","gapScale","cornerScale","children","providerTheme","useChartTheme","onMouseMove","onMouseLeave","tooltipOpen","tooltipData","tooltipLeft","tooltipTop","useChartMouseHandler","isValid","message","length","some","item","percentage","value","totalPercentage","reduce","sum","Math","abs","validateData","_jsx","clsx","styles","width","height","radius","min","centerX","centerY","padAngle","PI","outerRadius","innerRadius","maxCornerRadius","cornerRadius","dataWithIndex","map","d","index","accessors","fill","color","colors","legendItems","label","toString","_jsxs","viewBox","preserveAspectRatio","Group","top","left","Pie","pieValue","pie","arcs","arc","centroidX","centroidY","path","centroid","hasSpaceForLabel","endAngle","startAngle","handleMouseMove","event","pathProps","x","y","dy","labelBackgroundColor","defaultTheme","fontSize","textAnchor","pointerEvents","Legend","items","orientation","BaseTooltip","style","transform","displayName","pieChart","withResponsive"],"mappings":"8iBA8DA,MA2BMA,EAAW,EAChBC,OACAC,gBAAe,EACfC,YACAC,aACAC,oBACAC,OACAC,YAAY,EACZC,UAAU,GACVC,WAAW,EACXC,cAAc,EACdC,WAAW,SAEX,MAAMC,EAAgBC,KAChBC,YAAEA,EAAWC,aAAEA,EAAYC,YAAEA,EAAWC,YAAEA,EAAWC,YAAEA,EAAWC,WAAEA,GACzEC,EAAsB,CACrBlB,kBAGImB,QAAEA,EAAOC,QAAEA,GA9CG,CAAErB,IACtB,IAAOA,EAAKsB,OACX,MAAO,CAAEF,SAAS,EAAOC,QAAS,qBAKnC,GAD0BrB,EAAKuB,MAAMC,GAAQA,EAAKC,WAAa,GAAKD,EAAKE,MAAQ,IAEhF,M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:{stroke:"#787C82",strokeWidth:1},tickLength:0,gridColor:"",gridColorDark:""};export{F as defaultTheme};
1
+ const o={backgroundColor:"#FFFFFF",labelBackgroundColor:"#FFFFFF",colors:["#98C8DF","#006DAB","#A6DC80","#1F9828","#FF8C8F"],gridStyles:{stroke:"#DCDCDE",strokeWidth:1},tickLength:4,gridColor:"",gridColorDark:"",xTickLineStyles:{stroke:"black"},xAxisLineStyles:{stroke:"#DCDCDE",strokeWidth:1}};export{o as defaultTheme};
2
2
  //# sourceMappingURL=themes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"themes.js","sources":["../../../../src/providers/theme/themes.ts"],"sourcesContent":[null],"names":["defaultTheme","backgroundColor","labelBackgroundColor","colors","gridStyles","stroke","strokeWidth","tickLength","gridColor","gridColorDark"],"mappings":"AAKA,MAAMA,EAA2B,CAChCC,gBAAiB,UACjBC,qBAAsB,UACtBC,OAAQ,CAAE,UAAW,UAAW,UAAW,UAAW,WACtDC,WAAY,CACXC,OAAQ,UACRC,YAAa,GAEdC,WAAY,EACZC,UAAW,GACXC,cAAe"}
1
+ {"version":3,"file":"themes.js","sources":["../../../../src/providers/theme/themes.ts"],"sourcesContent":[null],"names":["defaultTheme","backgroundColor","labelBackgroundColor","colors","gridStyles","stroke","strokeWidth","tickLength","gridColor","gridColorDark","xTickLineStyles","xAxisLineStyles"],"mappings":"AAKA,MAAMA,EAA2B,CAChCC,gBAAiB,UACjBC,qBAAsB,UACtBC,OAAQ,CAAE,UAAW,UAAW,UAAW,UAAW,WACtDC,WAAY,CACXC,OAAQ,UACRC,YAAa,GAEdC,WAAY,EACZC,UAAW,GACXC,cAAe,GACfC,gBAAiB,CAAEL,OAAQ,SAC3BM,gBAAiB,CAAEN,OAAQ,UAAWC,YAAa"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/charts",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Display charts within Automattic products.",
5
5
  "homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/charts/#readme",
6
6
  "bugs": {
@@ -49,6 +49,7 @@
49
49
  "@babel/runtime": "7.26.0",
50
50
  "@react-spring/web": "9.7.3",
51
51
  "@visx/axis": "^3.12.0",
52
+ "@visx/curve": "3.12.0",
52
53
  "@visx/event": "^3.8.0",
53
54
  "@visx/gradient": "3.12.0",
54
55
  "@visx/grid": "^3.12.0",
@@ -64,11 +65,14 @@
64
65
  "tslib": "2.5.0"
65
66
  },
66
67
  "devDependencies": {
68
+ "@automattic/jetpack-webpack-config": "workspace:*",
67
69
  "@babel/core": "7.26.0",
70
+ "@babel/plugin-transform-react-jsx": "7.25.9",
68
71
  "@babel/plugin-transform-runtime": "7.25.9",
69
72
  "@babel/preset-env": "7.26.0",
70
73
  "@babel/preset-react": "7.26.3",
71
74
  "@babel/preset-typescript": "7.26.0",
75
+ "@jest/globals": "^29.0.0",
72
76
  "@rollup/plugin-commonjs": "26.0.1",
73
77
  "@rollup/plugin-json": "6.1.0",
74
78
  "@rollup/plugin-node-resolve": "15.3.0",
@@ -76,8 +80,15 @@
76
80
  "@rollup/plugin-typescript": "12.1.0",
77
81
  "@storybook/blocks": "8.4.7",
78
82
  "@storybook/react": "8.4.7",
83
+ "@testing-library/jest-dom": "^6.0.0",
84
+ "@testing-library/react": "^14.0.0",
85
+ "@types/jest": "^29.0.0",
79
86
  "@types/react": "18.3.18",
80
87
  "@types/react-dom": "18.3.5",
88
+ "@types/testing-library__jest-dom": "^5.14.9",
89
+ "@wordpress/babel-plugin-import-jsx-pragma": "5.14.0",
90
+ "@wordpress/element": "6.14.0",
91
+ "babel-jest": "^29.7.0",
81
92
  "babel-loader": "9.1.2",
82
93
  "clean-webpack-plugin": "^4.0.0",
83
94
  "css-loader": "^6.7.0",
@@ -102,17 +113,7 @@
102
113
  "tsconfig-paths-webpack-plugin": "4.2.0",
103
114
  "typescript": "5.7.2",
104
115
  "webpack": "^5.88.0",
105
- "webpack-cli": "^5.1.0",
106
- "@testing-library/react": "^14.0.0",
107
- "@testing-library/jest-dom": "^6.0.0",
108
- "@types/jest": "^29.0.0",
109
- "@types/testing-library__jest-dom": "^5.14.9",
110
- "@jest/globals": "^29.0.0",
111
- "babel-jest": "^29.7.0",
112
- "@automattic/jetpack-webpack-config": "workspace:*",
113
- "@wordpress/babel-plugin-import-jsx-pragma": "5.14.0",
114
- "@wordpress/element": "6.14.0",
115
- "@babel/plugin-transform-react-jsx": "7.25.9"
116
+ "webpack-cli": "^6.0.0"
116
117
  },
117
118
  "peerDependencies": {
118
119
  "react": "^17.0.0 || ^18.0.0",
@@ -48,7 +48,6 @@ const BarChart: FC< BarChartProps > = ( {
48
48
  ) => {
49
49
  const coords = localPoint( event );
50
50
  if ( ! coords ) return;
51
-
52
51
  showTooltip( {
53
52
  tooltipData: { value, xLabel, yLabel, seriesIndex },
54
53
  tooltipLeft: coords.x,
@@ -58,12 +57,25 @@ const BarChart: FC< BarChartProps > = ( {
58
57
  [ showTooltip ]
59
58
  );
60
59
 
61
- const handleMouseLeave = useCallback( () => {
62
- hideTooltip();
63
- }, [ hideTooltip ] );
64
-
60
+ // Check for empty data
65
61
  if ( ! data?.length ) {
66
- return <div className={ clsx( 'bar-chart-empty', styles[ 'bat-chart-empty' ] ) }>Empty...</div>;
62
+ return <div className={ clsx( styles[ 'bar-chart-empty' ] ) }>No data available</div>;
63
+ }
64
+
65
+ // Add date validation to hasInvalidData check
66
+ const hasInvalidData = data.some( series =>
67
+ series.data.some(
68
+ d =>
69
+ d.value === null ||
70
+ d.value === undefined ||
71
+ isNaN( d.value ) ||
72
+ ! d.label ||
73
+ ( d.date && isNaN( d.date.getTime() ) ) // Add date validation
74
+ )
75
+ );
76
+
77
+ if ( hasInvalidData ) {
78
+ return <div className={ clsx( styles[ 'bar-chart-error' ] ) }>Invalid data</div>;
67
79
  }
68
80
 
69
81
  const margins = margin;
@@ -102,7 +114,12 @@ const BarChart: FC< BarChartProps > = ( {
102
114
  } ) );
103
115
 
104
116
  return (
105
- <div className={ clsx( 'bar-chart', className, styles[ 'bar-chart' ] ) }>
117
+ <div
118
+ className={ clsx( 'bar-chart', styles[ 'bar-chart' ], className ) }
119
+ data-testid="bar-chart"
120
+ role="img"
121
+ aria-label="bar chart"
122
+ >
106
123
  <svg width={ width } height={ height }>
107
124
  <Group left={ margins.left } top={ margins.top }>
108
125
  <GridControl
@@ -133,7 +150,7 @@ const BarChart: FC< BarChartProps > = ( {
133
150
  height={ yMax - ( yScale( d.value ) ?? 0 ) }
134
151
  fill={ theme.colors[ seriesIndex % theme.colors.length ] }
135
152
  onMouseMove={ withTooltips ? handleBarMouseMove : undefined }
136
- onMouseLeave={ withTooltips ? handleMouseLeave : undefined }
153
+ onMouseLeave={ withTooltips ? hideTooltip : undefined }
137
154
  />
138
155
  );
139
156
  } ) }
@@ -159,7 +176,7 @@ const BarChart: FC< BarChartProps > = ( {
159
176
  <Legend
160
177
  items={ legendItems }
161
178
  orientation={ legendOrientation }
162
- className={ styles[ 'bar-chart-legend' ] }
179
+ className={ styles[ 'bar-chart__legend' ] }
163
180
  />
164
181
  ) }
165
182
  </div>
@@ -1,7 +1,7 @@
1
+ import { curveNatural } from '@visx/curve';
1
2
  import { LinearGradient } from '@visx/gradient';
2
3
  import {
3
4
  XYChart,
4
- AnimatedLineSeries,
5
5
  AnimatedAreaSeries,
6
6
  AnimatedAxis,
7
7
  AnimatedGrid,
@@ -9,7 +9,7 @@ import {
9
9
  buildChartTheme,
10
10
  } from '@visx/xychart';
11
11
  import clsx from 'clsx';
12
- import { FC } from 'react';
12
+ import { FC, useMemo } from 'react';
13
13
  import { useChartTheme } from '../../providers/theme/theme-provider';
14
14
  import { Legend } from '../legend';
15
15
  import { withResponsive } from '../shared/with-responsive';
@@ -75,12 +75,29 @@ const formatDateTick = ( value: number ) => {
75
75
  } );
76
76
  };
77
77
 
78
+ const validateData = ( data: SeriesData[] ) => {
79
+ if ( ! data?.length ) return 'No data available';
80
+
81
+ const hasInvalidData = data.some( series =>
82
+ series.data.some(
83
+ point =>
84
+ isNaN( point.value as number ) ||
85
+ point.value === null ||
86
+ point.value === undefined ||
87
+ isNaN( point.date.getTime() )
88
+ )
89
+ );
90
+
91
+ if ( hasInvalidData ) return 'Invalid data';
92
+ return null;
93
+ };
94
+
78
95
  const LineChart: FC< LineChartProps > = ( {
79
96
  data,
80
97
  width,
81
98
  height,
82
- margin = { top: 20, right: 20, bottom: 40, left: 40 },
83
99
  className,
100
+ margin,
84
101
  withTooltips = true,
85
102
  showLegend = false,
86
103
  legendOrientation = 'horizontal',
@@ -89,10 +106,32 @@ const LineChart: FC< LineChartProps > = ( {
89
106
  } ) => {
90
107
  const providerTheme = useChartTheme();
91
108
 
92
- if ( ! data?.length ) {
93
- return (
94
- <div className={ clsx( 'line-chart-empty', styles[ 'line-chart-empty' ] ) }>Empty...</div>
95
- );
109
+ const theme = useMemo( () => {
110
+ const seriesColors =
111
+ data?.map( series => series.options?.stroke ?? '' ).filter( Boolean ) ?? [];
112
+ return buildChartTheme( {
113
+ ...providerTheme,
114
+ colors: [ ...seriesColors, ...providerTheme.colors ],
115
+ } );
116
+ }, [ providerTheme, data ] );
117
+
118
+ margin = useMemo( () => {
119
+ // Auto-margin unless specified to make room for axis labels.
120
+ // Default margin is for bottom and left axis labels.
121
+ let defaultMargin = { top: 0, right: 0, bottom: 40, left: 40 };
122
+ if ( options.axis?.y?.orientation === 'right' ) {
123
+ defaultMargin = { ...defaultMargin, right: 40, left: 0 };
124
+ }
125
+ if ( options.axis?.x?.orientation === 'top' ) {
126
+ defaultMargin = { ...defaultMargin, top: 40, bottom: 0 };
127
+ }
128
+ // Merge default margin with user-specified margin.
129
+ return { ...defaultMargin, ...margin };
130
+ }, [ margin, options ] );
131
+
132
+ const error = validateData( data );
133
+ if ( error ) {
134
+ return <div className={ clsx( 'line-chart', styles[ 'line-chart' ] ) }>{ error }</div>;
96
135
  }
97
136
 
98
137
  // Create legend items from group labels, this iterates over groups rather than data points
@@ -107,24 +146,20 @@ const LineChart: FC< LineChartProps > = ( {
107
146
  yAccessor: ( d: DataPointDate ) => d.value,
108
147
  };
109
148
 
110
- const theme = buildChartTheme( {
111
- backgroundColor: providerTheme.backgroundColor,
112
- colors: providerTheme.colors,
113
- gridStyles: providerTheme.gridStyles,
114
- tickLength: providerTheme?.tickLength || 0,
115
- gridColor: providerTheme?.gridColor || '',
116
- gridColorDark: providerTheme?.gridColorDark || '',
117
- } );
118
-
119
149
  return (
120
- <div className={ clsx( 'line-chart', styles[ 'line-chart' ], className ) }>
150
+ <div
151
+ className={ clsx( 'line-chart', styles[ 'line-chart' ], className ) }
152
+ data-testid="line-chart"
153
+ role="img"
154
+ aria-label="line chart"
155
+ >
121
156
  <XYChart
122
157
  theme={ theme }
123
158
  width={ width }
124
159
  height={ height }
125
160
  margin={ margin }
126
- xScale={ { type: 'time' } }
127
- yScale={ { type: 'linear', nice: true } }
161
+ xScale={ { type: 'time', ...options?.xScale } }
162
+ yScale={ { type: 'linear', nice: true, zero: false, ...options?.yScale } }
128
163
  >
129
164
  <AnimatedGrid columns={ false } numTicks={ 4 } />
130
165
  <AnimatedAxis
@@ -137,39 +172,28 @@ const LineChart: FC< LineChartProps > = ( {
137
172
 
138
173
  { data.map( ( seriesData, index ) => {
139
174
  const stroke = seriesData.options?.stroke ?? theme.colors[ index % theme.colors.length ];
140
-
141
175
  return (
142
- <>
143
- <LinearGradient
144
- id={ `area-gradient-${ index + 1 }` }
145
- from={ stroke }
146
- to="white"
147
- toOpacity={ 0.1 }
148
- { ...seriesData.options?.gradient }
149
- />
150
- <AnimatedLineSeries
176
+ <g key={ seriesData?.label || index }>
177
+ { withGradientFill && (
178
+ <LinearGradient
179
+ id={ `area-gradient-${ index + 1 }` }
180
+ from={ stroke }
181
+ to="white"
182
+ toOpacity={ 0.1 }
183
+ { ...seriesData.options?.gradient }
184
+ data-testid="line-gradient"
185
+ />
186
+ ) }
187
+ <AnimatedAreaSeries
151
188
  key={ seriesData?.label }
152
189
  dataKey={ seriesData?.label }
153
- data={ seriesData.data as DataPointDate[] } // TODO: this needs fixing or a more specific type for each chart
190
+ data={ seriesData.data as DataPointDate[] }
154
191
  { ...accessors }
155
- stroke={ stroke }
156
- strokeWidth={ 2 }
192
+ fill={ withGradientFill ? `url(#area-gradient-${ index + 1 })` : undefined }
193
+ renderLine={ true }
194
+ curve={ curveNatural }
157
195
  />
158
- { /** Theoretically the area series should work without the line series; however it outlines the area with borders, which isn't ideal. */ }
159
- { /** TODO: Investigate whehter we could leverage area series alone. */ }
160
- { withGradientFill && (
161
- <AnimatedAreaSeries
162
- key={ seriesData?.label }
163
- dataKey={ seriesData?.label }
164
- data={ seriesData.data as DataPointDate[] } // TODO: this needs fixing or a more specific type for each chart
165
- { ...accessors }
166
- stroke={ stroke }
167
- strokeWidth={ 0 }
168
- fill={ `url(#area-gradient-${ index + 1 })` }
169
- renderLine={ false }
170
- />
171
- ) }
172
- </>
196
+ </g>
173
197
  );
174
198
  } ) }
175
199
 
@@ -48,6 +48,11 @@ interface PieChartProps extends OmitBaseChartProps {
48
48
  * A value between 0 and 1, where 0 means no corner radius.
49
49
  */
50
50
  cornerScale?: number;
51
+
52
+ /**
53
+ * Use the children prop to render additional elements on the chart.
54
+ */
55
+ children?: React.ReactNode;
51
56
  }
52
57
 
53
58
  /**
@@ -93,6 +98,7 @@ const PieChart = ( {
93
98
  padding = 20,
94
99
  gapScale = 0,
95
100
  cornerScale = 0,
101
+ children = null,
96
102
  }: PieChartProps ) => {
97
103
  const providerTheme = useChartTheme();
98
104
  const { onMouseMove, onMouseLeave, tooltipOpen, tooltipData, tooltipLeft, tooltipTop } =
@@ -206,6 +212,8 @@ const PieChart = ( {
206
212
  } );
207
213
  } }
208
214
  </Pie>
215
+
216
+ { children }
209
217
  </Group>
210
218
  </svg>
211
219
 
@@ -8,12 +8,14 @@ const defaultTheme: ChartTheme = {
8
8
  labelBackgroundColor: '#FFFFFF', // label background color
9
9
  colors: [ '#98C8DF', '#006DAB', '#A6DC80', '#1F9828', '#FF8C8F' ],
10
10
  gridStyles: {
11
- stroke: '#787C82',
11
+ stroke: '#DCDCDE',
12
12
  strokeWidth: 1,
13
13
  },
14
- tickLength: 0,
14
+ tickLength: 4,
15
15
  gridColor: '',
16
16
  gridColorDark: '',
17
+ xTickLineStyles: { stroke: 'black' },
18
+ xAxisLineStyles: { stroke: '#DCDCDE', strokeWidth: 1 },
17
19
  };
18
20
 
19
21
  /**
@@ -24,12 +26,14 @@ const jetpackTheme: ChartTheme = {
24
26
  labelBackgroundColor: '#FFFFFF', // label background color
25
27
  colors: [ '#98C8DF', '#006DAB', '#A6DC80', '#1F9828', '#FF8C8F' ],
26
28
  gridStyles: {
27
- stroke: '#787C82',
29
+ stroke: '#DCDCDE',
28
30
  strokeWidth: 1,
29
31
  },
30
- tickLength: 0,
32
+ tickLength: 4,
31
33
  gridColor: '',
32
34
  gridColorDark: '',
35
+ xTickLineStyles: { stroke: 'black' },
36
+ xAxisLineStyles: { stroke: '#DCDCDE', strokeWidth: 1 },
33
37
  };
34
38
 
35
39
  /**
@@ -43,9 +47,11 @@ const wooTheme: ChartTheme = {
43
47
  stroke: '#787C82',
44
48
  strokeWidth: 1,
45
49
  },
46
- tickLength: 0,
50
+ tickLength: 4,
47
51
  gridColor: '',
48
52
  gridColorDark: '',
53
+ xTickLineStyles: { stroke: 'black' },
54
+ xAxisLineStyles: { stroke: '#DCDCDE', strokeWidth: 1 },
49
55
  };
50
56
 
51
57
  export { defaultTheme, jetpackTheme, wooTheme };
package/src/types.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { Orientation } from '@visx/axis';
2
+ import { ScaleType } from '@visx/scale';
3
+ import { LineStyles } from '@visx/xychart';
2
4
  import type { CSSProperties } from 'react';
3
5
 
4
6
  type ValueOf< T > = T[ keyof T ];
@@ -12,8 +14,8 @@ export type DataPoint = {
12
14
 
13
15
  export type DataPointDate = {
14
16
  date: Date;
17
+ value: number | null;
15
18
  label?: string;
16
- value: number;
17
19
  };
18
20
 
19
21
  export type SeriesData = {
@@ -69,6 +71,10 @@ export type ChartTheme = {
69
71
  gridColor: string;
70
72
  /** Color of the grid lines in dark mode */
71
73
  gridColorDark: string;
74
+ /** Styles for x-axis tick lines */
75
+ xTickLineStyles?: LineStyles;
76
+ /** Styles for x-axis line */
77
+ xAxisLineStyles?: LineStyles;
72
78
  };
73
79
 
74
80
  declare type AxisOptions = {
@@ -130,6 +136,8 @@ export type BaseChartProps< T = DataPoint | DataPointDate > = {
130
136
  * More options for the chart.
131
137
  */
132
138
  options?: {
139
+ yScale?: { type?: ScaleType; zero?: boolean };
140
+ xScale?: { type?: ScaleType };
133
141
  axis?: {
134
142
  x?: AxisOptions;
135
143
  y?: AxisOptions;
package/global.d.ts DELETED
@@ -1,14 +0,0 @@
1
- /// <reference types="jest" />
2
-
3
- declare global {
4
- const describe: jest.Describe;
5
- const test: jest.It;
6
- const expect: jest.Expect;
7
- const it: jest.It;
8
- const beforeAll: jest.Lifecycle;
9
- const afterAll: jest.Lifecycle;
10
- const beforeEach: jest.Lifecycle;
11
- const afterEach: jest.Lifecycle;
12
- }
13
-
14
- export {};
@@ -1,59 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
-
5
- import { render, screen } from '@testing-library/react';
6
- import { ThemeProvider } from '../../../providers/theme';
7
- import PieChart from '../pie-chart';
8
-
9
- describe( 'PieChart', () => {
10
- const defaultProps = {
11
- size: 500,
12
- data: [
13
- { label: 'A', percentage: 50, value: 50 },
14
- { label: 'B', percentage: 50, value: 50 },
15
- ],
16
- };
17
-
18
- const renderWithTheme = ( props = {} ) => {
19
- return render(
20
- <ThemeProvider>
21
- <PieChart { ...defaultProps } { ...props } />
22
- </ThemeProvider>
23
- );
24
- };
25
-
26
- describe( 'Data Validation', () => {
27
- test( 'validates total percentage equals 100', () => {
28
- renderWithTheme( {
29
- data: [
30
- { label: 'A', percentage: 60, value: 60 },
31
- { label: 'B', percentage: 50, value: 50 },
32
- ],
33
- } );
34
- expect( screen.getByText( /invalid percentage total/i ) ).toBeInTheDocument();
35
- } );
36
-
37
- test( 'handles negative values', () => {
38
- renderWithTheme( {
39
- data: [
40
- { label: 'A', percentage: -30, value: -30 },
41
- { label: 'B', percentage: 130, value: 130 },
42
- ],
43
- } );
44
- expect( screen.getByText( /invalid data/i ) ).toBeInTheDocument();
45
- } );
46
-
47
- test( 'handles empty data array', () => {
48
- renderWithTheme( { data: [] } );
49
- expect( screen.getByText( /no data available/i ) ).toBeInTheDocument();
50
- } );
51
-
52
- test( 'handles single data point', () => {
53
- renderWithTheme( {
54
- data: [ { label: 'A', percentage: 100, value: 100 } ],
55
- } );
56
- expect( screen.getByText( 'A' ) ).toBeInTheDocument();
57
- } );
58
- } );
59
- } );