@gravity-ui/chartkit 4.17.0 → 4.18.1

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 (55) hide show
  1. package/build/i18n/keysets/en.json +2 -1
  2. package/build/i18n/keysets/ru.json +2 -1
  3. package/build/plugins/d3/examples/area/PercentStacking.d.ts +2 -0
  4. package/build/plugins/d3/examples/area/PercentStacking.js +47 -0
  5. package/build/plugins/d3/examples/bar-x/PercentStack.d.ts +2 -0
  6. package/build/plugins/d3/examples/bar-x/PercentStack.js +47 -0
  7. package/build/plugins/d3/examples/bar-y/PercentStacking.d.ts +2 -0
  8. package/build/plugins/d3/examples/bar-y/PercentStacking.js +49 -0
  9. package/build/plugins/d3/examples/pie/DonutWithTotals.d.ts +2 -0
  10. package/build/plugins/d3/examples/pie/DonutWithTotals.js +36 -0
  11. package/build/plugins/d3/examples/scatter/Basic.js +0 -21
  12. package/build/plugins/d3/index.d.ts +1 -0
  13. package/build/plugins/d3/index.js +1 -0
  14. package/build/plugins/d3/renderer/D3Widget.js +4 -2
  15. package/build/plugins/d3/renderer/components/Tooltip/TooltipTriggerArea.js +5 -4
  16. package/build/plugins/d3/renderer/hooks/useSeries/constants.d.ts +2 -0
  17. package/build/plugins/d3/renderer/hooks/useSeries/constants.js +7 -1
  18. package/build/plugins/d3/renderer/hooks/useSeries/prepare-area.d.ts +2 -2
  19. package/build/plugins/d3/renderer/hooks/useSeries/prepare-area.js +2 -8
  20. package/build/plugins/d3/renderer/hooks/useSeries/{prepare-line-series.d.ts → prepare-line.d.ts} +2 -2
  21. package/build/plugins/d3/renderer/hooks/useSeries/{prepare-line-series.js → prepare-line.js} +2 -8
  22. package/build/plugins/d3/renderer/hooks/useSeries/prepare-pie.js +1 -0
  23. package/build/plugins/d3/renderer/hooks/useSeries/prepare-scatter.d.ts +11 -0
  24. package/build/plugins/d3/renderer/hooks/useSeries/prepare-scatter.js +45 -0
  25. package/build/plugins/d3/renderer/hooks/useSeries/prepareSeries.js +3 -24
  26. package/build/plugins/d3/renderer/hooks/useSeries/types.d.ts +24 -4
  27. package/build/plugins/d3/renderer/hooks/useSeries/utils.d.ts +1 -1
  28. package/build/plugins/d3/renderer/hooks/useSeries/utils.js +1 -1
  29. package/build/plugins/d3/renderer/hooks/useShapes/area/prepare-data.js +18 -0
  30. package/build/plugins/d3/renderer/hooks/useShapes/bar-x/prepare-data.js +15 -3
  31. package/build/plugins/d3/renderer/hooks/useShapes/bar-y/prepare-data.js +15 -4
  32. package/build/plugins/d3/renderer/hooks/useShapes/index.d.ts +2 -2
  33. package/build/plugins/d3/renderer/hooks/useShapes/marker.d.ts +4 -3
  34. package/build/plugins/d3/renderer/hooks/useShapes/marker.js +18 -19
  35. package/build/plugins/d3/renderer/hooks/useShapes/pie/index.js +14 -0
  36. package/build/plugins/d3/renderer/hooks/useShapes/scatter/index.d.ts +1 -2
  37. package/build/plugins/d3/renderer/hooks/useShapes/scatter/index.js +44 -56
  38. package/build/plugins/d3/renderer/hooks/useShapes/scatter/prepare-data.d.ts +1 -10
  39. package/build/plugins/d3/renderer/hooks/useShapes/scatter/prepare-data.js +6 -8
  40. package/build/plugins/d3/renderer/hooks/useShapes/scatter/types.d.ts +15 -0
  41. package/build/plugins/d3/renderer/hooks/useShapes/scatter/types.js +1 -0
  42. package/build/plugins/d3/renderer/hooks/useShapes/utils.d.ts +1 -1
  43. package/build/plugins/d3/renderer/utils/symbol.d.ts +1 -3
  44. package/build/plugins/d3/renderer/validation/index.js +18 -1
  45. package/build/plugins/d3/utils/index.d.ts +4 -0
  46. package/build/plugins/d3/utils/index.js +4 -0
  47. package/build/plugins/d3/utils/pie-center-text.d.ts +7 -0
  48. package/build/plugins/d3/utils/pie-center-text.js +23 -0
  49. package/build/types/widget-data/area.d.ts +2 -2
  50. package/build/types/widget-data/line.d.ts +1 -5
  51. package/build/types/widget-data/marker.d.ts +2 -0
  52. package/build/types/widget-data/pie.d.ts +11 -0
  53. package/build/types/widget-data/series.d.ts +9 -4
  54. package/build/types/widget-data/tooltip.d.ts +5 -1
  55. package/package.json +5 -3
