@gravity-ui/charts 1.51.7 → 1.52.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 (199) hide show
  1. package/dist/cjs/components/ChartInner/useChartInnerHandlers.d.ts +3 -2
  2. package/dist/cjs/components/ChartInner/useChartInnerHandlers.js +1 -3
  3. package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +3 -2
  4. package/dist/cjs/components/ChartInner/useDefaultState.d.ts +3 -2
  5. package/dist/cjs/components/index.d.ts +1 -0
  6. package/dist/cjs/components/index.js +1 -0
  7. package/dist/cjs/core/series/plugin.d.ts +47 -2
  8. package/dist/cjs/core/series/types.d.ts +4 -0
  9. package/dist/cjs/core/shapes/area/prepare-data.js +29 -19
  10. package/dist/cjs/core/shapes/area/renderer.d.ts +0 -5
  11. package/dist/cjs/core/shapes/area/renderer.js +0 -75
  12. package/dist/cjs/core/shapes/area/types.d.ts +2 -8
  13. package/dist/cjs/core/shapes/bar-x/prepare-data.js +18 -7
  14. package/dist/cjs/core/shapes/bar-x/renderer.d.ts +0 -1
  15. package/dist/cjs/core/shapes/bar-x/renderer.js +0 -18
  16. package/dist/cjs/core/shapes/bar-x/types.d.ts +2 -1
  17. package/dist/cjs/core/shapes/bar-y/get-tooltip-data.js +4 -2
  18. package/dist/cjs/core/shapes/bar-y/prepare-data.js +8 -2
  19. package/dist/cjs/core/shapes/funnel/prepare-data.js +121 -68
  20. package/dist/cjs/core/shapes/heatmap/prepare-data.js +11 -2
  21. package/dist/cjs/core/shapes/line/prepare-data.js +27 -17
  22. package/dist/cjs/core/shapes/line/renderer.d.ts +0 -5
  23. package/dist/cjs/core/shapes/line/renderer.js +0 -75
  24. package/dist/cjs/core/shapes/line/types.d.ts +2 -8
  25. package/dist/cjs/core/shapes/marker.d.ts +30 -0
  26. package/dist/cjs/core/shapes/marker.js +68 -0
  27. package/dist/cjs/core/shapes/pie/prepare-data.js +24 -9
  28. package/dist/cjs/core/shapes/radar/prepare-data.js +3 -0
  29. package/dist/cjs/core/shapes/sankey/prepare-data.js +10 -1
  30. package/dist/cjs/core/shapes/scatter/prepare-data.js +8 -1
  31. package/dist/cjs/core/shapes/scatter/renderer.js +3 -2
  32. package/dist/cjs/core/shapes/scatter/types.d.ts +1 -1
  33. package/dist/cjs/core/shapes/treemap/prepare-data.js +9 -1
  34. package/dist/cjs/core/shapes/types.d.ts +35 -0
  35. package/dist/cjs/core/shapes/waterfall/prepare-data.js +5 -2
  36. package/dist/cjs/core/shapes/x-range/prepare-data.js +7 -2
  37. package/dist/cjs/core/types/chart/base.d.ts +22 -2
  38. package/dist/cjs/core/types/chart/funnel.d.ts +25 -1
  39. package/dist/cjs/core/types/chart/tooltip.d.ts +6 -1
  40. package/dist/cjs/core/utils/data-labels.d.ts +34 -0
  41. package/dist/cjs/core/utils/data-labels.js +26 -0
  42. package/dist/cjs/core/utils/get-closest-data.d.ts +2 -2
  43. package/dist/cjs/core/utils/get-closest-data.js +14 -34
  44. package/dist/cjs/core/utils/tooltip-helpers.d.ts +16 -0
  45. package/dist/cjs/core/utils/tooltip-helpers.js +12 -0
  46. package/dist/cjs/hooks/useShapes/AnnotationLayer.d.ts +9 -0
  47. package/dist/cjs/hooks/useShapes/AnnotationLayer.js +17 -0
  48. package/dist/cjs/hooks/useShapes/HoverMarkerLayer.d.ts +10 -0
  49. package/dist/cjs/hooks/useShapes/HoverMarkerLayer.js +22 -0
  50. package/dist/cjs/hooks/useShapes/MarkerLayer.d.ts +7 -0
  51. package/dist/cjs/hooks/useShapes/MarkerLayer.js +12 -0
  52. package/dist/cjs/hooks/useShapes/SeriesShapes.d.ts +18 -0
  53. package/dist/cjs/hooks/useShapes/SeriesShapes.js +32 -0
  54. package/dist/cjs/hooks/useShapes/index.d.ts +5 -18
  55. package/dist/cjs/hooks/useShapes/index.js +39 -229
  56. package/dist/cjs/index.d.ts +0 -1
  57. package/dist/cjs/index.js +0 -1
  58. package/dist/cjs/plugins/area/index.js +42 -0
  59. package/dist/cjs/plugins/bar-x/index.js +42 -0
  60. package/dist/cjs/plugins/bar-y/index.js +26 -0
  61. package/dist/cjs/plugins/funnel/index.js +18 -0
  62. package/dist/cjs/plugins/funnel/prepare.js +17 -12
  63. package/dist/cjs/plugins/heatmap/index.js +23 -0
  64. package/dist/cjs/plugins/line/index.js +28 -0
  65. package/dist/cjs/plugins/pie/index.js +18 -0
  66. package/dist/cjs/plugins/radar/index.js +18 -0
  67. package/dist/cjs/plugins/sankey/index.js +18 -0
  68. package/dist/cjs/plugins/scatter/index.js +26 -0
  69. package/dist/cjs/plugins/treemap/index.js +18 -0
  70. package/dist/cjs/plugins/waterfall/index.js +39 -0
  71. package/dist/cjs/plugins/x-range/index.js +25 -0
  72. package/dist/cjs/setup-jsdom.d.ts +0 -1
  73. package/dist/cjs/setup-jsdom.js +1 -1
  74. package/dist/esm/components/ChartInner/useChartInnerHandlers.d.ts +3 -2
  75. package/dist/esm/components/ChartInner/useChartInnerHandlers.js +1 -3
  76. package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +3 -2
  77. package/dist/esm/components/ChartInner/useDefaultState.d.ts +3 -2
  78. package/dist/esm/components/index.d.ts +1 -0
  79. package/dist/esm/components/index.js +1 -0
  80. package/dist/esm/core/series/plugin.d.ts +47 -2
  81. package/dist/esm/core/series/types.d.ts +4 -0
  82. package/dist/esm/core/shapes/area/prepare-data.js +29 -19
  83. package/dist/esm/core/shapes/area/renderer.d.ts +0 -5
  84. package/dist/esm/core/shapes/area/renderer.js +0 -75
  85. package/dist/esm/core/shapes/area/types.d.ts +2 -8
  86. package/dist/esm/core/shapes/bar-x/prepare-data.js +18 -7
  87. package/dist/esm/core/shapes/bar-x/renderer.d.ts +0 -1
  88. package/dist/esm/core/shapes/bar-x/renderer.js +0 -18
  89. package/dist/esm/core/shapes/bar-x/types.d.ts +2 -1
  90. package/dist/esm/core/shapes/bar-y/get-tooltip-data.js +4 -2
  91. package/dist/esm/core/shapes/bar-y/prepare-data.js +8 -2
  92. package/dist/esm/core/shapes/funnel/prepare-data.js +121 -68
  93. package/dist/esm/core/shapes/heatmap/prepare-data.js +11 -2
  94. package/dist/esm/core/shapes/line/prepare-data.js +27 -17
  95. package/dist/esm/core/shapes/line/renderer.d.ts +0 -5
  96. package/dist/esm/core/shapes/line/renderer.js +0 -75
  97. package/dist/esm/core/shapes/line/types.d.ts +2 -8
  98. package/dist/esm/core/shapes/marker.d.ts +30 -0
  99. package/dist/esm/core/shapes/marker.js +68 -0
  100. package/dist/esm/core/shapes/pie/prepare-data.js +24 -9
  101. package/dist/esm/core/shapes/radar/prepare-data.js +3 -0
  102. package/dist/esm/core/shapes/sankey/prepare-data.js +10 -1
  103. package/dist/esm/core/shapes/scatter/prepare-data.js +8 -1
  104. package/dist/esm/core/shapes/scatter/renderer.js +3 -2
  105. package/dist/esm/core/shapes/scatter/types.d.ts +1 -1
  106. package/dist/esm/core/shapes/treemap/prepare-data.js +9 -1
  107. package/dist/esm/core/shapes/types.d.ts +35 -0
  108. package/dist/esm/core/shapes/waterfall/prepare-data.js +5 -2
  109. package/dist/esm/core/shapes/x-range/prepare-data.js +7 -2
  110. package/dist/esm/core/types/chart/base.d.ts +22 -2
  111. package/dist/esm/core/types/chart/funnel.d.ts +25 -1
  112. package/dist/esm/core/types/chart/tooltip.d.ts +6 -1
  113. package/dist/esm/core/utils/data-labels.d.ts +34 -0
  114. package/dist/esm/core/utils/data-labels.js +26 -0
  115. package/dist/esm/core/utils/get-closest-data.d.ts +2 -2
  116. package/dist/esm/core/utils/get-closest-data.js +14 -34
  117. package/dist/esm/core/utils/tooltip-helpers.d.ts +16 -0
  118. package/dist/esm/core/utils/tooltip-helpers.js +12 -0
  119. package/dist/esm/hooks/useShapes/AnnotationLayer.d.ts +9 -0
  120. package/dist/esm/hooks/useShapes/AnnotationLayer.js +17 -0
  121. package/dist/esm/hooks/useShapes/HoverMarkerLayer.d.ts +10 -0
  122. package/dist/esm/hooks/useShapes/HoverMarkerLayer.js +22 -0
  123. package/dist/esm/hooks/useShapes/MarkerLayer.d.ts +7 -0
  124. package/dist/esm/hooks/useShapes/MarkerLayer.js +12 -0
  125. package/dist/esm/hooks/useShapes/SeriesShapes.d.ts +18 -0
  126. package/dist/esm/hooks/useShapes/SeriesShapes.js +32 -0
  127. package/dist/esm/hooks/useShapes/index.d.ts +5 -18
  128. package/dist/esm/hooks/useShapes/index.js +39 -229
  129. package/dist/esm/index.d.ts +0 -1
  130. package/dist/esm/index.js +0 -1
  131. package/dist/esm/plugins/area/index.js +42 -0
  132. package/dist/esm/plugins/bar-x/index.js +42 -0
  133. package/dist/esm/plugins/bar-y/index.js +26 -0
  134. package/dist/esm/plugins/funnel/index.js +18 -0
  135. package/dist/esm/plugins/funnel/prepare.js +17 -12
  136. package/dist/esm/plugins/heatmap/index.js +23 -0
  137. package/dist/esm/plugins/line/index.js +28 -0
  138. package/dist/esm/plugins/pie/index.js +18 -0
  139. package/dist/esm/plugins/radar/index.js +18 -0
  140. package/dist/esm/plugins/sankey/index.js +18 -0
  141. package/dist/esm/plugins/scatter/index.js +26 -0
  142. package/dist/esm/plugins/treemap/index.js +18 -0
  143. package/dist/esm/plugins/waterfall/index.js +39 -0
  144. package/dist/esm/plugins/x-range/index.js +25 -0
  145. package/dist/esm/setup-jsdom.d.ts +0 -1
  146. package/dist/esm/setup-jsdom.js +1 -1
  147. package/package.json +2 -3
  148. package/dist/cjs/hooks/useShapes/area/index.d.ts +0 -15
  149. package/dist/cjs/hooks/useShapes/area/index.js +0 -52
  150. package/dist/cjs/hooks/useShapes/bar-x/index.d.ts +0 -16
  151. package/dist/cjs/hooks/useShapes/bar-x/index.js +0 -45
  152. package/dist/cjs/hooks/useShapes/bar-y/index.d.ts +0 -13
  153. package/dist/cjs/hooks/useShapes/bar-y/index.js +0 -19
  154. package/dist/cjs/hooks/useShapes/funnel/index.d.ts +0 -13
  155. package/dist/cjs/hooks/useShapes/funnel/index.js +0 -21
  156. package/dist/cjs/hooks/useShapes/heatmap/index.d.ts +0 -13
  157. package/dist/cjs/hooks/useShapes/heatmap/index.js +0 -20
  158. package/dist/cjs/hooks/useShapes/line/index.d.ts +0 -15
  159. package/dist/cjs/hooks/useShapes/line/index.js +0 -38
  160. package/dist/cjs/hooks/useShapes/pie/index.d.ts +0 -12
  161. package/dist/cjs/hooks/useShapes/pie/index.js +0 -20
  162. package/dist/cjs/hooks/useShapes/radar/index.d.ts +0 -12
  163. package/dist/cjs/hooks/useShapes/radar/index.js +0 -19
  164. package/dist/cjs/hooks/useShapes/sankey/index.d.ts +0 -12
  165. package/dist/cjs/hooks/useShapes/sankey/index.js +0 -18
  166. package/dist/cjs/hooks/useShapes/scatter/index.d.ts +0 -13
  167. package/dist/cjs/hooks/useShapes/scatter/index.js +0 -22
  168. package/dist/cjs/hooks/useShapes/treemap/index.d.ts +0 -12
  169. package/dist/cjs/hooks/useShapes/treemap/index.js +0 -18
  170. package/dist/cjs/hooks/useShapes/waterfall/index.d.ts +0 -14
  171. package/dist/cjs/hooks/useShapes/waterfall/index.js +0 -31
  172. package/dist/cjs/hooks/useShapes/x-range/index.d.ts +0 -14
  173. package/dist/cjs/hooks/useShapes/x-range/index.js +0 -20
  174. package/dist/esm/hooks/useShapes/area/index.d.ts +0 -15
  175. package/dist/esm/hooks/useShapes/area/index.js +0 -52
  176. package/dist/esm/hooks/useShapes/bar-x/index.d.ts +0 -16
  177. package/dist/esm/hooks/useShapes/bar-x/index.js +0 -45
  178. package/dist/esm/hooks/useShapes/bar-y/index.d.ts +0 -13
  179. package/dist/esm/hooks/useShapes/bar-y/index.js +0 -19
  180. package/dist/esm/hooks/useShapes/funnel/index.d.ts +0 -13
  181. package/dist/esm/hooks/useShapes/funnel/index.js +0 -21
  182. package/dist/esm/hooks/useShapes/heatmap/index.d.ts +0 -13
  183. package/dist/esm/hooks/useShapes/heatmap/index.js +0 -20
  184. package/dist/esm/hooks/useShapes/line/index.d.ts +0 -15
  185. package/dist/esm/hooks/useShapes/line/index.js +0 -38
  186. package/dist/esm/hooks/useShapes/pie/index.d.ts +0 -12
  187. package/dist/esm/hooks/useShapes/pie/index.js +0 -20
  188. package/dist/esm/hooks/useShapes/radar/index.d.ts +0 -12
  189. package/dist/esm/hooks/useShapes/radar/index.js +0 -19
  190. package/dist/esm/hooks/useShapes/sankey/index.d.ts +0 -12
  191. package/dist/esm/hooks/useShapes/sankey/index.js +0 -18
  192. package/dist/esm/hooks/useShapes/scatter/index.d.ts +0 -13
  193. package/dist/esm/hooks/useShapes/scatter/index.js +0 -22
  194. package/dist/esm/hooks/useShapes/treemap/index.d.ts +0 -12
  195. package/dist/esm/hooks/useShapes/treemap/index.js +0 -18
  196. package/dist/esm/hooks/useShapes/waterfall/index.d.ts +0 -14
  197. package/dist/esm/hooks/useShapes/waterfall/index.js +0 -31
  198. package/dist/esm/hooks/useShapes/x-range/index.d.ts +0 -14
  199. package/dist/esm/hooks/useShapes/x-range/index.js +0 -20
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import type { Dispatch } from 'd3-dispatch';
3
+ import type { SeriesShapeData } from '../../core/shapes/types';
4
+ interface Props {
5
+ preparedData: SeriesShapeData[];
6
+ dispatcher?: Dispatch<object>;
7
+ namespace: string;
8
+ }
9
+ export declare const HoverMarkerLayer: ({ preparedData, dispatcher, namespace }: Props) => React.JSX.Element;
10
+ export {};
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { select } from 'd3-selection';
3
+ import { renderHoverMarkers } from '../../core/shapes/marker';
4
+ export const HoverMarkerLayer = ({ preparedData, dispatcher, namespace }) => {
5
+ const ref = React.useRef(null);
6
+ React.useEffect(() => {
7
+ if (!ref.current)
8
+ return () => { };
9
+ const container = select(ref.current);
10
+ function handleHover(data) {
11
+ var _a;
12
+ const hoveredData = (_a = data === null || data === void 0 ? void 0 : data.map((d) => d.data)) !== null && _a !== void 0 ? _a : [];
13
+ const items = preparedData.flatMap((d) => d.getHoverMarkers(hoveredData));
14
+ renderHoverMarkers(container, items);
15
+ }
16
+ dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.on(`hover-shape.${namespace}`, handleHover);
17
+ return () => {
18
+ dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.on(`hover-shape.${namespace}`, null);
19
+ };
20
+ }, [preparedData, dispatcher, namespace]);
21
+ return React.createElement("g", { ref: ref });
22
+ };
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import type { MarkerItem } from '../../core/shapes/types';
3
+ interface Props {
4
+ markers: MarkerItem[];
5
+ }
6
+ export declare const MarkerLayer: ({ markers }: Props) => React.JSX.Element;
7
+ export {};
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { select } from 'd3-selection';
3
+ import { renderMarkers } from '../../core/shapes/marker';
4
+ export const MarkerLayer = ({ markers }) => {
5
+ const ref = React.useRef(null);
6
+ React.useEffect(() => {
7
+ if (ref.current) {
8
+ renderMarkers(select(ref.current), markers);
9
+ }
10
+ }, [markers]);
11
+ return React.createElement("g", { ref: ref });
12
+ };
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import type { Dispatch } from 'd3-dispatch';
3
+ import type { SeriesPlugin } from '../../core/series/plugin';
4
+ import type { PreparedSeriesOptions } from '../../core/series/types';
5
+ import type { SeriesShapeData } from '../../core/shapes/types';
6
+ interface Props {
7
+ boundsHeight: number;
8
+ boundsWidth: number;
9
+ clipPathId?: string;
10
+ dispatcher?: Dispatch<object>;
11
+ htmlLayout: HTMLElement | null;
12
+ namespace: string;
13
+ plugin: SeriesPlugin;
14
+ preparedData: SeriesShapeData[];
15
+ seriesOptions: PreparedSeriesOptions;
16
+ }
17
+ export declare const SeriesShapes: ({ boundsHeight, boundsWidth, clipPathId, dispatcher, htmlLayout, namespace, plugin, preparedData, seriesOptions, }: Props) => React.JSX.Element;
18
+ export {};
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import { block } from '../../utils';
3
+ import { AnnotationLayer } from './AnnotationLayer';
4
+ import { HoverMarkerLayer } from './HoverMarkerLayer';
5
+ import { HtmlLayer } from './HtmlLayer';
6
+ import { MarkerLayer } from './MarkerLayer';
7
+ export const SeriesShapes = ({ boundsHeight, boundsWidth, clipPathId, dispatcher, htmlLayout, namespace, plugin, preparedData, seriesOptions, }) => {
8
+ const b = block(plugin.type);
9
+ const ref = React.useRef(null);
10
+ React.useEffect(() => {
11
+ var _a;
12
+ if (!ref.current)
13
+ return () => { };
14
+ return ((_a = plugin.renderShapes({
15
+ plot: ref.current,
16
+ preparedData,
17
+ seriesOptions,
18
+ boundsWidth,
19
+ boundsHeight,
20
+ dispatcher,
21
+ })) !== null && _a !== void 0 ? _a : undefined);
22
+ }, [boundsHeight, boundsWidth, dispatcher, plugin, preparedData, seriesOptions]);
23
+ const markers = React.useMemo(() => preparedData.flatMap((d) => d.markers), [preparedData]);
24
+ const annotations = React.useMemo(() => preparedData.flatMap((d) => d.annotations), [preparedData]);
25
+ const htmlLayerData = React.useMemo(() => ({ htmlElements: preparedData.flatMap((d) => d.htmlLabels) }), [preparedData]);
26
+ return (React.createElement(React.Fragment, null,
27
+ React.createElement("g", { ref: ref, className: b(), clipPath: clipPathId ? `url(#${clipPathId})` : undefined }),
28
+ React.createElement(MarkerLayer, { markers: markers }),
29
+ React.createElement(HoverMarkerLayer, { preparedData: preparedData, dispatcher: dispatcher, namespace: namespace }),
30
+ React.createElement(AnnotationLayer, { annotations: annotations, boundsWidth: boundsWidth, boundsHeight: boundsHeight }),
31
+ React.createElement(HtmlLayer, { preparedData: htmlLayerData, htmlLayout: htmlLayout })));
32
+ };
@@ -1,26 +1,14 @@
1
1
  import React from 'react';
