@gravity-ui/charts 0.6.1 → 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.
Files changed (166) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/components/Axis/AxisY.d.ts +1 -0
  3. package/dist/cjs/components/Axis/AxisY.js +55 -13
  4. package/dist/cjs/components/ChartInner/index.js +3 -2
  5. package/dist/cjs/components/ChartInner/useChartInnerHandlers.js +4 -0
  6. package/dist/cjs/components/Legend/index.js +1 -2
  7. package/dist/cjs/components/PlotTitle/index.js +1 -1
  8. package/dist/cjs/components/PlotTitle/styles.css +1 -1
  9. package/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +2 -2
  10. package/dist/cjs/components/Tooltip/DefaultContent.js +19 -3
  11. package/dist/cjs/components/Tooltip/index.js +5 -5
  12. package/dist/cjs/components/Tooltip/styles.css +2 -15
  13. package/dist/cjs/components/index.d.ts +10 -9
  14. package/dist/cjs/constants/index.d.ts +1 -0
  15. package/dist/cjs/constants/index.js +1 -0
  16. package/dist/cjs/hooks/useChartOptions/types.d.ts +11 -1
  17. package/dist/cjs/hooks/useChartOptions/x-axis.js +1 -0
  18. package/dist/cjs/hooks/useChartOptions/y-axis.js +9 -1
  19. package/dist/cjs/hooks/useSeries/prepare-area.d.ts +1 -1
  20. package/dist/cjs/hooks/useSeries/prepare-bar-x.d.ts +2 -1
  21. package/dist/cjs/hooks/useSeries/prepare-bar-x.js +2 -1
  22. package/dist/cjs/hooks/useSeries/prepare-bar-y.d.ts +2 -1
  23. package/dist/cjs/hooks/useSeries/prepare-bar-y.js +3 -1
  24. package/dist/cjs/hooks/useSeries/prepare-line.d.ts +1 -1
  25. package/dist/cjs/hooks/useSeries/prepare-pie.js +2 -2
  26. package/dist/cjs/hooks/useSeries/prepare-sankey.d.ts +11 -0
  27. package/dist/cjs/hooks/useSeries/prepare-sankey.js +38 -0
  28. package/dist/cjs/hooks/useSeries/prepareSeries.js +21 -2
  29. package/dist/cjs/hooks/useSeries/types.d.ts +12 -2
  30. package/dist/cjs/hooks/useSeries/utils.js +1 -1
  31. package/dist/cjs/hooks/useShapes/bar-x/index.js +16 -2
  32. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +2 -1
  33. package/dist/cjs/hooks/useShapes/bar-x/types.d.ts +1 -0
  34. package/dist/cjs/hooks/useShapes/bar-y/index.js +16 -2
  35. package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +2 -1
  36. package/dist/cjs/hooks/useShapes/bar-y/types.d.ts +1 -0
  37. package/dist/cjs/hooks/useShapes/index.d.ts +2 -1
  38. package/dist/cjs/hooks/useShapes/index.js +19 -0
  39. package/dist/cjs/hooks/useShapes/line/index.js +2 -2
  40. package/dist/cjs/hooks/useShapes/pie/index.js +3 -3
  41. package/dist/cjs/hooks/useShapes/pie/prepare-data.js +37 -35
  42. package/dist/cjs/hooks/useShapes/pie/types.d.ts +1 -1
  43. package/dist/cjs/hooks/useShapes/sankey/index.d.ts +12 -0
  44. package/dist/cjs/hooks/useShapes/sankey/index.js +67 -0
  45. package/dist/cjs/hooks/useShapes/sankey/prepare-data.d.ts +7 -0
  46. package/dist/cjs/hooks/useShapes/sankey/prepare-data.js +72 -0
  47. package/dist/cjs/hooks/useShapes/sankey/types.d.ts +33 -0
  48. package/dist/cjs/hooks/useShapes/sankey/types.js +1 -0
  49. package/dist/cjs/hooks/useShapes/styles.css +2 -2
  50. package/dist/cjs/hooks/useShapes/utils.d.ts +7 -2
  51. package/dist/cjs/hooks/useShapes/utils.js +22 -17
  52. package/dist/cjs/hooks/useShapes/waterfall/index.js +1 -2
  53. package/dist/cjs/types/chart/area.d.ts +6 -6
  54. package/dist/cjs/types/chart/axis.d.ts +32 -7
  55. package/dist/cjs/types/chart/bar-x.d.ts +9 -4
  56. package/dist/cjs/types/chart/bar-y.d.ts +10 -6
  57. package/dist/cjs/types/chart/base.d.ts +6 -6
  58. package/dist/cjs/types/chart/chart.d.ts +4 -4
  59. package/dist/cjs/types/chart/halo.d.ts +2 -2
  60. package/dist/cjs/types/chart/legend.d.ts +10 -10
  61. package/dist/cjs/types/chart/line.d.ts +4 -4
  62. package/dist/cjs/types/chart/marker.d.ts +2 -2
  63. package/dist/cjs/types/chart/pie.d.ts +6 -4
  64. package/dist/cjs/types/chart/sankey.d.ts +22 -0
  65. package/dist/cjs/types/chart/sankey.js +1 -0
  66. package/dist/cjs/types/chart/scatter.d.ts +4 -4
  67. package/dist/cjs/types/chart/series.d.ts +21 -10
  68. package/dist/cjs/types/chart/split.d.ts +4 -4
  69. package/dist/cjs/types/chart/title.d.ts +2 -2
  70. package/dist/cjs/types/chart/tooltip.d.ts +27 -21
  71. package/dist/cjs/types/chart/treemap.d.ts +4 -4
  72. package/dist/cjs/types/chart/waterfall.d.ts +4 -4
  73. package/dist/cjs/types/chart-ui.d.ts +6 -6
  74. package/dist/cjs/types/formatter.d.ts +4 -4
  75. package/dist/cjs/types/index.d.ts +35 -4
  76. package/dist/cjs/types/index.js +1 -0
  77. package/dist/cjs/utils/chart/get-closest-data.d.ts +2 -0
  78. package/dist/cjs/utils/chart/get-closest-data.js +39 -3
  79. package/dist/cjs/utils/chart/index.js +1 -1
  80. package/dist/cjs/utils/chart/series/index.d.ts +1 -0
  81. package/dist/cjs/utils/chart/series/index.js +1 -0
  82. package/dist/cjs/utils/chart/series/line.d.ts +2 -0
  83. package/dist/cjs/utils/chart/series/line.js +17 -0
  84. package/dist/esm/components/Axis/AxisY.d.ts +1 -0
  85. package/dist/esm/components/Axis/AxisY.js +55 -13
  86. package/dist/esm/components/ChartInner/index.js +3 -2
  87. package/dist/esm/components/ChartInner/useChartInnerHandlers.js +4 -0
  88. package/dist/esm/components/Legend/index.js +1 -2
  89. package/dist/esm/components/PlotTitle/index.js +1 -1
  90. package/dist/esm/components/PlotTitle/styles.css +1 -1
  91. package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +2 -2
  92. package/dist/esm/components/Tooltip/DefaultContent.js +19 -3
  93. package/dist/esm/components/Tooltip/index.js +5 -5
  94. package/dist/esm/components/Tooltip/styles.css +2 -15
  95. package/dist/esm/components/index.d.ts +10 -9
  96. package/dist/esm/constants/index.d.ts +1 -0
  97. package/dist/esm/constants/index.js +1 -0
  98. package/dist/esm/hooks/useChartOptions/types.d.ts +11 -1
  99. package/dist/esm/hooks/useChartOptions/x-axis.js +1 -0
  100. package/dist/esm/hooks/useChartOptions/y-axis.js +9 -1
  101. package/dist/esm/hooks/useSeries/prepare-area.d.ts +1 -1
  102. package/dist/esm/hooks/useSeries/prepare-bar-x.d.ts +2 -1
  103. package/dist/esm/hooks/useSeries/prepare-bar-x.js +2 -1
  104. package/dist/esm/hooks/useSeries/prepare-bar-y.d.ts +2 -1
  105. package/dist/esm/hooks/useSeries/prepare-bar-y.js +3 -1
  106. package/dist/esm/hooks/useSeries/prepare-line.d.ts +1 -1
  107. package/dist/esm/hooks/useSeries/prepare-pie.js +2 -2
  108. package/dist/esm/hooks/useSeries/prepare-sankey.d.ts +11 -0
  109. package/dist/esm/hooks/useSeries/prepare-sankey.js +38 -0
  110. package/dist/esm/hooks/useSeries/prepareSeries.js +21 -2
  111. package/dist/esm/hooks/useSeries/types.d.ts +12 -2
  112. package/dist/esm/hooks/useSeries/utils.js +1 -1
  113. package/dist/esm/hooks/useShapes/bar-x/index.js +16 -2
  114. package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +2 -1
  115. package/dist/esm/hooks/useShapes/bar-x/types.d.ts +1 -0
  116. package/dist/esm/hooks/useShapes/bar-y/index.js +16 -2
  117. package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +2 -1
  118. package/dist/esm/hooks/useShapes/bar-y/types.d.ts +1 -0
  119. package/dist/esm/hooks/useShapes/index.d.ts +2 -1
  120. package/dist/esm/hooks/useShapes/index.js +19 -0
  121. package/dist/esm/hooks/useShapes/line/index.js +2 -2
  122. package/dist/esm/hooks/useShapes/pie/index.js +3 -3
  123. package/dist/esm/hooks/useShapes/pie/prepare-data.js +37 -35
  124. package/dist/esm/hooks/useShapes/pie/types.d.ts +1 -1
  125. package/dist/esm/hooks/useShapes/sankey/index.d.ts +12 -0
  126. package/dist/esm/hooks/useShapes/sankey/index.js +67 -0
  127. package/dist/esm/hooks/useShapes/sankey/prepare-data.d.ts +7 -0
  128. package/dist/esm/hooks/useShapes/sankey/prepare-data.js +72 -0
  129. package/dist/esm/hooks/useShapes/sankey/types.d.ts +33 -0
  130. package/dist/esm/hooks/useShapes/sankey/types.js +1 -0
  131. package/dist/esm/hooks/useShapes/styles.css +2 -2
  132. package/dist/esm/hooks/useShapes/utils.d.ts +7 -2
  133. package/dist/esm/hooks/useShapes/utils.js +22 -17
  134. package/dist/esm/hooks/useShapes/waterfall/index.js +1 -2
  135. package/dist/esm/types/chart/area.d.ts +6 -6
  136. package/dist/esm/types/chart/axis.d.ts +32 -7
  137. package/dist/esm/types/chart/bar-x.d.ts +9 -4
  138. package/dist/esm/types/chart/bar-y.d.ts +10 -6
  139. package/dist/esm/types/chart/base.d.ts +6 -6
  140. package/dist/esm/types/chart/chart.d.ts +4 -4
  141. package/dist/esm/types/chart/halo.d.ts +2 -2
  142. package/dist/esm/types/chart/legend.d.ts +10 -10
  143. package/dist/esm/types/chart/line.d.ts +4 -4
  144. package/dist/esm/types/chart/marker.d.ts +2 -2
  145. package/dist/esm/types/chart/pie.d.ts +6 -4
  146. package/dist/esm/types/chart/sankey.d.ts +22 -0
  147. package/dist/esm/types/chart/sankey.js +1 -0
  148. package/dist/esm/types/chart/scatter.d.ts +4 -4
  149. package/dist/esm/types/chart/series.d.ts +21 -10
  150. package/dist/esm/types/chart/split.d.ts +4 -4
  151. package/dist/esm/types/chart/title.d.ts +2 -2
  152. package/dist/esm/types/chart/tooltip.d.ts +27 -21
  153. package/dist/esm/types/chart/treemap.d.ts +4 -4
  154. package/dist/esm/types/chart/waterfall.d.ts +4 -4
  155. package/dist/esm/types/chart-ui.d.ts +6 -6
  156. package/dist/esm/types/formatter.d.ts +4 -4
  157. package/dist/esm/types/index.d.ts +35 -4
  158. package/dist/esm/types/index.js +1 -0
  159. package/dist/esm/utils/chart/get-closest-data.d.ts +2 -0
  160. package/dist/esm/utils/chart/get-closest-data.js +39 -3
  161. package/dist/esm/utils/chart/index.js +1 -1
  162. package/dist/esm/utils/chart/series/index.d.ts +1 -0
  163. package/dist/esm/utils/chart/series/index.js +1 -0
  164. package/dist/esm/utils/chart/series/line.d.ts +2 -0
  165. package/dist/esm/utils/chart/series/line.js +17 -0
  166. package/package.json +9 -4
