@gravity-ui/chartkit 4.13.0 → 4.14.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 (51) hide show
  1. package/build/i18n/keysets/en.json +6 -1
  2. package/build/i18n/keysets/ru.json +6 -1
  3. package/build/libs/chartkit-error/chartkit-error.d.ts +1 -0
  4. package/build/libs/chartkit-error/chartkit-error.js +1 -0
  5. package/build/plugins/d3/examples/area/Basic.d.ts +2 -0
  6. package/build/plugins/d3/examples/area/Basic.js +35 -0
  7. package/build/plugins/d3/examples/area/StackedArea.d.ts +2 -0
  8. package/build/plugins/d3/examples/area/StackedArea.js +48 -0
  9. package/build/plugins/d3/examples/bar-x/Basic.js +11 -5
  10. package/build/plugins/d3/renderer/D3Widget.js +27 -23
  11. package/build/plugins/d3/renderer/components/Tooltip/DefaultContent.js +1 -0
  12. package/build/plugins/d3/renderer/components/Tooltip/TooltipTriggerArea.js +1 -1
  13. package/build/plugins/d3/renderer/constants/defaults/axis.d.ts +2 -0
  14. package/build/plugins/d3/renderer/constants/defaults/axis.js +1 -0
  15. package/build/plugins/d3/renderer/constants/defaults/series-options.js +16 -4
  16. package/build/plugins/d3/renderer/hooks/useAxisScales/index.js +3 -2
  17. package/build/plugins/d3/renderer/hooks/useChartOptions/y-axis.js +2 -1
  18. package/build/plugins/d3/renderer/hooks/useSeries/constants.d.ts +3 -1
  19. package/build/plugins/d3/renderer/hooks/useSeries/constants.js +5 -0
  20. package/build/plugins/d3/renderer/hooks/useSeries/prepare-area.d.ts +19 -0
  21. package/build/plugins/d3/renderer/hooks/useSeries/prepare-area.js +66 -0
  22. package/build/plugins/d3/renderer/hooks/useSeries/prepare-bar-x.js +2 -7
  23. package/build/plugins/d3/renderer/hooks/useSeries/prepare-bar-y.js +2 -7
  24. package/build/plugins/d3/renderer/hooks/useSeries/prepare-line-series.js +2 -6
  25. package/build/plugins/d3/renderer/hooks/useSeries/prepareSeries.js +9 -0
  26. package/build/plugins/d3/renderer/hooks/useSeries/types.d.ts +39 -2
  27. package/build/plugins/d3/renderer/hooks/useSeries/utils.d.ts +2 -1
  28. package/build/plugins/d3/renderer/hooks/useSeries/utils.js +10 -0
  29. package/build/plugins/d3/renderer/hooks/useShapes/area/index.d.ts +11 -0
  30. package/build/plugins/d3/renderer/hooks/useShapes/area/index.js +194 -0
  31. package/build/plugins/d3/renderer/hooks/useShapes/area/prepare-data.d.ts +11 -0
  32. package/build/plugins/d3/renderer/hooks/useShapes/area/prepare-data.js +114 -0
  33. package/build/plugins/d3/renderer/hooks/useShapes/area/types.d.ts +27 -0
  34. package/build/plugins/d3/renderer/hooks/useShapes/area/types.js +1 -0
  35. package/build/plugins/d3/renderer/hooks/useShapes/index.d.ts +2 -1
  36. package/build/plugins/d3/renderer/hooks/useShapes/index.js +16 -0
  37. package/build/plugins/d3/renderer/utils/index.d.ts +1 -1
  38. package/build/plugins/d3/renderer/utils/index.js +16 -9
  39. package/build/plugins/d3/renderer/validation/__mocks__/index.d.ts +3 -0
  40. package/build/plugins/d3/renderer/validation/__mocks__/index.js +44 -0
  41. package/build/plugins/d3/renderer/validation/index.d.ts +2 -0
  42. package/build/plugins/d3/renderer/validation/index.js +145 -0
  43. package/build/types/widget-data/area.d.ts +57 -0
  44. package/build/types/widget-data/area.js +1 -0
  45. package/build/types/widget-data/index.d.ts +1 -0
  46. package/build/types/widget-data/index.js +1 -0
  47. package/build/types/widget-data/line.d.ts +3 -3
  48. package/build/types/widget-data/marker.d.ts +8 -0
  49. package/build/types/widget-data/series.d.ts +24 -8
  50. package/build/types/widget-data/tooltip.d.ts +10 -1
  51. package/package.json +2 -2