@@ -33,7 +33,8 @@
33
33
  "label_invalid-axis-datetime-data-point": "It seems you are trying to use inappropriate data type for \"{{key}}\" value in series \"{{seriesName}}\" for axis with type \"datetime\". Only numbers are allowed.",
34
34
  "label_invalid-axis-linear-data-point": "It seems you are trying to use inappropriate data type for \"{{key}}\" value in series \"{{seriesName}}\" for axis with type \"linear\". Numbers and nulls are allowed.",
35
35
  "label_invalid-pie-data-value": "It seems you are trying to use inappropriate data type for \"value\" value. Only numbers are allowed.",
36
- "label_invalid-series-type": "It seems you haven't defined \"series.type\" property, or defined it incorrectly. Available values: [{{types}}]."
36
+ "label_invalid-series-type": "It seems you haven't defined \"series.type\" property, or defined it incorrectly. Available values: [{{types}}].",
37
+ "label_invalid-series-property": "It seems you are trying to use inappropriate value for \"{{key}}\", or defined it incorrectly. Available values: [{{values}}]."
37
38
  },
38
39
  "highcharts": {
39
40
  "reset-zoom-title": "Reset zoom",
@@ -35,7 +35,8 @@
35
35
  "label_invalid-axis-datetime-data-point": "Похоже, что вы пытаетесь использовать недопустимый тип данных для значения \"{{key}}\" в серии \"{{seriesName}}\" для оси с типом \"datetime\". Допускается только использование чисел.",
36
36
  "label_invalid-axis-linear-data-point": "Похоже, что вы пытаетесь использовать недопустимый тип данных для значения \"{{key}}\" в серии \"{{seriesName}}\" для оси с типом \"linear\". Допускается использование чисел и значений null.",
37
37
  "label_invalid-pie-data-value": "Похоже, что вы пытаетесь использовать недопустимый тип данных для значения \"value\". Допускается только использование чисел.",
38
- "label_invalid-series-type": "Похоже, что вы не указали значение \"series.type\" или указали его неверно. Доступные значения: [{{types}}]."
38
+ "label_invalid-series-type": "Похоже, что вы не указали значение \"series.type\" или указали его неверно. Доступные значения: [{{types}}].",
39
+ "label_invalid-series-property": "Похоже, что вы пытаетесь использовать недопустимое значение для \"{{key}}\", или указали его неверно. Доступные значения: [{{values}}]."
39
40
  },
