@automattic/charts 0.7.0 → 0.8.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 +18 -0
- package/dist/cjs/components/grid-control/grid-control.js +1 -1
- package/dist/cjs/components/grid-control/grid-control.js.map +1 -1
- package/dist/cjs/components/legend/base-legend.js +1 -1
- package/dist/cjs/components/legend/base-legend.js.map +1 -1
- package/dist/cjs/components/line-chart/line-chart.js +1 -1
- package/dist/cjs/components/line-chart/line-chart.js.map +1 -1
- package/dist/cjs/components/pie-chart/pie-chart.js.map +1 -1
- package/dist/cjs/components/pie-semi-circle-chart/pie-semi-circle-chart.js +1 -1
- package/dist/cjs/components/pie-semi-circle-chart/pie-semi-circle-chart.js.map +1 -1
- package/dist/cjs/components/shared/with-responsive.js +1 -1
- package/dist/cjs/components/shared/with-responsive.js.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/providers/theme/themes.js +1 -1
- package/dist/cjs/providers/theme/themes.js.map +1 -1
- package/dist/index.d.ts +34 -24
- package/dist/mjs/components/grid-control/grid-control.js +1 -1
- package/dist/mjs/components/grid-control/grid-control.js.map +1 -1
- package/dist/mjs/components/legend/base-legend.js +1 -1
- package/dist/mjs/components/legend/base-legend.js.map +1 -1
- package/dist/mjs/components/line-chart/line-chart.js +1 -1
- package/dist/mjs/components/line-chart/line-chart.js.map +1 -1
- package/dist/mjs/components/pie-chart/pie-chart.js.map +1 -1
- package/dist/mjs/components/pie-semi-circle-chart/pie-semi-circle-chart.js +1 -1
- package/dist/mjs/components/pie-semi-circle-chart/pie-semi-circle-chart.js.map +1 -1
- package/dist/mjs/components/shared/with-responsive.js +1 -1
- package/dist/mjs/components/shared/with-responsive.js.map +1 -1
- package/dist/mjs/index.js +1 -1
- package/dist/mjs/providers/theme/themes.js +1 -1
- package/dist/mjs/providers/theme/themes.js.map +1 -1
- package/package.json +5 -3
- package/src/components/grid-control/grid-control.tsx +6 -2
- package/src/components/legend/base-legend.tsx +10 -2
- package/src/components/legend/legend.test.tsx +76 -0
- package/src/components/line-chart/line-chart.tsx +6 -5
- package/src/components/pie-chart/pie-chart.tsx +0 -5
- package/src/components/pie-semi-circle-chart/pie-semi-circle-chart.tsx +97 -41
- package/src/components/shared/with-responsive.tsx +3 -4
- package/src/index.ts +2 -1
- package/src/types.ts +11 -4
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,22 @@ 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.8.0] - 2025-02-04
|
|
9
|
+
### Added
|
|
10
|
+
- Charts: add additional testing for library [#41449]
|
|
11
|
+
- Charts: add line smoothing toggle on line chart [#41495]
|
|
12
|
+
- Charts: adds donut pie chart story [#41496]
|
|
13
|
+
- Charts: adds tests for mouse-handler hook, responsive HOC, and grid control [#41455]
|
|
14
|
+
- Charts: adds tests for semi circle chart [#41416]
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
- Small type and style fixes [#41523]
|
|
18
|
+
- Updated package dependencies. [#41491]
|
|
19
|
+
|
|
20
|
+
## [0.7.1] - 2025-02-04
|
|
21
|
+
### Changed
|
|
22
|
+
- Internal updates.
|
|
23
|
+
|
|
8
24
|
## [0.7.0] - 2025-01-31
|
|
9
25
|
### Added
|
|
10
26
|
- Automatic margin for axis labels [#41325]
|
|
@@ -89,6 +105,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
89
105
|
- Fixed lints following ESLint rule changes for TS [#40584]
|
|
90
106
|
- Fixing a bug in Chart storybook data. [#40640]
|
|
91
107
|
|
|
108
|
+
[0.8.0]: https://github.com/Automattic/charts/compare/v0.7.1...v0.8.0
|
|
109
|
+
[0.7.1]: https://github.com/Automattic/charts/compare/v0.7.0...v0.7.1
|
|
92
110
|
[0.7.0]: https://github.com/Automattic/charts/compare/v0.6.0...v0.7.0
|
|
93
111
|
[0.6.0]: https://github.com/Automattic/charts/compare/v0.5.0...v0.6.0
|
|
94
112
|
[0.5.0]: https://github.com/Automattic/charts/compare/v0.4.0...v0.5.0
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var r=require("react/jsx-runtime"),e=require("@visx/grid");require("react");var i=require("./grid-control.module.scss.js");module.exports=({width:s,height:t,xScale:
|
|
1
|
+
"use strict";var r=require("react/jsx-runtime"),e=require("@visx/grid");require("react");var i=require("./grid-control.module.scss.js");module.exports=({width:s,height:t,xScale:d,yScale:a,gridVisibility:l="x",top:c=0})=>r.jsxs("g",{transform:`translate(0, ${c})`,className:i["grid-control"],children:[l.includes("x")&&r.jsx(e.GridRows,{scale:d,width:s,"data-testid":"x-grid"}),l.includes("y")&&r.jsx(e.GridColumns,{scale:a,height:t,"data-testid":"y-grid"})]});
|
|
2
2
|
//# sourceMappingURL=grid-control.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid-control.js","sources":["/@automattic/charts/../../../../src/components/grid-control/grid-control.tsx"],"sourcesContent":[null],"names":["width","height","xScale","yScale","gridVisibility","top","_jsxs","transform","className","styles","children","includes","_jsx","GridRows","scale","GridColumns"],"mappings":"uJAK2C,EAC1CA,QACAC,SACAC,SACAC,SACAC,iBAAiB,IACjBC,MAAM,KAGLC,
|
|
1
|
+
{"version":3,"file":"grid-control.js","sources":["/@automattic/charts/../../../../src/components/grid-control/grid-control.tsx"],"sourcesContent":[null],"names":["width","height","xScale","yScale","gridVisibility","top","_jsxs","jsxs","transform","className","styles","children","includes","_jsx","jsx","GridRows","scale","GridColumns"],"mappings":"uJAK2C,EAC1CA,QACAC,SACAC,SACAC,SACAC,iBAAiB,IACjBC,MAAM,KAGLC,EAAAC,KAAA,IAAA,CAAGC,UAAY,gBAAiBH,KAAUI,UAAYC,EAAQ,gBAC3DC,SAAA,CAAAP,EAAeQ,SAAU,MAC1BC,EAAAC,IAACC,WAAQ,CAACC,MAAQd,EAASF,MAAQA,EAAoB,cAAA,WAEtDI,EAAeQ,SAAU,MAC1BC,EAAAC,IAACG,EAAWA,YAAA,CAACD,MAAQb,EAASF,OAASA,EAAM,cAAe"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),l=require("@visx/legend"),s=require("@visx/scale"),a=require("clsx");require("react");var i=require("./legend.module.scss.js");const
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),l=require("@visx/legend"),s=require("@visx/scale"),a=require("clsx");require("react");var i=require("./legend.module.scss.js");const t={horizontal:"row",vertical:"column"};exports.BaseLegend=({items:r,className:n,orientation:d="horizontal"})=>{const c=s.scaleOrdinal({domain:r.map((e=>e.label)),range:r.map((e=>e.color))});return e.jsx("div",{className:a(i.legend,i[`legend--${d}`],n),role:"list","data-testid":`legend-${d}`,children:e.jsx(l.LegendOrdinal,{scale:c,direction:t[d],shape:"rect",shapeWidth:16,shapeHeight:16,className:i["legend-items"],children:l=>e.jsx("div",{className:i[`legend--${d}`],children:l.map((l=>e.jsxs("div",{className:i["legend-item"],role:"listitem","data-testid":"legend-item",children:[e.jsx("svg",{width:16,height:16,role:"img",children:e.jsx("rect",{width:16,height:16,fill:l.value,className:i["legend-item-swatch"],"data-testid":"legend-marker",role:"presentation"})}),e.jsxs("span",{className:i["legend-item-label"],children:[l.text,r.find((e=>e.label===l.text))?.value&&e.jsx("span",{className:i["legend-item-value"],children:r.find((e=>e.label===l.text))?.value})]})]},l.text)))})})})};
|
|
2
2
|
//# sourceMappingURL=base-legend.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-legend.js","sources":["/@automattic/charts/../../../../src/components/legend/base-legend.tsx"],"sourcesContent":[null],"names":["orientationToFlexDirection","horizontal","vertical","items","className","orientation","legendScale","scaleOrdinal","domain","map","item","label","range","color","_jsx","clsx","styles","legend","role","children","LegendOrdinal","scale","direction","shape","shapeWidth","shapeHeight","labels","_jsxs","
|
|
1
|
+
{"version":3,"file":"base-legend.js","sources":["/@automattic/charts/../../../../src/components/legend/base-legend.tsx"],"sourcesContent":[null],"names":["orientationToFlexDirection","horizontal","vertical","items","className","orientation","legendScale","scaleOrdinal","domain","map","item","label","range","color","_jsx","clsx","styles","legend","role","children","LegendOrdinal","scale","direction","shape","shapeWidth","shapeHeight","labels","_jsxs","jsxs","width","height","fill","value","text","find"],"mappings":"+KAeA,MAAMA,EAA6B,CAClCC,WAAY,MACZC,SAAU,6BAGkC,EAC5CC,QACAC,YACAC,cAAc,iBAEd,MAAMC,EAAcC,EAAAA,aAAc,CACjCC,OAAQL,EAAMM,KAAKC,GAAQA,EAAKC,QAChCC,MAAOT,EAAMM,KAAKC,GAAQA,EAAKG,UAGhC,OACCC,EAAAA,WACCV,UAAYW,EAAMC,EAAOC,OAAQD,EAAQ,WAAYX,KAAkBD,GACvEc,KAAK,OACS,cAAA,UAAWb,IAAcc,SAEvCL,MAACM,EAAaA,cAAA,CACbC,MAAQf,EACRgB,UAAYtB,EAA4BK,GACxCkB,MAAM,OACNC,WAAa,GACbC,YAAc,GACdrB,UAAYY,EAAQ,gBAAgBG,SAElCO,GACDZ,MAAK,MAAA,CAAAV,UAAYY,EAAQ,WAAYX,KAClCc,SAAAO,EAAOjB,KAAKE,GACbgB,EAAAC,KAAA,MAAA,CAECxB,UAAYY,EAAQ,eACpBE,KAAK,WACO,cAAA,cAEZC,SAAA,CAAAL,EAAAA,IAAA,MAAA,CAAKe,MAAQ,GAAKC,OAAS,GAAKZ,KAAK,MACpCC,SAAAL,EAAAA,IAAA,OAAA,CACCe,MAAQ,GACRC,OAAS,GACTC,KAAOpB,EAAMqB,MACb5B,UAAYY,EAAQ,sBAAsB,cAC9B,gBACZE,KAAK,mBAGPS,EAAMC,KAAA,OAAA,CAAAxB,UAAYY,EAAQ,qBACvBG,SAAA,CAAAR,EAAMsB,KACN9B,EAAM+B,MAAMxB,GAAQA,EAAKC,QAAUA,EAAMsB,QAAQD,OAClDlB,EAAAA,IAAA,OAAA,CAAMV,UAAYY,EAAQ,qBAAqBG,SAC5ChB,EAAM+B,MAAMxB,GAAQA,EAAKC,QAAUA,EAAMsB,QAAQD,aAnBhDrB,EAAMsB,aA6BjB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
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
|
|
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 m=n.withResponsive((({data:n,width:m,height:u,className:p,margin:v,withTooltips:x=!0,showLegend:g=!1,legendOrientation:j="horizontal",withGradientFill:y=!1,smoothing:b=!0,options:N={}})=>{const T=l.useChartTheme(),w=s.useMemo((()=>{const e=n?.map((e=>e.options?.stroke??"")).filter(Boolean)??[];return i.buildChartTheme({...T,colors:[...e,...T.colors]})}),[T,n]);v=s.useMemo((()=>{let e={};return"right"===N.axis?.y?.orientation&&(e={...e,right:40,left:0}),"top"===N.axis?.x?.orientation&&(e={...e,top:40,bottom:0}),{...e,...v}}),[v,N]);const q=(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(q)return e.jsx("div",{className:r("line-chart",c["line-chart"]),children:q});const _=n.map(((e,t)=>({label:e.label,value:"",color:T.colors[t%T.colors.length]}))),k={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:w,width:m,height:u,margin:{top:0,right:0,bottom:0,left:0,...v},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??w.colors[s%w.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,...k,fill:y?`url(#area-gradient-${s+1})`:void 0,renderLine:!0,curve:b?t.curveCatmullRom:t.curveLinear},r?.label)]},r?.label||s)})),x&&e.jsx(i.Tooltip,{snapTooltipToDatumX:!0,snapTooltipToDatumY:!0,showSeriesGlyphs:!0,renderTooltip:d})]}),g&&e.jsx(o.BaseLegend,{items:_,orientation:j,className:c["line-chart-legend"]})]})}));module.exports=m;
|
|
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","withTooltips","showLegend","legendOrientation","withGradientFill","options","providerTheme","useChartTheme","theme","useMemo","seriesColors","series","stroke","filter","Boolean","buildChartTheme","colors","defaultMargin","
|
|
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","smoothing","options","providerTheme","useChartTheme","theme","useMemo","seriesColors","series","stroke","filter","Boolean","buildChartTheme","colors","defaultMargin","axis","y","orientation","right","left","x","top","bottom","error","length","some","isNaN","getTime","validateData","clsx","legendItems","group","index","label","color","accessors","xAccessor","d","yAccessor","role","XYChart","xScale","type","yScale","nice","zero","jsx","AnimatedGrid","columns","numTicks","AnimatedAxis","tickFormat","seriesData","LinearGradient","id","from","to","toOpacity","gradient","AnimatedAreaSeries","dataKey","fill","renderLine","curve","curveCatmullRom","curveLinear","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,CAAA,GAC/EC,KAAK,EAAIC,GAAON,aAAiB,CACjCM,MACAC,MAAOP,EAAMO,UAEbC,MAAM,CAAEC,EAAGC,IAAOA,EAAEH,MAAQE,EAAEF,QAEhC,OACCI,EAAKC,KAAA,MAAA,CAAAC,UAAYC,EAAQ,uBACxBC,SAAA,CAAAC,EAAAA,IAAA,MAAA,CAAKH,UAAYC,EAAQ,4BACtBC,SAAAhB,EAAakB,KAAKC,uBAEnBjB,EAAcI,KAAKc,GACpBR,EAAAC,KAAA,MAAA,CAAuBC,UAAYC,EAAQ,2BAC1CC,SAAA,CAAAJ,EAAAC,KAAA,OAAA,CAAMC,UAAYC,EAAQ,6BAA6BC,SAAA,CAAKI,EAAMb,IAAa,OAC/EU,EAAAA,YAAMH,UAAYC,EAAQ,6BAA6BC,SAAKI,EAAMZ,UAFxDY,EAAMb,SAMlB,EAGGc,EAAmBb,GACX,IAAIc,KAAMd,GACXW,wBAAoBI,EAAW,CAC1CC,MAAO,QACPC,IAAK,YAoJP,IAAeC,EAAAA,EAAAA,gBA/HyB,EACvCC,OACAC,QACAC,SACAf,YACAgB,SACAC,gBAAe,EACfC,cAAa,EACbC,oBAAoB,aACpBC,oBAAmB,EACnBC,aAAY,EACZC,UAAU,CAAA,MAEV,MAAMC,EAAgBC,EAAAA,gBAEhBC,EAAQC,EAAAA,SAAS,KACtB,MAAMC,EACLd,GAAMrB,KAAKoC,GAAUA,EAAON,SAASO,QAAU,KAAKC,OAAQC,UAAa,GAC1E,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UAAWxC,GAASuC,QACrCE,OAAS,CAAED,KAAM,SAAUE,MAAM,EAAMC,MAAM,KAAU3C,GAASyC,kBAEhE5D,EAAC+D,IAAAC,eAAa,CAAAC,SAAU,EAAQC,SAAW,IAC3ClE,EAAC+D,IAAAI,gBACAjC,YAAY,SACZgC,SAAW,EACXE,WAAahE,KACRe,GAASa,MAAMK,IAErBrC,MAACmE,eAAY,CAACjC,YAAY,OAAOgC,SAAW,KAAS/C,GAASa,MAAMC,IAElEvB,EAAKrB,KAAK,CAAEgF,EAAYpB,KACzB,MAAMvB,EAAS2C,EAAWlD,SAASO,QAAUJ,EAAMQ,OAAQmB,EAAQ3B,EAAMQ,OAAOW,QAChF,OACC9C,sBACGsB,GACDjB,EAAAA,IAACsE,EAAcA,gBACdC,GAAK,iBAAkBtB,EAAQ,IAC/BuB,KAAO9C,EACP+C,GAAG,QACHC,UAAY,MACPL,EAAWlD,SAASwD,SAAQ,cACrB,kBAGd3E,EAAA+D,IAACa,EAAkBA,mBAElB,CAAAC,QAAUR,GAAYnB,MACtBxC,KAAO2D,EAAW3D,QACb0C,EACL0B,KAAO7D,EAAmB,sBAAuBgC,EAAQ,UAAQ3C,EACjEyE,YAAa,EACbC,MAAQ9D,EAAY+D,EAAAA,gBAAkBC,EAAAA,aANhCb,GAAYnB,SAZXmB,GAAYnB,OAASD,EAqB7B,IAGDnC,GACDd,EAAAA,IAACmF,EAAAA,SACAC,qBAAmB,EACnBC,qBACA,EAAAC,oBACAzG,cAAgBA,OAKjBkC,GACDf,EAAAA,IAACuF,EAAAA,WACA,CAAAC,MAAQzC,EACRb,YAAclB,EACdnB,UAAYC,EAAQ,yBAItB"}
|
|
@@ -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","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":"+
|
|
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":"+bAyDA,MA2BMA,EAAW,EAChBC,OACAC,gBAAe,EACfC,YACAC,aACAC,oBACAC,OACAC,YAAY,EACZC,UAAU,GACVC,WAAW,EACXC,cAAc,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ACD8B,EAACC,IAAAwD,EAAMC,WACN,CAAAC,MAAQnC,EACRoC,YAAczF,EACdF,UAAYkC,EAAQ,sBAIpBnC,GAAgBc,GAAeC,GAChCiB,EAAAC,IAAC4D,EAAWA,YAAA,CACX9F,KAAOgB,EACPgD,IAAM9C,GAAc,EACpB+C,KAAOhD,GAAe,EACtB8E,MAAQ,CACPC,UAAW,8BAKd,EAGHjG,EAASkG,YAAc,WACvB,IAAeC,EAAAA,EAAAA,eAAiCnG"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),a=require("@visx/event"),t=require("@visx/group"),i=require("@visx/shape"),l=require("@visx/text"),s=require("@visx/tooltip"),r=require("clsx"),o=require("react"),c=require("../../providers/theme/theme-provider.js"),d=require("../legend/base-legend.js"),n=require("../shared/with-responsive.js"),h=require("../tooltip/base-tooltip.js"),p=require("./pie-semi-circle-chart.module.scss.js");const u=({data:n,width:u=400,thickness:v=.4,clockwise:m=!0,withTooltips:x=!1,showLegend:g=!1,legendOrientation:j="horizontal",label:b,note:q,className:w})=>{const N=c.useChartTheme(),{tooltipOpen:T,tooltipLeft:f,tooltipTop:M,tooltipData:y,hideTooltip:A,showTooltip:P}=s.useTooltip(),C=o.useCallback(((e,t)=>{const i=a.localPoint(e);i&&P({tooltipData:t.data,tooltipLeft:i.x,tooltipTop:i.y-10})}),[P]),I=o.useCallback((()=>{A()}),[A]),V=o.useCallback((e=>a=>{C(a,e)}),[C]),{isValid:k,message:D}=(e=>e.length?e.some((e=>e.percentage<0||e.value<0))?{isValid:!1,message:"Invalid data: Negative values are not allowed"}:e.reduce(((e,a)=>e+a.percentage),0)<=0?{isValid:!1,message:"Invalid percentage total: Must be greater than 0"}:{isValid:!0,message:""}:{isValid:!1,message:"No data available"})(n);if(!k)return e.jsx("div",{className:p["pie-semi-circle-chart"],children:e.jsx("svg",{width:u,height:u/2,"data-testid":"pie-chart-svg",children:e.jsx("text",{x:"50%",y:"50%",textAnchor:"middle",className:p.error,children:D})})});const L=u/2,R=.03,B=u-.06,S=L-R,G=Math.min(B,2*S)/2,O=G*(1-v+R),$=n.map(((e,a)=>({...e,index:a}))),z=m?-Math.PI/2:Math.PI/2,E=m?Math.PI/2:-Math.PI/2,F={value:e=>e.value,sort:(e,a)=>a.value-e.value,fill:e=>e.color||N.colors[e.index%N.colors.length]},H=n.map(((e,a)=>({label:e.label,value:e.valueDisplay||e.value.toString(),color:F.fill({...e,index:a})})));return e.jsxs("div",{className:r("pie-semi-circle-chart",p["pie-semi-circle-chart"],w),"data-testid":"pie-chart-container",children:[e.jsx("svg",{width:u,height:L,viewBox:`0 0 ${u} ${L}`,"data-testid":"pie-chart-svg",children:e.jsxs(t.Group,{top:G,left:G,children:[e.jsx(i.Pie,{data:$,pieValue:F.value,outerRadius:G,innerRadius:O,cornerRadius:3,padAngle:R,startAngle:z,endAngle:E,pieSort:F.sort,children:a=>a.arcs.map((t=>e.jsx("g",{onMouseMove:V(t),onMouseLeave:I,children:e.jsx("path",{d:a.path(t)||"",fill:F.fill(t.data),"data-testid":"pie-segment"})},t.data.label)))}),e.jsxs(t.Group,{children:[e.jsx(l.Text,{textAnchor:"middle",verticalAnchor:"start",y:-40,className:p.label,children:b}),e.jsx(l.Text,{textAnchor:"middle",verticalAnchor:"start",y:-20,className:p.note,children:q})]})]})}),x&&T&&y&&e.jsx(h.BaseTooltip,{data:{label:y.label,value:y.value,valueDisplay:y.valueDisplay},top:M||0,left:f||0}),g&&e.jsx(d.BaseLegend,{items:H,orientation:j,className:p["pie-semi-circle-chart-legend"]})]})};u.displayName="PieSemiCircleChart";var v=n.withResponsive(u);module.exports=v;
|
|
2
2
|
//# sourceMappingURL=pie-semi-circle-chart.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pie-semi-circle-chart.js","sources":["/@automattic/charts/../../../../src/components/pie-semi-circle-chart/pie-semi-circle-chart.tsx"],"sourcesContent":[null],"names":["PieSemiCircleChart","data","width","
|
|
1
|
+
{"version":3,"file":"pie-semi-circle-chart.js","sources":["/@automattic/charts/../../../../src/components/pie-semi-circle-chart/pie-semi-circle-chart.tsx"],"sourcesContent":[null],"names":["PieSemiCircleChart","data","width","thickness","clockwise","withTooltips","showLegend","legendOrientation","label","note","className","providerTheme","useChartTheme","tooltipOpen","tooltipLeft","tooltipTop","tooltipData","hideTooltip","showTooltip","useTooltip","handleMouseMove","useCallback","event","arc","coords","localPoint","x","y","handleMouseLeave","handleArcMouseMove","isValid","message","length","some","item","percentage","value","reduce","sum","validateData","_jsx","styles","children","height","jsx","textAnchor","error","pad","chartWidth","chartHeight","radius","Math","min","innerRadius","dataWithIndex","map","d","index","startAngle","PI","endAngle","accessors","sort","a","b","fill","color","colors","legendItems","valueDisplay","toString","_jsxs","clsx","viewBox","Group","top","left","Pie","pieValue","outerRadius","cornerRadius","padAngle","pieSort","pie","arcs","onMouseMove","onMouseLeave","path","Text","verticalAnchor","BaseTooltip","Legend","items","orientation","displayName","withResponsive"],"mappings":"obAkDA,MAoBMA,EAAoD,EACzDC,OACAC,QAAQ,IACRC,YAAY,GACZC,aAAY,EACZC,gBAAe,EACfC,cAAa,EACbC,oBAAoB,aACpBC,QACAC,OACAC,gBAEA,MAAMC,EAAgBC,EAAAA,iBAChBC,YAAEA,EAAWC,YAAEA,EAAWC,WAAEA,EAAUC,YAAEA,EAAWC,YAAEA,EAAWC,YAAEA,GACvEC,EAAAA,aAEKC,EAAkBC,EAAAA,aACvB,CAAEC,EAAyBC,KAC1B,MAAMC,EAASC,aAAYH,GACpBE,GAEPN,EAAa,CACZF,YAAaO,EAAItB,KACjBa,YAAaU,EAAOE,EACpBX,WAAYS,EAAOG,EAAI,IACrB,GAEJ,CAAET,IAGGU,EAAmBP,EAAAA,aAAa,KACrCJ,GAAa,GACX,CAAEA,IAECY,EAAqBR,EAAWA,aACnCE,GAAoBD,IACrBF,EAAiBE,EAAOC,EAAK,GAE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AE3BM,IAAM5D,GAAc,EACpB6D,KAAO9D,GAAe,IAItBR,GACDkC,MAACmD,EAAAA,WACA,CAAAC,MAAQxB,EACRyB,YAActF,EACdG,UAAY+B,EAAQ,oCAItB,EAGHzC,EAAmB8F,YAAc,qBACjC,IAAeC,EAAAA,EAAAA,eAA2C/F"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),i=require("@visx/responsive");require("react"),exports.withResponsive=function(t,n){const{maxWidth:r=1200,aspectRatio:s=.5,debounceTime:
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),i=require("@visx/responsive");require("react"),exports.withResponsive=function(t,n){const{maxWidth:r=1200,aspectRatio:s=.5,debounceTime:h=50}=n||{};return function(n){const{parentRef:a,width:u}=i.useParentSize({debounceTime:h,enableDebounceLeadingCall:!0,initialSize:{width:600,height:400}}),c=u?Math.min(u,r):600,o=n.height??c*s;return e.jsx("div",{ref:a,style:{width:"100%"},children:e.jsx(t,{width:c,height:o,size:c,...n})})}};
|
|
2
2
|
//# sourceMappingURL=with-responsive.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-responsive.js","sources":["/@automattic/charts/../../../../src/components/shared/with-responsive.tsx"],"sourcesContent":[null],"names":["WrappedComponent","config","maxWidth","aspectRatio","debounceTime","props","parentRef","width","parentWidth","useParentSize","enableDebounceLeadingCall","initialSize","height","containerWidth","Math","min","containerHeight","_jsx","jsx","ref","style","
|
|
1
|
+
{"version":3,"file":"with-responsive.js","sources":["/@automattic/charts/../../../../src/components/shared/with-responsive.tsx"],"sourcesContent":[null],"names":["WrappedComponent","config","maxWidth","aspectRatio","debounceTime","props","parentRef","width","parentWidth","useParentSize","enableDebounceLeadingCall","initialSize","height","containerWidth","Math","min","containerHeight","_jsx","jsx","ref","style","children","size"],"mappings":"sHAmBgB,SACfA,EACAC,GAEA,MAAMC,SAAEA,EAAW,KAAIC,YAAEA,EAAc,GAAGC,aAAEA,EAAe,IAAOH,GAAU,GAE5E,OAAO,SAA0BI,GAChC,MAAMC,UAAEA,EAAWC,MAAOC,GAAgBC,EAAAA,cAAe,CACxDL,eACAM,2BAA2B,EAC3BC,YAAa,CAAEJ,MAAO,IAAKK,OAAQ,OAI9BC,EAAiBL,EAAcM,KAAKC,IAAKP,EAAaN,GAAa,IACnEc,EAAkBX,EAAMO,QAAUC,EAAiBV,EAEzD,OACCc,EACCC,IAAA,MAAA,CAAAC,IAAMb,EACNc,MAAQ,CACPb,MAAO,QACPc,SAEDJ,MAACjB,EAAgB,CAChBO,MAAQM,EACRD,OAASI,EACTM,KAAOT,KACAR,KAIX,CACD"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("./components/bar-chart/bar-chart.js"),r=require("./components/line-chart/line-chart.js"),t=require("./components/pie-chart/pie-chart.js"),
|
|
1
|
+
"use strict";var e=require("./components/bar-chart/bar-chart.js"),r=require("./components/line-chart/line-chart.js"),t=require("./components/pie-chart/pie-chart.js"),o=require("./components/pie-semi-circle-chart/pie-semi-circle-chart.js"),s=require("./components/tooltip/base-tooltip.js"),i=require("./components/legend/base-legend.js"),p=require("./providers/theme/theme-provider.js"),a=require("./providers/theme/themes.js"),h=require("./hooks/use-chart-mouse-handler.js");exports.BarChart=e,exports.LineChart=r,exports.PieChart=t,exports.PieSemiCircleChart=o,exports.BaseTooltip=s.BaseTooltip,exports.Legend=i.BaseLegend,exports.ThemeProvider=p.ThemeProvider,exports.defaultTheme=a.defaultTheme,exports.jetpackTheme=a.jetpackTheme,exports.wooTheme=a.wooTheme,exports.useChartMouseHandler=h;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
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}};
|
|
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}},exports.jetpackTheme={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}},exports.wooTheme={backgroundColor:"#FFFFFF",labelBackgroundColor:"#FFFFFF",colors:["#80C8FF","#B999FF","#3858E9"],gridStyles:{stroke:"#787C82",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","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"}
|
|
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,yBAMnB,CAChCL,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,qBAMvB,CAC5BL,gBAAiB,UACjBC,qBAAsB,UACtBC,OAAQ,CAAE,UAAW,UAAW,WAChCC,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
|
@@ -5,6 +5,7 @@ import { LineStyles } from '@visx/xychart';
|
|
|
5
5
|
import { CSSProperties, ComponentType, ReactNode, FC } from 'react';
|
|
6
6
|
|
|
7
7
|
type ValueOf<T> = T[keyof T];
|
|
8
|
+
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
8
9
|
declare type OrientationType = ValueOf<typeof Orientation>;
|
|
9
10
|
type DataPoint = {
|
|
10
11
|
label: string;
|
|
@@ -80,6 +81,7 @@ declare type AxisOptions = {
|
|
|
80
81
|
axisLineClassName?: string;
|
|
81
82
|
labelClassName?: string;
|
|
82
83
|
tickClassName?: string;
|
|
84
|
+
tickFormat?: (value: number) => string;
|
|
83
85
|
};
|
|
84
86
|
/**
|
|
85
87
|
* Base properties shared across all chart components
|
|
@@ -101,14 +103,18 @@ type BaseChartProps<T = DataPoint | DataPointDate> = {
|
|
|
101
103
|
* Height of the chart in pixels
|
|
102
104
|
*/
|
|
103
105
|
height?: number;
|
|
106
|
+
/**
|
|
107
|
+
* Size of the chart in pixels for pie and donut charts
|
|
108
|
+
*/
|
|
109
|
+
size?: number;
|
|
104
110
|
/**
|
|
105
111
|
* Chart margins
|
|
106
112
|
*/
|
|
107
113
|
margin?: {
|
|
108
|
-
top
|
|
109
|
-
right
|
|
110
|
-
bottom
|
|
111
|
-
left
|
|
114
|
+
top?: number;
|
|
115
|
+
right?: number;
|
|
116
|
+
bottom?: number;
|
|
117
|
+
left?: number;
|
|
112
118
|
};
|
|
113
119
|
/**
|
|
114
120
|
* Whether to show tooltips on hover. False by default.
|
|
@@ -146,18 +152,13 @@ type BaseChartProps<T = DataPoint | DataPointDate> = {
|
|
|
146
152
|
|
|
147
153
|
interface BarChartProps extends BaseChartProps<SeriesData[]> {
|
|
148
154
|
}
|
|
149
|
-
declare const _default$3: (props:
|
|
155
|
+
declare const _default$3: (props: Optional<BarChartProps, "height" | "width" | "size">) => react_jsx_runtime.JSX.Element;
|
|
150
156
|
|
|
151
157
|
interface LineChartProps extends BaseChartProps<SeriesData[]> {
|
|
152
|
-
margin?: {
|
|
153
|
-
top: number;
|
|
154
|
-
right: number;
|
|
155
|
-
bottom: number;
|
|
156
|
-
left: number;
|
|
157
|
-
};
|
|
158
158
|
withGradientFill: boolean;
|
|
159
|
+
smoothing?: boolean;
|
|
159
160
|
}
|
|
160
|
-
declare const _default$2: (props:
|
|
161
|
+
declare const _default$2: (props: Optional<LineChartProps, "height" | "width" | "size">) => react_jsx_runtime.JSX.Element;
|
|
161
162
|
|
|
162
163
|
type OmitBaseChartProps = Omit<BaseChartProps<DataPointPercentage[]>, 'width' | 'height'>;
|
|
163
164
|
interface PieChartProps extends OmitBaseChartProps {
|
|
@@ -165,10 +166,6 @@ interface PieChartProps extends OmitBaseChartProps {
|
|
|
165
166
|
* Inner radius in pixels. If > 0, creates a donut chart. Defaults to 0.
|
|
166
167
|
*/
|
|
167
168
|
innerRadius?: number;
|
|
168
|
-
/**
|
|
169
|
-
* Size of the chart in pixels
|
|
170
|
-
*/
|
|
171
|
-
size?: number;
|
|
172
169
|
/**
|
|
173
170
|
* Add padding to the chart
|
|
174
171
|
*/
|
|
@@ -194,7 +191,7 @@ interface PieChartProps extends OmitBaseChartProps {
|
|
|
194
191
|
*/
|
|
195
192
|
children?: React.ReactNode;
|
|
196
193
|
}
|
|
197
|
-
declare const _default$1: (props:
|
|
194
|
+
declare const _default$1: (props: Optional<PieChartProps, "height" | "width" | "size">) => react_jsx_runtime.JSX.Element;
|
|
198
195
|
|
|
199
196
|
interface PieSemiCircleChartProps extends BaseChartProps<DataPointPercentage[]> {
|
|
200
197
|
/**
|
|
@@ -205,6 +202,11 @@ interface PieSemiCircleChartProps extends BaseChartProps<DataPointPercentage[]>
|
|
|
205
202
|
* Thickness of the pie chart. A value between 0 and 1
|
|
206
203
|
*/
|
|
207
204
|
thickness?: number;
|
|
205
|
+
/**
|
|
206
|
+
* Direction of chart rendering
|
|
207
|
+
* true for clockwise, false for counter-clockwise
|
|
208
|
+
*/
|
|
209
|
+
clockwise?: boolean;
|
|
208
210
|
/**
|
|
209
211
|
* Label text to display above the chart
|
|
210
212
|
*/
|
|
@@ -213,13 +215,8 @@ interface PieSemiCircleChartProps extends BaseChartProps<DataPointPercentage[]>
|
|
|
213
215
|
* Note text to display below the label
|
|
214
216
|
*/
|
|
215
217
|
note?: string;
|
|
216
|
-
/**
|
|
217
|
-
* Direction of chart rendering
|
|
218
|
-
* true for clockwise, false for counter-clockwise
|
|
219
|
-
*/
|
|
220
|
-
clockwise?: boolean;
|
|
221
218
|
}
|
|
222
|
-
declare const _default: (props:
|
|
219
|
+
declare const _default: (props: Optional<PieSemiCircleChartProps, "height" | "width" | "size">) => react_jsx_runtime.JSX.Element;
|
|
223
220
|
|
|
224
221
|
type TooltipData = {
|
|
225
222
|
label: string;
|
|
@@ -274,6 +271,19 @@ type ThemeProviderProps = {
|
|
|
274
271
|
};
|
|
275
272
|
declare const ThemeProvider: FC<ThemeProviderProps>;
|
|
276
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Default theme configuration
|
|
276
|
+
*/
|
|
277
|
+
declare const defaultTheme: ChartTheme;
|
|
278
|
+
/**
|
|
279
|
+
* Jetpack theme configuration
|
|
280
|
+
*/
|
|
281
|
+
declare const jetpackTheme: ChartTheme;
|
|
282
|
+
/**
|
|
283
|
+
* Woo theme configuration
|
|
284
|
+
*/
|
|
285
|
+
declare const wooTheme: ChartTheme;
|
|
286
|
+
|
|
277
287
|
type UseChartMouseHandlerProps = {
|
|
278
288
|
/**
|
|
279
289
|
* Whether tooltips are enabled
|
|
@@ -314,4 +324,4 @@ type UseChartMouseHandlerReturn = {
|
|
|
314
324
|
*/
|
|
315
325
|
declare const useChartMouseHandler: ({ withTooltips, }: UseChartMouseHandlerProps) => UseChartMouseHandlerReturn;
|
|
316
326
|
|
|
317
|
-
export { _default$3 as BarChart, BaseTooltip, BaseLegend as Legend, _default$2 as LineChart, _default$1 as PieChart, _default as PieSemiCircleChart, ThemeProvider, useChartMouseHandler };
|
|
327
|
+
export { _default$3 as BarChart, BaseTooltip, BaseLegend as Legend, _default$2 as LineChart, _default$1 as PieChart, _default as PieSemiCircleChart, ThemeProvider, defaultTheme, jetpackTheme, useChartMouseHandler, wooTheme };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsxs as
|
|
1
|
+
import{jsxs as t,jsx as i}from"react/jsx-runtime";import{GridRows as r,GridColumns as e}from"@visx/grid";import"react";import s from"./grid-control.module.scss.js";const a=({width:a,height:d,xScale:o,yScale:c,gridVisibility:l="x",top:m=0})=>t("g",{transform:`translate(0, ${m})`,className:s["grid-control"],children:[l.includes("x")&&i(r,{scale:o,width:a,"data-testid":"x-grid"}),l.includes("y")&&i(e,{scale:c,height:d,"data-testid":"y-grid"})]});export{a as default};
|
|
2
2
|
//# sourceMappingURL=grid-control.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid-control.js","sources":["../../../../src/components/grid-control/grid-control.tsx"],"sourcesContent":[null],"names":["GridControl","width","height","xScale","yScale","gridVisibility","top","_jsxs","transform","className","styles","children","includes","_jsx","GridRows","scale","GridColumns"],"mappings":"oKAKM,MAAAA,EAAqC,EAC1CC,QACAC,SACAC,SACAC,SACAC,iBAAiB,IACjBC,MAAM,KAGLC,
|
|
1
|
+
{"version":3,"file":"grid-control.js","sources":["../../../../src/components/grid-control/grid-control.tsx"],"sourcesContent":[null],"names":["GridControl","width","height","xScale","yScale","gridVisibility","top","_jsxs","transform","className","styles","children","includes","_jsx","GridRows","scale","GridColumns"],"mappings":"oKAKM,MAAAA,EAAqC,EAC1CC,QACAC,SACAC,SACAC,SACAC,iBAAiB,IACjBC,MAAM,KAGLC,EAAA,IAAA,CAAGC,UAAY,gBAAiBF,KAAUG,UAAYC,EAAQ,gBAC3DC,SAAA,CAAAN,EAAeO,SAAU,MAC1BC,EAACC,EAAQ,CAACC,MAAQZ,EAASF,MAAQA,EAAoB,cAAA,WAEtDI,EAAeO,SAAU,MAC1BC,EAACG,EAAW,CAACD,MAAQX,EAASF,OAASA,EAAM,cAAe"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as e,jsxs as l}from"react/jsx-runtime";import{LegendOrdinal as
|
|
1
|
+
import{jsx as e,jsxs as l}from"react/jsx-runtime";import{LegendOrdinal as t}from"@visx/legend";import{scaleOrdinal as a}from"@visx/scale";import i from"clsx";import"react";import s from"./legend.module.scss.js";const r={horizontal:"row",vertical:"column"},n=({items:n,className:d,orientation:m="horizontal"})=>{const o=a({domain:n.map((e=>e.label)),range:n.map((e=>e.color))});return e("div",{className:i(s.legend,s[`legend--${m}`],d),role:"list","data-testid":`legend-${m}`,children:e(t,{scale:o,direction:r[m],shape:"rect",shapeWidth:16,shapeHeight:16,className:s["legend-items"],children:t=>e("div",{className:s[`legend--${m}`],children:t.map((t=>l("div",{className:s["legend-item"],role:"listitem","data-testid":"legend-item",children:[e("svg",{width:16,height:16,role:"img",children:e("rect",{width:16,height:16,fill:t.value,className:s["legend-item-swatch"],"data-testid":"legend-marker",role:"presentation"})}),l("span",{className:s["legend-item-label"],children:[t.text,n.find((e=>e.label===t.text))?.value&&e("span",{className:s["legend-item-value"],children:n.find((e=>e.label===t.text))?.value})]})]},t.text)))})})})};export{n as BaseLegend};
|
|
2
2
|
//# sourceMappingURL=base-legend.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-legend.js","sources":["../../../../src/components/legend/base-legend.tsx"],"sourcesContent":[null],"names":["orientationToFlexDirection","horizontal","vertical","BaseLegend","items","className","orientation","legendScale","scaleOrdinal","domain","map","item","label","range","color","_jsx","clsx","styles","legend","role","children","LegendOrdinal","scale","direction","shape","shapeWidth","shapeHeight","labels","_jsxs","width","height","fill","value","text","find"],"mappings":"mNAeA,MAAMA,EAA6B,CAClCC,WAAY,MACZC,SAAU,UAGEC,EAAgC,EAC5CC,QACAC,YACAC,cAAc,iBAEd,MAAMC,EAAcC,EAAc,CACjCC,OAAQL,EAAMM,KAAKC,GAAQA,EAAKC,QAChCC,MAAOT,EAAMM,KAAKC,GAAQA,EAAKG,UAGhC,OACCC,SACCV,UAAYW,EAAMC,EAAOC,OAAQD,EAAQ,WAAYX,KAAkBD,GACvEc,KAAK,
|
|
1
|
+
{"version":3,"file":"base-legend.js","sources":["../../../../src/components/legend/base-legend.tsx"],"sourcesContent":[null],"names":["orientationToFlexDirection","horizontal","vertical","BaseLegend","items","className","orientation","legendScale","scaleOrdinal","domain","map","item","label","range","color","_jsx","clsx","styles","legend","role","children","LegendOrdinal","scale","direction","shape","shapeWidth","shapeHeight","labels","_jsxs","width","height","fill","value","text","find"],"mappings":"mNAeA,MAAMA,EAA6B,CAClCC,WAAY,MACZC,SAAU,UAGEC,EAAgC,EAC5CC,QACAC,YACAC,cAAc,iBAEd,MAAMC,EAAcC,EAAc,CACjCC,OAAQL,EAAMM,KAAKC,GAAQA,EAAKC,QAChCC,MAAOT,EAAMM,KAAKC,GAAQA,EAAKG,UAGhC,OACCC,SACCV,UAAYW,EAAMC,EAAOC,OAAQD,EAAQ,WAAYX,KAAkBD,GACvEc,KAAK,OACS,cAAA,UAAWb,IAAcc,SAEvCL,EAACM,EAAa,CACbC,MAAQf,EACRgB,UAAYvB,EAA4BM,GACxCkB,MAAM,OACNC,WAAa,GACbC,YAAc,GACdrB,UAAYY,EAAQ,gBAAgBG,SAElCO,GACDZ,EAAK,MAAA,CAAAV,UAAYY,EAAQ,WAAYX,KAClCc,SAAAO,EAAOjB,KAAKE,GACbgB,EAAA,MAAA,CAECvB,UAAYY,EAAQ,eACpBE,KAAK,WACO,cAAA,cAEZC,SAAA,CAAAL,EAAA,MAAA,CAAKc,MAAQ,GAAKC,OAAS,GAAKX,KAAK,MACpCC,SAAAL,EAAA,OAAA,CACCc,MAAQ,GACRC,OAAS,GACTC,KAAOnB,EAAMoB,MACb3B,UAAYY,EAAQ,sBAAsB,cAC9B,gBACZE,KAAK,mBAGPS,EAAM,OAAA,CAAAvB,UAAYY,EAAQ,qBACvBG,SAAA,CAAAR,EAAMqB,KACN7B,EAAM8B,MAAMvB,GAAQA,EAAKC,QAAUA,EAAMqB,QAAQD,OAClDjB,EAAA,OAAA,CAAMV,UAAYY,EAAQ,qBAAqBG,SAC5ChB,EAAM8B,MAAMvB,GAAQA,EAAKC,QAAUA,EAAMqB,QAAQD,aAnBhDpB,EAAMqB,aA6BjB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t}from"react/jsx-runtime";import{
|
|
1
|
+
import{jsx as e,jsxs as t}from"react/jsx-runtime";import{curveCatmullRom as a,curveLinear as o}from"@visx/curve";import{LinearGradient as i}from"@visx/gradient";import{buildChartTheme as r,XYChart as l,AnimatedGrid as n,AnimatedAxis as s,AnimatedAreaSeries as c,Tooltip as m}from"@visx/xychart";import d from"clsx";import{useMemo as h}from"react";import{useChartTheme as p}from"../../providers/theme/theme-provider.js";import{BaseLegend as u}from"../legend/base-legend.js";import{withResponsive as v}from"../shared/with-responsive.js";import g from"./line-chart.module.scss.js";const f=({tooltipData:a})=>{const o=a?.nearestDatum?.datum;if(!o)return null;const i=Object.entries(a?.datumByKey||{}).map((([e,{datum:t}])=>({key:e,value:t.value}))).sort(((e,t)=>t.value-e.value));return t("div",{className:g["line-chart__tooltip"],children:[e("div",{className:g["line-chart__tooltip-date"],children:o.date.toLocaleDateString()}),i.map((a=>t("div",{className:g["line-chart__tooltip-row"],children:[t("span",{className:g["line-chart__tooltip-label"],children:[a.key,":"]}),e("span",{className:g["line-chart__tooltip-value"],children:a.value})]},a.key)))]})},y=e=>new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"});var x=v((({data:v,width:x,height:N,className:b,margin:w,withTooltips:T=!0,showLegend:_=!1,legendOrientation:k="horizontal",withGradientFill:D=!1,smoothing:S=!0,options:j={}})=>{const L=p(),O=h((()=>{const e=v?.map((e=>e.options?.stroke??"")).filter(Boolean)??[];return r({...L,colors:[...e,...L.colors]})}),[L,v]);w=h((()=>{let e={};return"right"===j.axis?.y?.orientation&&(e={...e,right:40,left:0}),"top"===j.axis?.x?.orientation&&(e={...e,top:40,bottom:0}),{...e,...w}}),[w,j]);const z=(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")(v);if(z)return e("div",{className:d("line-chart",g["line-chart"]),children:z});const A=v.map(((e,t)=>({label:e.label,value:"",color:L.colors[t%L.colors.length]}))),B={xAccessor:e=>e.date,yAccessor:e=>e.value};return t("div",{className:d("line-chart",g["line-chart"],b),"data-testid":"line-chart",role:"img","aria-label":"line chart",children:[t(l,{theme:O,width:x,height:N,margin:{top:0,right:0,bottom:0,left:0,...w},xScale:{type:"time",...j?.xScale},yScale:{type:"linear",nice:!0,zero:!1,...j?.yScale},children:[e(n,{columns:!1,numTicks:4}),e(s,{orientation:"bottom",numTicks:5,tickFormat:y,...j?.axis?.x}),e(s,{orientation:"left",numTicks:4,...j?.axis?.y}),v.map(((r,l)=>{const n=r.options?.stroke??O.colors[l%O.colors.length];return t("g",{children:[D&&e(i,{id:`area-gradient-${l+1}`,from:n,to:"white",toOpacity:.1,...r.options?.gradient,"data-testid":"line-gradient"}),e(c,{dataKey:r?.label,data:r.data,...B,fill:D?`url(#area-gradient-${l+1})`:void 0,renderLine:!0,curve:S?a:o},r?.label)]},r?.label||l)})),T&&e(m,{snapTooltipToDatumX:!0,snapTooltipToDatumY:!0,showSeriesGlyphs:!0,renderTooltip:f})]}),_&&e(u,{items:A,orientation:k,className:g["line-chart-legend"]})]})}));export{x 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","withTooltips","showLegend","legendOrientation","withGradientFill","options","providerTheme","useChartTheme","theme","useMemo","seriesColors","series","stroke","filter","Boolean","buildChartTheme","colors","defaultMargin","
|
|
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","smoothing","options","providerTheme","useChartTheme","theme","useMemo","seriesColors","series","stroke","filter","Boolean","buildChartTheme","colors","defaultMargin","axis","y","orientation","right","left","x","top","bottom","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","curveCatmullRom","curveLinear","Tooltip","snapTooltipToDatumX","snapTooltipToDatumY","showSeriesGlyphs","Legend","items"],"mappings":"kkBAiCA,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,YAoJP,IAAeC,EA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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":"
|
|
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":"8iBAyDA,MA2B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AKyD,UAdL,OAAQN,IAkBhB,MAKHzC,OAIFP,GACD8B,EAACuD,EACA,CAAAC,MAAQjC,EACRkC,YAActF,EACdF,UAAYiC,EAAQ,sBAIpBlC,GAAgBc,GAAeC,GAChCiB,EAAC0D,EAAW,CACX3F,KAAOgB,EACP+C,IAAM7C,GAAc,EACpB8C,KAAO/C,GAAe,EACtB2E,MAAQ,CACPC,UAAW,8BAKd,EAGH9F,EAAS+F,YAAc,WACvB,IAAeC,EAAAC,EAAiCjG"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{jsx as e,jsxs as t}from"react/jsx-runtime";import{localPoint as a}from"@visx/event";import{Group as i}from"@visx/group";import{Pie as l}from"@visx/shape";import{Text as o}from"@visx/text";import{useTooltip as r}from"@visx/tooltip";import s from"clsx";import{useCallback as d}from"react";import{useChartTheme as c}from"../../providers/theme/theme-provider.js";import{BaseLegend as n}from"../legend/base-legend.js";import{withResponsive as p}from"../shared/with-responsive.js";import{BaseTooltip as m}from"../tooltip/base-tooltip.js";import h from"./pie-semi-circle-chart.module.scss.js";const v=({data:p,width:v=400,thickness:g=.4,clockwise:u=!0,withTooltips:f=!1,showLegend:x=!1,legendOrientation:b="horizontal",label:w,note:N,className:M})=>{const y=c(),{tooltipOpen:A,tooltipLeft:j,tooltipTop:I,tooltipData:V,hideTooltip:D,showTooltip:P}=r(),T=d(((e,t)=>{const i=a(e);i&&P({tooltipData:t.data,tooltipLeft:i.x,tooltipTop:i.y-10})}),[P]),L=d((()=>{D()}),[D]),R=d((e=>t=>{T(t,e)}),[T]),{isValid:S,message:k}=(e=>e.length?e.some((e=>e.percentage<0||e.value<0))?{isValid:!1,message:"Invalid data: Negative values are not allowed"}:e.reduce(((e,t)=>e+t.percentage),0)<=0?{isValid:!1,message:"Invalid percentage total: Must be greater than 0"}:{isValid:!0,message:""}:{isValid:!1,message:"No data available"})(p);if(!S)return e("div",{className:h["pie-semi-circle-chart"],children:e("svg",{width:v,height:v/2,"data-testid":"pie-chart-svg",children:e("text",{x:"50%",y:"50%",textAnchor:"middle",className:h.error,children:k})})});const C=v/2,O=.03,$=v-.06,z=C-O,B=Math.min($,2*z)/2,q=B*(1-g+O),E=p.map(((e,t)=>({...e,index:t}))),F=u?-Math.PI/2:Math.PI/2,G=u?Math.PI/2:-Math.PI/2,H={value:e=>e.value,sort:(e,t)=>t.value-e.value,fill:e=>e.color||y.colors[e.index%y.colors.length]},J=p.map(((e,t)=>({label:e.label,value:e.valueDisplay||e.value.toString(),color:H.fill({...e,index:t})})));return t("div",{className:s("pie-semi-circle-chart",h["pie-semi-circle-chart"],M),"data-testid":"pie-chart-container",children:[e("svg",{width:v,height:C,viewBox:`0 0 ${v} ${C}`,"data-testid":"pie-chart-svg",children:t(i,{top:B,left:B,children:[e(l,{data:E,pieValue:H.value,outerRadius:B,innerRadius:q,cornerRadius:3,padAngle:O,startAngle:F,endAngle:G,pieSort:H.sort,children:t=>t.arcs.map((a=>e("g",{onMouseMove:R(a),onMouseLeave:L,children:e("path",{d:t.path(a)||"",fill:H.fill(a.data),"data-testid":"pie-segment"})},a.data.label)))}),t(i,{children:[e(o,{textAnchor:"middle",verticalAnchor:"start",y:-40,className:h.label,children:w}),e(o,{textAnchor:"middle",verticalAnchor:"start",y:-20,className:h.note,children:N})]})]})}),f&&A&&V&&e(m,{data:{label:V.label,value:V.value,valueDisplay:V.valueDisplay},top:I||0,left:j||0}),x&&e(n,{items:J,orientation:b,className:h["pie-semi-circle-chart-legend"]})]})};v.displayName="PieSemiCircleChart";var g=p(v);export{g as default};
|
|
2
2
|
//# sourceMappingURL=pie-semi-circle-chart.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pie-semi-circle-chart.js","sources":["../../../../src/components/pie-semi-circle-chart/pie-semi-circle-chart.tsx"],"sourcesContent":[null],"names":["PieSemiCircleChart","data","width","
|
|
1
|
+
{"version":3,"file":"pie-semi-circle-chart.js","sources":["../../../../src/components/pie-semi-circle-chart/pie-semi-circle-chart.tsx"],"sourcesContent":[null],"names":["PieSemiCircleChart","data","width","thickness","clockwise","withTooltips","showLegend","legendOrientation","label","note","className","providerTheme","useChartTheme","tooltipOpen","tooltipLeft","tooltipTop","tooltipData","hideTooltip","showTooltip","useTooltip","handleMouseMove","useCallback","event","arc","coords","localPoint","x","y","handleMouseLeave","handleArcMouseMove","isValid","message","length","some","item","percentage","value","reduce","sum","validateData","_jsx","styles","children","height","textAnchor","error","pad","chartWidth","chartHeight","radius","Math","min","innerRadius","dataWithIndex","map","d","index","startAngle","PI","endAngle","accessors","sort","a","b","fill","color","colors","legendItems","valueDisplay","toString","_jsxs","clsx","viewBox","Group","top","left","Pie","pieValue","outerRadius","cornerRadius","padAngle","pieSort","pie","arcs","onMouseMove","onMouseLeave","path","Text","verticalAnchor","BaseTooltip","Legend","items","orientation","displayName","pieSemiCircleChart","withResponsive"],"mappings":"ilBAkDA,MAoBMA,EAAoD,EACzDC,OACAC,QAAQ,IACRC,YAAY,GACZC,aAAY,EACZC,gBAAe,EACfC,cAAa,EACbC,oBAAoB,aACpBC,QACAC,OACAC,gBAEA,MAAMC,EAAgBC,KAChBC,YAAEA,EAAWC,YAAEA,EAAWC,WAAEA,EAAUC,YAAEA,EAAWC,YAAEA,EAAWC,YAAEA,GACvEC,IAEKC,EAAkBC,GACvB,CAAEC,EAAyBC,KAC1B,MAAMC,EAASC,EAAYH,GACpBE,GAEPN,EAAa,CACZF,YAAaO,EAAItB,KACjBa,YAAaU,EAAOE,EACpBX,WAAYS,EAAOG,EAAI,IACrB,GAEJ,CAAET,IAGGU,EAAmBP,GAAa,KACrCJ,GAAa,GACX,CAAEA,IAECY,EAAqBR,GACxBE,GAAoBD,IACrBF,EAAiBE,EAAOC,EAAK,GAE9B,CAAEH,KAIGU,QAAEA,EAAOC,QAAEA,GA9DG,CAAE9B,GACfA,EAAK+B,OAKc/B,EAAKgC,MAAMC,GAAQA,EAAKC,WAAa,GAAKD,EAAKE,MAAQ,I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import{useParentSize as i}from"@visx/responsive";import"react";function t(t,n){const{maxWidth:r=1200,aspectRatio:o=.5,debounceTime:h=50}=n||{};return function(n){const{parentRef:a,width:c}=i({debounceTime:h,enableDebounceLeadingCall:!0,initialSize:{width:600,height:400}}),
|
|
1
|
+
import{jsx as e}from"react/jsx-runtime";import{useParentSize as i}from"@visx/responsive";import"react";function t(t,n){const{maxWidth:r=1200,aspectRatio:o=.5,debounceTime:h=50}=n||{};return function(n){const{parentRef:a,width:c}=i({debounceTime:h,enableDebounceLeadingCall:!0,initialSize:{width:600,height:400}}),d=c?Math.min(c,r):600,m=n.height??d*o;return e("div",{ref:a,style:{width:"100%"},children:e(t,{width:d,height:m,size:d,...n})})}}export{t as withResponsive};
|
|
2
2
|
//# sourceMappingURL=with-responsive.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-responsive.js","sources":["../../../../src/components/shared/with-responsive.tsx"],"sourcesContent":[null],"names":["withResponsive","WrappedComponent","config","maxWidth","aspectRatio","debounceTime","props","parentRef","width","parentWidth","useParentSize","enableDebounceLeadingCall","initialSize","height","containerWidth","Math","min","containerHeight","_jsx","ref","style","
|
|
1
|
+
{"version":3,"file":"with-responsive.js","sources":["../../../../src/components/shared/with-responsive.tsx"],"sourcesContent":[null],"names":["withResponsive","WrappedComponent","config","maxWidth","aspectRatio","debounceTime","props","parentRef","width","parentWidth","useParentSize","enableDebounceLeadingCall","initialSize","height","containerWidth","Math","min","containerHeight","_jsx","ref","style","children","size"],"mappings":"uGAmBgB,SAAAA,EACfC,EACAC,GAEA,MAAMC,SAAEA,EAAW,KAAIC,YAAEA,EAAc,GAAGC,aAAEA,EAAe,IAAOH,GAAU,GAE5E,OAAO,SAA0BI,GAChC,MAAMC,UAAEA,EAAWC,MAAOC,GAAgBC,EAAe,CACxDL,eACAM,2BAA2B,EAC3BC,YAAa,CAAEJ,MAAO,IAAKK,OAAQ,OAI9BC,EAAiBL,EAAcM,KAAKC,IAAKP,EAAaN,GAAa,IACnEc,EAAkBX,EAAMO,QAAUC,EAAiBV,EAEzD,OACCc,EACC,MAAA,CAAAC,IAAMZ,EACNa,MAAQ,CACPZ,MAAO,QACPa,SAEDH,EAACjB,EAAgB,CAChBO,MAAQM,EACRD,OAASI,EACTK,KAAOR,KACAR,KAIX,CACD"}
|
package/dist/mjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{default as BarChart}from"./components/bar-chart/bar-chart.js";export{default as LineChart}from"./components/line-chart/line-chart.js";export{default as PieChart}from"./components/pie-chart/pie-chart.js";export{default as PieSemiCircleChart}from"./components/pie-semi-circle-chart/pie-semi-circle-chart.js";export{BaseTooltip}from"./components/tooltip/base-tooltip.js";export{BaseLegend as Legend}from"./components/legend/base-legend.js";export{ThemeProvider}from"./providers/theme/theme-provider.js";export{default as useChartMouseHandler}from"./hooks/use-chart-mouse-handler.js";
|
|
1
|
+
export{default as BarChart}from"./components/bar-chart/bar-chart.js";export{default as LineChart}from"./components/line-chart/line-chart.js";export{default as PieChart}from"./components/pie-chart/pie-chart.js";export{default as PieSemiCircleChart}from"./components/pie-semi-circle-chart/pie-semi-circle-chart.js";export{BaseTooltip}from"./components/tooltip/base-tooltip.js";export{BaseLegend as Legend}from"./components/legend/base-legend.js";export{ThemeProvider}from"./providers/theme/theme-provider.js";export{defaultTheme,jetpackTheme,wooTheme}from"./providers/theme/themes.js";export{default as useChartMouseHandler}from"./hooks/use-chart-mouse-handler.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
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};
|
|
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}},F={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}},r={backgroundColor:"#FFFFFF",labelBackgroundColor:"#FFFFFF",colors:["#80C8FF","#B999FF","#3858E9"],gridStyles:{stroke:"#787C82",strokeWidth:1},tickLength:4,gridColor:"",gridColorDark:"",xTickLineStyles:{stroke:"black"},xAxisLineStyles:{stroke:"#DCDCDE",strokeWidth:1}};export{o as defaultTheme,F as jetpackTheme,r as wooTheme};
|
|
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","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"}
|
|
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","jetpackTheme","wooTheme"],"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,IAM9CM,EAA2B,CAChCX,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,IAM9CO,EAAuB,CAC5BZ,gBAAiB,UACjBC,qBAAsB,UACtBC,OAAQ,CAAE,UAAW,UAAW,WAChCC,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.
|
|
3
|
+
"version": "0.8.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": {
|
|
@@ -80,14 +80,16 @@
|
|
|
80
80
|
"@rollup/plugin-typescript": "12.1.0",
|
|
81
81
|
"@storybook/blocks": "8.4.7",
|
|
82
82
|
"@storybook/react": "8.4.7",
|
|
83
|
+
"@testing-library/dom": "^8.20.1",
|
|
83
84
|
"@testing-library/jest-dom": "^6.0.0",
|
|
84
85
|
"@testing-library/react": "^14.0.0",
|
|
86
|
+
"@testing-library/user-event": "^14.4.3",
|
|
85
87
|
"@types/jest": "^29.0.0",
|
|
86
88
|
"@types/react": "18.3.18",
|
|
87
89
|
"@types/react-dom": "18.3.5",
|
|
88
90
|
"@types/testing-library__jest-dom": "^5.14.9",
|
|
89
|
-
"@wordpress/babel-plugin-import-jsx-pragma": "5.
|
|
90
|
-
"@wordpress/element": "6.
|
|
91
|
+
"@wordpress/babel-plugin-import-jsx-pragma": "5.17.0",
|
|
92
|
+
"@wordpress/element": "6.17.0",
|
|
91
93
|
"babel-jest": "^29.7.0",
|
|
92
94
|
"babel-loader": "9.1.2",
|
|
93
95
|
"clean-webpack-plugin": "^4.0.0",
|
|
@@ -13,8 +13,12 @@ const GridControl: React.FC< GridProps > = ( {
|
|
|
13
13
|
} ) => {
|
|
14
14
|
return (
|
|
15
15
|
<g transform={ `translate(0, ${ top })` } className={ styles[ 'grid-control' ] }>
|
|
16
|
-
{ gridVisibility.includes( 'x' ) &&
|
|
17
|
-
|
|
16
|
+
{ gridVisibility.includes( 'x' ) && (
|
|
17
|
+
<GridRows scale={ xScale } width={ width } data-testid="x-grid" />
|
|
18
|
+
) }
|
|
19
|
+
{ gridVisibility.includes( 'y' ) && (
|
|
20
|
+
<GridColumns scale={ yScale } height={ height } data-testid="y-grid" />
|
|
21
|
+
) }
|
|
18
22
|
</g>
|
|
19
23
|
);
|
|
20
24
|
};
|
|
@@ -32,6 +32,7 @@ export const BaseLegend: FC< LegendProps > = ( {
|
|
|
32
32
|
<div
|
|
33
33
|
className={ clsx( styles.legend, styles[ `legend--${ orientation }` ], className ) }
|
|
34
34
|
role="list"
|
|
35
|
+
data-testid={ `legend-${ orientation }` }
|
|
35
36
|
>
|
|
36
37
|
<LegendOrdinal
|
|
37
38
|
scale={ legendScale }
|
|
@@ -44,13 +45,20 @@ export const BaseLegend: FC< LegendProps > = ( {
|
|
|
44
45
|
{ labels => (
|
|
45
46
|
<div className={ styles[ `legend--${ orientation }` ] }>
|
|
46
47
|
{ labels.map( label => (
|
|
47
|
-
<div
|
|
48
|
-
|
|
48
|
+
<div
|
|
49
|
+
key={ label.text }
|
|
50
|
+
className={ styles[ 'legend-item' ] }
|
|
51
|
+
role="listitem"
|
|
52
|
+
data-testid="legend-item"
|
|
53
|
+
>
|
|
54
|
+
<svg width={ 16 } height={ 16 } role="img">
|
|
49
55
|
<rect
|
|
50
56
|
width={ 16 }
|
|
51
57
|
height={ 16 }
|
|
52
58
|
fill={ label.value }
|
|
53
59
|
className={ styles[ 'legend-item-swatch' ] }
|
|
60
|
+
data-testid="legend-marker"
|
|
61
|
+
role="presentation"
|
|
54
62
|
/>
|
|
55
63
|
</svg>
|
|
56
64
|
<span className={ styles[ 'legend-item-label' ] }>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { BaseLegend } from './base-legend';
|
|
3
|
+
|
|
4
|
+
describe( 'BaseLegend', () => {
|
|
5
|
+
const defaultItems = [
|
|
6
|
+
{ label: 'Item 1', value: '50%', color: '#ff0000' },
|
|
7
|
+
{ label: 'Item 2', value: '30%', color: '#00ff00' },
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
test( 'renders horizontal legend items', () => {
|
|
11
|
+
render( <BaseLegend items={ defaultItems } orientation="horizontal" /> );
|
|
12
|
+
expect( screen.getByText( 'Item 1' ) ).toBeInTheDocument();
|
|
13
|
+
expect( screen.getByText( 'Item 2' ) ).toBeInTheDocument();
|
|
14
|
+
expect( screen.getByText( '50%' ) ).toBeInTheDocument();
|
|
15
|
+
expect( screen.getByText( '30%' ) ).toBeInTheDocument();
|
|
16
|
+
} );
|
|
17
|
+
|
|
18
|
+
test( 'renders vertical legend items', () => {
|
|
19
|
+
render( <BaseLegend items={ defaultItems } orientation="vertical" /> );
|
|
20
|
+
const items = screen.getAllByText( /Item \d/ );
|
|
21
|
+
expect( items ).toHaveLength( 2 );
|
|
22
|
+
} );
|
|
23
|
+
|
|
24
|
+
test( 'applies color styles to legend markers', () => {
|
|
25
|
+
render( <BaseLegend items={ defaultItems } orientation="horizontal" /> );
|
|
26
|
+
const markers = screen.getAllByTestId( 'legend-marker' );
|
|
27
|
+
expect( markers[ 0 ] ).toHaveAttribute( 'fill', '#ff0000' );
|
|
28
|
+
expect( markers[ 1 ] ).toHaveAttribute( 'fill', '#00ff00' );
|
|
29
|
+
} );
|
|
30
|
+
|
|
31
|
+
test( 'handles empty items array', () => {
|
|
32
|
+
render( <BaseLegend items={ [] } orientation="horizontal" /> );
|
|
33
|
+
const legendItems = screen.queryAllByRole( 'listitem' );
|
|
34
|
+
expect( legendItems ).toHaveLength( 0 );
|
|
35
|
+
} );
|
|
36
|
+
|
|
37
|
+
test( 'handles missing values', () => {
|
|
38
|
+
const itemsWithoutValues = [
|
|
39
|
+
{ label: 'Item 1', color: '#ff0000', value: undefined },
|
|
40
|
+
{ label: 'Item 2', color: '#00ff00', value: undefined },
|
|
41
|
+
];
|
|
42
|
+
render( <BaseLegend items={ itemsWithoutValues } orientation="horizontal" /> );
|
|
43
|
+
expect( screen.getByText( 'Item 1' ) ).toBeInTheDocument();
|
|
44
|
+
expect( screen.getByText( 'Item 2' ) ).toBeInTheDocument();
|
|
45
|
+
} );
|
|
46
|
+
|
|
47
|
+
test( 'applies custom className', () => {
|
|
48
|
+
render(
|
|
49
|
+
<BaseLegend items={ defaultItems } className="custom-legend" orientation="horizontal" />
|
|
50
|
+
);
|
|
51
|
+
expect( screen.getByRole( 'list' ) ).toHaveClass( 'custom-legend' );
|
|
52
|
+
} );
|
|
53
|
+
|
|
54
|
+
test( 'renders with correct orientation styles', () => {
|
|
55
|
+
const { rerender } = render( <BaseLegend items={ defaultItems } orientation="horizontal" /> );
|
|
56
|
+
expect( screen.getByTestId( 'legend-horizontal' ) ).toBeInTheDocument();
|
|
57
|
+
|
|
58
|
+
rerender( <BaseLegend items={ defaultItems } orientation="vertical" /> );
|
|
59
|
+
expect( screen.getByTestId( 'legend-vertical' ) ).toBeInTheDocument();
|
|
60
|
+
} );
|
|
61
|
+
|
|
62
|
+
test( 'renders legend items with correct spacing', () => {
|
|
63
|
+
render( <BaseLegend items={ defaultItems } orientation="horizontal" /> );
|
|
64
|
+
const items = screen.getAllByTestId( 'legend-item' );
|
|
65
|
+
expect( items ).toHaveLength( 2 );
|
|
66
|
+
} );
|
|
67
|
+
|
|
68
|
+
test( 'handles items with long labels', () => {
|
|
69
|
+
const itemsWithLongLabels = [
|
|
70
|
+
{ label: 'Very Long Label That Should Still Display', value: '50%', color: '#ff0000' },
|
|
71
|
+
{ label: 'Another Long Label for Testing', value: '30%', color: '#00ff00' },
|
|
72
|
+
];
|
|
73
|
+
render( <BaseLegend items={ itemsWithLongLabels } orientation="horizontal" /> );
|
|
74
|
+
expect( screen.getByText( 'Very Long Label That Should Still Display' ) ).toBeInTheDocument();
|
|
75
|
+
} );
|
|
76
|
+
} );
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { curveCatmullRom, curveLinear } from '@visx/curve';
|
|
2
2
|
import { LinearGradient } from '@visx/gradient';
|
|
3
3
|
import {
|
|
4
4
|
XYChart,
|
|
@@ -17,8 +17,8 @@ import styles from './line-chart.module.scss';
|
|
|
17
17
|
import type { BaseChartProps, DataPointDate, SeriesData } from '../../types';
|
|
18
18
|
|
|
19
19
|
interface LineChartProps extends BaseChartProps< SeriesData[] > {
|
|
20
|
-
margin?: { top: number; right: number; bottom: number; left: number };
|
|
21
20
|
withGradientFill: boolean;
|
|
21
|
+
smoothing?: boolean;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
type TooltipData = {
|
|
@@ -102,6 +102,7 @@ const LineChart: FC< LineChartProps > = ( {
|
|
|
102
102
|
showLegend = false,
|
|
103
103
|
legendOrientation = 'horizontal',
|
|
104
104
|
withGradientFill = false,
|
|
105
|
+
smoothing = true,
|
|
105
106
|
options = {},
|
|
106
107
|
} ) => {
|
|
107
108
|
const providerTheme = useChartTheme();
|
|
@@ -118,7 +119,7 @@ const LineChart: FC< LineChartProps > = ( {
|
|
|
118
119
|
margin = useMemo( () => {
|
|
119
120
|
// Auto-margin unless specified to make room for axis labels.
|
|
120
121
|
// Default margin is for bottom and left axis labels.
|
|
121
|
-
let defaultMargin = {
|
|
122
|
+
let defaultMargin = {};
|
|
122
123
|
if ( options.axis?.y?.orientation === 'right' ) {
|
|
123
124
|
defaultMargin = { ...defaultMargin, right: 40, left: 0 };
|
|
124
125
|
}
|
|
@@ -157,7 +158,7 @@ const LineChart: FC< LineChartProps > = ( {
|
|
|
157
158
|
theme={ theme }
|
|
158
159
|
width={ width }
|
|
159
160
|
height={ height }
|
|
160
|
-
margin={ margin }
|
|
161
|
+
margin={ { top: 0, right: 0, bottom: 0, left: 0, ...margin } }
|
|
161
162
|
xScale={ { type: 'time', ...options?.xScale } }
|
|
162
163
|
yScale={ { type: 'linear', nice: true, zero: false, ...options?.yScale } }
|
|
163
164
|
>
|
|
@@ -191,7 +192,7 @@ const LineChart: FC< LineChartProps > = ( {
|
|
|
191
192
|
{ ...accessors }
|
|
192
193
|
fill={ withGradientFill ? `url(#area-gradient-${ index + 1 })` : undefined }
|
|
193
194
|
renderLine={ true }
|
|
194
|
-
curve={
|
|
195
|
+
curve={ smoothing ? curveCatmullRom : curveLinear }
|
|
195
196
|
/>
|
|
196
197
|
</g>
|
|
197
198
|
);
|
|
@@ -24,66 +24,66 @@ interface PieSemiCircleChartProps extends BaseChartProps< DataPointPercentage[]
|
|
|
24
24
|
*/
|
|
25
25
|
thickness?: number;
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Direction of chart rendering
|
|
29
|
+
* true for clockwise, false for counter-clockwise
|
|
30
|
+
*/
|
|
31
|
+
clockwise?: boolean;
|
|
32
|
+
|
|
27
33
|
/**
|
|
28
34
|
* Label text to display above the chart
|
|
29
35
|
*/
|
|
30
36
|
label?: string;
|
|
37
|
+
|
|
31
38
|
/**
|
|
32
39
|
* Note text to display below the label
|
|
33
40
|
*/
|
|
34
41
|
note?: string;
|
|
35
|
-
/**
|
|
36
|
-
* Direction of chart rendering
|
|
37
|
-
* true for clockwise, false for counter-clockwise
|
|
38
|
-
*/
|
|
39
|
-
clockwise?: boolean;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
type ArcData = PieArcDatum< DataPointPercentage >;
|
|
43
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Validates the semi-circle pie chart data
|
|
48
|
+
* @param data - The data to validate
|
|
49
|
+
* @return Object containing validation result and error message
|
|
50
|
+
*/
|
|
51
|
+
const validateData = ( data: DataPointPercentage[] ) => {
|
|
52
|
+
if ( ! data.length ) {
|
|
53
|
+
return { isValid: false, message: 'No data available' };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Check for negative values
|
|
57
|
+
const hasNegativeValues = data.some( item => item.percentage < 0 || item.value < 0 );
|
|
58
|
+
if ( hasNegativeValues ) {
|
|
59
|
+
return { isValid: false, message: 'Invalid data: Negative values are not allowed' };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Validate total percentage is greater than 0
|
|
63
|
+
const totalPercentage = data.reduce( ( sum, item ) => sum + item.percentage, 0 );
|
|
64
|
+
if ( totalPercentage <= 0 ) {
|
|
65
|
+
return { isValid: false, message: 'Invalid percentage total: Must be greater than 0' };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return { isValid: true, message: '' };
|
|
69
|
+
};
|
|
70
|
+
|
|
44
71
|
const PieSemiCircleChart: FC< PieSemiCircleChartProps > = ( {
|
|
45
72
|
data,
|
|
46
|
-
width,
|
|
73
|
+
width = 400,
|
|
74
|
+
thickness = 0.4,
|
|
75
|
+
clockwise = true,
|
|
76
|
+
withTooltips = false,
|
|
77
|
+
showLegend = false,
|
|
78
|
+
legendOrientation = 'horizontal',
|
|
47
79
|
label,
|
|
48
80
|
note,
|
|
49
81
|
className,
|
|
50
|
-
withTooltips = false,
|
|
51
|
-
clockwise = true,
|
|
52
|
-
thickness = 0.4,
|
|
53
|
-
showLegend,
|
|
54
|
-
legendOrientation,
|
|
55
82
|
} ) => {
|
|
56
83
|
const providerTheme = useChartTheme();
|
|
57
84
|
const { tooltipOpen, tooltipLeft, tooltipTop, tooltipData, hideTooltip, showTooltip } =
|
|
58
85
|
useTooltip< DataPointPercentage >();
|
|
59
86
|
|
|
60
|
-
const centerX = width / 2;
|
|
61
|
-
const height = width / 2;
|
|
62
|
-
const radius = width / 2;
|
|
63
|
-
const pad = 0.03;
|
|
64
|
-
const innerRadius = radius * ( 1 - thickness + pad );
|
|
65
|
-
|
|
66
|
-
// Map the data to include index for color assignment
|
|
67
|
-
const dataWithIndex = data.map( ( d, index ) => ( {
|
|
68
|
-
...d,
|
|
69
|
-
index,
|
|
70
|
-
} ) );
|
|
71
|
-
|
|
72
|
-
// Set the clockwise direction based on the prop
|
|
73
|
-
const startAngle = clockwise ? -Math.PI / 2 : Math.PI / 2;
|
|
74
|
-
const endAngle = clockwise ? Math.PI / 2 : -Math.PI / 2;
|
|
75
|
-
|
|
76
|
-
const accessors = {
|
|
77
|
-
value: ( d: DataPointPercentage & { index: number } ) => d.value,
|
|
78
|
-
sort: (
|
|
79
|
-
a: DataPointPercentage & { index: number },
|
|
80
|
-
b: DataPointPercentage & { index: number }
|
|
81
|
-
) => b.value - a.value,
|
|
82
|
-
// Use the color property from the data object as a last resort. The theme provides colours by default.
|
|
83
|
-
fill: ( d: DataPointPercentage & { index: number } ) =>
|
|
84
|
-
d.color || providerTheme.colors[ d.index % providerTheme.colors.length ],
|
|
85
|
-
};
|
|
86
|
-
|
|
87
87
|
const handleMouseMove = useCallback(
|
|
88
88
|
( event: React.MouseEvent, arc: ArcData ) => {
|
|
89
89
|
const coords = localPoint( event );
|
|
@@ -109,6 +109,52 @@ const PieSemiCircleChart: FC< PieSemiCircleChartProps > = ( {
|
|
|
109
109
|
[ handleMouseMove ]
|
|
110
110
|
);
|
|
111
111
|
|
|
112
|
+
// Add validation check
|
|
113
|
+
const { isValid, message } = validateData( data );
|
|
114
|
+
|
|
115
|
+
if ( ! isValid ) {
|
|
116
|
+
return (
|
|
117
|
+
<div className={ styles[ 'pie-semi-circle-chart' ] }>
|
|
118
|
+
<svg width={ width } height={ width / 2 } data-testid="pie-chart-svg">
|
|
119
|
+
<text x="50%" y="50%" textAnchor="middle" className={ styles.error }>
|
|
120
|
+
{ message }
|
|
121
|
+
</text>
|
|
122
|
+
</svg>
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const height = width / 2;
|
|
128
|
+
const pad = 0.03;
|
|
129
|
+
|
|
130
|
+
// Use padding for the overall chart dimensions
|
|
131
|
+
const chartWidth = width - pad * 2;
|
|
132
|
+
const chartHeight = height - pad;
|
|
133
|
+
const radius = Math.min( chartWidth, chartHeight * 2 ) / 2;
|
|
134
|
+
|
|
135
|
+
const innerRadius = radius * ( 1 - thickness + pad );
|
|
136
|
+
|
|
137
|
+
// Map the data to include index for color assignment
|
|
138
|
+
const dataWithIndex = data.map( ( d, index ) => ( {
|
|
139
|
+
...d,
|
|
140
|
+
index,
|
|
141
|
+
} ) );
|
|
142
|
+
|
|
143
|
+
// Set the clockwise direction based on the prop
|
|
144
|
+
const startAngle = clockwise ? -Math.PI / 2 : Math.PI / 2;
|
|
145
|
+
const endAngle = clockwise ? Math.PI / 2 : -Math.PI / 2;
|
|
146
|
+
|
|
147
|
+
const accessors = {
|
|
148
|
+
value: ( d: DataPointPercentage & { index: number } ) => d.value,
|
|
149
|
+
sort: (
|
|
150
|
+
a: DataPointPercentage & { index: number },
|
|
151
|
+
b: DataPointPercentage & { index: number }
|
|
152
|
+
) => b.value - a.value,
|
|
153
|
+
// Use the color property from the data object as a last resort. The theme provides colours by default.
|
|
154
|
+
fill: ( d: DataPointPercentage & { index: number } ) =>
|
|
155
|
+
d.color || providerTheme.colors[ d.index % providerTheme.colors.length ],
|
|
156
|
+
};
|
|
157
|
+
|
|
112
158
|
// Create legend items
|
|
113
159
|
const legendItems = data.map( ( item, index ) => ( {
|
|
114
160
|
label: item.label,
|
|
@@ -119,10 +165,16 @@ const PieSemiCircleChart: FC< PieSemiCircleChartProps > = ( {
|
|
|
119
165
|
return (
|
|
120
166
|
<div
|
|
121
167
|
className={ clsx( 'pie-semi-circle-chart', styles[ 'pie-semi-circle-chart' ], className ) }
|
|
168
|
+
data-testid="pie-chart-container"
|
|
122
169
|
>
|
|
123
|
-
<svg
|
|
170
|
+
<svg
|
|
171
|
+
width={ width }
|
|
172
|
+
height={ height }
|
|
173
|
+
viewBox={ `0 0 ${ width } ${ height }` }
|
|
174
|
+
data-testid="pie-chart-svg"
|
|
175
|
+
>
|
|
124
176
|
{ /* Main chart group that contains both the pie and text elements */ }
|
|
125
|
-
<Group top={
|
|
177
|
+
<Group top={ radius } left={ radius }>
|
|
126
178
|
{ /* Pie chart */ }
|
|
127
179
|
<Pie< DataPointPercentage & { index: number } >
|
|
128
180
|
data={ dataWithIndex }
|
|
@@ -142,7 +194,11 @@ const PieSemiCircleChart: FC< PieSemiCircleChartProps > = ( {
|
|
|
142
194
|
onMouseMove={ handleArcMouseMove( arc ) }
|
|
143
195
|
onMouseLeave={ handleMouseLeave }
|
|
144
196
|
>
|
|
145
|
-
<path
|
|
197
|
+
<path
|
|
198
|
+
d={ pie.path( arc ) || '' }
|
|
199
|
+
fill={ accessors.fill( arc.data ) }
|
|
200
|
+
data-testid="pie-segment"
|
|
201
|
+
/>
|
|
146
202
|
</g>
|
|
147
203
|
) );
|
|
148
204
|
} }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useParentSize } from '@visx/responsive';
|
|
2
2
|
import { ComponentType } from 'react';
|
|
3
|
-
import type { BaseChartProps } from '../../types';
|
|
3
|
+
import type { BaseChartProps, Optional } from '../../types';
|
|
4
4
|
|
|
5
5
|
type ResponsiveConfig = {
|
|
6
6
|
maxWidth?: number;
|
|
@@ -23,7 +23,7 @@ export function withResponsive< T extends BaseChartProps< unknown > >(
|
|
|
23
23
|
) {
|
|
24
24
|
const { maxWidth = 1200, aspectRatio = 0.5, debounceTime = 50 } = config || {};
|
|
25
25
|
|
|
26
|
-
return function ResponsiveChart( props:
|
|
26
|
+
return function ResponsiveChart( props: Optional< T, 'width' | 'height' | 'size' > ) {
|
|
27
27
|
const { parentRef, width: parentWidth } = useParentSize( {
|
|
28
28
|
debounceTime,
|
|
29
29
|
enableDebounceLeadingCall: true,
|
|
@@ -32,14 +32,13 @@ export function withResponsive< T extends BaseChartProps< unknown > >(
|
|
|
32
32
|
|
|
33
33
|
// Calculate dimensions
|
|
34
34
|
const containerWidth = parentWidth ? Math.min( parentWidth, maxWidth ) : 600;
|
|
35
|
-
const containerHeight = containerWidth * aspectRatio;
|
|
35
|
+
const containerHeight = props.height ?? containerWidth * aspectRatio;
|
|
36
36
|
|
|
37
37
|
return (
|
|
38
38
|
<div
|
|
39
39
|
ref={ parentRef }
|
|
40
40
|
style={ {
|
|
41
41
|
width: '100%',
|
|
42
|
-
minHeight: `${ containerHeight }px`,
|
|
43
42
|
} }
|
|
44
43
|
>
|
|
45
44
|
<WrappedComponent
|
package/src/index.ts
CHANGED
|
@@ -8,8 +8,9 @@ export { PieSemiCircleChart } from './components/pie-semi-circle-chart';
|
|
|
8
8
|
export { BaseTooltip } from './components/tooltip';
|
|
9
9
|
export { Legend } from './components/legend';
|
|
10
10
|
|
|
11
|
-
//
|
|
11
|
+
// Themes
|
|
12
12
|
export { ThemeProvider } from './providers/theme';
|
|
13
|
+
export { defaultTheme, jetpackTheme, wooTheme } from './providers/theme/themes';
|
|
13
14
|
|
|
14
15
|
// Hooks
|
|
15
16
|
export { default as useChartMouseHandler } from './hooks/use-chart-mouse-handler';
|
package/src/types.ts
CHANGED
|
@@ -5,6 +5,8 @@ import type { CSSProperties } from 'react';
|
|
|
5
5
|
|
|
6
6
|
type ValueOf< T > = T[ keyof T ];
|
|
7
7
|
|
|
8
|
+
export type Optional< T, K extends keyof T > = Pick< Partial< T >, K > & Omit< T, K >;
|
|
9
|
+
|
|
8
10
|
declare type OrientationType = ValueOf< typeof Orientation >;
|
|
9
11
|
|
|
10
12
|
export type DataPoint = {
|
|
@@ -84,6 +86,7 @@ declare type AxisOptions = {
|
|
|
84
86
|
axisLineClassName?: string;
|
|
85
87
|
labelClassName?: string;
|
|
86
88
|
tickClassName?: string;
|
|
89
|
+
tickFormat?: ( value: number ) => string;
|
|
87
90
|
};
|
|
88
91
|
|
|
89
92
|
/**
|
|
@@ -106,14 +109,18 @@ export type BaseChartProps< T = DataPoint | DataPointDate > = {
|
|
|
106
109
|
* Height of the chart in pixels
|
|
107
110
|
*/
|
|
108
111
|
height?: number;
|
|
112
|
+
/**
|
|
113
|
+
* Size of the chart in pixels for pie and donut charts
|
|
114
|
+
*/
|
|
115
|
+
size?: number;
|
|
109
116
|
/**
|
|
110
117
|
* Chart margins
|
|
111
118
|
*/
|
|
112
119
|
margin?: {
|
|
113
|
-
top
|
|
114
|
-
right
|
|
115
|
-
bottom
|
|
116
|
-
left
|
|
120
|
+
top?: number;
|
|
121
|
+
right?: number;
|
|
122
|
+
bottom?: number;
|
|
123
|
+
left?: number;
|
|
117
124
|
};
|
|
118
125
|
/**
|
|
119
126
|
* Whether to show tooltips on hover. False by default.
|