@@ -1,12 +1,12 @@
1
1
  import type { MeaningfulAny } from '../misc';
2
2
  import type { ChartTooltipRendererArgs } from './tooltip';
3
- export type ChartMargin = {
3
+ export interface ChartMargin {
4
4
  top: number;
5
5
  right: number;
6
6
  bottom: number;
7
7
  left: number;
8
- };
9
- export type ChartOptions = {
8
+ }
9
+ export interface ChartOptions {
10
10
  margin?: Partial<ChartMargin>;
11
11
  events?: {
12
12
  click?: (data: {
@@ -15,4 +15,4 @@ export type ChartOptions = {
15
15
  }, event: PointerEvent) => void;
16
16
  pointermove?: (data: ChartTooltipRendererArgs | undefined, event: PointerEvent) => void;
17
17
  };
18
- };
18
+ }
@@ -1,9 +1,9 @@
1
1
  /** The halo appearing around the hovered part of series(point in line-type series or slice in pie charts) */
2
- export type Halo = {
2
+ export interface Halo {
3
3
  /** Enable or disable the halo */
4
4
  enabled?: boolean;
5
5
  /** The opacity of halo */
6
6
  opacity?: number;
7
7
  /** The pixel size of the halo. Radius for point markers or width of the outside slice in pie charts. */
8
8
  size?: number;
9
- };
9
+ }
@@ -1,5 +1,5 @@
1
1
  import type { BaseTextStyle } from './base';
2
- export type ChartLegend = {
2
+ export interface ChartLegend {
3
3
  enabled?: boolean;
4
4
  /**
5
5
  * Different types for different color schemes.
@@ -47,16 +47,16 @@ export type ChartLegend = {
47
47
  domain?: number[];
48
48
  };
49
49
  width?: number;
50
- };
51
- export type BaseLegendSymbol = {
50
+ }
51
+ export interface BaseLegendSymbol {
52
52
  /**
53
53
  * The pixel padding between the legend item symbol and the legend item text.
54
54
  *
55
55
  * @default 5
56
56
  * */
57
57
  padding?: number;
58
- };
59
- export type RectLegendSymbolOptions = BaseLegendSymbol & {
58
+ }
59
+ export interface RectLegendSymbolOptions extends BaseLegendSymbol {
60
60
  /**
61
61
  * The pixel width of the symbol for series types that use a rectangle in the legend
62
62
  *
@@ -75,20 +75,20 @@ export type RectLegendSymbolOptions = BaseLegendSymbol & {
75
75
  * Defaults to half the symbolHeight, effectively creating a circle.
76
76
  */
77
77
  radius?: number;
78
- };
79
- export type PathLegendSymbolOptions = BaseLegendSymbol & {
78
+ }
79
+ export interface PathLegendSymbolOptions extends BaseLegendSymbol {
80
80
  /**
81
81
  * The pixel width of the symbol for series types that use a path in the legend
82
82
  *
83
83
  * @default 16
84
84
  * */
85
85
  width?: number;
86
- };
87
- export type SymbolLegendSymbolOptions = BaseLegendSymbol & {
86
+ }
87
+ export interface SymbolLegendSymbolOptions extends BaseLegendSymbol {
88
88
  /**
89
89
  * The pixel width of the symbol for series types that use a symbol in the legend
90
90
  *
91
91
  * @default 8
92
92
  * */
93
93
  width?: number;
94
- };
94
+ }
@@ -3,7 +3,7 @@ import type { MeaningfulAny } from '../misc';
3
3
  import type { BaseSeries, BaseSeriesData } from './base';
4
4
  import type { ChartLegend, RectLegendSymbolOptions } from './legend';
5
5
  import type { PointMarkerOptions } from './marker';
6
- export type LineSeriesData<T = MeaningfulAny> = BaseSeriesData<T> & {
6
+ export interface LineSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
7
7
  /**
8
8
  * The `x` value of the point. Depending on the context , it may represents:
9
9
  * - numeric value (for `linear` x axis)
@@ -27,8 +27,8 @@ export type LineSeriesData<T = MeaningfulAny> = BaseSeriesData<T> & {
27
27
  };
28
28
  };
29
29
  };
30
- };
31
- export type LineSeries<T = MeaningfulAny> = BaseSeries & {
30
+ }
31
+ export interface LineSeries<T = MeaningfulAny> extends BaseSeries {
32
32
  type: typeof SeriesType.Line;
33
33
  data: LineSeriesData<T>[];
34
34
  /** The name of the series (used in legend, tooltip etc) */
@@ -54,4 +54,4 @@ export type LineSeries<T = MeaningfulAny> = BaseSeries & {
54
54
  opacity?: number;
55
55
  /** Y-axis index (when using two axes) */
56
56
  yAxis?: number;
57
- };
57
+ }
@@ -1,5 +1,5 @@
1
1
  import type { SymbolType } from '../../constants';
2
- export type PointMarkerOptions = {
2
+ export interface PointMarkerOptions {
3
3
  /** Enable or disable the point marker */
4
4
  enabled?: boolean;
5
5
  /** The radius of the point marker */
@@ -9,4 +9,4 @@ export type PointMarkerOptions = {
9
9
  /** The width of the point marker's border */
10
10
  borderWidth?: number;
11
11
  symbol?: `${SymbolType}`;
12
- };
12
+ }
@@ -3,7 +3,7 @@ import type { SeriesType } from '../../constants';
3
3
  import type { MeaningfulAny } from '../misc';
4
4
  import type { BaseSeries, BaseSeriesData } from './base';
5
5
  import type { ChartLegend, RectLegendSymbolOptions } from './legend';
6
- export type PieSeriesData<T = MeaningfulAny> = BaseSeriesData<T> & {
6
+ export interface PieSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
7
7
  /** The value of the pie segment. */
8
8
  value: number;
9
9
  /** The name of the pie segment (used in legend, tooltip etc). */
@@ -14,10 +14,12 @@ export type PieSeriesData<T = MeaningfulAny> = BaseSeriesData<T> & {
14
14
  label?: string;
15
15
  /** Individual opacity for the pie segment. */
16
16
  opacity?: number;
17
- };
17
+ /** The individual radius of the pie segment. The default value is series.radius */
18
+ radius?: string | number;
19
+ }
18
20
  export type ConnectorShape = 'straight-line' | 'polyline';
19
21
  export type ConnectorCurve = 'linear' | 'basic';
20
- export type PieSeries<T = MeaningfulAny> = BaseSeries & {
22
+ export interface PieSeries<T = MeaningfulAny> extends BaseSeries {
21
23
  type: typeof SeriesType.Pie;
22
24
  data: PieSeriesData<T>[];
23
25
  /**
@@ -85,4 +87,4 @@ export type PieSeries<T = MeaningfulAny> = BaseSeries & {
85
87
  innerRadius: number;
86
88
  };
87
89
  }) => BaseType;
88
- };
90
+ }
@@ -0,0 +1,22 @@
1
+ import type { SeriesType } from '../../constants';
2
+ import type { MeaningfulAny } from '../misc';
3
+ import type { BaseSeries, BaseSeriesData } from './base';
4
+ import type { ChartLegend, RectLegendSymbolOptions } from './legend';
5
+ export interface SankeySeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
6
+ name: string;
7
+ color?: string;
8
+ links: {
9
+ name: string;
10
+ value: number;
11
+ }[];
12
+ }
13
+ export interface SankeySeries<T = MeaningfulAny> extends BaseSeries {
14
+ type: typeof SeriesType.Sankey;
15
+ /** The name of the series (used in legend, tooltip etc). */
16
+ name: string;
17
+ data: SankeySeriesData<T>[];
18
+ /** Individual series legend options. Has higher priority than legend options in widget data. */
19
+ legend?: ChartLegend & {
20
+ symbol?: RectLegendSymbolOptions;
21
+ };
22
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -2,7 +2,7 @@ import type { SeriesType, SymbolType } from '../../constants';
2
2
  import type { MeaningfulAny } from '../misc';
3
3
  import type { BaseSeries, BaseSeriesData } from './base';
4
4
  import type { ChartLegend, RectLegendSymbolOptions } from './legend';
5
- export type ScatterSeriesData<T = MeaningfulAny> = BaseSeriesData<T> & {
5
+ export interface ScatterSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
6
6
  /**
7
7
  * The `x` value of the point. Depending on the context , it may represents:
8
8
  * - numeric value (for `linear` x axis)
@@ -27,8 +27,8 @@ export type ScatterSeriesData<T = MeaningfulAny> = BaseSeriesData<T> & {
27
27
  radius?: number;
28
28
  /** Individual opacity for the point. */
29
29
  opacity?: number;
30
- };
31
- export type ScatterSeries<T = MeaningfulAny> = BaseSeries & {
30
+ }
31
+ export interface ScatterSeries<T = MeaningfulAny> extends BaseSeries {
32
32
  type: typeof SeriesType.Scatter;
33
33
  data: ScatterSeriesData<T>[];
34
34
  /** The name of the series (used in legend, tooltip etc) */
@@ -43,4 +43,4 @@ export type ScatterSeries<T = MeaningfulAny> = BaseSeries & {
43
43
  };
44
44
  /** Y-axis index (when using two axes) */
45
45
  yAxis?: number;
46
- };
46
+ }
@@ -8,15 +8,16 @@ import type { Halo } from './halo';
8
8
  import type { LineSeries, LineSeriesData } from './line';
9
9
  import type { PointMarkerOptions } from './marker';
10
10
  import type { PieSeries, PieSeriesData } from './pie';
11
+ import type { SankeySeries, SankeySeriesData } from './sankey';
11
12
  import type { ScatterSeries, ScatterSeriesData } from './scatter';
12
13
  import type { TreemapSeries, TreemapSeriesData } from './treemap';
13
14
  import type { WaterfallSeries, WaterfallSeriesData } from './waterfall';
14
- export type ChartSeries<T = MeaningfulAny> = ScatterSeries<T> | PieSeries<T> | BarXSeries<T> | BarYSeries<T> | LineSeries<T> | AreaSeries<T> | TreemapSeries<T> | WaterfallSeries<T>;
15
- export type ChartSeriesData<T = MeaningfulAny> = ScatterSeriesData<T> | PieSeriesData<T> | BarXSeriesData<T> | BarYSeriesData<T> | LineSeriesData<T> | AreaSeriesData<T> | TreemapSeriesData<T> | WaterfallSeriesData<T>;
16
- export type DataLabelRendererData<T = MeaningfulAny> = {
15
+ export type ChartSeries<T = MeaningfulAny> = ScatterSeries<T> | PieSeries<T> | BarXSeries<T> | BarYSeries<T> | LineSeries<T> | AreaSeries<T> | TreemapSeries<T> | WaterfallSeries<T> | SankeySeries<T>;
16
+ export type ChartSeriesData<T = MeaningfulAny> = ScatterSeriesData<T> | PieSeriesData<T> | BarXSeriesData<T> | BarYSeriesData<T> | LineSeriesData<T> | AreaSeriesData<T> | TreemapSeriesData<T> | WaterfallSeriesData<T> | SankeySeriesData<T>;
17
+ export interface DataLabelRendererData<T = MeaningfulAny> {
17
18
  data: ChartSeriesData<T>;
18
- };
19
- export type BasicHoverState = {
19
+ }
20
+ export interface BasicHoverState {
20
21
  /**
21
22
  * Enable separate styles for the hovered series.
22
23
  *
@@ -32,8 +33,8 @@ export type BasicHoverState = {
32
33
  * @default 0.3
33
34
  */
34
35
  brightness?: number;
35
- };
36
- export type BasicInactiveState = {
36
+ }
37
+ export interface BasicInactiveState {
37
38
  /**
38
39
  * Enable separate styles for the inactive series.
39
40
  *
@@ -46,8 +47,8 @@ export type BasicInactiveState = {
46
47
  * @default 0.5
47
48
  * */
48
49
  opacity?: number;
49
- };
50
- export type ChartSeriesOptions = {
50
+ }
51
+ export interface ChartSeriesOptions {
51
52
  /** Individual data label for each point. */
52
53
  dataLabels?: {
53
54
  /** Enable or disable the data labels */
@@ -72,6 +73,11 @@ export type ChartSeriesOptions = {
72
73
  * @default 0.2
73
74
  */
74
75
  groupPadding?: number;
76
+ /**
77
+ * The corner radius of the border surrounding each bar.
78
+ * @default 0
79
+ */
80
+ borderRadius?: number;
75
81
  dataSorting?: {
76
82
  /** Determines what data value should be used to sort by.
77
83
  * Possible values are undefined to disable, "name" to sort by series name or "y"
@@ -108,6 +114,11 @@ export type ChartSeriesOptions = {
108
114
  * @default 0.2
109
115
  */
110
116
  groupPadding?: number;
117
+ /**
118
+ * The corner radius of the border surrounding each bar.
119
+ * @default 0
120
+ */
121
+ borderRadius?: number;
111
122
  dataSorting?: {
112
123
  /** Determines what data value should be used to sort by.
113
124
  * Possible values are undefined to disable, "name" to sort by series name or "x"
@@ -222,4 +233,4 @@ export type ChartSeriesOptions = {
222
233
  inactive?: BasicInactiveState;
223
234
  };
224
235
  };
225
- };
236
+ }
@@ -1,13 +1,13 @@
1
1
  import type { BaseTextStyle } from './base';
2
- export type SplitPlotOptions = {
2
+ export interface SplitPlotOptions {
3
3
  title?: {
4
4
  text: string;
5
5
  style?: Partial<BaseTextStyle>;
6
6
  };
7
- };
8
- export type ChartSplit = {
7
+ }
8
+ export interface ChartSplit {
9
9
  enable: boolean;
10
10
  layout?: 'vertical';
11
11
  gap?: string | number;
12
12
  plots?: SplitPlotOptions[];
13
- };
13
+ }
@@ -1,5 +1,5 @@
1
1
  import type { BaseTextStyle } from './base';
2
- export type ChartTitle = {
2
+ export interface ChartTitle {
3
3
  text: string;
4
4
  style?: Partial<BaseTextStyle>;
5
- };
5
+ }
@@ -5,66 +5,72 @@ import type { BarXSeries, BarXSeriesData } from './bar-x';
5
5
  import type { BarYSeries, BarYSeriesData } from './bar-y';
6
6
  import type { LineSeries, LineSeriesData } from './line';
7
7
  import type { PieSeries, PieSeriesData } from './pie';
8
+ import type { SankeySeries, SankeySeriesData } from './sankey';
8
9
  import type { ScatterSeries, ScatterSeriesData } from './scatter';
9
10
  import type { TreemapSeries, TreemapSeriesData } from './treemap';
10
11
  import type { WaterfallSeries, WaterfallSeriesData } from './waterfall';
11
- export type TooltipDataChunkBarX<T = MeaningfulAny> = {
12
+ export interface TooltipDataChunkBarX<T = MeaningfulAny> {
12
13
  data: BarXSeriesData<T>;
13
14
  series: BarXSeries<T>;
14
- };
15
- export type TooltipDataChunkBarY<T = MeaningfulAny> = {
15
+ }
16
+ export interface TooltipDataChunkBarY<T = MeaningfulAny> {
16
17
  data: BarYSeriesData<T>;
17
18
  series: BarYSeries<T>;
18
- };
19
- export type TooltipDataChunkPie<T = MeaningfulAny> = {
19
+ }
20
+ export interface TooltipDataChunkPie<T = MeaningfulAny> {
20
21
  data: PieSeriesData<T>;
21
22
  series: {
22
23
  type: PieSeries['type'];
23
24
  id: string;
24
25
  name: string;
25
26
  };
26
- };
27
- export type TooltipDataChunkScatter<T = MeaningfulAny> = {
27
+ }
28
+ export interface TooltipDataChunkScatter<T = MeaningfulAny> {
28
29
  data: ScatterSeriesData<T>;
29
30
  series: {
30
31
  type: ScatterSeries['type'];
31
32
  id: string;
32
33
  name: string;
33
34
  };
34
- };
35
- export type TooltipDataChunkLine<T = MeaningfulAny> = {
35
+ }
36
+ export interface TooltipDataChunkLine<T = MeaningfulAny> {
36
37
  data: LineSeriesData<T>;
37
38
  series: {
38
39
  type: LineSeries['type'];
39
40
  id: string;
40
41
  name: string;
41
42
  };
42
- };
43
- export type TooltipDataChunkArea<T = MeaningfulAny> = {
43
+ }
44
+ export interface TooltipDataChunkArea<T = MeaningfulAny> {
44
45
  data: AreaSeriesData<T>;
45
46
  series: {
46
47
  type: AreaSeries['type'];
47
48
  id: string;
48
49
  name: string;
49
50
  };
50
- };
51
- export type TooltipDataChunkTreemap<T = MeaningfulAny> = {
51
+ }
52
+ export interface TooltipDataChunkTreemap<T = MeaningfulAny> {
52
53
  data: TreemapSeriesData<T>;
53
54
  series: TreemapSeries<T>;
54
- };
55
- export type TooltipDataChunkWaterfall<T = MeaningfulAny> = {
55
+ }
56
+ export interface TooltipDataChunkSankey<T = MeaningfulAny> {
57
+ data: SankeySeriesData<T>;
58
+ target?: SankeySeriesData<T>;
59
+ series: SankeySeries<T>;
60
+ }
61
+ export interface TooltipDataChunkWaterfall<T = MeaningfulAny> {
56
62
  data: WaterfallSeriesData<T>;
57
63
  series: WaterfallSeries<T>;
58
- };
59
- export type TooltipDataChunk<T = MeaningfulAny> = (TooltipDataChunkBarX<T> | TooltipDataChunkBarY<T> | TooltipDataChunkPie<T> | TooltipDataChunkScatter<T> | TooltipDataChunkLine<T> | TooltipDataChunkArea<T> | TooltipDataChunkTreemap<T> | TooltipDataChunkWaterfall<T>) & {
64
+ }
65
+ export type TooltipDataChunk<T = MeaningfulAny> = (TooltipDataChunkBarX<T> | TooltipDataChunkBarY<T> | TooltipDataChunkPie<T> | TooltipDataChunkScatter<T> | TooltipDataChunkLine<T> | TooltipDataChunkArea<T> | TooltipDataChunkTreemap<T> | TooltipDataChunkSankey<T> | TooltipDataChunkWaterfall<T>) & {
60
66
  closest?: boolean;
61
67
  };
62
- export type ChartTooltipRendererArgs<T = MeaningfulAny> = {
68
+ export interface ChartTooltipRendererArgs<T = MeaningfulAny> {
63
69
  hovered: TooltipDataChunk<T>[];
64
70
  xAxis?: ChartXAxis;
65
71
  yAxis?: ChartYAxis;
66
- };
67
- export type ChartTooltip<T = MeaningfulAny> = {
72
+ }
73
+ export interface ChartTooltip<T = MeaningfulAny> {
68
74
  enabled?: boolean;
69
75
  /** Specifies the renderer for the tooltip. If returned null default tooltip renderer will be used. */
70
76
  renderer?: (args: ChartTooltipRendererArgs<T>) => React.ReactElement | null;
@@ -72,4 +78,4 @@ export type ChartTooltip<T = MeaningfulAny> = {
72
78
  enabled?: boolean;
73
79
  modifierKey?: 'altKey' | 'metaKey';
74
80
  };
75
- };
81
+ }
@@ -2,7 +2,7 @@ import type { LayoutAlgorithm, SeriesType } from '../../constants';
2
2
  import type { MeaningfulAny } from '../misc';
3
3
  import type { BaseSeries, BaseSeriesData } from './base';
4
4
  import type { ChartLegend, RectLegendSymbolOptions } from './legend';
5
- export type TreemapSeriesData<T = MeaningfulAny> = BaseSeriesData<T> & {
5
+ export interface TreemapSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
6
6
  /** The name of the node (used in legend, tooltip etc). */
7
7
  name: string | string[];
8
8
  /** The value of the node. All nodes should have this property except nodes that have children. */
@@ -14,8 +14,8 @@ export type TreemapSeriesData<T = MeaningfulAny> = BaseSeriesData<T> & {
14
14
  * If no nodes has a matching id, or this option is undefined, then the parent will be set to the root.
15
15
  */
16
16
  parentId?: string;
17
- };
18
- export type TreemapSeries<T = MeaningfulAny> = BaseSeries & {
17
+ }
18
+ export interface TreemapSeries<T = MeaningfulAny> extends BaseSeries {
19
19
  type: typeof SeriesType.Treemap;
20
20
  data: TreemapSeriesData<T>[];
21
21
  /** The name of the series (used in legend, tooltip etc). */
@@ -43,4 +43,4 @@ export type TreemapSeries<T = MeaningfulAny> = BaseSeries & {
43
43
  /** Horizontal alignment of the data label inside the tile. */
44
44
  align?: 'left' | 'center' | 'right';
45
45
  };
46
- };
46
+ }
@@ -2,7 +2,7 @@ import type { SeriesType } from '../../constants';
2
2
  import type { MeaningfulAny } from '../misc';
3
3
  import type { BaseSeries, BaseSeriesData } from './base';
4
4
  import type { ChartLegend, RectLegendSymbolOptions } from './legend';
5
- export type WaterfallSeriesData<T = MeaningfulAny> = BaseSeriesData<T> & {
5
+ export interface WaterfallSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
6
6
  /**
7
7
  * The `x` value. Depending on the context , it may represents:
8
8
  * - numeric value (for `linear` x axis)
@@ -21,8 +21,8 @@ export type WaterfallSeriesData<T = MeaningfulAny> = BaseSeriesData<T> & {
21
21
  opacity?: number;
22
22
  /** When this property is true, the point display the total sum across the entire series. */
23
23
  total?: boolean;
24
- };
25
- export type WaterfallSeries<T = MeaningfulAny> = BaseSeries & {
24
+ }
25
+ export interface WaterfallSeries<T = MeaningfulAny> extends BaseSeries {
26
26
  type: typeof SeriesType.Waterfall;
27
27
  data: WaterfallSeriesData<T>[];
28
28
  /** The name of the series (used in legend, tooltip etc). */
@@ -37,4 +37,4 @@ export type WaterfallSeries<T = MeaningfulAny> = BaseSeries & {
37
37
  legend?: ChartLegend & {
38
38
  symbol?: RectLegendSymbolOptions;
39
39
  };
40
- };
40
+ }
@@ -1,5 +1,5 @@
1
1
  import type { BaseTextStyle } from './chart/base';
2
- export type LabelData = {
2
+ export interface LabelData {
3
3
  text: string;
4
4
  x: number;
5
5
  y: number;
@@ -13,8 +13,8 @@ export type LabelData = {
13
13
  id: string;
14
14
  };
15
15
  active?: boolean;
16
- };
17
- export type HtmlItem = {
16
+ }
17
+ export interface HtmlItem {
18
18
  x: number;
19
19
  y: number;
20
20
  content: string;
@@ -22,7 +22,7 @@ export type HtmlItem = {
22
22
  width: number;
23
23
  height: number;
24
24
  };
25
- };
26
- export type ShapeDataWithHtmlItems = {
25
+ }
26
+ export interface ShapeDataWithHtmlItems {
27
27
  htmlElements: HtmlItem[];
28
- };
28
+ }
@@ -1,14 +1,14 @@
1
- export type FormatOptions = {
1
+ export interface FormatOptions {
2
2
  precision?: number | 'auto';
3
3
  unitRate?: number;
4
4
  showRankDelimiter?: boolean;
5
5
  lang?: string;
6
6
  labelMode?: string;
7
- };
8
- export type FormatNumberOptions = FormatOptions & {
7
+ }
8
+ export interface FormatNumberOptions extends FormatOptions {
9
9
  format?: 'number' | 'percent';
10
10
  multiplier?: number;
11
11
  prefix?: string;
12
12
  postfix?: string;
13
13
  unit?: 'auto' | 'k' | 'm' | 'b' | 't' | null;
14
- };
14
+ }
@@ -25,18 +25,49 @@ export * from './chart/tooltip';
25
25
  export * from './chart/halo';
26
26
  export * from './chart/treemap';
27
27
  export * from './chart/waterfall';
28
- export type ChartData<T = MeaningfulAny> = {
28
+ export * from './chart/sankey';
29
+ export interface ChartData<T = MeaningfulAny> {
30
+ /**
31
+ * General options for the chart.
32
+ */
29
33
  chart?: ChartOptions;
34
+ /**
35
+ * The legend displays a labeled box for each data element in the chart.
36
+ * It shows a distinctive symbol paired with a name for every series.
37
+ */
30
38
  legend?: ChartLegend;
39
+ /**
40
+ * Represents the series data and series options.
41
+ */
31
42
  series: {
43
+ /**
44
+ * Contains data points to be plotted.
45
+ */
32
46
  data: ChartSeries<T>[];
47
+ /**
48
+ * Allows for customizing the appearance and behavior of the series.
49
+ */
33
50
  options?: ChartSeriesOptions;
34
51
  };
52
+ /**
53
+ * The main title of the chart.
54
+ */
35
55
  title?: ChartTitle;
56
+ /**
57
+ * Options for the tooltip that appears when the user hovers over a series or point.
58
+ */
36
59
  tooltip?: ChartTooltip<T>;
60
+ /**
61
+ * Options for the the X axis.
62
+ */
37
63
  xAxis?: ChartXAxis;
64
+ /**
65
+ * Options for the the Y axis or multiple Y axes.
66
+ */
38
67
  yAxis?: ChartYAxis[];
39
- /** Setting for displaying charts on different plots.
40
- * It can be used to visualize related information on multiple charts. */
68
+ /**
69
+ * Setting for displaying charts on different plots.
70
+ * It can be used to visualize related information on multiple charts.
71
+ */
41
72
  split?: ChartSplit;
42
- };
73
+ }
@@ -17,3 +17,4 @@ export * from './chart/tooltip';
17
17
  export * from './chart/halo';
18
18
  export * from './chart/treemap';
19
19
  export * from './chart/waterfall';
20
+ export * from './chart/sankey';
@@ -3,6 +3,8 @@ import type { ChartSeries, ChartSeriesData, TooltipDataChunk } from '../../types
3
3
  type GetClosestPointsArgs = {
4
4
  position: [number, number];
5
5
  shapesData: ShapeData[];
6
+ boundsHeight: number;
7
+ boundsWidth: number;
6
8
  };
7
9
  export type ShapePoint = {
8
10
  x: number;
@@ -35,7 +35,7 @@ function getSeriesType(shapeData) {
35
35
  return get(shapeData, 'series.type') || get(shapeData, 'point.series.type');
36
36
  }
37
37
  export function getClosestPoints(args) {
38
- const { position, shapesData } = args;
38
+ const { position, shapesData, boundsHeight, boundsWidth } = args;
39
39
  const [pointerX, pointerY] = position;
40
40
  const result = [];
41
41
  const groups = groupBy(shapesData, getSeriesType);
@@ -135,13 +135,13 @@ export function getClosestPoints(args) {
135
135
  case 'pie': {
136
136
  const points = list.map((d) => d.segments).flat();
137
137
  const closestPoint = points.find((p) => {
138
- const { center, radius } = p.data.pie;
138
+ const { center } = p.data.pie;
139
139
  const x = pointerX - center[0];
140
140
  const y = pointerY - center[1];
141
141
  let angle = Math.atan2(y, x) + 0.5 * Math.PI;
142
142
  angle = angle < 0 ? Math.PI * 2 + angle : angle;
143
143
  const polarRadius = Math.sqrt(x * x + y * y);
144
- return angle >= p.startAngle && angle <= p.endAngle && polarRadius < radius;
144
+ return (angle >= p.startAngle && angle <= p.endAngle && polarRadius < p.data.radius);
145
145
  });
146
146
  if (closestPoint) {
147
147
  result.push({
@@ -166,7 +166,43 @@ export function getClosestPoints(args) {
166
166
  }
167
167
  break;
168
168
  }
169
+ case 'sankey': {
170
+ const [data] = list;
171
+ const closestLink = data.links.find((d) => {
172
+ var _a;
173
+ return isInsidePath({
174
+ path: (_a = d.path) !== null && _a !== void 0 ? _a : '',
175
+ strokeWidth: d.strokeWidth,
176
+ point: [pointerX, pointerY],
177
+ width: boundsWidth,
178
+ height: boundsHeight,
179
+ });
180
+ });
181
+ if (closestLink) {
182
+ result.push({
183
+ data: closestLink.source,
184
+ target: closestLink.target,
185
+ series: data.series,
186
+ closest: true,
187
+ });
188
+ }
189
+ break;
190
+ }
169
191
  }
170
192
  });
171
193
  return result;
172
194
  }
195
+ function isInsidePath(args) {
196
+ const { path, point, width, height, strokeWidth } = args;
197
+ const canvas = document.createElement('canvas');
198
+ canvas.width = width;
199
+ canvas.height = height;
200
+ const ctx = canvas.getContext('2d');
201
+ if (ctx) {
202
+ ctx.lineWidth = strokeWidth;
203
+ const path2D = new Path2D(path);
204
+ ctx.stroke(path2D);
205
+ return ctx.isPointInPath(path2D, ...point) || ctx.isPointInStroke(path2D, ...point);
206
+ }
207
+ return null;
208
+ }