@automattic/charts 1.8.1 → 1.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 +16 -0
- package/dist/index.cjs +530 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +122 -34
- package/dist/index.d.cts +97 -7
- package/dist/index.d.ts +97 -7
- package/dist/index.js +527 -54
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/charts/area-chart/area-chart.module.scss +3 -1
- package/src/charts/area-chart/area-chart.tsx +5 -2
- package/src/charts/bar-chart/bar-chart.module.scss +6 -2
- package/src/charts/bar-chart/private/comparison-bars.tsx +6 -0
- package/src/charts/conversion-funnel-chart/conversion-funnel-chart.module.scss +15 -12
- package/src/charts/geo-chart/geo-chart.tsx +6 -1
- package/src/charts/geo-chart/test/geo-chart.test.tsx +11 -1
- package/src/charts/heatmap-chart/heatmap-chart.module.scss +103 -0
- package/src/charts/heatmap-chart/heatmap-chart.tsx +422 -0
- package/src/charts/heatmap-chart/index.ts +4 -0
- package/src/charts/heatmap-chart/private/build-calendar-data.ts +81 -0
- package/src/charts/heatmap-chart/private/heatmap-legend.tsx +53 -0
- package/src/charts/heatmap-chart/private/index.ts +5 -0
- package/src/charts/heatmap-chart/private/use-heatmap-colors.ts +45 -0
- package/src/charts/heatmap-chart/test/build-calendar-data.test.ts +88 -0
- package/src/charts/heatmap-chart/test/heatmap-chart.test.tsx +301 -0
- package/src/charts/heatmap-chart/test/use-heatmap-colors.test.ts +34 -0
- package/src/charts/heatmap-chart/types.ts +42 -0
- package/src/charts/index.ts +1 -0
- package/src/charts/leaderboard-chart/leaderboard-chart.module.scss +18 -6
- package/src/charts/line-chart/line-chart.module.scss +6 -4
- package/src/charts/line-chart/line-chart.tsx +6 -2
- package/src/charts/line-chart/private/line-chart-annotation.tsx +16 -3
- package/src/charts/private/grid-control/grid-control.module.scss +1 -4
- package/src/charts/private/svg-empty-state/svg-empty-state.module.scss +1 -1
- package/src/charts/private/with-responsive/test/with-responsive.test.tsx +14 -0
- package/src/charts/private/with-responsive/with-responsive.tsx +12 -0
- package/src/charts/private/x-zoom.module.scss +6 -3
- package/src/components/legend/private/base-legend.module.scss +3 -1
- package/src/components/tooltip/base-tooltip.module.scss +4 -1
- package/src/components/trend-indicator/trend-indicator.module.scss +5 -3
- package/src/hooks/use-xychart-theme.ts +24 -0
- package/src/index.ts +12 -0
- package/src/providers/chart-context/themes.ts +29 -16
- package/src/types.ts +19 -2
- package/src/utils/color-utils.ts +36 -0
- package/src/utils/test/color-utils.test.ts +33 -0
package/dist/index.d.ts
CHANGED
|
@@ -188,8 +188,8 @@ type GradientStop = {
|
|
|
188
188
|
};
|
|
189
189
|
type SeriesDataOptions = {
|
|
190
190
|
gradient?: {
|
|
191
|
-
from
|
|
192
|
-
to
|
|
191
|
+
from?: string;
|
|
192
|
+
to?: string;
|
|
193
193
|
fromOpacity?: number;
|
|
194
194
|
toOpacity?: number;
|
|
195
195
|
stops?: GradientStop[];
|
|
@@ -311,6 +311,19 @@ type ChartTheme = {
|
|
|
311
311
|
}; /** Stroke width for the sparkline line */
|
|
312
312
|
strokeWidth?: number;
|
|
313
313
|
};
|
|
314
|
+
/**
|
|
315
|
+
* HeatmapChart settings. Cell gap, radius, value size and the selection ring come from
|
|
316
|
+
* WPDS tokens in CSS, so only the scale color and the compact sizing live here.
|
|
317
|
+
*/
|
|
318
|
+
heatmapChart?: {
|
|
319
|
+
/**
|
|
320
|
+
* Color the cell scale interpolates toward at the highest value (prop > this >
|
|
321
|
+
* palette `colors[0]`), fed to CSS `color-mix`. Omit to use the palette color.
|
|
322
|
+
*/
|
|
323
|
+
primaryColor?: string; /** Gap in px between cells in compact mode */
|
|
324
|
+
compactCellGap?: number; /** Fixed square cell size in px for compact mode */
|
|
325
|
+
compactCellSize?: number;
|
|
326
|
+
};
|
|
314
327
|
};
|
|
315
328
|
/**
|
|
316
329
|
* Theme configuration with all properties guaranteed to be defined.
|
|
@@ -329,6 +342,7 @@ type CompleteChartTheme = Required<ChartTheme> & {
|
|
|
329
342
|
sparkline: Required<NonNullable<ChartTheme['sparkline']>> & {
|
|
330
343
|
margin: Required<NonNullable<ChartTheme['sparkline']>['margin']>;
|
|
331
344
|
};
|
|
345
|
+
heatmapChart: Omit<Required<NonNullable<ChartTheme['heatmapChart']>>, 'primaryColor'> & Pick<NonNullable<ChartTheme['heatmapChart']>, 'primaryColor'>;
|
|
332
346
|
};
|
|
333
347
|
type AxisOptions = {
|
|
334
348
|
orientation?: OrientationType;
|
|
@@ -925,7 +939,7 @@ declare const BarListChartResponsive: ({
|
|
|
925
939
|
width,
|
|
926
940
|
height,
|
|
927
941
|
...chartProps
|
|
928
|
-
}: Omit<BarListChartProps, "
|
|
942
|
+
}: Omit<BarListChartProps, "size" | "width" | "height"> & {
|
|
929
943
|
width?: number;
|
|
930
944
|
height?: number;
|
|
931
945
|
size?: number;
|
|
@@ -1069,12 +1083,72 @@ declare const GeoChartResponsive: ({
|
|
|
1069
1083
|
width,
|
|
1070
1084
|
height,
|
|
1071
1085
|
...chartProps
|
|
1072
|
-
}: Omit<GeoChartProps, "
|
|
1086
|
+
}: Omit<GeoChartProps, "size" | "width" | "height"> & {
|
|
1073
1087
|
width?: number;
|
|
1074
1088
|
height?: number;
|
|
1075
1089
|
size?: number;
|
|
1076
1090
|
} & ResponsiveConfig) => import("react/jsx-runtime").JSX.Element;
|
|
1077
1091
|
//#endregion
|
|
1092
|
+
//#region src/charts/heatmap-chart/types.d.ts
|
|
1093
|
+
/** A single heatmap cell. `value: null` marks an empty cell. */
|
|
1094
|
+
type HeatmapCell = {
|
|
1095
|
+
/** Per-cell label used in the tooltip / accessible name. */label?: string;
|
|
1096
|
+
value: number | null;
|
|
1097
|
+
};
|
|
1098
|
+
/** A heatmap column (rendered left→right); its cells render top→bottom. */
|
|
1099
|
+
type HeatmapColumn = {
|
|
1100
|
+
/** x-axis label for this column. Empty/omitted renders blank. */label?: string;
|
|
1101
|
+
data: HeatmapCell[];
|
|
1102
|
+
};
|
|
1103
|
+
type HeatmapTooltipData = {
|
|
1104
|
+
value: number | null;
|
|
1105
|
+
rowLabel?: string;
|
|
1106
|
+
columnLabel?: string;
|
|
1107
|
+
cellLabel?: string;
|
|
1108
|
+
row: number;
|
|
1109
|
+
column: number;
|
|
1110
|
+
};
|
|
1111
|
+
interface HeatmapChartProps extends Omit<BaseChartProps<HeatmapColumn[]>, 'showLegend' | 'legend' | 'gridVisibility'> {
|
|
1112
|
+
/** y-axis labels by row index. Empty entries render blank. */
|
|
1113
|
+
rowLabels?: string[];
|
|
1114
|
+
/** Compact mode: hide in-cell values, tighten gap, thin axis labels. Default false. */
|
|
1115
|
+
compact?: boolean;
|
|
1116
|
+
/** Render the numeric value inside each cell. Default `! compact`. */
|
|
1117
|
+
showValues?: boolean;
|
|
1118
|
+
/**
|
|
1119
|
+
* Color the cell scale interpolates toward at the highest value
|
|
1120
|
+
* (this prop > theme `heatmapChart.primaryColor` > palette `colors[0]`).
|
|
1121
|
+
*/
|
|
1122
|
+
primaryColor?: string;
|
|
1123
|
+
renderTooltip?: (data: HeatmapTooltipData) => ReactNode;
|
|
1124
|
+
children?: ReactNode;
|
|
1125
|
+
}
|
|
1126
|
+
//#endregion
|
|
1127
|
+
//#region src/charts/heatmap-chart/private/build-calendar-data.d.ts
|
|
1128
|
+
type CalendarHeatmapResult = {
|
|
1129
|
+
data: HeatmapColumn[];
|
|
1130
|
+
rowLabels: string[];
|
|
1131
|
+
};
|
|
1132
|
+
declare const buildCalendarHeatmapData: (series: DataPointDate[], options?: {
|
|
1133
|
+
weekStartsOn?: 0 | 1;
|
|
1134
|
+
}) => CalendarHeatmapResult;
|
|
1135
|
+
//#endregion
|
|
1136
|
+
//#region src/charts/heatmap-chart/private/heatmap-legend.d.ts
|
|
1137
|
+
interface HeatmapLegendProps {
|
|
1138
|
+
/** Number of swatches in the scale. Default 5. */
|
|
1139
|
+
steps?: number;
|
|
1140
|
+
lessLabel?: string;
|
|
1141
|
+
moreLabel?: string;
|
|
1142
|
+
}
|
|
1143
|
+
declare const HeatmapLegend: FC<HeatmapLegendProps>;
|
|
1144
|
+
//#endregion
|
|
1145
|
+
//#region src/charts/heatmap-chart/heatmap-chart.d.ts
|
|
1146
|
+
interface HeatmapChartSubComponents {
|
|
1147
|
+
Legend: typeof HeatmapLegend;
|
|
1148
|
+
}
|
|
1149
|
+
declare const HeatmapChart: FC<HeatmapChartProps> & HeatmapChartSubComponents;
|
|
1150
|
+
declare const HeatmapChartResponsive: FC<HeatmapChartProps & ResponsiveConfig> & HeatmapChartSubComponents;
|
|
1151
|
+
//#endregion
|
|
1078
1152
|
//#region src/charts/leaderboard-chart/types.d.ts
|
|
1079
1153
|
interface LeaderboardChartProps extends Pick<BaseChartProps<LeaderboardEntry>, 'className' | 'data' | 'showLegend' | 'legend' | 'chartId' | 'width' | 'height' | 'size' | 'gap' | 'animation'> {
|
|
1080
1154
|
/**
|
|
@@ -1145,7 +1219,7 @@ declare const LeaderboardChartResponsive: (({
|
|
|
1145
1219
|
width,
|
|
1146
1220
|
height,
|
|
1147
1221
|
...chartProps
|
|
1148
|
-
}: Omit<LeaderboardChartProps, "
|
|
1222
|
+
}: Omit<LeaderboardChartProps, "size" | "width" | "height"> & {
|
|
1149
1223
|
width?: number;
|
|
1150
1224
|
height?: number;
|
|
1151
1225
|
size?: number;
|
|
@@ -1331,6 +1405,22 @@ declare const normalizeColorToHex: (color: string, element?: HTMLElement | null,
|
|
|
1331
1405
|
* @throws {Error} if hex string is malformed
|
|
1332
1406
|
*/
|
|
1333
1407
|
declare const lightenHexColor: (hex: string, blend: number) => string;
|
|
1408
|
+
/**
|
|
1409
|
+
* WCAG relative luminance of a hex color (0 = black, 1 = white).
|
|
1410
|
+
*
|
|
1411
|
+
* @param hex - Hex color string (e.g., '#98C8DF')
|
|
1412
|
+
* @return Relative luminance in the range [0, 1]
|
|
1413
|
+
* @throws {Error} if hex string is malformed
|
|
1414
|
+
*/
|
|
1415
|
+
declare const relativeLuminance: (hex: string) => number;
|
|
1416
|
+
/**
|
|
1417
|
+
* Whether light text reads better than dark text on the given background, using the W3C
|
|
1418
|
+
* luminance threshold (0.179) that maximizes contrast against black vs white.
|
|
1419
|
+
*
|
|
1420
|
+
* @param backgroundHex - Hex background color
|
|
1421
|
+
* @return true if light text should be used; false (dark text) for malformed colors
|
|
1422
|
+
*/
|
|
1423
|
+
declare const prefersLightText: (backgroundHex: string) => boolean;
|
|
1334
1424
|
//#endregion
|
|
1335
1425
|
//#region src/charts/leaderboard-chart/hooks/use-leaderboard-legend-items.d.ts
|
|
1336
1426
|
/**
|
|
@@ -1652,7 +1742,7 @@ declare const Sparkline: ({
|
|
|
1652
1742
|
width,
|
|
1653
1743
|
height,
|
|
1654
1744
|
...chartProps
|
|
1655
|
-
}: Omit<SparklineProps, "
|
|
1745
|
+
}: Omit<SparklineProps, "size" | "width" | "height"> & {
|
|
1656
1746
|
width?: number;
|
|
1657
1747
|
height?: number;
|
|
1658
1748
|
size?: number;
|
|
@@ -1845,5 +1935,5 @@ declare const useGlobalChartsTheme: () => CompleteChartTheme;
|
|
|
1845
1935
|
*/
|
|
1846
1936
|
declare const defaultTheme: CompleteChartTheme;
|
|
1847
1937
|
//#endregion
|
|
1848
|
-
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 EventHandlerParams, type FunnelStep, GeoChartResponsive as GeoChart, type GeoChartProps, GeoChartWithProvider as GeoChartUnresponsive, type GeoData, type GeoRegion, type GeoResolution, GlobalChartsContext, GlobalChartsProvider, GlobalChartsProvider as ThemeProvider, type GoogleDataTableColumn, type GoogleDataTableColumnRoleType, type GoogleDataTableRow, type GradientConfig, type GradientStop, type GridProps, type GridStyles, LeaderboardChartResponsive as LeaderboardChart, type LeaderboardChartProps, LeaderboardChart as LeaderboardChartUnresponsive, type LeaderboardEntry, Legend, type LegendItemStyles, type LegendLabelStyles, type LegendPosition, type LegendProps, type LegendShape, type LegendShapeLabel, type LegendShapeRenderProps, type LegendShapeStyles, type LegendValueDisplay, LineChartResponsive as LineChart, type LineChartAnnotationProps, type LineChartProps, LineChart as LineChartUnresponsive, type LineStyles, 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 RenderTooltipGlyphProps, type RenderTooltipParams, type RenderValueProps, type ScaleOptions, type SeriesData, type SeriesDataOptions, Sparkline, type SparklineDataPoint, type SparklineProps, SparklineUnresponsive, type StepLabelRenderProps, type StepRateRenderProps, type TooltipData, type TooltipDatum, type TooltipProps, type TooltipRenderProps, type TrendDirection, TrendIndicator, type TrendIndicatorProps, type XyChartTooltipProps, defaultTheme, formatMetricValue, formatPercentage, getColorDistance, hexToRgba, isValidHexColor, lightenHexColor, mergeThemes, normalizeColorToHex, parseAsLocalDate, parseHslString, parseRgbString, useChartLegendItems, useGlobalChartsContext, useGlobalChartsTheme, useLeaderboardLegendItems, validateHexColor };
|
|
1938
|
+
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 CalendarHeatmapResult, type ChartLegendConfig, type ChartLegendOptions, type ChartTheme, type CompleteChartTheme, ConversionFunnelChartWithProvider as ConversionFunnelChart, type ConversionFunnelChartProps, type CurveType, type DataPoint, type DataPointDate, type DataPointPercentage, type EventHandlerParams, type FunnelStep, GeoChartResponsive as GeoChart, type GeoChartProps, GeoChartWithProvider as GeoChartUnresponsive, type GeoData, type GeoRegion, type GeoResolution, GlobalChartsContext, GlobalChartsProvider, GlobalChartsProvider as ThemeProvider, type GoogleDataTableColumn, type GoogleDataTableColumnRoleType, type GoogleDataTableRow, type GradientConfig, type GradientStop, type GridProps, type GridStyles, type HeatmapCell, HeatmapChartResponsive as HeatmapChart, type HeatmapChartProps, HeatmapChart as HeatmapChartUnresponsive, type HeatmapColumn, type HeatmapTooltipData, LeaderboardChartResponsive as LeaderboardChart, type LeaderboardChartProps, LeaderboardChart as LeaderboardChartUnresponsive, type LeaderboardEntry, Legend, type LegendItemStyles, type LegendLabelStyles, type LegendPosition, type LegendProps, type LegendShape, type LegendShapeLabel, type LegendShapeRenderProps, type LegendShapeStyles, type LegendValueDisplay, LineChartResponsive as LineChart, type LineChartAnnotationProps, type LineChartProps, LineChart as LineChartUnresponsive, type LineStyles, 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 RenderTooltipGlyphProps, type RenderTooltipParams, type RenderValueProps, type ScaleOptions, type SeriesData, type SeriesDataOptions, Sparkline, type SparklineDataPoint, type SparklineProps, SparklineUnresponsive, type StepLabelRenderProps, type StepRateRenderProps, type TooltipData, type TooltipDatum, type TooltipProps, type TooltipRenderProps, type TrendDirection, TrendIndicator, type TrendIndicatorProps, type XyChartTooltipProps, buildCalendarHeatmapData, defaultTheme, formatMetricValue, formatPercentage, getColorDistance, hexToRgba, isValidHexColor, lightenHexColor, mergeThemes, normalizeColorToHex, parseAsLocalDate, parseHslString, parseRgbString, prefersLightText, relativeLuminance, useChartLegendItems, useGlobalChartsContext, useGlobalChartsTheme, useLeaderboardLegendItems, validateHexColor };
|
|
1849
1939
|
//# sourceMappingURL=index.d.ts.map
|