@@ -28,7 +28,12 @@
28
28
  "error": {
29
29
  "label_no-data": "No data",
30
30
  "label_unknown-plugin": "Unknown plugin type \"{{type}}\"",
31
- "label_unknown-error": "Unknown error"
31
+ "label_unknown-error": "Unknown error",
32
+ "label_invalid-axis-category-data-point": "It seems you are trying to use inappropriate data type for \"{{key}}\" value in series \"{{seriesName}}\" for axis with type \"category\". Strings and numbers are allowed.",
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
+ "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
+ "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}}]."
32
37
  },
33
38
  "highcharts": {
34
39
  "reset-zoom-title": "Reset zoom",
@@ -30,7 +30,12 @@
30
30
  "error": {
31
31
  "label_no-data": "Нет данных",
32
32
  "label_unknown-plugin": "Неизвестный тип плагина \"{{type}}\"",
33
- "label_unknown-error": "Неизвестная ошибка"
33
+ "label_unknown-error": "Неизвестная ошибка",
34
+ "label_invalid-axis-category-data-point": "Похоже, что вы пытаетесь использовать недопустимый тип данных для значения \"{{key}}\" в серии \"{{seriesName}}\" для оси с типом \"category\". Допускается использование строк и чисел.",
35
+ "label_invalid-axis-datetime-data-point": "Похоже, что вы пытаетесь использовать недопустимый тип данных для значения \"{{key}}\" в серии \"{{seriesName}}\" для оси с типом \"datetime\". Допускается только использование чисел.",
36
+ "label_invalid-axis-linear-data-point": "Похоже, что вы пытаетесь использовать недопустимый тип данных для значения \"{{key}}\" в серии \"{{seriesName}}\" для оси с типом \"linear\". Допускается использование чисел и значений null.",
37
+ "label_invalid-pie-data-value": "Похоже, что вы пытаетесь использовать недопустимый тип данных для значения \"value\". Допускается только использование чисел.",
38
+ "label_invalid-series-type": "Похоже, что вы не указали значение \"series.type\" или указали его неверно. Доступные значения: [{{types}}]."
34
39
  },
35
40
  "highcharts": {
36
41
  "reset-zoom-title": "Сбросить увеличение",
@@ -5,6 +5,7 @@ export type ChartKitErrorArgs = {
5
5
  };
6
6
  export declare const CHARTKIT_ERROR_CODE: {
7
7
  NO_DATA: string;
8
+ INVALID_DATA: string;
8
9
  UNKNOWN: string;
9
10
  UNKNOWN_PLUGIN: string;
10
11
  TOO_MANY_LINES: string;
@@ -1,5 +1,6 @@
1
1
  export const CHARTKIT_ERROR_CODE = {
2
2
  NO_DATA: 'ERR.CK.NO_DATA',
3
+ INVALID_DATA: 'ERR.CK.INVALID_DATA',
3
4
  UNKNOWN: 'ERR.CK.UNKNOWN_ERROR',
4
5
  UNKNOWN_PLUGIN: 'ERR.CK.UNKNOWN_PLUGIN',
5
6
  TOO_MANY_LINES: 'ERR.CK.TOO_MANY_LINES',
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const Basic: () => React.JSX.Element;
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ import { ChartKit } from '../../../../components/ChartKit';
3
+ import nintendoGames from '../nintendoGames';
4
+ function prepareData() {
5
+ const games = nintendoGames.filter((d) => {
6
+ return d.date && d.user_score && d.genres.includes('Puzzle');
7
+ });
8
+ return [
9
+ {
10
+ name: 'User score',
11
+ type: 'area',
12
+ data: games.map((d) => {
13
+ return {
14
+ x: Number(d.date),
15
+ y: Number(d.user_score),
16
+ };
17
+ }),
18
+ },
19
+ ];
20
+ }
21
+ export const Basic = () => {
22
+ const series = prepareData();
23
+ const widgetData = {
24
+ title: {
25
+ text: 'User score (puzzle genre)',
26
+ },
27
+ series: {
28
+ data: series,
29
+ },
30
+ xAxis: {
31
+ type: 'datetime',
32
+ },
33
+ };
34
+ return React.createElement(ChartKit, { type: "d3", data: widgetData });
35
+ };
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const StackedArea: () => React.JSX.Element;
@@ -0,0 +1,48 @@
1
+ import { groups } from 'd3';
2
+ import React from 'react';
3
+ import { ChartKit } from '../../../../components/ChartKit';
4
+ import nintendoGames from '../nintendoGames';
5
+ const years = Array.from(new Set(nintendoGames.map((d) => d.date ? String(new Date(d.date).getFullYear()) : 'unknown'))).sort();
6
+ function prepareData() {
7
+ const grouped = groups(nintendoGames, (d) => d.platform, (d) => (d.date ? String(new Date(d.date).getFullYear()) : 'unknown'));
8
+ const series = grouped.map(([platform, gamesByYear]) => {
9
+ const platformGames = Object.fromEntries(gamesByYear) || {};
10
+ return {
11
+ name: platform,
12
+ data: years.reduce((acc, year) => {
13
+ if (year in platformGames) {
14
+ acc.push({
15
+ x: year,
16
+ y: platformGames[year].length,
17
+ });
18
+ }
19
+ return acc;
20
+ }, []),
21
+ };
22
+ });
23
+ return { series };
24
+ }
25
+ export const StackedArea = () => {
26
+ const { series } = prepareData();
27
+ const data = series.map((s) => {
28
+ return {
29
+ type: 'area',
30
+ stacking: 'normal',
31
+ name: s.name,
32
+ data: s.data,
33
+ };
34
+ });
35
+ const widgetData = {
36
+ series: {
37
+ data: data,
38
+ },
39
+ xAxis: {
40
+ type: 'category',
41
+ categories: years,
42
+ title: {
43
+ text: 'Release year',
44
+ },
45
+ },
46
+ };
47
+ return React.createElement(ChartKit, { type: "d3", data: widgetData });
48
+ };
@@ -2,14 +2,20 @@ import React from 'react';
2
2
  import { ChartKit } from '../../../../components/ChartKit';
3
3
  import nintendoGames from '../nintendoGames';
4
4
  import { groups } from 'd3';
5
- function prepareData(field = 'platform') {
5
+ function prepareData({ field, filterNulls } = {
6
+ field: 'platform',
7
+ }) {
6
8
  const gamesByPlatform = groups(nintendoGames, (item) => item[field]);
7
- const data = gamesByPlatform.map(([value, games]) => ({
9
+ let resultData = gamesByPlatform;
10
+ if (filterNulls) {
11
+ resultData = gamesByPlatform.filter(([value]) => typeof value === 'number');
12
+ }
13
+ const data = resultData.map(([value, games]) => ({
8
14
  x: value,
9
15
  y: games.length,
10
16
  }));
11
17
  return {
12
- categories: gamesByPlatform.map(([key]) => key),
18
+ categories: resultData.map(([key]) => key),
13
19
  series: [
14
20
  {
15
21
  data,
@@ -40,7 +46,7 @@ export const BasicBarXChart = () => {
40
46
  return React.createElement(ChartKit, { type: "d3", data: widgetData });
41
47
  };
42
48
  export const BasicLinearBarXChart = () => {
43
- const { series } = prepareData('meta_score');
49
+ const { series } = prepareData({ field: 'meta_score' });
44
50
  const widgetData = {
45
51
  series: {
46
52
  data: series.map((s) => ({
@@ -58,7 +64,7 @@ export const BasicLinearBarXChart = () => {
58
64
  return React.createElement(ChartKit, { type: "d3", data: widgetData });
59
65
  };
60
66
  export const BasicDateTimeBarXChart = () => {
61
- const { series } = prepareData('date');
67
+ const { series } = prepareData({ field: 'date', filterNulls: true });
62
68
  const widgetData = {
63
69
  series: {
64
70
  data: series.map((s) => ({
@@ -4,35 +4,13 @@ import debounce from 'lodash/debounce';
4
4
  import afterFrame from 'afterframe';
5
5
  import { getRandomCKId, measurePerformance } from '../../../utils';
6
6
  import { Chart } from './components';
7
+ import { validateData } from './validation';
7
8
  const D3Widget = React.forwardRef(function D3Widget(props, forwardedRef) {
8
9
  const { data, onLoad, onRender, onChartLoad } = props;
9
10
  const ref = React.useRef(null);
10
11
  const debounced = React.useRef();
11
12
  const [dimensions, setDimensions] = React.useState();
12
13
  const performanceMeasure = React.useRef(measurePerformance());
13
- React.useLayoutEffect(() => {
14
- if (onChartLoad) {
15
- onChartLoad({});
16
- }
17
- }, [onChartLoad]);
18
- React.useLayoutEffect(() => {
19
- if (dimensions === null || dimensions === void 0 ? void 0 : dimensions.width) {
20
- if (!performanceMeasure.current) {
21
- performanceMeasure.current = measurePerformance();
22
- }
23
- afterFrame(() => {
24
- var _a;
25
- const renderTime = (_a = performanceMeasure.current) === null || _a === void 0 ? void 0 : _a.end();
26
- onRender === null || onRender === void 0 ? void 0 : onRender({
27
- renderTime,
28
- });
29
- onLoad === null || onLoad === void 0 ? void 0 : onLoad({
30
- widgetRendering: renderTime,
31
- });
32
- performanceMeasure.current = null;
33
- });
34
- }
35
- }, [data, onRender, onLoad, dimensions]);
36
14
  const handleResize = React.useCallback(() => {
37
15
  var _a;
38
16
  const parentElement = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.parentElement;
@@ -66,6 +44,32 @@ const D3Widget = React.forwardRef(function D3Widget(props, forwardedRef) {
66
44
  // dimensions initialize
67
45
  handleResize();
68
46
  }, [handleResize]);
47
+ React.useEffect(() => {
48
+ validateData(data);
49
+ }, [data]);
50
+ React.useLayoutEffect(() => {
51
+ if (onChartLoad) {
52
+ onChartLoad({});
53
+ }
54
+ }, [onChartLoad]);
55
+ React.useLayoutEffect(() => {
56
+ if (dimensions === null || dimensions === void 0 ? void 0 : dimensions.width) {
57
+ if (!performanceMeasure.current) {
58
+ performanceMeasure.current = measurePerformance();
59
+ }
60
+ afterFrame(() => {
61
+ var _a;
62
+ const renderTime = (_a = performanceMeasure.current) === null || _a === void 0 ? void 0 : _a.end();
63
+ onRender === null || onRender === void 0 ? void 0 : onRender({
64
+ renderTime,
65
+ });
66
+ onLoad === null || onLoad === void 0 ? void 0 : onLoad({
67
+ widgetRendering: renderTime,
68
+ });
69
+ performanceMeasure.current = null;
70
+ });
71
+ }
72
+ }, [data, onRender, onLoad, dimensions]);
69
73
  return (React.createElement("div", { ref: ref, style: {
70
74
  width: (dimensions === null || dimensions === void 0 ? void 0 : dimensions.width) || '100%',
71
75
  height: (dimensions === null || dimensions === void 0 ? void 0 : dimensions.height) || '100%',
@@ -32,6 +32,7 @@ export const DefaultContent = ({ hovered, xAxis, yAxis }) => {
32
32
  switch (series.type) {
33
33
  case 'scatter':
34
34
  case 'line':
35
+ case 'area':
35
36
  case 'bar-x': {
36
37
  const xRow = getXRowData(xAxis, data);
37
38
  const yRow = getYRowData(yAxis, data);
@@ -72,7 +72,7 @@ export const TooltipTriggerArea = (args) => {
72
72
  }, [shapesData]);
73
73
  const xLineData = React.useMemo(() => {
74
74
  const result = shapesData
75
- .filter((sd) => sd.series.type === 'line')
75
+ .filter((sd) => ['line', 'area'].includes(sd.series.type))
76
76
  .reduce((acc, sd) => {
77
77
  return acc.concat(sd.points.map((d) => ({
78
78
  x: d.x,
@@ -1,3 +1,4 @@
1
+ import { ChartKitWidgetAxisType } from '../../../../../types';
1
2
  export declare const axisLabelsDefaults: {
2
3
  margin: number;
3
4
  padding: number;
@@ -12,3 +13,4 @@ export declare const yAxisTitleDefaults: {
12
13
  margin: number;
13
14
  fontSize: string;
14
15
  };
16
+ export declare const DEFAULT_AXIS_TYPE: ChartKitWidgetAxisType;
@@ -9,3 +9,4 @@ const axisTitleDefaults = {
9
9
  };
10
10
  export const xAxisTitleDefaults = Object.assign(Object.assign({}, axisTitleDefaults), { margin: 4 });
11
11
  export const yAxisTitleDefaults = Object.assign(Object.assign({}, axisTitleDefaults), { margin: 8 });
12
+ export const DEFAULT_AXIS_TYPE = 'linear';
@@ -9,7 +9,7 @@ export const seriesOptionsDefaults = {
9
9
  brightness: 0.3,
10
10
  },
11
11
  inactive: {
12
- enabled: true,
12
+ enabled: false,
13
13
  opacity: 0.5,
14
14
  },
15
15
  },
@@ -24,7 +24,7 @@ export const seriesOptionsDefaults = {
24
24
  brightness: 0.3,
25
25
  },
26
26
  inactive: {
27
- enabled: true,
27
+ enabled: false,
28
28
  opacity: 0.5,
29
29
  },
30
30
  },
@@ -36,7 +36,7 @@ export const seriesOptionsDefaults = {
36
36
  brightness: 0.3,
37
37
  },
38
38
  inactive: {
39
- enabled: true,
39
+ enabled: false,
40
40
  opacity: 0.5,
41
41
  },
42
42
  },
@@ -48,7 +48,7 @@ export const seriesOptionsDefaults = {
48
48
  brightness: 0.3,
49
49
  },
50
50
  inactive: {
51
- enabled: true,
51
+ enabled: false,
52
52
  opacity: 0.5,
53
53
  },
54
54
  },
@@ -60,7 +60,19 @@ export const seriesOptionsDefaults = {
60
60
  brightness: 0.3,
61
61
  },
62
62
  inactive: {
63
+ enabled: false,
64
+ opacity: 0.5,
65
+ },
66
+ },
67
+ },
68
+ area: {
69
+ states: {
70
+ hover: {
63
71
  enabled: true,
72
+ brightness: 0.3,
73
+ },
74
+ inactive: {
75
+ enabled: false,
64
76
  opacity: 0.5,
65
77
  },
66
78
  },
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { scaleBand, scaleLinear, scaleUtc, extent } from 'd3';
3
3
  import get from 'lodash/get';
4
4
  import { getOnlyVisibleSeries, getDataCategoryValue, getDomainDataYBySeries, getDomainDataXBySeries, isAxisRelatedSeries, isSeriesWithCategoryValues, } from '../../utils';
5
+ import { DEFAULT_AXIS_TYPE } from '../../constants';
5
6
  const isNumericalArrayData = (data) => {
6
7
  return data.every((d) => typeof d === 'number' || d === null);
7
8
  };
@@ -18,7 +19,7 @@ const filterCategoriesByVisibleSeries = (args) => {
18
19
  return categories.filter((c) => visibleCategories.has(c));
19
20
  };
20
21
  export function createYScale(axis, series, boundsHeight) {
21
- const yType = get(axis, 'type', 'linear');
22
+ const yType = get(axis, 'type', DEFAULT_AXIS_TYPE);
22
23
  const yMin = get(axis, 'min');
23
24
  const yCategories = get(axis, 'categories');
24
25
  const yTimestamps = get(axis, 'timestamps');
@@ -78,7 +79,7 @@ function calculateXAxisPadding(series) {
78
79
  }
79
80
  export function createXScale(axis, series, boundsWidth) {
80
81
  const xMin = get(axis, 'min');
81
- const xType = get(axis, 'type', 'linear');
82
+ const xType = get(axis, 'type', DEFAULT_AXIS_TYPE);
82
83
  const xCategories = get(axis, 'categories');
83
84
  const xTimestamps = get(axis, 'timestamps');
84
85
  const maxPadding = get(axis, 'maxPadding', 0);
@@ -24,7 +24,8 @@ const getAxisLabelMaxWidth = (args) => {
24
24
  };
25
25
  function getAxisMin(axis, series) {
26
26
  const min = axis === null || axis === void 0 ? void 0 : axis.min;
27
- if (typeof min === 'undefined' && (series === null || series === void 0 ? void 0 : series.some((s) => s.type === 'bar-x'))) {
27
+ const seriesWithVolume = ['bar-x', 'area'];
28
+ if (typeof min === 'undefined' && (series === null || series === void 0 ? void 0 : series.some((s) => seriesWithVolume.includes(s.type)))) {
28
29
  return 0;
29
30
  }
30
31
  return min;
@@ -1,5 +1,7 @@
1
- import { BaseTextStyle } from '../../../../../types';
1
+ import type { BaseTextStyle } from '../../../../../types';
2
+ import type { PointMarkerHalo } 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;
7
+ export declare const DEFAULT_HALO_OPTIONS: Required<PointMarkerHalo>;
@@ -6,3 +6,8 @@ export const DEFAULT_DATALABELS_STYLE = {
6
6
  fontWeight: 'bold',
7
7
  fontColor: 'var(--d3-data-labels)',
8
8
  };
9
+ export const DEFAULT_HALO_OPTIONS = {
10
+ enabled: true,
11
+ opacity: 0.25,
12
+ radius: 10,
13
+ };
@@ -0,0 +1,19 @@
1
+ import { ScaleOrdinal } from 'd3';
2
+ import { ChartKitWidgetSeriesOptions, AreaSeries } from '../../../../../types';
3
+ import { PreparedAreaSeries, PreparedLegend } from './types';
4
+ export declare const DEFAULT_LINE_WIDTH = 1;
5
+ export declare const DEFAULT_MARKER: {
6
+ enabled: boolean;
7
+ symbol: string;
8
+ radius: number;
9
+ borderWidth: number;
10
+ borderColor: string;
11
+ };
12
+ type PrepareAreaSeriesArgs = {
13
+ colorScale: ScaleOrdinal<string, string>;
14
+ series: AreaSeries[];
15
+ seriesOptions?: ChartKitWidgetSeriesOptions;
16
+ legend: PreparedLegend;
17
+ };
18
+ export declare function prepareArea(args: PrepareAreaSeriesArgs): PreparedAreaSeries[];
19
+ export {};
@@ -0,0 +1,66 @@
1
+ import get from 'lodash/get';
2
+ import merge from 'lodash/merge';
3
+ import { DEFAULT_DATALABELS_PADDING, DEFAULT_DATALABELS_STYLE, DEFAULT_HALO_OPTIONS, } from './constants';
4
+ import { getRandomCKId } from '../../../../../utils';
5
+ import { getSeriesStackId, prepareLegendSymbol } from './utils';
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
+ };
14
+ function prepareMarker(series, seriesOptions) {
15
+ var _a;
16
+ const seriesHoverState = get(seriesOptions, 'area.states.hover');
17
+ const markerNormalState = Object.assign({}, DEFAULT_MARKER, (_a = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions.area) === null || _a === void 0 ? void 0 : _a.marker, series.marker);
18
+ const hoveredMarkerDefaultOptions = {
19
+ enabled: true,
20
+ radius: markerNormalState.radius,
21
+ borderWidth: 1,
22
+ borderColor: '#ffffff',
23
+ halo: DEFAULT_HALO_OPTIONS,
24
+ };
25
+ return {
26
+ states: {
27
+ normal: markerNormalState,
28
+ hover: merge(hoveredMarkerDefaultOptions, seriesHoverState === null || seriesHoverState === void 0 ? void 0 : seriesHoverState.marker),
29
+ },
30
+ };
31
+ }
32
+ export function prepareArea(args) {
33
+ const { colorScale, series: seriesList, seriesOptions, legend } = args;
34
+ const defaultAreaWidth = get(seriesOptions, 'area.lineWidth', DEFAULT_LINE_WIDTH);
35
+ const defaultOpacity = get(seriesOptions, 'area.opacity', 0.75);
36
+ return seriesList.map((series) => {
37
+ var _a, _b;
38
+ const id = getRandomCKId();
39
+ const name = series.name || '';
40
+ const color = series.color || colorScale(name);
41
+ const prepared = {
42
+ type: series.type,
43
+ color,
44
+ opacity: get(series, 'opacity', defaultOpacity),
45
+ lineWidth: get(series, 'lineWidth', defaultAreaWidth),
46
+ name,
47
+ id,
48
+ visible: get(series, 'visible', true),
49
+ legend: {
50
+ enabled: get(series, 'legend.enabled', legend.enabled),
51
+ symbol: prepareLegendSymbol(series),
52
+ },
53
+ data: series.data,
54
+ stacking: series.stacking,
55
+ stackId: getSeriesStackId(series),
56
+ dataLabels: {
57
+ enabled: ((_a = series.dataLabels) === null || _a === void 0 ? void 0 : _a.enabled) || false,
58
+ style: Object.assign({}, DEFAULT_DATALABELS_STYLE, (_b = series.dataLabels) === null || _b === void 0 ? void 0 : _b.style),
59
+ padding: get(series, 'dataLabels.padding', DEFAULT_DATALABELS_PADDING),
60
+ allowOverlap: get(series, 'dataLabels.allowOverlap', false),
61
+ },
62
+ marker: prepareMarker(series, seriesOptions),
63
+ };
64
+ return prepared;
65
+ }, []);
66
+ }
@@ -1,18 +1,13 @@
1
1
  import get from 'lodash/get';
2
2
  import { getRandomCKId } from '../../../../../utils';
3
- import { prepareLegendSymbol } from './utils';
3
+ import { getSeriesStackId, prepareLegendSymbol } from './utils';
4
4
  import { DEFAULT_DATALABELS_PADDING, DEFAULT_DATALABELS_STYLE } from './constants';
5
5
  export function prepareBarXSeries(args) {
6
6
  const { colorScale, series: seriesList, legend } = args;
7
- const commonStackId = getRandomCKId();
8
7
  return seriesList.map((series) => {
9
8
  var _a, _b, _c, _d, _e;
10
9
  const name = series.name || '';
11
10
  const color = series.color || colorScale(name);
12
- let stackId = series.stackId;
13
- if (!stackId) {
14
- stackId = series.stacking === 'normal' ? commonStackId : getRandomCKId();
15
- }
16
11
  return {
17
12
  type: series.type,
18
13
  color,
@@ -25,7 +20,7 @@ export function prepareBarXSeries(args) {
25
20
  },
26
21
  data: series.data,
27
22
  stacking: series.stacking,
28
- stackId,
23
+ stackId: getSeriesStackId(series),
29
24
  dataLabels: {
30
25
  enabled: ((_a = series.dataLabels) === null || _a === void 0 ? void 0 : _a.enabled) || false,
31
26
  inside: typeof ((_b = series.dataLabels) === null || _b === void 0 ? void 0 : _b.inside) === 'boolean'
@@ -1,6 +1,6 @@
1
1
  import get from 'lodash/get';
2
2
  import { getRandomCKId } from '../../../../../utils';
3
- import { prepareLegendSymbol } from './utils';
3
+ import { getSeriesStackId, prepareLegendSymbol } from './utils';
4
4
  import { DEFAULT_DATALABELS_STYLE } from './constants';
5
5
  import { getLabelsSize } from '../../utils';
6
6
  function prepareDataLabels(series) {
@@ -23,14 +23,9 @@ function prepareDataLabels(series) {
23
23
  }
24
24
  export function prepareBarYSeries(args) {
25
25
  const { colorScale, series: seriesList, legend } = args;
26
- const commonStackId = getRandomCKId();
27
26
  return seriesList.map((series) => {
28
27
  const name = series.name || '';
29
28
  const color = series.color || colorScale(name);
30
- let stackId = series.stackId;
31
- if (!stackId) {
32
- stackId = series.stacking === 'normal' ? commonStackId : getRandomCKId();
33
- }
34
29
  return {
35
30
  type: series.type,
36
31
  color,
@@ -43,7 +38,7 @@ export function prepareBarYSeries(args) {
43
38
  },
44
39
  data: series.data,
45
40
  stacking: series.stacking,
46
- stackId,
41
+ stackId: getSeriesStackId(series),
47
42
  dataLabels: prepareDataLabels(series),
48
43
  };
49
44
  }, []);
@@ -1,6 +1,6 @@
1
1
  import get from 'lodash/get';
2
2
  import merge from 'lodash/merge';
3
- import { DEFAULT_DATALABELS_PADDING, DEFAULT_DATALABELS_STYLE, DEFAULT_LEGEND_SYMBOL_PADDING, } from './constants';
3
+ import { DEFAULT_DATALABELS_PADDING, DEFAULT_DATALABELS_STYLE, DEFAULT_HALO_OPTIONS, DEFAULT_LEGEND_SYMBOL_PADDING, } from './constants';
4
4
  import { getRandomCKId } from '../../../../../utils';
5
5
  export const DEFAULT_LEGEND_SYMBOL_SIZE = 16;
6
6
  export const DEFAULT_LINE_WIDTH = 1;
@@ -31,11 +31,7 @@ function prepareMarker(series, seriesOptions) {
31
31
  radius: markerNormalState.radius,
32
32
  borderWidth: 1,
33
33
  borderColor: '#ffffff',
34
- halo: {
35
- enabled: true,
36
- opacity: 0.25,
37
- radius: 10,
38
- },
34
+ halo: DEFAULT_HALO_OPTIONS,
39
35
  };
40
36
  return {
41
37
  states: {
@@ -6,6 +6,7 @@ import { prepareBarYSeries } from './prepare-bar-y';
6
6
  import { prepareLegendSymbol } from './utils';
7
7
  import { ChartKitError } from '../../../../../libs';
8
8
  import { preparePieSeries } from './prepare-pie';
9
+ import { prepareArea } from './prepare-area';
9
10
  function prepareAxisRelatedSeries(args) {
10
11
  const { colorScale, series, legend } = args;
11
12
  const preparedSeries = cloneDeep(series);
@@ -48,6 +49,14 @@ export function prepareSeries(args) {
48
49
  colorScale,
49
50
  });
50
51
  }
52
+ case 'area': {
53
+ return prepareArea({
54
+ series: series,
55
+ seriesOptions,
56
+ legend,
57
+ colorScale,
58
+ });
59
+ }
51
60
  default: {
52
61
  throw new ChartKitError({
53
62
  message: `Series type "${type}" does not support data preparation for series that do not support the presence of axes`,
@@ -1,4 +1,4 @@
1
- import { BarXSeries, BarXSeriesData, BaseTextStyle, ChartKitWidgetLegend, PieSeries, PieSeriesData, RectLegendSymbolOptions, ScatterSeries, ScatterSeriesData, BarYSeries, BarYSeriesData, LineSeries, LineSeriesData, ConnectorShape, ConnectorCurve, PathLegendSymbolOptions } from '../../../../../types';
1
+ import { BarXSeries, BarXSeriesData, BaseTextStyle, ChartKitWidgetLegend, PieSeries, PieSeriesData, RectLegendSymbolOptions, ScatterSeries, ScatterSeriesData, BarYSeries, BarYSeriesData, LineSeries, LineSeriesData, ConnectorShape, ConnectorCurve, PathLegendSymbolOptions, AreaSeries, AreaSeriesData } from '../../../../../types';
2
2
  import type { SeriesOptionsDefaults } from '../../constants';
3
3
  export type RectLegendSymbol = {
4
4
  shape: 'rect';
@@ -127,6 +127,43 @@ export type PreparedLineSeries = {
127
127
  };
128
128
  };
129
129
  } & BasePreparedSeries;
130
- export type PreparedSeries = PreparedScatterSeries | PreparedBarXSeries | PreparedBarYSeries | PreparedPieSeries | PreparedLineSeries;
130
+ export type PreparedAreaSeries = {
131
+ type: AreaSeries['type'];
132
+ data: AreaSeriesData[];
133
+ stacking: AreaSeries['stacking'];
134
+ stackId: string;
135
+ lineWidth: number;
136
+ opacity: number;
137
+ dataLabels: {
138
+ enabled: boolean;
139
+ style: BaseTextStyle;
140
+ padding: number;
141
+ allowOverlap: boolean;
142
+ };
143
+ marker: {
144
+ states: {
145
+ normal: {
146
+ symbol: string;
147
+ enabled: boolean;
148
+ radius: number;
149
+ borderWidth: number;
150
+ borderColor: string;
151
+ };
152
+ hover: {
153
+ enabled: boolean;
154
+ radius: number;
155
+ borderWidth: number;
156
+ borderColor: string;
157
+ halo: {
158
+ enabled: boolean;
159
+ opacity: number;
160
+ radius: number;
161
+ };
162
+ };
163
+ };
164
+ };
165
+ } & BasePreparedSeries;
166
+ export type PreparedSeries = PreparedScatterSeries | PreparedBarXSeries | PreparedBarYSeries | PreparedPieSeries | PreparedLineSeries | PreparedAreaSeries;
131
167
  export type PreparedSeriesOptions = SeriesOptionsDefaults;
168
+ export type StackedSeries = BarXSeries | AreaSeries | BarYSeries;
132
169
  export {};
@@ -1,5 +1,6 @@
1
- import { PreparedLegendSymbol, PreparedSeries } from './types';
1
+ import { PreparedLegendSymbol, PreparedSeries, StackedSeries } from './types';
2
2
  import { ChartKitWidgetSeries } from '../../../../../types';
3
3
  export declare const getActiveLegendItems: (series: PreparedSeries[]) => string[];
4
4
  export declare const getAllLegendItems: (series: PreparedSeries[]) => string[];
5
5
  export declare function prepareLegendSymbol(series: ChartKitWidgetSeries): PreparedLegendSymbol;
6
+ export declare function getSeriesStackId(series: StackedSeries): string;