@classic-homes/charts-react 0.2.1 → 0.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.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { ReactNode, RefObject } from 'react';
3
- import { ChartLegendPosition, LegendRenderProps, ChartLegendConfig, LineChartProps, BarChartProps, PieChartProps, AreaChartProps, ScatterChartProps, DonutChartProps, RadarChartProps, FunnelChartProps, GaugeChartProps, HeatmapChartProps, TreemapChartProps, CandlestickChartProps, SankeyChartProps } from '@classic-homes/charts-core';
4
- export { AreaChartData, AreaChartProps, AreaSeriesData, AxisChartProps, AxisConfig, BarChartData, BarChartProps, BarSeriesData, BaseChartProps, CandlestickChartProps, CandlestickData, CandlestickEventParams, CandlestickItem, ChartFormatter, ChartLegendConfig, ChartLegendPosition, DataPointEventParams, DonutChartProps, FunnelChartProps, FunnelSliceData, GaugeChartProps, HeatmapChartProps, HeatmapData, HeatmapEventParams, LabelChartProps, LabelFormatterParams, LegendChartProps, LegendItem, LegendRenderProps, LineChartData, LineChartProps, LineSeriesData, PieChartProps, PieSliceData, RadarChartData, RadarChartProps, RadarIndicator, RadarSeriesData, SankeyChartProps, SankeyData, SankeyEventParams, SankeyLink, SankeyNode, ScatterChartData, ScatterChartProps, ScatterSeriesData, SliceEventParams, TooltipFormatterParams, TreemapChartProps, TreemapEventParams, TreemapLevel, TreemapNode } from '@classic-homes/charts-core';
3
+ import { ChartLegendPosition, ChartDataTable as ChartDataTable$1, ChartExportConfig, LegendRenderProps, ChartLegendConfig, LineChartProps, BarChartProps, PieChartProps, AreaChartProps, ScatterChartProps, DonutChartProps, RadarChartProps, FunnelChartProps, GaugeChartProps, HeatmapChartProps, TreemapChartProps, CandlestickChartProps, SankeyChartProps, ChartEventHandlers } from '@classic-homes/charts-core';
4
+ export { AreaChartData, AreaChartProps, AreaSeriesData, AxisChartProps, AxisConfig, BarChartData, BarChartProps, BarSeriesData, BaseChartProps, CandlestickChartProps, CandlestickData, CandlestickEventParams, CandlestickItem, ChartDataTable as ChartDataTableData, ChartEventHandlers, ChartExportConfig, ChartFormatter, ChartLegendConfig, ChartLegendPosition, DataPointEventParams, DonutChartProps, FunnelChartProps, FunnelSliceData, GaugeChartProps, HeatmapChartProps, HeatmapData, HeatmapEventParams, LabelChartProps, LabelFormatterParams, LegendChartProps, LegendItem, LegendRenderProps, LineChartData, LineChartProps, LineSeriesData, PieChartProps, PieSliceData, RadarChartData, RadarChartProps, RadarIndicator, RadarSeriesData, ReferenceBand, ReferenceLine, SankeyChartProps, SankeyData, SankeyEventParams, SankeyLink, SankeyNode, ScatterChartData, ScatterChartProps, ScatterSeriesData, SliceEventParams, TooltipFormatterParams, TreemapChartProps, TreemapEventParams, TreemapLevel, TreemapNode, ValueFormat, ValueFormatPreset } from '@classic-homes/charts-core';
5
5
  import * as echarts from 'echarts/core';
6
6
  import { EChartsOption } from 'echarts';
7
7
  import { ClassValue } from 'clsx';
