@automattic/charts 0.8.3 → 0.9.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,14 @@ 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.9.0] - 2025-03-02
9
+ ### Added
10
+ - Expose event handling for line chart [#42168]
11
+
12
+ ## [0.8.4] - 2025-02-27
13
+ ### Fixed
14
+ - Line chart: no need for min x tick num [#42087]
15
+
8
16
  ## [0.8.3] - 2025-02-25
9
17
  ### Changed
10
18
  - Set options as optional for series [#42047]
@@ -124,6 +132,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
124
132
  - Fixed lints following ESLint rule changes for TS [#40584]
125
133
  - Fixing a bug in Chart storybook data. [#40640]
126
134
 
135
+ [0.9.0]: https://github.com/Automattic/charts/compare/v0.8.4...v0.9.0
136
+ [0.8.4]: https://github.com/Automattic/charts/compare/v0.8.3...v0.8.4
127
137
  [0.8.3]: https://github.com/Automattic/charts/compare/v0.8.2...v0.8.3
128
138
  [0.8.2]: https://github.com/Automattic/charts/compare/v0.8.1...v0.8.2
129
139
  [0.8.1]: https://github.com/Automattic/charts/compare/v0.8.0...v0.8.1
@@ -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");require("@visx/xychart/lib/components/Tooltip");var r=require("clsx"),o=require("react"),s=require("../../providers/theme/theme-provider.js"),l=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)))]})},m=e=>new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"});var u=n.withResponsive((({data:n,width:u,height:h,className:p,margin:x,withTooltips:v=!0,showLegend:g=!1,legendOrientation:j="horizontal",withGradientFill:y=!1,smoothing:T=!0,renderTooltip:b=d,options:N={}})=>{const q=s.useChartTheme(),f=o.useId(),k=o.useMemo((()=>n.map((e=>({...e,data:e.data.sort(((e,t)=>e.date.getTime()-t.date.getTime()))})))),[n]),w=o.useMemo((()=>{const e=k?.map((e=>e.options?.stroke??"")).filter(Boolean)??[];return i.buildChartTheme({...q,colors:[...e,...q.colors]})}),[q,k]);x=o.useMemo((()=>{let e={};return"right"===N.axis?.y?.orientation&&(e={...e,right:40,left:0}),"top"===N.axis?.x?.orientation&&(e={...e,top:20,bottom:10}),{...e,...x}}),[x,N]);const _=o.useMemo((()=>Math.max(Math.floor(Math.min(k[0]?.data.length,u/60)),5)),[k,u]),A=(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")(k);if(A)return e.jsx("div",{className:r("line-chart",c["line-chart"]),children:A});const S=k.map(((e,t)=>({label:e.label,value:"",color:q.colors[t%q.colors.length]}))),D={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:u,height:h,margin:{top:10,right:0,bottom:20,left:40,...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:_,tickFormat:m,...N?.axis?.x}),e.jsx(i.AnimatedAxis,{orientation:"left",numTicks:4,...N?.axis?.y}),k.map(((r,o)=>{const s=r.options?.stroke??w.colors[o%w.colors.length];return e.jsxs("g",{children:[y&&e.jsx(a.LinearGradient,{id:`area-gradient-${f}-${o+1}`,from:s,fromOpacity:.4,toOpacity:.1,to:w.backgroundColor,...r.options?.gradient,"data-testid":"line-gradient"}),e.jsx(i.AnimatedAreaSeries,{dataKey:r?.label,data:r.data,...D,fill:y?`url(#area-gradient-${f}-${o+1})`:void 0,renderLine:!0,curve:T?t.curveCatmullRom:t.curveLinear},r?.label)]},r?.label||o)})),v&&e.jsx(i.Tooltip,{snapTooltipToDatumX:!0,snapTooltipToDatumY:!0,showSeriesGlyphs:!0,renderTooltip:b})]}),g&&e.jsx(l.BaseLegend,{items:S,orientation:j,className:c["line-chart-legend"]})]})}));module.exports=u;
1
+ "use strict";var e=require("react/jsx-runtime"),t=require("@visx/curve"),a=require("@visx/gradient"),i=require("@visx/xychart");require("@visx/xychart/lib/components/Tooltip");var r=require("clsx"),o=require("react"),n=require("../../providers/theme/theme-provider.js"),s=require("../legend/base-legend.js"),l=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)))]})},m=e=>new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"});var u=l.withResponsive((({data:l,width:u,height:h,className:p,margin:v,withTooltips:x=!0,showLegend:g=!1,legendOrientation:j="horizontal",withGradientFill:y=!1,smoothing:T=!0,renderTooltip:b=d,options:N={},onPointerDown:w,onPointerUp:q,onPointerMove:k,onPointerOut:D})=>{const _=n.useChartTheme(),f=o.useId(),A=o.useMemo((()=>l.map((e=>({...e,data:e.data.sort(((e,t)=>e.date.getTime()-t.date.getTime()))})))),[l]),M=o.useMemo((()=>{const e=A?.map((e=>e.options?.stroke??"")).filter(Boolean)??[];return i.buildChartTheme({..._,colors:[...e,..._.colors]})}),[_,A]);v=o.useMemo((()=>{let e={};return"right"===N.axis?.y?.orientation&&(e={...e,right:40,left:0}),"top"===N.axis?.x?.orientation&&(e={...e,top:20,bottom:10}),{...e,...v}}),[v,N]);const P=o.useMemo((()=>Math.min(A[0]?.data.length,Math.ceil(u/100))),[A,u]),S=(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")(A);if(S)return e.jsx("div",{className:r("line-chart",c["line-chart"]),children:S});const L=A.map(((e,t)=>({label:e.label,value:"",color:_.colors[t%_.colors.length]}))),O={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:M,width:u,height:h,margin:{top:10,right:0,bottom:20,left:40,...v},xScale:{type:"time",...N?.xScale},yScale:{type:"linear",nice:!0,zero:!1,...N?.yScale},onPointerDown:w,onPointerUp:q,onPointerMove:k,onPointerOut:D,pointerEventsDataKey:"nearest",children:[e.jsx(i.AnimatedGrid,{columns:!1,numTicks:4}),e.jsx(i.AnimatedAxis,{orientation:"bottom",numTicks:P,tickFormat:m,...N?.axis?.x}),e.jsx(i.AnimatedAxis,{orientation:"left",numTicks:4,...N?.axis?.y}),A.map(((r,o)=>{const n=r.options?.stroke??M.colors[o%M.colors.length];return e.jsxs("g",{children:[y&&e.jsx(a.LinearGradient,{id:`area-gradient-${f}-${o+1}`,from:n,fromOpacity:.4,toOpacity:.1,to:M.backgroundColor,...r.options?.gradient,"data-testid":"line-gradient"}),e.jsx(i.AnimatedAreaSeries,{dataKey:r?.label,data:r.data,...O,fill:y?`url(#area-gradient-${f}-${o+1})`:void 0,renderLine:!0,curve:T?t.curveCatmullRom:t.curveLinear},r?.label)]},r?.label||o)})),x&&e.jsx(i.Tooltip,{detectBounds:!0,snapTooltipToDatumX:!0,snapTooltipToDatumY:!0,showSeriesGlyphs:!0,renderTooltip:b})]}),g&&e.jsx(s.BaseLegend,{items:L,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":["renderDefaultTooltip","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","renderTooltip","options","providerTheme","useChartTheme","chartId","useId","dataSorted","useMemo","series","getTime","theme","seriesColors","stroke","filter","Boolean","buildChartTheme","colors","defaultMargin","axis","y","orientation","right","left","x","top","bottom","xNumTicks","Math","max","floor","min","length","error","some","isNaN","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","fromOpacity","toOpacity","to","backgroundColor","gradient","AnimatedAreaSeries","dataKey","fill","renderLine","curve","curveCatmullRom","curveLinear","Tooltip","snapTooltipToDatumX","snapTooltipToDatumY","showSeriesGlyphs","Legend","items"],"mappings":"u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,MAAQ3C,EACRjB,YAAcvB,EACdnB,UAAYC,EAAQ,yBAItB"}
1
+ {"version":3,"file":"line-chart.js","sources":["/@automattic/charts/../../../../src/components/line-chart/line-chart.tsx"],"sourcesContent":[null],"names":["renderDefaultTooltip","tooltipData","nearestDatum","datum","tooltipPoints","Object","entries","datumByKey","map","key","value","sort","a","b","_jsxs","jsxs","className","styles","children","_jsx","date","toLocaleDateString","point","formatDateTick","timestamp","Date","undefined","month","day","withResponsive","data","width","height","margin","withTooltips","showLegend","legendOrientation","withGradientFill","smoothing","renderTooltip","options","onPointerDown","onPointerUp","onPointerMove","onPointerOut","providerTheme","useChartTheme","chartId","useId","dataSorted","useMemo","series","getTime","theme","seriesColors","stroke","filter","Boolean","buildChartTheme","colors","defaultMargin","axis","y","orientation","right","left","x","top","bottom","xNumTicks","Math","min","length","ceil","error","some","isNaN","validateData","clsx","legendItems","group","index","label","color","accessors","xAccessor","d","yAccessor","role","XYChart","xScale","type","yScale","nice","zero","pointerEventsDataKey","jsx","AnimatedGrid","columns","numTicks","AnimatedAxis","tickFormat","seriesData","LinearGradient","id","from","fromOpacity","toOpacity","to","backgroundColor","gradient","AnimatedAreaSeries","dataKey","fill","renderLine","curve","curveCatmullRom","curveLinear","Tooltip","detectBounds","snapTooltipToDatumX","snapTooltipToDatumY","showSeriesGlyphs","Legend","BaseLegend","items"],"mappings":"uYAmBA,MAaMA,EAAuB,EAC5BC,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,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ACfmD,qBAAqB,UAAS7E,SAAA,CAE9BC,EAAC6E,IAAAC,EAAYA,aAAC,CAAAC,SAAU,EAAQC,SAAW,IAC3ChF,EAAC6E,IAAAI,EAAYA,aACZ,CAAArC,YAAY,SACZoC,SAAW9B,EACXgC,WAAa9E,KACRiB,GAASqB,MAAMK,IAErB/C,EAAAA,IAACiF,EAAAA,aAAa,CAAArC,YAAY,OAAOoC,SAAW,KAAS3D,GAASqB,MAAMC,IAElEb,EAAWzC,KAAK,CAAE8F,EAAYrB,KAC/B,MAAM1B,EAAS+C,EAAW9D,SAASe,QAAUF,EAAMM,OAAQsB,EAAQ5B,EAAMM,OAAOa,QAChF,OACC1D,EAAAA,KACG,IAAA,CAAAI,SAAA,CAAAmB,GACDlB,EAAAA,IAACoF,EAAAA,eAAc,CACdC,GAAK,iBAAkBzD,KAAakC,EAAQ,IAC5CwB,KAAOlD,EACPmD,YAAc,GACdC,UAAY,GACZC,GAAKvD,EAAMwD,mBACNP,EAAW9D,SAASsE,SACb,cAAA,kBAGd3F,EAAAA,IAAC4F,EAAAA,mBAEA,CAAAC,QAAUV,GAAYpB,MACtBpD,KAAOwE,EAAWxE,QACbsD,EACL6B,KACC5E,EAAmB,sBAAuBU,KAAakC,EAAQ,UAAQvD,EAExEwF,YAAa,EACbC,MAAQ7E,EAAY8E,kBAAkBC,EAAAA,aARhCf,GAAYpB,SAbXoB,GAAYpB,OAASD,EAwB7B,IAGD/C,GACDf,EAAC6E,IAAAsB,EAAOA,SACPC,cAAY,EACZC,qBACA,EAAAC,uBACAC,kBAAgB,EAChBnF,cAAgBA,OAKjBJ,GACDhB,MAACwG,EAAMC,WAAA,CACNC,MAAQ9C,EACRhB,YAAc3B,EACdpB,UAAYC,EAAQ,yBAItB"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { Orientation } from '@visx/axis';
3
3
  import { ScaleType, scaleOrdinal } from '@visx/scale';
4
- import { LineStyles } from '@visx/xychart';
5
- import { CSSProperties, ReactNode, ComponentType, FC } from 'react';
4
+ import { LineStyles, EventHandlerParams } from '@visx/xychart';
5
+ import { CSSProperties, PointerEvent, ReactNode, ComponentType, FC } from 'react';
6
6
  import { RenderTooltipParams } from '@visx/xychart/lib/components/Tooltip';
7
7
 
8
8
  type ValueOf<T> = T[keyof T];
@@ -118,6 +118,22 @@ type BaseChartProps<T = DataPoint | DataPointDate> = {
118
118
  bottom?: number;
119
119
  left?: number;
120
120
  };
121
+ /**
122
+ * Callback function for pointer down event
123
+ */
124
+ onPointerDown?: (event: EventHandlerParams<object>) => void;
125
+ /**
126
+ * Callback function for pointer down event
127
+ */
128
+ onPointerUp?: (event: EventHandlerParams<object>) => void;
129
+ /**
130
+ * Callback function for pointer down event
131
+ */
132
+ onPointerMove?: (event: EventHandlerParams<object>) => void;
133
+ /**
134
+ * Callback function for pointer up event
135
+ */
136
+ onPointerOut?: (event: PointerEvent<Element>) => void;
121
137
  /**
122
138
  * Whether to show tooltips on hover. False by default.
123
139
  */
@@ -1,2 +1,2 @@
1
- import{jsx as t,jsxs as e}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"@visx/xychart/lib/components/Tooltip";import d from"clsx";import{useId as h,useMemo as p}from"react";import{useChartTheme as u}from"../../providers/theme/theme-provider.js";import{BaseLegend as v}from"../legend/base-legend.js";import{withResponsive as g}from"../shared/with-responsive.js";import f from"./line-chart.module.scss.js";const x=({tooltipData:a})=>{const o=a?.nearestDatum?.datum;if(!o)return null;const i=Object.entries(a?.datumByKey||{}).map((([t,{datum:e}])=>({key:t,value:e.value}))).sort(((t,e)=>e.value-t.value));return e("div",{className:f["line-chart__tooltip"],children:[t("div",{className:f["line-chart__tooltip-date"],children:o.date?.toLocaleDateString()}),i.map((a=>e("div",{className:f["line-chart__tooltip-row"],children:[e("span",{className:f["line-chart__tooltip-label"],children:[a.key,":"]}),t("span",{className:f["line-chart__tooltip-value"],children:a.value})]},a.key)))]})},y=t=>new Date(t).toLocaleDateString(void 0,{month:"short",day:"numeric"});var b=g((({data:g,width:b,height:N,className:T,margin:k,withTooltips:_=!0,showLegend:w=!1,legendOrientation:D="horizontal",withGradientFill:S=!1,smoothing:j=!0,renderTooltip:L=x,options:O={}})=>{const $=u(),M=h(),z=p((()=>g.map((t=>({...t,data:t.data.sort(((t,e)=>t.date.getTime()-e.date.getTime()))})))),[g]),A=p((()=>{const t=z?.map((t=>t.options?.stroke??"")).filter(Boolean)??[];return r({...$,colors:[...t,...$.colors]})}),[$,z]);k=p((()=>{let t={};return"right"===O.axis?.y?.orientation&&(t={...t,right:40,left:0}),"top"===O.axis?.x?.orientation&&(t={...t,top:20,bottom:10}),{...t,...k}}),[k,O]);const B=p((()=>Math.max(Math.floor(Math.min(z[0]?.data.length,b/60)),5)),[z,b]),F=(t=>t?.length?t.some((t=>t.data.some((t=>isNaN(t.value)||null===t.value||void 0===t.value||isNaN(t.date.getTime())))))?"Invalid data":null:"No data available")(z);if(F)return t("div",{className:d("line-chart",f["line-chart"]),children:F});const G=z.map(((t,e)=>({label:t.label,value:"",color:$.colors[e%$.colors.length]}))),K={xAccessor:t=>t?.date,yAccessor:t=>t?.value};return e("div",{className:d("line-chart",f["line-chart"],T),"data-testid":"line-chart",role:"img","aria-label":"line chart",children:[e(l,{theme:A,width:b,height:N,margin:{top:10,right:0,bottom:20,left:40,...k},xScale:{type:"time",...O?.xScale},yScale:{type:"linear",nice:!0,zero:!1,...O?.yScale},children:[t(n,{columns:!1,numTicks:4}),t(s,{orientation:"bottom",numTicks:B,tickFormat:y,...O?.axis?.x}),t(s,{orientation:"left",numTicks:4,...O?.axis?.y}),z.map(((r,l)=>{const n=r.options?.stroke??A.colors[l%A.colors.length];return e("g",{children:[S&&t(i,{id:`area-gradient-${M}-${l+1}`,from:n,fromOpacity:.4,toOpacity:.1,to:A.backgroundColor,...r.options?.gradient,"data-testid":"line-gradient"}),t(c,{dataKey:r?.label,data:r.data,...K,fill:S?`url(#area-gradient-${M}-${l+1})`:void 0,renderLine:!0,curve:j?a:o},r?.label)]},r?.label||l)})),_&&t(m,{snapTooltipToDatumX:!0,snapTooltipToDatumY:!0,showSeriesGlyphs:!0,renderTooltip:L})]}),w&&t(v,{items:G,orientation:D,className:f["line-chart-legend"]})]})}));export{b as default};
1
+ import{jsx as t,jsxs as e}from"react/jsx-runtime";import{curveCatmullRom as o,curveLinear as a}from"@visx/curve";import{LinearGradient as i}from"@visx/gradient";import{buildChartTheme as r,XYChart as n,AnimatedGrid as l,AnimatedAxis as s,AnimatedAreaSeries as c,Tooltip as m}from"@visx/xychart";import"@visx/xychart/lib/components/Tooltip";import d from"clsx";import{useId as h,useMemo as p}from"react";import{useChartTheme as u}from"../../providers/theme/theme-provider.js";import{BaseLegend as v}from"../legend/base-legend.js";import{withResponsive as g}from"../shared/with-responsive.js";import f from"./line-chart.module.scss.js";const y=({tooltipData:o})=>{const a=o?.nearestDatum?.datum;if(!a)return null;const i=Object.entries(o?.datumByKey||{}).map((([t,{datum:e}])=>({key:t,value:e.value}))).sort(((t,e)=>e.value-t.value));return e("div",{className:f["line-chart__tooltip"],children:[t("div",{className:f["line-chart__tooltip-date"],children:a.date?.toLocaleDateString()}),i.map((o=>e("div",{className:f["line-chart__tooltip-row"],children:[e("span",{className:f["line-chart__tooltip-label"],children:[o.key,":"]}),t("span",{className:f["line-chart__tooltip-value"],children:o.value})]},o.key)))]})},x=t=>new Date(t).toLocaleDateString(void 0,{month:"short",day:"numeric"});var b=g((({data:g,width:b,height:N,className:T,margin:w,withTooltips:k=!0,showLegend:D=!1,legendOrientation:_="horizontal",withGradientFill:P=!1,smoothing:S=!0,renderTooltip:j=y,options:O={},onPointerDown:L,onPointerUp:M,onPointerMove:$,onPointerOut:B})=>{const K=u(),z=h(),A=p((()=>g.map((t=>({...t,data:t.data.sort(((t,e)=>t.date.getTime()-e.date.getTime()))})))),[g]),F=p((()=>{const t=A?.map((t=>t.options?.stroke??"")).filter(Boolean)??[];return r({...K,colors:[...t,...K.colors]})}),[K,A]);w=p((()=>{let t={};return"right"===O.axis?.y?.orientation&&(t={...t,right:40,left:0}),"top"===O.axis?.x?.orientation&&(t={...t,top:20,bottom:10}),{...t,...w}}),[w,O]);const G=p((()=>Math.min(A[0]?.data.length,Math.ceil(b/100))),[A,b]),U=(t=>t?.length?t.some((t=>t.data.some((t=>isNaN(t.value)||null===t.value||void 0===t.value||isNaN(t.date.getTime())))))?"Invalid data":null:"No data available")(A);if(U)return t("div",{className:d("line-chart",f["line-chart"]),children:U});const C=A.map(((t,e)=>({label:t.label,value:"",color:K.colors[e%K.colors.length]}))),E={xAccessor:t=>t?.date,yAccessor:t=>t?.value};return e("div",{className:d("line-chart",f["line-chart"],T),"data-testid":"line-chart",role:"img","aria-label":"line chart",children:[e(n,{theme:F,width:b,height:N,margin:{top:10,right:0,bottom:20,left:40,...w},xScale:{type:"time",...O?.xScale},yScale:{type:"linear",nice:!0,zero:!1,...O?.yScale},onPointerDown:L,onPointerUp:M,onPointerMove:$,onPointerOut:B,pointerEventsDataKey:"nearest",children:[t(l,{columns:!1,numTicks:4}),t(s,{orientation:"bottom",numTicks:G,tickFormat:x,...O?.axis?.x}),t(s,{orientation:"left",numTicks:4,...O?.axis?.y}),A.map(((r,n)=>{const l=r.options?.stroke??F.colors[n%F.colors.length];return e("g",{children:[P&&t(i,{id:`area-gradient-${z}-${n+1}`,from:l,fromOpacity:.4,toOpacity:.1,to:F.backgroundColor,...r.options?.gradient,"data-testid":"line-gradient"}),t(c,{dataKey:r?.label,data:r.data,...E,fill:P?`url(#area-gradient-${z}-${n+1})`:void 0,renderLine:!0,curve:S?o:a},r?.label)]},r?.label||n)})),k&&t(m,{detectBounds:!0,snapTooltipToDatumX:!0,snapTooltipToDatumY:!0,showSeriesGlyphs:!0,renderTooltip:j})]}),D&&t(v,{items:C,orientation:_,className:f["line-chart-legend"]})]})}));export{b 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":["renderDefaultTooltip","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","renderTooltip","options","providerTheme","useChartTheme","chartId","useId","dataSorted","useMemo","series","getTime","theme","seriesColors","stroke","filter","Boolean","buildChartTheme","colors","defaultMargin","axis","y","orientation","right","left","x","top","bottom","xNumTicks","Math","max","floor","min","length","error","some","isNaN","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","fromOpacity","toOpacity","to","backgroundColor","gradient","AnimatedAreaSeries","dataKey","fill","renderLine","curve","curveCatmullRom","curveLinear","Tooltip","snapTooltipToDatumX","snapTooltipToDatumY","showSeriesGlyphs","Legend","items"],"mappings":"0nBAmBA,MAaMA,EAAuB,EAC5BC,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,MAAMC,uBAEpBh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AAEwF,EAAYnB,KAC/B,MAAM3B,EAAS8C,EAAWzD,SAASW,QAAUF,EAAMM,OAAQuB,EAAQ7B,EAAMM,OAAOe,QAChF,OACCvD,EACG,IAAA,CAAAG,SAAA,CAAAmB,GACDlB,EAAC+E,EAAc,CACdC,GAAK,iBAAkBxD,KAAamC,EAAQ,IAC5CsB,KAAOjD,EACPkD,YAAc,GACdC,UAAY,GACZC,GAAKtD,EAAMuD,mBACNP,EAAWzD,SAASiE,SACb,cAAA,kBAGdtF,EAACuF,EAEA,CAAAC,QAAUV,GAAYlB,MACtBjD,KAAOmE,EAAWnE,QACbmD,EACL2B,KACCvE,EAAmB,sBAAuBM,KAAamC,EAAQ,UAAQrD,EAExEoF,YAAa,EACbC,MAAQxE,EAAYyE,EAAkBC,GARhCf,GAAYlB,SAbXkB,GAAYlB,OAASD,EAwB7B,IAGD5C,GACDf,EAAC8F,GACAC,qBAAmB,EACnBC,qBACA,EAAAC,oBACA7E,cAAgBA,OAKjBJ,GACDhB,EAACkG,EACA,CAAAC,MAAQ1C,EACRjB,YAAcvB,EACdpB,UAAYC,EAAQ,yBAItB"}
1
+ {"version":3,"file":"line-chart.js","sources":["../../../../src/components/line-chart/line-chart.tsx"],"sourcesContent":[null],"names":["renderDefaultTooltip","tooltipData","nearestDatum","datum","tooltipPoints","Object","entries","datumByKey","map","key","value","sort","a","b","_jsxs","className","styles","children","_jsx","date","toLocaleDateString","point","formatDateTick","timestamp","Date","undefined","month","day","lineChart","withResponsive","data","width","height","margin","withTooltips","showLegend","legendOrientation","withGradientFill","smoothing","renderTooltip","options","onPointerDown","onPointerUp","onPointerMove","onPointerOut","providerTheme","useChartTheme","chartId","useId","dataSorted","useMemo","series","getTime","theme","seriesColors","stroke","filter","Boolean","buildChartTheme","colors","defaultMargin","axis","y","orientation","right","left","x","top","bottom","xNumTicks","Math","min","length","ceil","error","some","isNaN","validateData","clsx","legendItems","group","index","label","color","accessors","xAccessor","d","yAccessor","role","XYChart","xScale","type","yScale","nice","zero","pointerEventsDataKey","AnimatedGrid","columns","numTicks","AnimatedAxis","tickFormat","seriesData","LinearGradient","id","from","fromOpacity","toOpacity","to","backgroundColor","gradient","AnimatedAreaSeries","dataKey","fill","renderLine","curve","curveCatmullRom","curveLinear","Tooltip","detectBounds","snapTooltipToDatumX","snapTooltipToDatumY","showSeriesGlyphs","Legend","items"],"mappings":"0nBAmBA,MAaMA,EAAuB,EAC5BC,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,MAAMC,uBAEpBhB,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,EAAmBC,GACX,IAAIC,KAAMD,GACXH,wBAAoBK,EAAW,CAC1CC,MAAO,QACPC,IAAK,YAkLP,IAAeC,EAAAC,GA7JyB,EACvCC,OACAC,QACAC,SACAjB,YACAkB,SACAC,gBAAe,EACfC,cAAa,EACbC,oBAAoB,aACpBC,oBAAmB,EACnBC,aAAY,EACZC,gBAAgBvC,EAChBwC,UAAU,CAAE,EACZC,gBACAC,cACAC,gBACAC,mBAEA,MAAMC,EAAgBC,IAChBC,EAAUC,IAEVC,EAAaC,GAClB,IACCpB,EAAKtB,KAAK2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6E,EAAkBC,GARhCf,GAAYnB,SAbXmB,GAAYnB,OAASD,EAwB7B,IAGD/C,GACDhB,EAACmG,GACAC,cAAY,EACZC,qBACA,EAAAC,uBACAC,kBAAgB,EAChBlF,cAAgBA,OAKjBJ,GACDjB,EAACwG,EAAM,CACNC,MAAQ5C,EACRhB,YAAc3B,EACdrB,UAAYC,EAAQ,yBAItB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/charts",
3
- "version": "0.8.3",
3
+ "version": "0.9.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": {
@@ -17,7 +17,7 @@ import { withResponsive } from '../shared/with-responsive';
17
17
  import styles from './line-chart.module.scss';
18
18
  import type { BaseChartProps, DataPointDate, SeriesData } from '../../types';
19
19
 
20
- const X_TICK_WIDTH = 60;
20
+ const X_TICK_WIDTH = 100;
21
21
 
22
22
  interface LineChartProps extends BaseChartProps< SeriesData[] > {
23
23
  withGradientFill: boolean;
@@ -66,8 +66,8 @@ const renderDefaultTooltip = ( {
66
66
  );
67
67
  };
68
68
 
69
- const formatDateTick = ( value: number ) => {
70
- const date = new Date( value );
69
+ const formatDateTick = ( timestamp: number ) => {
70
+ const date = new Date( timestamp );
71
71
  return date.toLocaleDateString( undefined, {
72
72
  month: 'short',
73
73
  day: 'numeric',
@@ -104,6 +104,10 @@ const LineChart: FC< LineChartProps > = ( {
104
104
  smoothing = true,
105
105
  renderTooltip = renderDefaultTooltip,
106
106
  options = {},
107
+ onPointerDown = undefined,
108
+ onPointerUp = undefined,
109
+ onPointerMove = undefined,
110
+ onPointerOut = undefined,
107
111
  } ) => {
108
112
  const providerTheme = useChartTheme();
109
113
  const chartId = useId(); // Ensure unique ids for gradient fill.
@@ -141,8 +145,7 @@ const LineChart: FC< LineChartProps > = ( {
141
145
  }, [ margin, options ] );
142
146
 
143
147
  const xNumTicks = useMemo(
144
- () =>
145
- Math.max( Math.floor( Math.min( dataSorted[ 0 ]?.data.length, width / X_TICK_WIDTH ) ), 5 ),
148
+ () => Math.min( dataSorted[ 0 ]?.data.length, Math.ceil( width / X_TICK_WIDTH ) ),
146
149
  [ dataSorted, width ]
147
150
  );
148
151
 
@@ -175,8 +178,14 @@ const LineChart: FC< LineChartProps > = ( {
175
178
  width={ width }
176
179
  height={ height }
177
180
  margin={ { top: 10, right: 0, bottom: 20, left: 40, ...margin } }
181
+ // xScale and yScale could be set in Axis as well, but they are `scale` props there.
178
182
  xScale={ { type: 'time', ...options?.xScale } }
179
183
  yScale={ { type: 'linear', nice: true, zero: false, ...options?.yScale } }
184
+ onPointerDown={ onPointerDown }
185
+ onPointerUp={ onPointerUp }
186
+ onPointerMove={ onPointerMove }
187
+ onPointerOut={ onPointerOut }
188
+ pointerEventsDataKey="nearest"
180
189
  >
181
190
  <AnimatedGrid columns={ false } numTicks={ 4 } />
182
191
  <AnimatedAxis
@@ -219,6 +228,7 @@ const LineChart: FC< LineChartProps > = ( {
219
228
 
220
229
  { withTooltips && (
221
230
  <Tooltip
231
+ detectBounds
222
232
  snapTooltipToDatumX
223
233
  snapTooltipToDatumY
224
234
  showSeriesGlyphs
package/src/types.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Orientation } from '@visx/axis';
2
2
  import { ScaleType } from '@visx/scale';
3
- import { LineStyles } from '@visx/xychart';
4
- import type { CSSProperties } from 'react';
3
+ import { EventHandlerParams, LineStyles } from '@visx/xychart';
4
+ import type { CSSProperties, PointerEvent } from 'react';
5
5
 
6
6
  type ValueOf< T > = T[ keyof T ];
7
7
 
@@ -125,6 +125,22 @@ export type BaseChartProps< T = DataPoint | DataPointDate > = {
125
125
  bottom?: number;
126
126
  left?: number;
127
127
  };
128
+ /**
129
+ * Callback function for pointer down event
130
+ */
131
+ onPointerDown?: ( event: EventHandlerParams< object > ) => void;
132
+ /**
133
+ * Callback function for pointer down event
134
+ */
135
+ onPointerUp?: ( event: EventHandlerParams< object > ) => void;
136
+ /**
137
+ * Callback function for pointer down event
138
+ */
139
+ onPointerMove?: ( event: EventHandlerParams< object > ) => void;
140
+ /**
141
+ * Callback function for pointer up event
142
+ */
143
+ onPointerOut?: ( event: PointerEvent< Element > ) => void;
128
144
  /**
129
145
  * Whether to show tooltips on hover. False by default.
130
146
  */