2
2
  import type { Dispatch } from 'd3-dispatch';
3
- import type { SeriesType } from '../../core/constants';
4
3
  import type { PreparedSplit } from '../../core/layout/split-types';
5
4
  import type { ChartScale } from '../../core/scales/types';
6
5
  import type { PreparedSeries, PreparedSeriesOptions } from '../../core/series/types';
7
- import type { PreparedAreaData } from '../../core/shapes/area/types';
8
- import type { PreparedBarXData } from '../../core/shapes/bar-x/types';
9
- import type { PreparedBarYData } from '../../core/shapes/bar-y/types';
10
- import type { PreparedFunnelData } from '../../core/shapes/funnel/types';
11
- import type { PreparedHeatmapData } from '../../core/shapes/heatmap/types';
12
- import type { PreparedLineData } from '../../core/shapes/line/types';
13
- import type { PreparedPieData } from '../../core/shapes/pie/types';
14
- import type { PreparedRadarData } from '../../core/shapes/radar/types';
15
- import type { PreparedSankeyData } from '../../core/shapes/sankey/types';
16
- import type { PreparedScatterData } from '../../core/shapes/scatter/types';
17
- import type { PreparedWaterfallData } from '../../core/shapes/waterfall/types';
18
- import type { PreparedXRangeData } from '../../core/shapes/x-range/types';
6
+ import type { TooltipItemData } from '../../core/shapes/types';
19
7
  import type { ZoomState } from '../../core/zoom/types';
