@automattic/charts 1.2.1 → 1.3.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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react from 'react';
2
- import { CSSProperties, ReactNode, PointerEvent, ComponentProps, FC, ComponentType, SVGProps, PropsWithChildren } from 'react';
2
+ import { CSSProperties, PointerEvent, ReactNode, ComponentProps, SVGProps, FC, ComponentType, PropsWithChildren } from 'react';
3
3
  import { LegendOrdinal } from '@visx/legend';
4
4
  import { CircleSubjectProps } from '@visx/annotation/lib/components/CircleSubject';
5
5
  import { ConnectorProps } from '@visx/annotation/lib/components/Connector';
@@ -7,7 +7,7 @@ import { LabelProps } from '@visx/annotation/lib/components/Label';
7
7
  import { LineSubjectProps } from '@visx/annotation/lib/components/LineSubject';
8
8
  import { Orientation, TickFormatter, AxisScale, AxisRendererProps } from '@visx/axis';
9
9
  import { LegendShape } from '@visx/legend/lib/types';
10
- import { ScaleInput, ScaleType } from '@visx/scale';
10
+ import { ScaleType, ScaleInput } from '@visx/scale';
11
11
  import { TextProps } from '@visx/text/lib/Text';
12
12
  import { LineStyles, EventHandlerParams, GridStyles, GlyphProps } from '@visx/xychart';
13
13
  export { EventHandlerParams, GridStyles, LineStyles } from '@visx/xychart';
@@ -22,7 +22,7 @@ import { PieArcDatum } from '@visx/shape/lib/shapes/Pie';
22
22
 
23
23
  type ValueOf<T> = T[keyof T];
24
24
  type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
25
- type ChartType = 'bar' | 'conversion-funnel' | 'leaderboard' | 'line' | 'pie' | 'pie-semi-circle';
25
+ type ChartType = 'area' | 'bar' | 'conversion-funnel' | 'leaderboard' | 'line' | 'pie' | 'pie-semi-circle';
26
26
  type OrientationType = ValueOf<typeof Orientation>;