@@ -13,6 +13,10 @@ interface ChartContainerProps extends React.HTMLAttributes<HTMLDivElement> {
13
13
  description?: string;
14
14
  /** Chart height */
15
15
  height?: number | string;
16
+ /** Minimum height in pixels */
17
+ minHeight?: number;
18
+ /** Maximum height in pixels */
19
+ maxHeight?: number;
16
20
  /** Show loading state */
17
21
  loading?: boolean;
18
22
  /** Error message */
@@ -32,10 +36,20 @@ interface ChartContainerProps extends React.HTMLAttributes<HTMLDivElement> {
32
36
  legend?: React.ReactNode;
33
37
  /** Where the custom legend sits (defaults to 'bottom') */
34
38
  legendPosition?: ChartLegendPosition;
39
+ /** The chart's data as a table, for screen readers, "Show data" and CSV export */
40
+ dataTable?: ChartDataTable$1;
41
+ /** 'sr-only' (the default) renders the table for screen readers, true adds a visible toggle */
42
+ showDataTable?: boolean | 'sr-only';
43
+ /** Formats values in the data table */
44
+ format?: (value: number) => string;
45
+ /** Show download buttons */
46
+ exportable?: boolean | ChartExportConfig;
47
+ /** Renders the chart to an image data URL, for the PNG download */
48
+ exportImage?: () => string | null;
35
49
  }
36
50
  /**
37
51
  * Container component for all charts
38
- * Handles loading, error, and empty states
52
+ * Handles loading, error, and empty states, the data table and export
39
53
  */
40
54
  declare const ChartContainer: React.ForwardRefExoticComponent<ChartContainerProps & React.RefAttributes<HTMLDivElement>>;
41
55
 
@@ -81,6 +95,22 @@ interface ChartLegendProps extends Pick<LegendRenderProps, 'items' | 'toggle'>,
81
95
  */
82
96
  declare const ChartLegend: React.ForwardRefExoticComponent<ChartLegendProps & React.RefAttributes<HTMLUListElement>>;
83
97
 
98
+ interface ChartDataTableProps {
99
+ /** Table contents */
100
+ table: ChartDataTable$1;
101
+ /** Caption naming the chart the data belongs to */
102
+ caption: string;
103
+ /** Formats 'value' columns */
104
+ format?: (value: number) => string;
105
+ /** Hide visually, leaving the table to screen readers */
106
+ srOnly?: boolean;
107
+ className?: string;
108
+ }
109
+ /**
110
+ * A chart's data as a table, for screen readers and the "Show data" toggle
111
+ */
112
+ declare function ChartDataTable({ table, caption, format, srOnly, className, }: ChartDataTableProps): React.JSX.Element;
113
+
84
114
  /** Props shared by charts that can render a custom legend */
85
115
  interface CustomLegendProps {
86
116
  /**
@@ -195,6 +225,11 @@ declare const CandlestickChart: React.ForwardRefExoticComponent<CandlestickChart
195
225
  */
196
226
  declare const SankeyChart: React.ForwardRefExoticComponent<SankeyChartProps & React.RefAttributes<HTMLDivElement>>;
197
227
 
228
+ /**
229
+ * Register extra ECharts modules (series types, components or renderers)
230
+ * that an `option` override needs, e.g. `registerEchartsModules([ToolboxComponent])`
231
+ */
232
+ declare const registerEchartsModules: typeof echarts.use;
198
233
  interface UseChartOptions {
199
234
  /** ECharts options */
200
235
  option: EChartsOption;
@@ -202,21 +237,55 @@ interface UseChartOptions {
202
237
  theme?: 'light' | 'dark' | 'auto';
203
238
  /** Override animation setting */
204
239
  animation?: boolean;
205
- /** Callback when chart is ready */
240
+ /** Fill series with decal patterns as well as colour */
241
+ patterns?: boolean;
242
+ /**
243
+ * ECharts event handlers by event name. Listeners are bound for each name
244
+ * with a handler and call the current handler at event time, so handlers
245
+ * set or replaced after mount work.
246
+ */
247
+ events?: ChartEventHandlers;
248
+ /**
249
+ * Callback when the chart instance is (re)created, before its option is
250
+ * applied. Register event handlers here; a theme change re-runs it so
251
+ * handlers are attached to the live instance.
252
+ */
206
253
  onReady?: (chart: echarts.ECharts) => void;
254
+ /**
255
+ * Consumer callback, called with each new instance once its option is
256
+ * applied (the chart's `onReady` prop)
257
+ */
258
+ onCreated?: (chart: echarts.ECharts) => void;
207
259
  }
208
260
  interface UseChartReturn {
209
261
  /** Chart instance ref */
210
262
  chartRef: RefObject<echarts.ECharts | null>;
211
263
  /** Container ref to attach to DOM element */
212
264
  containerRef: RefObject<HTMLDivElement>;
265
+ /** Current chart instance (null before mount) */
266
+ chart: echarts.ECharts | null;
213
267
  /** Current theme name */
214
268
  currentTheme: string;
269
+ /** Render the chart to an image data URL */
270
+ exportImage: (options?: ExportImageOptions) => string | null;
271
+ }
272
+ interface ExportImageOptions {
273
+ /** Image format (defaults to 'png') */
274
+ type?: 'png' | 'jpeg';
275
+ /** Resolution multiplier (defaults to 2) */
276
+ pixelRatio?: number;
277
+ /** Background colour (defaults to the card colour, so the image is not transparent) */
278
+ backgroundColor?: string;
215
279
  }
280
+ /**
281
+ * Render a chart instance to an image data URL, or null when it has no
282
+ * live instance
283
+ */
284
+ declare function exportChartImage(chart: echarts.ECharts | null | undefined, { type, pixelRatio, backgroundColor }?: ExportImageOptions): string | null;
216
285
  /**
217
286
  * Hook to manage ECharts instance lifecycle
218
287
  */
219
- declare function useChart({ option, theme, animation, onReady, }: UseChartOptions): UseChartReturn;
288
+ declare function useChart({ option, theme, animation, patterns, events, onReady, onCreated, }: UseChartOptions): UseChartReturn;
220
289
 
221
290
  /**
222
291
  * Register Classic Theme ECharts themes
@@ -239,4 +308,4 @@ declare function useReducedMotion(): boolean;
239
308
 
240
309
  declare function cn(...inputs: ClassValue[]): string;
241
310
 
242
- export { AreaChart, type AreaChartComponentProps, BarChart, type BarChartComponentProps, CandlestickChart, ChartContainer, type ChartContainerProps, ChartEmpty, type ChartEmptyProps, ChartError, type ChartErrorProps, ChartLegend, type ChartLegendProps, ChartSkeleton, type ChartSkeletonProps, type CustomLegendProps, DonutChart, type DonutChartComponentProps, FunnelChart, type FunnelChartComponentProps, GaugeChart, HeatmapChart, LineChart, type LineChartComponentProps, PieChart, type PieChartComponentProps, RadarChart, type RadarChartComponentProps, SankeyChart, ScatterChart, type ScatterChartComponentProps, TreemapChart, type UseChartLegendOptions, type UseChartLegendReturn, type UseChartOptions, type UseChartReturn, cn, registerClassicThemes, useChart, useChartLegend, useChartResize, useChartTheme, useReducedMotion };
311
+ export { AreaChart, type AreaChartComponentProps, BarChart, type BarChartComponentProps, CandlestickChart, ChartContainer, type ChartContainerProps, ChartDataTable, type ChartDataTableProps, ChartEmpty, type ChartEmptyProps, ChartError, type ChartErrorProps, ChartLegend, type ChartLegendProps, ChartSkeleton, type ChartSkeletonProps, type CustomLegendProps, DonutChart, type DonutChartComponentProps, type ExportImageOptions, FunnelChart, type FunnelChartComponentProps, GaugeChart, HeatmapChart, LineChart, type LineChartComponentProps, PieChart, type PieChartComponentProps, RadarChart, type RadarChartComponentProps, SankeyChart, ScatterChart, type ScatterChartComponentProps, TreemapChart, type UseChartLegendOptions, type UseChartLegendReturn, type UseChartOptions, type UseChartReturn, cn, exportChartImage, registerClassicThemes, registerEchartsModules, useChart, useChartLegend, useChartResize, useChartTheme, useReducedMotion };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { ReactNode, RefObject } from 'react';
3
- import { ChartLegendPosition, LegendRenderProps, ChartLegendConfig, LineChartProps, BarChartProps, PieChartProps, AreaChartProps, ScatterChartProps, DonutChartProps, RadarChartProps, FunnelChartProps, GaugeChartProps, HeatmapChartProps, TreemapChartProps, CandlestickChartProps, SankeyChartProps } from '@classic-homes/charts-core';
4
- export { AreaChartData, AreaChartProps, AreaSeriesData, AxisChartProps, AxisConfig, BarChartData, BarChartProps, BarSeriesData, BaseChartProps, CandlestickChartProps, CandlestickData, CandlestickEventParams, CandlestickItem, ChartFormatter, ChartLegendConfig, ChartLegendPosition, DataPointEventParams, DonutChartProps, FunnelChartProps, FunnelSliceData, GaugeChartProps, HeatmapChartProps, HeatmapData, HeatmapEventParams, LabelChartProps, LabelFormatterParams, LegendChartProps, LegendItem, LegendRenderProps, LineChartData, LineChartProps, LineSeriesData, PieChartProps, PieSliceData, RadarChartData, RadarChartProps, RadarIndicator, RadarSeriesData, SankeyChartProps, SankeyData, SankeyEventParams, SankeyLink, SankeyNode, ScatterChartData, ScatterChartProps, ScatterSeriesData, SliceEventParams, TooltipFormatterParams, TreemapChartProps, TreemapEventParams, TreemapLevel, TreemapNode } from '@classic-homes/charts-core';
3
+ import { ChartLegendPosition, ChartDataTable as ChartDataTable$1, ChartExportConfig, LegendRenderProps, ChartLegendConfig, LineChartProps, BarChartProps, PieChartProps, AreaChartProps, ScatterChartProps, DonutChartProps, RadarChartProps, FunnelChartProps, GaugeChartProps, HeatmapChartProps, TreemapChartProps, CandlestickChartProps, SankeyChartProps, ChartEventHandlers } from '@classic-homes/charts-core';
4
+ export { AreaChartData, AreaChartProps, AreaSeriesData, AxisChartProps, AxisConfig, BarChartData, BarChartProps, BarSeriesData, BaseChartProps, CandlestickChartProps, CandlestickData, CandlestickEventParams, CandlestickItem, ChartDataTable as ChartDataTableData, ChartEventHandlers, ChartExportConfig, ChartFormatter, ChartLegendConfig, ChartLegendPosition, DataPointEventParams, DonutChartProps, FunnelChartProps, FunnelSliceData, GaugeChartProps, HeatmapChartProps, HeatmapData, HeatmapEventParams, LabelChartProps, LabelFormatterParams, LegendChartProps, LegendItem, LegendRenderProps, LineChartData, LineChartProps, LineSeriesData, PieChartProps, PieSliceData, RadarChartData, RadarChartProps, RadarIndicator, RadarSeriesData, ReferenceBand, ReferenceLine, SankeyChartProps, SankeyData, SankeyEventParams, SankeyLink, SankeyNode, ScatterChartData, ScatterChartProps, ScatterSeriesData, SliceEventParams, TooltipFormatterParams, TreemapChartProps, TreemapEventParams, TreemapLevel, TreemapNode, ValueFormat, ValueFormatPreset } from '@classic-homes/charts-core';
5
5
  import * as echarts from 'echarts/core';
6
6
  import { EChartsOption } from 'echarts';
7
7
  import { ClassValue } from 'clsx';
@@ -13,6 +13,10 @@ interface ChartContainerProps extends React.HTMLAttributes<HTMLDivElement> {
13
13
  description?: string;
14
14
  /** Chart height */
15
15
  height?: number | string;
16
+ /** Minimum height in pixels */
17
+ minHeight?: number;
18
+ /** Maximum height in pixels */
19
+ maxHeight?: number;
16
20
  /** Show loading state */
17
21
  loading?: boolean;
18
22
  /** Error message */
@@ -32,10 +36,20 @@ interface ChartContainerProps extends React.HTMLAttributes<HTMLDivElement> {
32
36
  legend?: React.ReactNode;
33
37
  /** Where the custom legend sits (defaults to 'bottom') */
34
38
  legendPosition?: ChartLegendPosition;
39
+ /** The chart's data as a table, for screen readers, "Show data" and CSV export */
40
+ dataTable?: ChartDataTable$1;
41
+ /** 'sr-only' (the default) renders the table for screen readers, true adds a visible toggle */
42
+ showDataTable?: boolean | 'sr-only';
43
+ /** Formats values in the data table */
44
+ format?: (value: number) => string;
45
+ /** Show download buttons */
46
+ exportable?: boolean | ChartExportConfig;
47
+ /** Renders the chart to an image data URL, for the PNG download */
48
+ exportImage?: () => string | null;
35
49
  }
36
50
  /**
37
51
  * Container component for all charts
38
- * Handles loading, error, and empty states
52
+ * Handles loading, error, and empty states, the data table and export
39
53
  */
40
54
  declare const ChartContainer: React.ForwardRefExoticComponent<ChartContainerProps & React.RefAttributes<HTMLDivElement>>;
41
55
 
@@ -81,6 +95,22 @@ interface ChartLegendProps extends Pick<LegendRenderProps, 'items' | 'toggle'>,
81
95
  */
82
96
  declare const ChartLegend: React.ForwardRefExoticComponent<ChartLegendProps & React.RefAttributes<HTMLUListElement>>;
83
97
 
98
+ interface ChartDataTableProps {
99
+ /** Table contents */
100
+ table: ChartDataTable$1;
101
+ /** Caption naming the chart the data belongs to */
102
+ caption: string;
103
+ /** Formats 'value' columns */
104
+ format?: (value: number) => string;
105
+ /** Hide visually, leaving the table to screen readers */
106
+ srOnly?: boolean;
107
+ className?: string;
108
+ }
109
+ /**
110
+ * A chart's data as a table, for screen readers and the "Show data" toggle
111
+ */
112
+ declare function ChartDataTable({ table, caption, format, srOnly, className, }: ChartDataTableProps): React.JSX.Element;
113
+
84
114
  /** Props shared by charts that can render a custom legend */
85
115
  interface CustomLegendProps {
86
116
  /**
@@ -195,6 +225,11 @@ declare const CandlestickChart: React.ForwardRefExoticComponent<CandlestickChart
195
225
  */
196
226
  declare const SankeyChart: React.ForwardRefExoticComponent<SankeyChartProps & React.RefAttributes<HTMLDivElement>>;
197
227
 
228
+ /**
229
+ * Register extra ECharts modules (series types, components or renderers)
230
+ * that an `option` override needs, e.g. `registerEchartsModules([ToolboxComponent])`
231
+ */
232
+ declare const registerEchartsModules: typeof echarts.use;
198
233
  interface UseChartOptions {
199
234
  /** ECharts options */
200
235
  option: EChartsOption;
@@ -202,21 +237,55 @@ interface UseChartOptions {
202
237
  theme?: 'light' | 'dark' | 'auto';
203
238
  /** Override animation setting */
204
239
  animation?: boolean;
205
- /** Callback when chart is ready */
240
+ /** Fill series with decal patterns as well as colour */
241
+ patterns?: boolean;
242
+ /**
243
+ * ECharts event handlers by event name. Listeners are bound for each name
244
+ * with a handler and call the current handler at event time, so handlers
245
+ * set or replaced after mount work.
246
+ */
247
+ events?: ChartEventHandlers;
248
+ /**
249
+ * Callback when the chart instance is (re)created, before its option is
250
+ * applied. Register event handlers here; a theme change re-runs it so
251
+ * handlers are attached to the live instance.
252
+ */
206
253
  onReady?: (chart: echarts.ECharts) => void;
254
+ /**
255
+ * Consumer callback, called with each new instance once its option is
256
+ * applied (the chart's `onReady` prop)
257
+ */
258
+ onCreated?: (chart: echarts.ECharts) => void;
207
259
  }
208
260
  interface UseChartReturn {
209
261
  /** Chart instance ref */
210
262
  chartRef: RefObject<echarts.ECharts | null>;
211
263
  /** Container ref to attach to DOM element */
212
264
  containerRef: RefObject<HTMLDivElement>;
265
+ /** Current chart instance (null before mount) */
266
+ chart: echarts.ECharts | null;
213
267
  /** Current theme name */
214
268
  currentTheme: string;
269
+ /** Render the chart to an image data URL */
270
+ exportImage: (options?: ExportImageOptions) => string | null;
271
+ }
272
+ interface ExportImageOptions {
273
+ /** Image format (defaults to 'png') */
274
+ type?: 'png' | 'jpeg';
275
+ /** Resolution multiplier (defaults to 2) */
276
+ pixelRatio?: number;
277
+ /** Background colour (defaults to the card colour, so the image is not transparent) */
278
+ backgroundColor?: string;
215
279
  }
280
+ /**
281
+ * Render a chart instance to an image data URL, or null when it has no
282
+ * live instance
283
+ */
284
+ declare function exportChartImage(chart: echarts.ECharts | null | undefined, { type, pixelRatio, backgroundColor }?: ExportImageOptions): string | null;
216
285
  /**
217
286
  * Hook to manage ECharts instance lifecycle
218
287
  */
219
- declare function useChart({ option, theme, animation, onReady, }: UseChartOptions): UseChartReturn;
288
+ declare function useChart({ option, theme, animation, patterns, events, onReady, onCreated, }: UseChartOptions): UseChartReturn;
220
289
 
221
290
  /**
222
291
  * Register Classic Theme ECharts themes
@@ -239,4 +308,4 @@ declare function useReducedMotion(): boolean;
239
308
 
240
309
  declare function cn(...inputs: ClassValue[]): string;
241
310
 
242
- export { AreaChart, type AreaChartComponentProps, BarChart, type BarChartComponentProps, CandlestickChart, ChartContainer, type ChartContainerProps, ChartEmpty, type ChartEmptyProps, ChartError, type ChartErrorProps, ChartLegend, type ChartLegendProps, ChartSkeleton, type ChartSkeletonProps, type CustomLegendProps, DonutChart, type DonutChartComponentProps, FunnelChart, type FunnelChartComponentProps, GaugeChart, HeatmapChart, LineChart, type LineChartComponentProps, PieChart, type PieChartComponentProps, RadarChart, type RadarChartComponentProps, SankeyChart, ScatterChart, type ScatterChartComponentProps, TreemapChart, type UseChartLegendOptions, type UseChartLegendReturn, type UseChartOptions, type UseChartReturn, cn, registerClassicThemes, useChart, useChartLegend, useChartResize, useChartTheme, useReducedMotion };
311
+ export { AreaChart, type AreaChartComponentProps, BarChart, type BarChartComponentProps, CandlestickChart, ChartContainer, type ChartContainerProps, ChartDataTable, type ChartDataTableProps, ChartEmpty, type ChartEmptyProps, ChartError, type ChartErrorProps, ChartLegend, type ChartLegendProps, ChartSkeleton, type ChartSkeletonProps, type CustomLegendProps, DonutChart, type DonutChartComponentProps, type ExportImageOptions, FunnelChart, type FunnelChartComponentProps, GaugeChart, HeatmapChart, LineChart, type LineChartComponentProps, PieChart, type PieChartComponentProps, RadarChart, type RadarChartComponentProps, SankeyChart, ScatterChart, type ScatterChartComponentProps, TreemapChart, type UseChartLegendOptions, type UseChartLegendReturn, type UseChartOptions, type UseChartReturn, cn, exportChartImage, registerClassicThemes, registerEchartsModules, useChart, useChartLegend, useChartResize, useChartTheme, useReducedMotion };