20
8
  import type { PreparedXAxis, PreparedYAxis } from '../useAxis/types';
21
9
  import './styles.css';
22
- export type ShapeData = PreparedBarXData | PreparedBarYData | PreparedScatterData | PreparedLineData | PreparedPieData | PreparedAreaData | PreparedWaterfallData | PreparedSankeyData | PreparedRadarData | PreparedHeatmapData | PreparedFunnelData | PreparedXRangeData;
23
- export type ClipPathBySeriesType = Partial<Record<SeriesType, boolean>>;
10
+ export type { TooltipItemData };
11
+ export type ClipPathBySeriesType = Partial<Record<string, boolean>>;
24
12
  type Args = {
25
13
  boundsWidth: number;
26
14
  boundsHeight: number;
@@ -41,11 +29,10 @@ type Args = {
41
29
  };
42
30
  export declare function getShapes(args: Args): Promise<{
43
31
  shapes: React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
44
- shapesData: ShapeData[];
32
+ shapesData: TooltipItemData[];
45
33
  }>;
46
34
  export declare const useShapes: (args: Args) => {
47
35
  shapes: React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
48
- shapesData: ShapeData[];
36
+ shapesData: TooltipItemData[];
49
37
  shapesReady: boolean;
50
38
  };
51
- export {};
@@ -1,35 +1,21 @@
1
1
  import React from 'react';
2
2
  import { group } from 'd3-array';
3
- import { SERIES_TYPE } from '../../core/constants';
4
- import { prepareAreaData } from '../../core/shapes/area/prepare-data';
5
- import { prepareLineData } from '../../core/shapes/line/prepare-data';
6
- import { preparePieData } from '../../core/shapes/pie/prepare-data';
7
- import { prepareRadarData } from '../../core/shapes/radar/prepare-data';
8
- import { prepareSankeyData } from '../../core/shapes/sankey/prepare-data';
9
- import { prepareTreemapData } from '../../core/shapes/treemap/prepare-data';
3
+ import { getSeriesPlugin } from '../../core/series/seriesRegistry';
4
+ import { getSeriesClipPathId } from '../../core/shapes/utils';
10
5
  import { getOnlyVisibleSeries } from '../../core/utils';
11
- import { ChartError } from '../../libs';
12
- import { AreaSeriesShapes } from './area';
13
- import { BarXSeriesShapes, prepareBarXData } from './bar-x';
14
- import { BarYSeriesShapes, prepareBarYData } from './bar-y';
15
- import { FunnelSeriesShapes, prepareFunnelData } from './funnel';
16
- import { HeatmapSeriesShapes, prepareHeatmapData } from './heatmap';
17
- import { LineSeriesShapes } from './line';
18
- import { PieSeriesShapes } from './pie';
19
- import { RadarSeriesShapes } from './radar';
20
- import { SankeySeriesShape } from './sankey';
21
- import { ScatterSeriesShape, prepareScatterData } from './scatter';
22
- import { TreemapSeriesShape } from './treemap';
23
- import { getSeriesClipPathId } from './utils';
24
- import { WaterfallSeriesShapes, prepareWaterfallData } from './waterfall';
25
- import { XRangeSeriesShapes, prepareXRangeData } from './x-range';
6
+ import { SeriesShapes } from './SeriesShapes';
26
7
  import './styles.css';
27
8
  function IS_OUTSIDE_BOUNDS() {
28
9
  return false;
29
10
  }
30
- function shouldUseClipPathId(seriesType, clipPathBySeriesType) {
31
- var _a;
32
- return (_a = clipPathBySeriesType === null || clipPathBySeriesType === void 0 ? void 0 : clipPathBySeriesType[seriesType]) !== null && _a !== void 0 ? _a : true;
11
+ function resolveClipPathId(args) {
12
+ var _a, _b;
13
+ const { plugin, clipPathId, clipPathBySeriesType, yAxis, zoomState } = args;
14
+ if (plugin.type === 'line') {
15
+ return getSeriesClipPathId({ clipPathId, yAxis, zoomState });
16
+ }
17
+ const useClip = (_b = (_a = clipPathBySeriesType === null || clipPathBySeriesType === void 0 ? void 0 : clipPathBySeriesType[plugin.type]) !== null && _a !== void 0 ? _a : plugin.useClipPath) !== null && _b !== void 0 ? _b : true;
18
+ return useClip ? clipPathId : undefined;
33
19
  }
34
20
  export async function getShapes(args) {
35
21
  const { boundsWidth, boundsHeight, clipPathId, clipPathBySeriesType, dispatcher, htmlLayout, isOutsideBounds = IS_OUTSIDE_BOUNDS, isRangeSlider, series, seriesOptions, split, xAxis, xScale, yAxis, yScale, zoomState, } = args;
@@ -45,212 +31,36 @@ export async function getShapes(args) {
45
31
  const layers = [];
46
32
  const groupedSeriesItems = Array.from(groupedSeries);
47
33
  for (let index = groupedSeriesItems.length - 1; index >= 0; index--) {
48
- const item = groupedSeriesItems[index];
49
- const [groupId, chartSeries] = item;
34
+ const [groupKey, chartSeries] = groupedSeriesItems[index];
50
35
  const seriesType = chartSeries[0].type;
51
- switch (seriesType) {
52
- case SERIES_TYPE.BarX: {
53
- if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
54
- const preparedData = await prepareBarXData({
55
- series: chartSeries,
56
- seriesOptions,
57
- xAxis,
58
- xScale,
59
- yAxis,
60
- yScale,
61
- boundsHeight,
62
- split,
63
- isRangeSlider,
64
- });
65
- shapes[index] = (React.createElement(BarXSeriesShapes, { key: SERIES_TYPE.BarX, boundsHeight: boundsHeight, boundsWidth: boundsWidth, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: clipPathId }));
66
- shapesData.splice(index, 0, ...preparedData);
67
- layers.push(...preparedData);
68
- }
69
- break;
70
- }
71
- case SERIES_TYPE.BarY: {
72
- if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
73
- const preparedData = await prepareBarYData({
74
- boundsHeight,
75
- boundsWidth,
76
- series: chartSeries,
77
- seriesOptions,
78
- xAxis,
79
- xScale,
80
- yAxis,
81
- yScale,
82
- });
83
- shapes[index] = (React.createElement(BarYSeriesShapes, { key: SERIES_TYPE.BarY, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: clipPathId }));
84
- shapesData.splice(index, 0, ...preparedData.shapes);
85
- }
86
- break;
87
- }
88
- case SERIES_TYPE.Waterfall: {
89
- if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
90
- const preparedData = await prepareWaterfallData({
91
- series: chartSeries,
92
- seriesOptions,
93
- xAxis,
94
- xScale,
95
- yAxis,
96
- yScale,
97
- });
98
- shapes[index] = (React.createElement(WaterfallSeriesShapes, { key: SERIES_TYPE.Waterfall, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: clipPathId }));
99
- shapesData.splice(index, 0, ...preparedData);
100
- }
101
- break;
102
- }
103
- case SERIES_TYPE.Line: {
104
- if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
105
- const preparedData = await prepareLineData({
106
- series: chartSeries,
107
- seriesOptions,
108
- xAxis,
109
- xScale,
110
- yAxis,
111
- yScale,
112
- split,
113
- isOutsideBounds,
114
- isRangeSlider,
115
- otherLayers: layers,
116
- });
117
- const resultClipPathId = getSeriesClipPathId({
118
- clipPathId,
119
- yAxis,
120
- zoomState,
121
- });
122
- shapes[index] = (React.createElement(LineSeriesShapes, { key: groupId, boundsHeight: boundsHeight, boundsWidth: boundsWidth, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: resultClipPathId }));
123
- shapesData.splice(index, 0, ...preparedData);
124
- layers.push(...preparedData);
125
- }
126
- break;
127
- }
128
- case SERIES_TYPE.Area: {
129
- if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
130
- const preparedData = await prepareAreaData({
131
- series: chartSeries,
132
- seriesOptions,
133
- xAxis,
134
- xScale,
135
- yAxis,
136
- yScale,
137
- split,
138
- isOutsideBounds,
139
- isRangeSlider,
140
- });
141
- shapes[index] = (React.createElement(AreaSeriesShapes, { key: SERIES_TYPE.Area, boundsHeight: boundsHeight, boundsWidth: boundsWidth, dispatcher: dispatcher, seriesOptions: seriesOptions, preparedData: preparedData, htmlLayout: htmlLayout, clipPathId: clipPathId }));
142
- shapesData.splice(index, 0, ...preparedData);
143
- layers.push(...preparedData);
144
- }
145
- break;
146
- }
147
- case SERIES_TYPE.Scatter: {
148
- if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
149
- const scatterShapeData = await prepareScatterData({
150
- series: chartSeries,
151
- xAxis,
152
- xScale,
153
- yAxis,
154
- yScale,
155
- split,
156
- isOutsideBounds,
157
- isRangeSlider,
158
- });
159
- shapes[index] = (React.createElement(ScatterSeriesShape, { key: SERIES_TYPE.Scatter, clipPathId: shouldUseClipPathId(SERIES_TYPE.Scatter, clipPathBySeriesType)
160
- ? clipPathId
161
- : undefined, dispatcher: dispatcher, preparedData: scatterShapeData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
162
- shapesData.splice(index, 0, ...scatterShapeData.markers);
163
- }
164
- break;
165
- }
166
- case SERIES_TYPE.Pie: {
167
- const preparedData = await preparePieData({
168
- series: chartSeries,
169
- boundsWidth,
170
- boundsHeight,
171
- });
172
- shapes[index] = (React.createElement(PieSeriesShapes, { key: SERIES_TYPE.Pie, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
173
- shapesData.splice(index, 0, ...preparedData);
174
- break;
175
- }
176
- case SERIES_TYPE.Treemap: {
177
- const preparedData = await prepareTreemapData({
178
- // We should have exactly one series with "treemap" type
179
- // Otherwise data validation should emit an error
180
- series: chartSeries[0],
181
- width: boundsWidth,
182
- height: boundsHeight,
183
- });
184
- shapes[index] = (React.createElement(TreemapSeriesShape, { key: SERIES_TYPE.Treemap, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
185
- shapesData.splice(index, 0, preparedData);
186
- break;
187
- }
188
- case SERIES_TYPE.Sankey: {
189
- const preparedData = prepareSankeyData({
190
- series: chartSeries[0],
191
- width: boundsWidth,
192
- height: boundsHeight,
193
- });
194
- shapes[index] = (React.createElement(SankeySeriesShape, { key: SERIES_TYPE.Sankey, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
195
- shapesData.splice(index, 0, preparedData);
196
- break;
197
- }
198
- case SERIES_TYPE.Radar: {
199
- const preparedData = await prepareRadarData({
200
- series: chartSeries,
201
- boundsWidth,
202
- boundsHeight,
203
- });
204
- shapes[index] = (React.createElement(RadarSeriesShapes, { key: SERIES_TYPE.Radar, dispatcher: dispatcher, series: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
205
- shapesData.splice(index, 0, ...preparedData);
206
- break;
207
- }
208
- case SERIES_TYPE.Heatmap: {
209
- if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale[0])) {
210
- const preparedData = await prepareHeatmapData({
211
- series: chartSeries[0],
212
- xAxis,
213
- xScale,
214
- yAxis: yAxis[0],
215
- yScale: yScale[0],
216
- });
217
- shapes[index] = (React.createElement(HeatmapSeriesShapes, { key: SERIES_TYPE.Heatmap, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
218
- shapesData.splice(index, 0, preparedData);
219
- }
220
- break;
221
- }
222
- case SERIES_TYPE.Funnel: {
223
- const preparedData = await prepareFunnelData({
224
- series: chartSeries,
225
- boundsWidth,
226
- boundsHeight,
227
- });
228
- shapes[index] = (React.createElement(FunnelSeriesShapes, { key: SERIES_TYPE.Funnel, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout }));
229
- shapesData.splice(index, 0, preparedData);
230
- break;
231
- }
232
- case SERIES_TYPE.XRange: {
233
- if (xAxis && xScale && (yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
234
- const preparedData = await prepareXRangeData({
235
- series: chartSeries,
236
- xAxis,
237
- xScale,
238
- yAxis,
239
- yScale,
240
- boundsWidth,
241
- isRangeSlider,
242
- });
243
- shapes[index] = (React.createElement(XRangeSeriesShapes, { key: SERIES_TYPE.XRange, dispatcher: dispatcher, preparedData: preparedData, seriesOptions: seriesOptions, htmlLayout: htmlLayout, clipPathId: clipPathId }));
244
- shapesData.splice(index, 0, ...preparedData);
245
- }
246
- break;
247
- }
248
- default: {
249
- throw new ChartError({
250
- message: `The display method is not defined for a series with type "${seriesType}"`,
251
- });
252
- }
36
+ const plugin = getSeriesPlugin(seriesType);
37
+ const { renderData, tooltipItems } = await plugin.prepareShapeData({
38
+ series: chartSeries,
39
+ boundsWidth,
40
+ boundsHeight,
41
+ seriesOptions,
42
+ xAxis,
43
+ yAxis,
44
+ xScale,
45
+ yScale,
46
+ split,
47
+ isOutsideBounds,
48
+ isRangeSlider,
49
+ otherLayers: layers,
50
+ });
51
+ if (renderData.length === 0) {
52
+ continue;
253
53
  }
54
+ const resolvedClipPathId = resolveClipPathId({
55
+ plugin,
56
+ clipPathId,
57
+ clipPathBySeriesType,
58
+ yAxis,
59
+ zoomState,
60
+ });
61
+ shapes[index] = (React.createElement(SeriesShapes, { key: groupKey, plugin: plugin, preparedData: renderData, boundsWidth: boundsWidth, boundsHeight: boundsHeight, clipPathId: resolvedClipPathId, seriesOptions: seriesOptions, dispatcher: dispatcher, htmlLayout: htmlLayout, namespace: `hover-markers-${groupKey}` }));
62
+ shapesData.splice(index, 0, ...tooltipItems);
63
+ layers.push(...renderData);
254
64
  }
255
65
  return { shapes, shapesData };
256
66
  }
@@ -1,4 +1,3 @@
1
- import './plugins';
2
1
  export { CustomShapeRenderer } from './utils';
3
2
  export { getFormattedValue } from './core/utils';
4
3
  export { getDefaultTooltipHeaderFormat } from './core/utils/tooltip';
package/dist/cjs/index.js CHANGED
@@ -1,4 +1,3 @@
1
- import './plugins';
2
1
  export { CustomShapeRenderer } from './utils';
3
2
  export { getFormattedValue } from './core/utils';
4
3
  export { getDefaultTooltipHeaderFormat } from './core/utils/tooltip';
@@ -1,5 +1,47 @@
1
+ import { getTooltipData } from '../../core/shapes/area/get-tooltip-data';
2
+ import { prepareAreaData } from '../../core/shapes/area/prepare-data';
3
+ import { renderArea } from '../../core/shapes/area/renderer';
4
+ import { filterOverlappingLabels } from '../../core/utils';
1
5
  import { prepareArea } from './prepare';
6
+ async function prepareShapeData(args) {
7
+ const { series, seriesOptions, xAxis, xScale, yAxis, yScale, split, isOutsideBounds, isRangeSlider, } = args;
8
+ if (!xAxis || !xScale || !(yScale === null || yScale === void 0 ? void 0 : yScale.length) || !split) {
9
+ return { renderData: [], tooltipItems: [] };
10
+ }
11
+ const data = await prepareAreaData({
12
+ series: series,
13
+ seriesOptions,
14
+ xAxis,
15
+ xScale,
16
+ yAxis: yAxis !== null && yAxis !== void 0 ? yAxis : [],
17
+ yScale,
18
+ split,
19
+ isOutsideBounds: isOutsideBounds !== null && isOutsideBounds !== void 0 ? isOutsideBounds : (() => false),
20
+ isRangeSlider,
21
+ });
22
+ const allowOverlap = data.some((d) => d.series.dataLabels.allowOverlap);
23
+ if (!allowOverlap) {
24
+ const filtered = filterOverlappingLabels(data.flatMap((d) => d.htmlLabels));
25
+ const [first, ...rest] = data;
26
+ if (first) {
27
+ const filteredData = [
28
+ Object.assign(Object.assign({}, first), { htmlLabels: filtered }),
29
+ ...rest.map((d) => (Object.assign(Object.assign({}, d), { htmlLabels: [] }))),
30
+ ];
31
+ return { renderData: filteredData, tooltipItems: filteredData };
32
+ }
33
+ }
34
+ return { renderData: data, tooltipItems: data };
35
+ }
36
+ function renderShapes({ plot, preparedData, seriesOptions, dispatcher }) {
37
+ const data = preparedData;
38
+ const allowOverlap = data.some((d) => d.series.dataLabels.allowOverlap);
39
+ return renderArea({ plot }, data, seriesOptions, allowOverlap, dispatcher);
40
+ }
2
41
  export const areaPlugin = {
3
42
  type: 'area',
4
43
  prepareSeries: ({ series, seriesOptions, legend, colorScale }) => prepareArea({ series: series, seriesOptions, legend, colorScale }),
44
+ prepareShapeData,
45
+ renderShapes,
46
+ getTooltipData: getTooltipData,
5
47
  };
@@ -1,5 +1,47 @@
1
+ import { getTooltipData } from '../../core/shapes/bar-x/get-tooltip-data';
2
+ import { prepareBarXData } from '../../core/shapes/bar-x/prepare-data';
3
+ import { renderBarX } from '../../core/shapes/bar-x/renderer';
4
+ import { filterOverlappingLabels } from '../../core/utils';
1
5
  import { prepareBarXSeries } from './prepare';
6
+ async function prepareShapeData(args) {
7
+ const { series, seriesOptions, xAxis, xScale, yAxis, yScale, boundsHeight, split, isRangeSlider, } = args;
8
+ if (!xAxis || !xScale || !(yScale === null || yScale === void 0 ? void 0 : yScale.length) || !split) {
9
+ return { renderData: [], tooltipItems: [] };
10
+ }
11
+ const data = await prepareBarXData({
12
+ series: series,
13
+ seriesOptions,
14
+ xAxis,
15
+ xScale,
16
+ yAxis: yAxis !== null && yAxis !== void 0 ? yAxis : [],
17
+ yScale,
18
+ boundsHeight,
19
+ split,
20
+ isRangeSlider,
21
+ });
22
+ const allowOverlap = data.some((d) => d.series.dataLabels.allowOverlap);
23
+ if (!allowOverlap) {
24
+ const filtered = filterOverlappingLabels(data.flatMap((d) => d.htmlLabels));
25
+ const [first, ...rest] = data;
26
+ if (first) {
27
+ const filteredData = [
28
+ Object.assign(Object.assign({}, first), { htmlLabels: filtered }),
29
+ ...rest.map((d) => (Object.assign(Object.assign({}, d), { htmlLabels: [] }))),
30
+ ];
31
+ return { renderData: filteredData, tooltipItems: filteredData };
32
+ }
33
+ }
34
+ return { renderData: data, tooltipItems: data };
35
+ }
36
+ function renderShapes({ plot, preparedData, seriesOptions, boundsWidth, boundsHeight, dispatcher, }) {
37
+ const data = preparedData;
38
+ const allowOverlap = data.some((d) => d.series.dataLabels.allowOverlap);
39
+ return renderBarX({ plot, boundsWidth, boundsHeight }, data, seriesOptions, allowOverlap, dispatcher);
40
+ }
2
41
  export const barXPlugin = {
3
42
  type: 'bar-x',
4
43
  prepareSeries: ({ series, seriesOptions, legend, colorScale }) => prepareBarXSeries({ series: series, seriesOptions, legend, colorScale }),
44
+ prepareShapeData,
45
+ renderShapes,
46
+ getTooltipData: getTooltipData,
5
47
  };
@@ -1,5 +1,31 @@
1
+ import { getTooltipData } from '../../core/shapes/bar-y/get-tooltip-data';
2
+ import { prepareBarYData } from '../../core/shapes/bar-y/prepare-data';
3
+ import { renderBarY } from '../../core/shapes/bar-y/renderer';
1
4
  import { prepareBarYSeries } from './prepare';
5
+ async function prepareShapeData(args) {
6
+ const { series, seriesOptions, xAxis, xScale, yAxis, yScale, boundsHeight, boundsWidth } = args;
7
+ if (!xAxis || !xScale || !(yScale === null || yScale === void 0 ? void 0 : yScale.length)) {
8
+ return { renderData: [], tooltipItems: [] };
9
+ }
10
+ const data = await prepareBarYData({
11
+ boundsHeight,
12
+ boundsWidth,
13
+ series: series,
14
+ seriesOptions,
15
+ xAxis,
16
+ xScale,
17
+ yAxis: yAxis !== null && yAxis !== void 0 ? yAxis : [],
18
+ yScale,
19
+ });
20
+ return { renderData: [data], tooltipItems: data.shapes };
21
+ }
22
+ function renderShapes({ plot, preparedData, seriesOptions, dispatcher }) {
23
+ return renderBarY({ plot }, preparedData[0], seriesOptions, dispatcher);
24
+ }
2
25
  export const barYPlugin = {
3
26
  type: 'bar-y',
4
27
  prepareSeries: ({ series, seriesOptions, legend, colorScale }) => prepareBarYSeries({ series: series, seriesOptions, legend, colorScale }),
28
+ prepareShapeData,
29
+ renderShapes,
30
+ getTooltipData: getTooltipData,
5
31
  };
@@ -1,5 +1,23 @@
1
+ import { getTooltipData } from '../../core/shapes/funnel/get-tooltip-data';
2
+ import { prepareFunnelData } from '../../core/shapes/funnel/prepare-data';
3
+ import { renderFunnel } from '../../core/shapes/funnel/renderer';
1
4
  import { prepareFunnelSeries } from './prepare';
5
+ async function prepareShapeData({ series, boundsWidth, boundsHeight, }) {
6
+ const data = await prepareFunnelData({
7
+ series: series,
8
+ boundsWidth,
9
+ boundsHeight,
10
+ });
11
+ return { renderData: [data], tooltipItems: [data] };
12
+ }
13
+ function renderShapes({ plot, preparedData, seriesOptions, dispatcher }) {
14
+ return renderFunnel({ plot }, preparedData[0], seriesOptions, dispatcher);
15
+ }
2
16
  export const funnelPlugin = {
3
17
  type: 'funnel',
18
+ useClipPath: false,
4
19
  prepareSeries: ({ series, seriesOptions, legend, colors }) => prepareFunnelSeries({ series: series, seriesOptions, legend, colors }),
20
+ prepareShapeData,
21
+ renderShapes,
22
+ getTooltipData: getTooltipData,
5
23
  };