27
27
  type AnnotationStyles = {
28
28
  circleSubject?: Omit<CircleSubjectProps, 'x' | 'y'> & {
@@ -612,6 +612,113 @@ interface ChartLegendOptions {
612
612
  */
613
613
  declare function useChartLegendItems<T extends SeriesData[] | DataPointDate[] | DataPointPercentageCalculated[]>(data: T, options?: ChartLegendOptions, legendShape?: LegendShape<SeriesData[], number>): BaseLegendItem[];
614
614
 
615
+ interface ChartInstanceRef {
616
+ getScales: () => {
617
+ xScale: unknown;
618
+ yScale: unknown;
619
+ } | null;
620
+ getChartDimensions: () => {
621
+ width: number;
622
+ height: number;
623
+ margin: {
624
+ top?: number;
625
+ right?: number;
626
+ bottom?: number;
627
+ left?: number;
628
+ };
629
+ };
630
+ }
631
+ type SingleChartRef = ChartInstanceRef;
632
+
633
+ type LineChartAnnotationProps = {
634
+ datum: DataPointDate;
635
+ title: string;
636
+ subtitle?: string;
637
+ subjectType?: 'circle' | 'line-vertical' | 'line-horizontal';
638
+ styles?: AnnotationStyles;
639
+ testId?: string;
640
+ renderLabel?: FC<{
641
+ title: string;
642
+ subtitle?: string;
643
+ }>;
644
+ renderLabelPopover?: FC<{
645
+ title: string;
646
+ subtitle?: string;
647
+ }>;
648
+ };
649
+ type CurveType = 'smooth' | 'linear' | 'monotone';
650
+ type RenderLineGlyphProps<Datum extends object> = GlyphProps<Datum> & {
651
+ glyphStyle?: SVGProps<SVGCircleElement>;
652
+ position?: 'start' | 'end';
653
+ };
654
+ interface LineChartProps extends BaseChartProps<SeriesData[]> {
655
+ withGradientFill: boolean;
656
+ smoothing?: boolean;
657
+ curveType?: CurveType;
658
+ renderTooltip?: (params: RenderTooltipParams<DataPointDate>) => ReactNode;
659
+ withStartGlyphs?: boolean;
660
+ withEndGlyphs?: boolean;
661
+ renderGlyph?: <Datum extends object>(props: GlyphProps<Datum>) => ReactNode;
662
+ glyphStyle?: SVGProps<SVGCircleElement>;
663
+ withLegendGlyph?: boolean;
664
+ withTooltipCrosshairs?: {
665
+ showVertical?: boolean;
666
+ showHorizontal?: boolean;
667
+ };
668
+ children?: ReactNode;
669
+ }
670
+ type TooltipDatum = {
671
+ key: string;
672
+ value: number;
673
+ };
674
+
675
+ interface AreaChartProps extends BaseChartProps<SeriesData[]> {
676
+ /**
677
+ * Whether series should be stacked on top of each other.
678
+ * When false, series are rendered as overlapping filled areas.
679
+ * @default true
680
+ */
681
+ stacked?: boolean;
682
+ /**
683
+ * Stack offset strategy when stacked is true. Mirrors d3-shape stack offsets.
684
+ * - 'none' (default): values stack at their natural magnitude
685
+ * - 'expand': values are normalized to the [0,1] range (percentage stacks)
686
+ * - 'wiggle': used for streamgraphs
687
+ * - 'silhouette': stack centered around zero
688
+ */
689
+ stackOffset?: 'none' | 'expand' | 'wiggle' | 'silhouette';
690
+ /**
691
+ * Smoothing using a Catmull-Rom curve. Ignored if `curveType` is set.
692
+ */
693
+ smoothing?: boolean;
694
+ /**
695
+ * Curve interpolation type. Takes precedence over `smoothing`.
696
+ */
697
+ curveType?: CurveType;
698
+ /**
699
+ * Custom tooltip renderer.
700
+ */
701
+ renderTooltip?: (params: RenderTooltipParams<DataPointDate>) => ReactNode;
702
+ /**
703
+ * Whether to show crosshair lines in the tooltip.
704
+ */
705
+ withTooltipCrosshairs?: {
706
+ showVertical?: boolean;
707
+ showHorizontal?: boolean;
708
+ };
709
+ /**
710
+ * Fill opacity for the stacked areas. 0–1.
711
+ * @default 0.85 when stacked, 0.4 when overlapping
712
+ */
713
+ fillOpacity?: number;
714
+ /**
715
+ * Whether to render a stroke (line) on top of each area.
716
+ * @default false when stacked, true when overlapping
717
+ */
718
+ withStroke?: boolean;
719
+ children?: ReactNode;
720
+ }
721
+
615
722
  type ResponsiveConfig = {
616
723
  /**
617
724
  * The maximum width of the chart. Defaults to 1200.
@@ -629,6 +736,15 @@ type ResponsiveConfig = {
629
736
  resizeDebounceTime?: number;
630
737
  };
631
738
 
739
+ type AreaChartSubComponents = {
740
+ Legend: typeof Legend;
741
+ };
742
+ type AreaChartBaseProps = Optional<AreaChartProps, 'width' | 'height' | 'size'>;
743
+ type AreaChartComponent = React.ForwardRefExoticComponent<AreaChartBaseProps & React.RefAttributes<SingleChartRef>> & AreaChartSubComponents;
744
+ type AreaChartResponsiveComponent = React.ForwardRefExoticComponent<AreaChartBaseProps & ResponsiveConfig & React.RefAttributes<SingleChartRef>> & AreaChartSubComponents;
745
+ declare const AreaChart: AreaChartComponent;
746
+ declare const AreaChartResponsive: AreaChartResponsiveComponent;
747
+
632
748
  interface BarChartProps extends BaseChartProps<SeriesData[]> {
633
749
  renderTooltip?: (params: RenderTooltipParams<DataPointDate>) => ReactNode;
634
750
  orientation?: 'horizontal' | 'vertical';
@@ -1109,71 +1225,11 @@ declare function useLeaderboardLegendItems({ data, primaryColor, secondaryColor,
1109
1225
  };
1110
1226
  }): BaseLegendItem[];
1111
1227
 
1112
- interface ChartInstanceRef {
1113
- getScales: () => {
1114
- xScale: unknown;
1115
- yScale: unknown;
1116
- } | null;
1117
- getChartDimensions: () => {
1118
- width: number;
1119
- height: number;
1120
- margin: {
1121
- top?: number;
1122
- right?: number;
1123
- bottom?: number;
1124
- left?: number;
1125
- };
1126
- };
1127
- }
1128
- type SingleChartRef = ChartInstanceRef;
1129
-
1130
1228
  interface LineChartAnnotationsProps {
1131
1229
  children?: ReactNode;
1132
1230
  }
1133
1231
  declare const LineChartAnnotationsOverlay: FC<LineChartAnnotationsProps>;
1134
1232
 
1135
- type LineChartAnnotationProps = {
1136
- datum: DataPointDate;
1137
- title: string;
1138
- subtitle?: string;
1139
- subjectType?: 'circle' | 'line-vertical' | 'line-horizontal';
1140
- styles?: AnnotationStyles;
1141
- testId?: string;
1142
- renderLabel?: FC<{
1143
- title: string;
1144
- subtitle?: string;
1145
- }>;
1146
- renderLabelPopover?: FC<{
1147
- title: string;
1148
- subtitle?: string;
1149
- }>;
1150
- };
1151
- type CurveType = 'smooth' | 'linear' | 'monotone';
1152
- type RenderLineGlyphProps<Datum extends object> = GlyphProps<Datum> & {
1153
- glyphStyle?: SVGProps<SVGCircleElement>;
1154
- position?: 'start' | 'end';
1155
- };
1156
- interface LineChartProps extends BaseChartProps<SeriesData[]> {
1157
- withGradientFill: boolean;
1158
- smoothing?: boolean;
1159
- curveType?: CurveType;
1160
- renderTooltip?: (params: RenderTooltipParams<DataPointDate>) => ReactNode;
1161
- withStartGlyphs?: boolean;
1162
- withEndGlyphs?: boolean;
1163
- renderGlyph?: <Datum extends object>(props: GlyphProps<Datum>) => ReactNode;
1164
- glyphStyle?: SVGProps<SVGCircleElement>;
1165
- withLegendGlyph?: boolean;
1166
- withTooltipCrosshairs?: {
1167
- showVertical?: boolean;
1168
- showHorizontal?: boolean;
1169
- };
1170
- children?: ReactNode;
1171
- }
1172
- type TooltipDatum = {
1173
- key: string;
1174
- value: number;
1175
- };
1176
-
1177
1233
  declare const LineChartAnnotation: FC<LineChartAnnotationProps>;
1178
1234
 
1179
1235
  type LineChartAnnotationComponents = {
@@ -1616,4 +1672,4 @@ declare const useGlobalChartsTheme: () => CompleteChartTheme;
1616
1672
  */
1617
1673
  declare const defaultTheme: CompleteChartTheme;
1618
1674
 
1619
- export { AccessibleTooltip, type AnnotationStyles, type ArcData, type AxisOptions, BarChartResponsive as BarChart, type BarChartProps, BarChart as BarChartUnresponsive, BarListChartResponsive as BarListChart, type BarListChartProps, BarListChart as BarListChartUnresponsive, type BaseChartProps, type BaseLegendItem, type BaseLegendProps, BaseTooltip, type BaseTooltipProps, type ChartLegendConfig, type ChartLegendOptions, type ChartTheme, type CompleteChartTheme, ConversionFunnelChartWithProvider as ConversionFunnelChart, type ConversionFunnelChartProps, type CurveType, type DataPoint, type DataPointDate, type DataPointPercentage, type FunnelStep, GeoChartResponsive as GeoChart, type GeoChartProps, GeoChartWithProvider as GeoChartUnresponsive, type GeoData, type GeoRegion, type GeoResolution, GlobalChartsContext, GlobalChartsProvider, type GradientConfig, type GradientStop, type GridProps, LeaderboardChartResponsive as LeaderboardChart, type LeaderboardChartProps, LeaderboardChart as LeaderboardChartUnresponsive, type LeaderboardEntry, Legend, type LegendItemStyles, type LegendLabelStyles, type LegendPosition, type LegendProps, type LegendShapeStyles, type LegendValueDisplay, LineChartResponsive as LineChart, type LineChartAnnotationProps, type LineChartProps, LineChart as LineChartUnresponsive, type MainMetricRenderProps, type MetricValueType, type MultipleDataPointsDate, type Optional, type OrientationType, PieChartResponsive as PieChart, type PieChartProps, type PieChartRenderTooltipParams, PieChart as PieChartUnresponsive, PieSemiCircleChartResponsive as PieSemiCircleChart, type PieSemiCircleChartProps, type PieSemiCircleChartRenderTooltipParams, PieSemiCircleChart as PieSemiCircleChartUnresponsive, type RenderLabelProps, type RenderLineGlyphProps, type RenderValueProps, type ScaleOptions, type SeriesData, type SeriesDataOptions, Sparkline, type SparklineDataPoint, type SparklineProps, SparklineUnresponsive, type StepLabelRenderProps, type StepRateRenderProps, GlobalChartsProvider as ThemeProvider, type TooltipData, type TooltipDatum, type TooltipProps, type TooltipRenderProps, type TrendDirection, TrendIndicator, type TrendIndicatorProps, defaultTheme, formatMetricValue, formatPercentage, getColorDistance, hexToRgba, isValidHexColor, lightenHexColor, mergeThemes, normalizeColorToHex, parseAsLocalDate, parseHslString, parseRgbString, useChartLegendItems, useGlobalChartsContext, useGlobalChartsTheme, useLeaderboardLegendItems, validateHexColor };
1675
+ export { AccessibleTooltip, type AnnotationStyles, type ArcData, AreaChartResponsive as AreaChart, type AreaChartProps, AreaChart as AreaChartUnresponsive, type AxisOptions, BarChartResponsive as BarChart, type BarChartProps, BarChart as BarChartUnresponsive, BarListChartResponsive as BarListChart, type BarListChartProps, BarListChart as BarListChartUnresponsive, type BaseChartProps, type BaseLegendItem, type BaseLegendProps, BaseTooltip, type BaseTooltipProps, type ChartLegendConfig, type ChartLegendOptions, type ChartTheme, type CompleteChartTheme, ConversionFunnelChartWithProvider as ConversionFunnelChart, type ConversionFunnelChartProps, type CurveType, type DataPoint, type DataPointDate, type DataPointPercentage, type FunnelStep, GeoChartResponsive as GeoChart, type GeoChartProps, GeoChartWithProvider as GeoChartUnresponsive, type GeoData, type GeoRegion, type GeoResolution, GlobalChartsContext, GlobalChartsProvider, type GradientConfig, type GradientStop, type GridProps, LeaderboardChartResponsive as LeaderboardChart, type LeaderboardChartProps, LeaderboardChart as LeaderboardChartUnresponsive, type LeaderboardEntry, Legend, type LegendItemStyles, type LegendLabelStyles, type LegendPosition, type LegendProps, type LegendShapeStyles, type LegendValueDisplay, LineChartResponsive as LineChart, type LineChartAnnotationProps, type LineChartProps, LineChart as LineChartUnresponsive, type MainMetricRenderProps, type MetricValueType, type MultipleDataPointsDate, type Optional, type OrientationType, PieChartResponsive as PieChart, type PieChartProps, type PieChartRenderTooltipParams, PieChart as PieChartUnresponsive, PieSemiCircleChartResponsive as PieSemiCircleChart, type PieSemiCircleChartProps, type PieSemiCircleChartRenderTooltipParams, PieSemiCircleChart as PieSemiCircleChartUnresponsive, type RenderLabelProps, type RenderLineGlyphProps, type RenderValueProps, type ScaleOptions, type SeriesData, type SeriesDataOptions, Sparkline, type SparklineDataPoint, type SparklineProps, SparklineUnresponsive, type StepLabelRenderProps, type StepRateRenderProps, GlobalChartsProvider as ThemeProvider, type TooltipData, type TooltipDatum, type TooltipProps, type TooltipRenderProps, type TrendDirection, TrendIndicator, type TrendIndicatorProps, defaultTheme, formatMetricValue, formatPercentage, getColorDistance, hexToRgba, isValidHexColor, lightenHexColor, mergeThemes, normalizeColorToHex, parseAsLocalDate, parseHslString, parseRgbString, useChartLegendItems, useGlobalChartsContext, useGlobalChartsTheme, useLeaderboardLegendItems, validateHexColor };