40
41
  "highcharts": {
41
42
  "reset-zoom-title": "Сбросить увеличение",
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const PercentStackingArea: () => React.JSX.Element;
@@ -0,0 +1,47 @@
1
+ import { groups } from 'd3';
2
+ import React from 'react';
3
+ import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
5
+ import nintendoGames from '../nintendoGames';
6
+ const years = Array.from(new Set(nintendoGames.map((d) => d.date ? String(new Date(d.date).getFullYear()) : 'unknown'))).sort();
7
+ function prepareData() {
8
+ const grouped = groups(nintendoGames, (d) => d.platform, (d) => (d.date ? String(new Date(d.date).getFullYear()) : 'unknown'));
9
+ const series = grouped.map(([platform, gamesByYear]) => {
10
+ const platformGames = Object.fromEntries(gamesByYear) || {};
11
+ return {
12
+ name: platform,
13
+ data: years.reduce((acc, year) => {
14
+ if (year in platformGames) {
15
+ acc.push({
16
+ x: year,
17
+ y: platformGames[year].length,
18
+ });
19
+ }
20
+ return acc;
21
+ }, []),
22
+ };
23
+ });
24
+ return { series };
25
+ }
26
+ export const PercentStackingArea = () => {
27
+ const { series } = prepareData();
28
+ const data = series.map((s) => {
29
+ return {
30
+ type: 'area',
31
+ stacking: 'percent',
32
+ name: s.name,
33
+ data: s.data,
34
+ };
35
+ });
36
+ const widgetData = {
37
+ series: {
38
+ data: data,
39
+ },
40
+ xAxis: {
41
+ type: 'category',
42
+ categories: years,
43
+ },
44
+ };
45
+ return (React.createElement(ExampleWrapper, null,
46
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
47
+ };
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const PercentStackColumns: () => React.JSX.Element;
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ import { groups } from 'd3';
3
+ import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
5
+ import nintendoGames from '../nintendoGames';
6
+ function prepareData() {
7
+ const grouped = groups(nintendoGames, (d) => d.platform, (d) => (d.date ? new Date(d.date).getFullYear() : 'unknown'));
8
+ const categories = [];
9
+ const series = grouped.map(([platform, years]) => {
10
+ return {
11
+ name: platform,
12
+ data: years.map(([year, list]) => {
13
+ categories.push(String(year));
14
+ return {
15
+ x: String(year),
16
+ y: list.length,
17
+ };
18
+ }),
19
+ };
20
+ });
21
+ return { categories, series };
22
+ }
23
+ export const PercentStackColumns = () => {
24
+ const { series, categories } = prepareData();
25
+ const data = series.map((s) => {
26
+ return {
27
+ type: 'bar-x',
28
+ stacking: 'percent',
29
+ name: s.name,
30
+ data: s.data,
31
+ };
32
+ });
33
+ const widgetData = {
34
+ series: {
35
+ data: data,
36
+ },
37
+ xAxis: {
38
+ type: 'category',
39
+ categories: categories.sort(),
40
+ title: {
41
+ text: 'Release year',
42
+ },
43
+ },
44
+ };
45
+ return (React.createElement(ExampleWrapper, null,
46
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
47
+ };
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const PercentStackingBars: () => React.JSX.Element;
@@ -0,0 +1,49 @@
1
+ import React from 'react';
2
+ import { groups } from 'd3';
3
+ import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
5
+ import nintendoGames from '../nintendoGames';
6
+ function prepareData() {
7
+ const grouped = groups(nintendoGames, (d) => d.platform, (d) => (d.date ? new Date(d.date).getFullYear() : 'unknown'));
8
+ const categories = [];
9
+ const series = grouped.map(([platform, years]) => {
10
+ return {
11
+ name: platform,
12
+ data: years.map(([year, list]) => {
13
+ categories.push(String(year));
14
+ return {
15
+ y: String(year),
16
+ x: list.length,
17
+ };
18
+ }),
19
+ };
20
+ });
21
+ return { categories, series };
22
+ }
23
+ export const PercentStackingBars = () => {
24
+ const { series, categories } = prepareData();
25
+ const data = series.map((s) => {
26
+ return {
27
+ type: 'bar-y',
28
+ stacking: 'percent',
29
+ name: s.name,
30
+ data: s.data,
31
+ };
32
+ });
33
+ const widgetData = {
34
+ series: {
35
+ data: data,
36
+ },
37
+ yAxis: [
38
+ {
39
+ type: 'category',
40
+ categories: categories.sort(),
41
+ title: {
42
+ text: 'Release year',
43
+ },
44
+ },
45
+ ],
46
+ };
47
+ return (React.createElement(ExampleWrapper, null,
48
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
49
+ };
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const DonutWithTotals: () => React.JSX.Element;
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import { groups } from 'd3';
3
+ import { ChartKit } from '../../../../components/ChartKit';
4
+ import { ExampleWrapper } from '../ExampleWrapper';
5
+ import nintendoGames from '../nintendoGames';
6
+ import { CustomShapeRenderer } from '../../utils';
7
+ function prepareData() {
8
+ const gamesByPlatform = groups(nintendoGames, (d) => d.esrb_rating || 'unknown');
9
+ return gamesByPlatform.map(([value, games]) => ({
10
+ name: value,
11
+ value: games.length,
12
+ }));
13
+ }
14
+ export const DonutWithTotals = () => {
15
+ const data = prepareData();
16
+ const totals = data.reduce((sum, d) => sum + d.value, 0);
17
+ const widgetData = {
18
+ series: {
19
+ data: [
20
+ {
21
+ type: 'pie',
22
+ innerRadius: '50%',
23
+ data: data,
24
+ renderCustomShape: CustomShapeRenderer.pieCenterText(`${totals}`),
25
+ },
26
+ ],
27
+ },
28
+ legend: { enabled: true },
29
+ title: {
30
+ text: 'ESRB ratings',
31
+ style: { fontSize: '12px', fontWeight: 'normal' },
32
+ },
33
+ };
34
+ return (React.createElement(ExampleWrapper, null,
35
+ React.createElement(ChartKit, { type: "d3", data: widgetData })));
36
+ };
@@ -1,5 +1,4 @@
1
1
  import React from 'react';
2
- import { dateTime } from '@gravity-ui/date-utils';
3
2
  import { ChartKit } from '../../../../components/ChartKit';
4
3
  import { ExampleWrapper } from '../ExampleWrapper';
5
4
  import nintendoGames from '../nintendoGames';
@@ -42,26 +41,6 @@ export const Basic = () => {
42
41
  text: 'Release dates',
43
42
  },
44
43
  },
45
- tooltip: {
46
- renderer: (d) => {
47
- var _a;
48
- const point = (_a = d.hovered[0]) === null || _a === void 0 ? void 0 : _a.data;
49
- if (!point) {
50
- return null;
51
- }
52
- const title = point.custom.title;
53
- const score = point.custom.user_score;
54
- const date = dateTime({ input: point.custom.date }).format('DD MMM YYYY');
55
- return (React.createElement(React.Fragment, null,
56
- React.createElement("b", null, title),
57
- React.createElement("br", null),
58
- "Release date: ",
59
- date,
60
- React.createElement("br", null),
61
- "User score: ",
62
- score));
63
- },
64
- },
65
44
  };
66
45
  return (React.createElement(ExampleWrapper, null,
67
46
  React.createElement(ChartKit, { type: "d3", data: widgetData })));
@@ -1,5 +1,6 @@
1
1
  import { ChartKitPlugin } from '../../types';
2
2
  export * from './types';
3
+ export * from './utils';
3
4
  /**
4
5
  * It is an experemental plugin
5
6
  *
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  export * from './types';
3
+ export * from './utils';
3
4
  /**
4
5
  * It is an experemental plugin
5
6
  *
@@ -7,6 +7,7 @@ import { Chart } from './components';
7
7
  import { validateData } from './validation';
8
8
  const D3Widget = React.forwardRef(function D3Widget(props, forwardedRef) {
9
9
  const { data, onLoad, onRender, onChartLoad } = props;
10
+ const validatedData = React.useRef();
10
11
  const ref = React.useRef(null);
11
12
  const debounced = React.useRef();
12
13
  const [dimensions, setDimensions] = React.useState();
@@ -44,9 +45,10 @@ const D3Widget = React.forwardRef(function D3Widget(props, forwardedRef) {
44
45
  // dimensions initialize
45
46
  handleResize();
46
47
  }, [handleResize]);
47
- React.useEffect(() => {
48
+ if (validatedData.current !== data) {
48
49
  validateData(data);
49
- }, [data]);
50
+ validatedData.current = data;
51
+ }
50
52
  React.useLayoutEffect(() => {
51
53
  if (onChartLoad) {
52
54
  onChartLoad({});
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import throttle from 'lodash/throttle';
3
3
  import { bisector, pointer, sort, group } from 'd3';
4
4
  import { extractD3DataFromNode, isNodeContainsD3Data } from '../../utils';
5
+ import get from 'lodash/get';
5
6
  const THROTTLE_DELAY = 50;
6
7
  const isNodeContainsData = (node) => {
7
8
  return isNodeContainsD3Data(node);
@@ -66,7 +67,7 @@ export const TooltipTriggerArea = (args) => {
66
67
  const rectRef = React.useRef(null);
67
68
  const xBarData = React.useMemo(() => {
68
69
  const result = shapesData
69
- .filter((sd) => sd.series.type === 'bar-x')
70
+ .filter((sd) => get(sd, 'series.type') === 'bar-x')
70
71
  .map((sd) => ({ x: sd.x, data: sd }));
71
72
  return sort(result, (item) => item.x);
72
73
  }, [shapesData]);
@@ -77,13 +78,13 @@ export const TooltipTriggerArea = (args) => {
77
78
  return acc.concat(sd.points.map((d) => ({
78
79
  x: d.x,
79
80
  data: d.data,
80
- series: sd.series,
81
+ series: d.series,
81
82
  })));
82
83
  }, []);
83
84
  return sort(result, (item) => item.x);
84
85
  }, [shapesData]);
85
86
  const barYData = React.useMemo(() => {
86
- const barYShapeData = shapesData.filter((sd) => sd.series.type === 'bar-y');
87
+ const barYShapeData = shapesData.filter((sd) => get(sd, 'series.type') === 'bar-y');
87
88
  const result = Array.from(group(barYShapeData, (sd) => sd.y)).map(([y, shapes]) => {
88
89
  const yValue = y + shapes[0].height / 2;
89
90
  return {
@@ -93,7 +94,7 @@ export const TooltipTriggerArea = (args) => {
93
94
  return {
94
95
  x: preparedData.x + preparedData.width,
95
96
  data: preparedData.data,
96
- series: shape.series,
97
+ series: preparedData.series,
97
98
  };
98
99
  }), (item) => item.x),
99
100
  };
@@ -1,6 +1,8 @@
1
1
  import type { BaseTextStyle, Halo } from '../../../../../types';
2
+ import { PointMarkerOptions } from '../../../../../types/widget-data/marker';
2
3
  export declare const DEFAULT_LEGEND_SYMBOL_SIZE = 8;
3
4
  export declare const DEFAULT_LEGEND_SYMBOL_PADDING = 5;
4
5
  export declare const DEFAULT_DATALABELS_PADDING = 5;
5
6
  export declare const DEFAULT_DATALABELS_STYLE: BaseTextStyle;
6
7
  export declare const DEFAULT_HALO_OPTIONS: Required<Halo>;
8
+ export declare const DEFAULT_POINT_MARKER_OPTIONS: Omit<Required<PointMarkerOptions>, 'enabled'>;
@@ -9,5 +9,11 @@ export const DEFAULT_DATALABELS_STYLE = {
9
9
  export const DEFAULT_HALO_OPTIONS = {
10
10
  enabled: true,
11
11
  opacity: 0.25,
12
- size: 10,
12
+ size: 6,
13
+ };
14
+ export const DEFAULT_POINT_MARKER_OPTIONS = {
15
+ radius: 4,
16
+ borderColor: '',
17
+ borderWidth: 0,
18
+ symbol: 'circle',
13
19
  };
@@ -4,10 +4,10 @@ import { PreparedAreaSeries, PreparedLegend } from './types';
4
4
  export declare const DEFAULT_LINE_WIDTH = 1;
5
5
  export declare const DEFAULT_MARKER: {
6
6
  enabled: boolean;
7
- symbol: string;
7
+ symbol: "circle" | "diamond" | "square" | "triangle" | "triangle-down";
8
8
  radius: number;
9
- borderWidth: number;
10
9
  borderColor: string;
10
+ borderWidth: number;
11
11
  };
12
12
  type PrepareAreaSeriesArgs = {
13
13
  colorScale: ScaleOrdinal<string, string>;
@@ -1,16 +1,10 @@
1
1
  import get from 'lodash/get';
2
2
  import merge from 'lodash/merge';
3
- import { DEFAULT_DATALABELS_PADDING, DEFAULT_DATALABELS_STYLE, DEFAULT_HALO_OPTIONS, } from './constants';
3
+ import { DEFAULT_DATALABELS_PADDING, DEFAULT_DATALABELS_STYLE, DEFAULT_HALO_OPTIONS, DEFAULT_POINT_MARKER_OPTIONS, } from './constants';
4
4
  import { getRandomCKId } from '../../../../../utils';
5
5
  import { getSeriesStackId, prepareLegendSymbol } from './utils';
6
6
  export const DEFAULT_LINE_WIDTH = 1;
7
- export const DEFAULT_MARKER = {
8
- enabled: false,
9
- symbol: 'circle',
10
- radius: 4,
11
- borderWidth: 0,
12
- borderColor: '',
13
- };
7
+ export const DEFAULT_MARKER = Object.assign(Object.assign({}, DEFAULT_POINT_MARKER_OPTIONS), { enabled: false });
14
8
  function prepareMarker(series, seriesOptions) {
15
9
  var _a;
16
10
  const seriesHoverState = get(seriesOptions, 'area.states.hover');
@@ -7,10 +7,10 @@ export declare const DEFAULT_LINE_WIDTH = 1;
7
7
  export declare const DEFAULT_DASH_STYLE = DashStyle.Solid;
8
8
  export declare const DEFAULT_MARKER: {
9
9
  enabled: boolean;
10
- symbol: string;
10
+ symbol: "circle" | "diamond" | "square" | "triangle" | "triangle-down";
11
11
  radius: number;
12
- borderWidth: number;
13
12
  borderColor: string;
13
+ borderWidth: number;
14
14
  };
15
15
  type PrepareLineSeriesArgs = {
16
16
  colorScale: ScaleOrdinal<string, string>;
@@ -1,18 +1,12 @@
1
1
  import get from 'lodash/get';
2
2
  import merge from 'lodash/merge';
3
3
  import { DashStyle, LineCap } from '../../../../../constants';
4
- import { DEFAULT_DATALABELS_PADDING, DEFAULT_DATALABELS_STYLE, DEFAULT_HALO_OPTIONS, DEFAULT_LEGEND_SYMBOL_PADDING, } from './constants';
4
+ import { DEFAULT_DATALABELS_PADDING, DEFAULT_DATALABELS_STYLE, DEFAULT_HALO_OPTIONS, DEFAULT_LEGEND_SYMBOL_PADDING, DEFAULT_POINT_MARKER_OPTIONS, } from './constants';
5
5
  import { getRandomCKId } from '../../../../../utils';
6
6
  export const DEFAULT_LEGEND_SYMBOL_SIZE = 16;
7
7
  export const DEFAULT_LINE_WIDTH = 1;
8
8
  export const DEFAULT_DASH_STYLE = DashStyle.Solid;
9
- export const DEFAULT_MARKER = {
10
- enabled: false,
11
- symbol: 'circle',
12
- radius: 4,
13
- borderWidth: 0,
14
- borderColor: '',
15
- };
9
+ export const DEFAULT_MARKER = Object.assign(Object.assign({}, DEFAULT_POINT_MARKER_OPTIONS), { enabled: false });
16
10
  function prepareLinecap(dashStyle, series, seriesOptions) {
17
11
  const defaultLineCap = dashStyle === DashStyle.Solid ? LineCap.Round : LineCap.None;
18
12
  const lineCapFromSeriesOptions = get(seriesOptions, 'line.linecap', defaultLineCap);
@@ -51,6 +51,7 @@ export function preparePieSeries(args) {
51
51
  },
52
52
  },
53
53
  },
54
+ renderCustomShape: series.renderCustomShape,
54
55
  };
55
56
  return result;
56
57
  });
@@ -0,0 +1,11 @@
1
+ import { ScaleOrdinal } from 'd3';
2
+ import type { PreparedLegend, PreparedScatterSeries } from './types';
3
+ import type { ChartKitWidgetSeriesOptions, ScatterSeries } from '../../../../../types';
4
+ interface PrepareScatterSeriesArgs {
5
+ colorScale: ScaleOrdinal<string, string>;
6
+ series: ScatterSeries[];
7
+ legend: PreparedLegend;
8
+ seriesOptions?: ChartKitWidgetSeriesOptions;
9
+ }
10
+ export declare function prepareScatterSeries(args: PrepareScatterSeriesArgs): PreparedScatterSeries[];
11
+ export {};
@@ -0,0 +1,45 @@
1
+ import get from 'lodash/get';
2
+ import merge from 'lodash/merge';
3
+ import { getSymbolType } from '../../utils';
4
+ import { prepareLegendSymbol } from './utils';
5
+ import { DEFAULT_HALO_OPTIONS, DEFAULT_POINT_MARKER_OPTIONS } from './constants';
6
+ import { getRandomCKId } from '../../../../../utils';
7
+ function prepareMarker(series, seriesOptions, index) {
8
+ const seriesHoverState = get(seriesOptions, 'scatter.states.hover');
9
+ const markerNormalState = Object.assign(Object.assign({}, DEFAULT_POINT_MARKER_OPTIONS), { enabled: true, symbol: series.symbolType || getSymbolType(index) });
10
+ const hoveredMarkerDefaultOptions = {
11
+ enabled: true,
12
+ radius: markerNormalState.radius,
13
+ borderWidth: 1,
14
+ borderColor: '#ffffff',
15
+ halo: DEFAULT_HALO_OPTIONS,
16
+ };
17
+ return {
18
+ states: {
19
+ normal: markerNormalState,
20
+ hover: merge(hoveredMarkerDefaultOptions, seriesHoverState === null || seriesHoverState === void 0 ? void 0 : seriesHoverState.marker),
21
+ },
22
+ };
23
+ }
24
+ export function prepareScatterSeries(args) {
25
+ const { colorScale, series, seriesOptions, legend } = args;
26
+ return series.map((s, index) => {
27
+ const id = getRandomCKId();
28
+ const name = 'name' in s && s.name ? s.name : '';
29
+ const symbolType = s.symbolType || getSymbolType(index);
30
+ const prepared = {
31
+ id,
32
+ type: s.type,
33
+ name,
34
+ color: get(s, 'color', colorScale(name)),
35
+ visible: get(s, 'visible', true),
36
+ legend: {
37
+ enabled: get(s, 'legend.enabled', legend.enabled),
38
+ symbol: prepareLegendSymbol(s, symbolType),
39
+ },
40
+ data: s.data,
41
+ marker: prepareMarker(s, seriesOptions, index),
42
+ };
43
+ return prepared;
44
+ }, []);
45
+ }
@@ -1,28 +1,10 @@
1
- import cloneDeep from 'lodash/cloneDeep';
2
- import get from 'lodash/get';
3
- import { getSymbolType } from '../../utils';
4
- import { prepareLineSeries } from './prepare-line-series';
1
+ import { prepareLineSeries } from './prepare-line';
5
2
  import { prepareBarXSeries } from './prepare-bar-x';
6
3
  import { prepareBarYSeries } from './prepare-bar-y';
7
- import { prepareLegendSymbol } from './utils';
8
4
  import { ChartKitError } from '../../../../../libs';
9
5
  import { preparePieSeries } from './prepare-pie';
10
6
  import { prepareArea } from './prepare-area';
11
- function prepareAxisRelatedSeries(args) {
12
- const { colorScale, series, legend, index } = args;
13
- const preparedSeries = cloneDeep(series);
14
- const name = 'name' in series && series.name ? series.name : '';
15
- const symbolType = (series.symbolType || getSymbolType(index));
16
- preparedSeries.symbolType = symbolType;
17
- preparedSeries.color = 'color' in series && series.color ? series.color : colorScale(name);
18
- preparedSeries.name = name;
19
- preparedSeries.visible = get(preparedSeries, 'visible', true);
20
- preparedSeries.legend = {
21
- enabled: get(preparedSeries, 'legend.enabled', legend.enabled),
22
- symbol: prepareLegendSymbol(series, symbolType),
23
- };
24
- return [preparedSeries];
25
- }
7
+ import { prepareScatterSeries } from './prepare-scatter';
26
8
  export function prepareSeries(args) {
27
9
  const { type, series, seriesOptions, legend, colorScale } = args;
28
10
  switch (type) {
@@ -39,10 +21,7 @@ export function prepareSeries(args) {
39
21
  return prepareBarYSeries({ series: series, legend, colorScale });
40
22
  }
41
23
  case 'scatter': {
42
- return series.reduce((acc, singleSeries, index) => {
43
- acc.push(...prepareAxisRelatedSeries({ series: singleSeries, legend, colorScale, index }));
44
- return acc;
45
- }, []);
24
+ return prepareScatterSeries({ series: series, legend, colorScale });
46
25
  }
47
26
  case 'line': {
48
27
  return prepareLineSeries({
@@ -10,7 +10,7 @@ export type PathLegendSymbol = {
10
10
  } & Required<PathLegendSymbolOptions>;
11
11
  export type SymbolLegendSymbol = {
12
12
  shape: 'symbol';
13
- symbolType: SymbolType;
13
+ symbolType: `${SymbolType}`;
14
14
  } & Required<SymbolLegendSymbolOptions>;
15
15
  export type PreparedLegendSymbol = RectLegendSymbol | PathLegendSymbol | SymbolLegendSymbol;
16
16
  export type PreparedLegend = Required<ChartKitWidgetLegend> & {
@@ -57,12 +57,30 @@ type BasePreparedSeries = {
57
57
  export type PreparedScatterSeries = {
58
58
  type: ScatterSeries['type'];
59
59
  data: ScatterSeriesData[];
60
- symbolType: SymbolType;
60
+ marker: {
61
+ states: {
62
+ normal: {
63
+ symbol: `${SymbolType}`;
64
+ enabled: boolean;
65
+ radius: number;
66
+ borderWidth: number;
67
+ borderColor: string;
68
+ };
69
+ hover: {
70
+ enabled: boolean;
71
+ radius: number;
72
+ borderWidth: number;
73
+ borderColor: string;
74
+ halo: PreparedHaloOptions;
75
+ };
76
+ };
77
+ };
61
78
  } & BasePreparedSeries;
62
79
  export type PreparedBarXSeries = {
63
80
  type: BarXSeries['type'];
64
81
  data: BarXSeriesData[];
65
82
  stackId: string;
83
+ stacking: BarXSeries['stacking'];
66
84
  dataLabels: {
67
85
  enabled: boolean;
68
86
  inside: boolean;
@@ -75,6 +93,7 @@ export type PreparedBarYSeries = {
75
93
  type: BarYSeries['type'];
76
94
  data: BarYSeriesData[];
77
95
  stackId: string;
96
+ stacking: BarYSeries['stacking'];
78
97
  dataLabels: {
79
98
  enabled: boolean;
80
99
  inside: boolean;
@@ -110,6 +129,7 @@ export type PreparedPieSeries = {
110
129
  halo: PreparedHaloOptions;
111
130
  };
112
131
  };
132
+ renderCustomShape?: PieSeries['renderCustomShape'];
113
133
  } & BasePreparedSeries;
114
134
  export type PreparedLineSeries = {
115
135
  type: LineSeries['type'];
@@ -124,7 +144,7 @@ export type PreparedLineSeries = {
124
144
  marker: {
125
145
  states: {
126
146
  normal: {
127
- symbol: string;
147
+ symbol: `${SymbolType}`;
128
148
  enabled: boolean;
129
149
  radius: number;
130
150
  borderWidth: number;
@@ -158,7 +178,7 @@ export type PreparedAreaSeries = {
158
178
  marker: {
159
179
  states: {
160
180
  normal: {
161
- symbol: string;
181
+ symbol: `${SymbolType}`;
162
182
  enabled: boolean;
163
183
  radius: number;
164
184
  borderWidth: number;
@@ -3,5 +3,5 @@ import { ChartKitWidgetSeries } from '../../../../../types';
3
3
  import { SymbolType } from '../../../../../constants';
4
4
  export declare const getActiveLegendItems: (series: PreparedSeries[]) => string[];
5
5
  export declare const getAllLegendItems: (series: PreparedSeries[]) => string[];
6
- export declare function prepareLegendSymbol(series: ChartKitWidgetSeries, symbolType?: SymbolType): PreparedLegendSymbol;
6
+ export declare function prepareLegendSymbol(series: ChartKitWidgetSeries, symbolType?: `${SymbolType}`): PreparedLegendSymbol;
7
7
  export declare function getSeriesStackId(series: StackedSeries): string;
@@ -27,7 +27,7 @@ const getCommonStackId = memoize(getRandomCKId);
27
27
  export function getSeriesStackId(series) {
28
28
  let stackId = series.stackId;
29
29
  if (!stackId) {
30
- stackId = series.stacking === 'normal' ? getCommonStackId() : getRandomCKId();
30
+ stackId = series.stacking ? getCommonStackId() : getRandomCKId();
31
31
  }
32
32
  return stackId;
33
33
  }