@gravity-ui/charts 0.9.0 → 0.11.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 (101) hide show
  1. package/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +1 -0
  2. package/dist/cjs/components/Tooltip/ChartTooltipContent.js +2 -2
  3. package/dist/cjs/components/Tooltip/DefaultContent.d.ts +3 -2
  4. package/dist/cjs/components/Tooltip/DefaultContent.js +54 -10
  5. package/dist/cjs/components/Tooltip/index.js +1 -1
  6. package/dist/cjs/constants/defaults/series-options.js +12 -0
  7. package/dist/cjs/constants/index.d.ts +1 -0
  8. package/dist/cjs/constants/index.js +1 -0
  9. package/dist/cjs/hooks/useSeries/prepare-area.js +2 -1
  10. package/dist/cjs/hooks/useSeries/prepare-bar-x.js +2 -1
  11. package/dist/cjs/hooks/useSeries/prepare-bar-y.js +6 -2
  12. package/dist/cjs/hooks/useSeries/prepare-line.js +2 -1
  13. package/dist/cjs/hooks/useSeries/prepare-pie.js +5 -4
  14. package/dist/cjs/hooks/useSeries/prepare-radar.d.ts +16 -0
  15. package/dist/cjs/hooks/useSeries/prepare-radar.js +64 -0
  16. package/dist/cjs/hooks/useSeries/prepare-sankey.js +2 -1
  17. package/dist/cjs/hooks/useSeries/prepare-treemap.js +2 -1
  18. package/dist/cjs/hooks/useSeries/prepare-waterfall.js +2 -1
  19. package/dist/cjs/hooks/useSeries/prepareSeries.js +8 -0
  20. package/dist/cjs/hooks/useSeries/types.d.ts +44 -2
  21. package/dist/cjs/hooks/useShapes/area/prepare-data.js +2 -1
  22. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +2 -1
  23. package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +2 -1
  24. package/dist/cjs/hooks/useShapes/index.d.ts +2 -1
  25. package/dist/cjs/hooks/useShapes/index.js +12 -0
  26. package/dist/cjs/hooks/useShapes/line/prepare-data.js +2 -1
  27. package/dist/cjs/hooks/useShapes/marker.d.ts +3 -2
  28. package/dist/cjs/hooks/useShapes/pie/prepare-data.js +2 -1
  29. package/dist/cjs/hooks/useShapes/radar/index.d.ts +12 -0
  30. package/dist/cjs/hooks/useShapes/radar/index.js +136 -0
  31. package/dist/cjs/hooks/useShapes/radar/prepare-data.d.ts +9 -0
  32. package/dist/cjs/hooks/useShapes/radar/prepare-data.js +156 -0
  33. package/dist/cjs/hooks/useShapes/radar/types.d.ts +58 -0
  34. package/dist/cjs/hooks/useShapes/radar/types.js +1 -0
  35. package/dist/cjs/hooks/useShapes/sankey/prepare-data.js +3 -1
  36. package/dist/cjs/hooks/useShapes/styles.css +4 -0
  37. package/dist/cjs/hooks/useShapes/treemap/prepare-data.js +8 -6
  38. package/dist/cjs/hooks/useShapes/waterfall/prepare-data.js +2 -1
  39. package/dist/cjs/types/chart/base.d.ts +12 -0
  40. package/dist/cjs/types/chart/radar.d.ts +50 -0
  41. package/dist/cjs/types/chart/radar.js +1 -0
  42. package/dist/cjs/types/chart/series.d.ts +17 -2
  43. package/dist/cjs/types/chart/tooltip.d.ts +11 -1
  44. package/dist/cjs/types/index.d.ts +1 -0
  45. package/dist/cjs/types/index.js +1 -0
  46. package/dist/cjs/utils/chart/axis-generators/bottom.js +4 -3
  47. package/dist/cjs/utils/chart/format.d.ts +5 -0
  48. package/dist/cjs/utils/chart/format.js +17 -0
  49. package/dist/cjs/utils/chart/get-closest-data.js +39 -2
  50. package/dist/cjs/utils/chart/index.js +1 -1
  51. package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +1 -0
  52. package/dist/esm/components/Tooltip/ChartTooltipContent.js +2 -2
  53. package/dist/esm/components/Tooltip/DefaultContent.d.ts +3 -2
  54. package/dist/esm/components/Tooltip/DefaultContent.js +54 -10
  55. package/dist/esm/components/Tooltip/index.js +1 -1
  56. package/dist/esm/constants/defaults/series-options.js +12 -0
  57. package/dist/esm/constants/index.d.ts +1 -0
  58. package/dist/esm/constants/index.js +1 -0
  59. package/dist/esm/hooks/useSeries/prepare-area.js +2 -1
  60. package/dist/esm/hooks/useSeries/prepare-bar-x.js +2 -1
  61. package/dist/esm/hooks/useSeries/prepare-bar-y.js +6 -2
  62. package/dist/esm/hooks/useSeries/prepare-line.js +2 -1
  63. package/dist/esm/hooks/useSeries/prepare-pie.js +5 -4
  64. package/dist/esm/hooks/useSeries/prepare-radar.d.ts +16 -0
  65. package/dist/esm/hooks/useSeries/prepare-radar.js +64 -0
  66. package/dist/esm/hooks/useSeries/prepare-sankey.js +2 -1
  67. package/dist/esm/hooks/useSeries/prepare-treemap.js +2 -1
  68. package/dist/esm/hooks/useSeries/prepare-waterfall.js +2 -1
  69. package/dist/esm/hooks/useSeries/prepareSeries.js +8 -0
  70. package/dist/esm/hooks/useSeries/types.d.ts +44 -2
  71. package/dist/esm/hooks/useShapes/area/prepare-data.js +2 -1
  72. package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +2 -1
  73. package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +2 -1
  74. package/dist/esm/hooks/useShapes/index.d.ts +2 -1
  75. package/dist/esm/hooks/useShapes/index.js +12 -0
  76. package/dist/esm/hooks/useShapes/line/prepare-data.js +2 -1
  77. package/dist/esm/hooks/useShapes/marker.d.ts +3 -2
  78. package/dist/esm/hooks/useShapes/pie/prepare-data.js +2 -1
  79. package/dist/esm/hooks/useShapes/radar/index.d.ts +12 -0
  80. package/dist/esm/hooks/useShapes/radar/index.js +136 -0
  81. package/dist/esm/hooks/useShapes/radar/prepare-data.d.ts +9 -0
  82. package/dist/esm/hooks/useShapes/radar/prepare-data.js +156 -0
  83. package/dist/esm/hooks/useShapes/radar/types.d.ts +58 -0
  84. package/dist/esm/hooks/useShapes/radar/types.js +1 -0
  85. package/dist/esm/hooks/useShapes/sankey/prepare-data.js +3 -1
  86. package/dist/esm/hooks/useShapes/styles.css +4 -0
  87. package/dist/esm/hooks/useShapes/treemap/prepare-data.js +8 -6
  88. package/dist/esm/hooks/useShapes/waterfall/prepare-data.js +2 -1
  89. package/dist/esm/types/chart/base.d.ts +12 -0
  90. package/dist/esm/types/chart/radar.d.ts +50 -0
  91. package/dist/esm/types/chart/radar.js +1 -0
  92. package/dist/esm/types/chart/series.d.ts +17 -2
  93. package/dist/esm/types/chart/tooltip.d.ts +11 -1
  94. package/dist/esm/types/index.d.ts +1 -0
  95. package/dist/esm/types/index.js +1 -0
  96. package/dist/esm/utils/chart/axis-generators/bottom.js +4 -3
  97. package/dist/esm/utils/chart/format.d.ts +5 -0
  98. package/dist/esm/utils/chart/format.js +17 -0
  99. package/dist/esm/utils/chart/get-closest-data.js +39 -2
  100. package/dist/esm/utils/chart/index.js +1 -1
  101. package/package.json +1 -1
@@ -5,5 +5,6 @@ export interface ChartTooltipContentProps {
5
5
  xAxis?: ChartXAxis;
6
6
  yAxis?: ChartYAxis;
7
7
  renderer?: ChartTooltip['renderer'];
8
+ valueFormat?: ChartTooltip['valueFormat'];
8
9
  }
9
10
  export declare const ChartTooltipContent: (props: ChartTooltipContentProps) => React.JSX.Element | null;
@@ -2,10 +2,10 @@ import React from 'react';
2
2
  import isNil from 'lodash/isNil';
3
3
  import { DefaultContent } from './DefaultContent';
4
4
  export const ChartTooltipContent = (props) => {
5
- const { hovered, xAxis, yAxis, renderer } = props;
5
+ const { hovered, xAxis, yAxis, renderer, valueFormat } = props;
6
6
  if (!hovered) {
7
7
  return null;
8
8
  }
9
9
  const customTooltip = renderer === null || renderer === void 0 ? void 0 : renderer({ hovered, xAxis, yAxis });
10
- return isNil(customTooltip) ? (React.createElement(DefaultContent, { hovered: hovered, xAxis: xAxis, yAxis: yAxis })) : (customTooltip);
10
+ return isNil(customTooltip) ? (React.createElement(DefaultContent, { hovered: hovered, xAxis: xAxis, yAxis: yAxis, valueFormat: valueFormat })) : (customTooltip);
11
11
  };
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
- import type { ChartXAxis, ChartYAxis, TooltipDataChunk } from '../../types';
2
+ import type { ChartXAxis, ChartYAxis, TooltipDataChunk, ValueFormat } from '../../types';
3
3
  type Props = {
4
4
  hovered: TooltipDataChunk[];
5
5
  xAxis?: ChartXAxis;
6
6
  yAxis?: ChartYAxis;
7
+ valueFormat?: ValueFormat;
7
8
  };
8
- export declare const DefaultContent: ({ hovered, xAxis, yAxis }: Props) => React.JSX.Element;
9
+ export declare const DefaultContent: ({ hovered, xAxis, yAxis, valueFormat }: Props) => React.JSX.Element;
9
10
  export {};
@@ -3,6 +3,7 @@ import { dateTime } from '@gravity-ui/date-utils';
3
3
  import get from 'lodash/get';
4
4
  import { formatNumber } from '../../libs';
5
5
  import { block, getDataCategoryValue, getWaterfallPointSubtotal } from '../../utils';
6
+ import { getFormattedValue } from '../../utils/chart/format';
6
7
  const b = block('tooltip');
7
8
  const DEFAULT_DATE_FORMAT = 'DD.MM.YY';
8
9
  const getRowData = (fieldName, data, axis) => {
@@ -28,16 +29,19 @@ const getRowData = (fieldName, data, axis) => {
28
29
  const getXRowData = (data, xAxis) => getRowData('x', data, xAxis);
29
30
  const getYRowData = (data, yAxis) => getRowData('y', data, yAxis);
30
31
  const getMeasureValue = (data, xAxis, yAxis) => {
31
- var _a, _b;
32
+ var _a, _b, _c, _d;
32
33
  if (data.every((item) => ['pie', 'treemap', 'waterfall', 'sankey'].includes(item.series.type))) {
33
34
  return null;
34
35
  }
36
+ if (data.some((item) => item.series.type === 'radar')) {
37
+ return (_b = (_a = data[0].category) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : null;
38
+ }
35
39
  if (data.some((item) => item.series.type === 'bar-y')) {
36
- return getYRowData((_a = data[0]) === null || _a === void 0 ? void 0 : _a.data, yAxis);
40
+ return getYRowData((_c = data[0]) === null || _c === void 0 ? void 0 : _c.data, yAxis);
37
41
  }
38
- return getXRowData((_b = data[0]) === null || _b === void 0 ? void 0 : _b.data, xAxis);
42
+ return getXRowData((_d = data[0]) === null || _d === void 0 ? void 0 : _d.data, xAxis);
39
43
  };
40
- export const DefaultContent = ({ hovered, xAxis, yAxis }) => {
44
+ export const DefaultContent = ({ hovered, xAxis, yAxis, valueFormat }) => {
41
45
  const measureValue = getMeasureValue(hovered, xAxis, yAxis);
42
46
  return (React.createElement(React.Fragment, null,
43
47
  measureValue && React.createElement("div", null, measureValue),
@@ -51,17 +55,29 @@ export const DefaultContent = ({ hovered, xAxis, yAxis }) => {
51
55
  case 'line':
52
56
  case 'area':
53
57
  case 'bar-x': {
58
+ const formattedValue = getFormattedValue({
59
+ value: getYRowData(data, yAxis),
60
+ format: valueFormat,
61
+ });
54
62
  const value = (React.createElement(React.Fragment, null,
55
63
  series.name,
56
64
  ": ",
57
- getYRowData(data, yAxis)));
65
+ formattedValue));
58
66
  return (React.createElement("div", { key: id, className: b('content-row') },
59
67
  React.createElement("div", { className: b('color'), style: { backgroundColor: color } }),
60
68
  React.createElement("div", null, closest ? React.createElement("b", null, value) : React.createElement("span", null, value))));
61
69
  }
62
70
  case 'waterfall': {
63
71
  const isTotal = get(data, 'total', false);
64
- const subTotal = getWaterfallPointSubtotal(data, series);
72
+ const subTotalValue = getWaterfallPointSubtotal(data, series);
73
+ const subTotal = getFormattedValue({
74
+ value: subTotalValue,
75
+ format: valueFormat,
76
+ });
77
+ const formattedValue = getFormattedValue({
78
+ value: getYRowData(data, yAxis),
79
+ format: valueFormat,
80
+ });
65
81
  return (React.createElement("div", { key: `${id}_${get(data, 'x')}` },
66
82
  !isTotal && (React.createElement(React.Fragment, null,
67
83
  React.createElement("div", { key: id, className: b('content-row') },
@@ -70,17 +86,21 @@ export const DefaultContent = ({ hovered, xAxis, yAxis }) => {
70
86
  React.createElement("span", null,
71
87
  series.name,
72
88
  "\u00A0"),
73
- React.createElement("span", null, getYRowData(data, yAxis))))),
89
+ React.createElement("span", null, formattedValue)))),
74
90
  React.createElement("div", { key: id, className: b('content-row') },
75
91
  isTotal ? 'Total' : 'Subtotal',
76
92
  ": ",
77
93
  subTotal)));
78
94
  }
79
95
  case 'bar-y': {
96
+ const formattedValue = getFormattedValue({
97
+ value: getXRowData(data, xAxis),
98
+ format: valueFormat,
99
+ });
80
100
  const value = (React.createElement(React.Fragment, null,
81
101
  series.name,
82
102
  ": ",
83
- getXRowData(data, xAxis)));
103
+ formattedValue));
84
104
  return (React.createElement("div", { key: id, className: b('content-row') },
85
105
  React.createElement("div", { className: b('color'), style: { backgroundColor: color } }),
86
106
  React.createElement("div", null, closest ? React.createElement("b", null, value) : React.createElement("span", null, value))));
@@ -88,16 +108,24 @@ export const DefaultContent = ({ hovered, xAxis, yAxis }) => {
88
108
  case 'pie':
89
109
  case 'treemap': {
90
110
  const seriesData = data;
111
+ const formattedValue = getFormattedValue({
112
+ value: seriesData.value,
113
+ format: valueFormat,
114
+ });
91
115
  return (React.createElement("div", { key: id, className: b('content-row') },
92
116
  React.createElement("div", { className: b('color'), style: { backgroundColor: color } }),
93
117
  React.createElement("span", null,
94
118
  seriesData.name || seriesData.id,
95
119
  "\u00A0"),
96
- React.createElement("span", null, seriesData.value)));
120
+ React.createElement("span", null, formattedValue)));
97
121
  }
98
122
  case 'sankey': {
99
123
  const { target, data: source } = seriesItem;
100
124
  const value = (_a = source.links.find((d) => d.name === (target === null || target === void 0 ? void 0 : target.name))) === null || _a === void 0 ? void 0 : _a.value;
125
+ const formattedValue = getFormattedValue({
126
+ value,
127
+ format: valueFormat,
128
+ });
101
129
  return (React.createElement("div", { key: id, className: b('content-row') },
102
130
  React.createElement("div", { className: b('color'), style: { backgroundColor: source.color } }),
103
131
  React.createElement("div", { style: { display: 'flex', gap: 8, verticalAlign: 'center' } },
@@ -107,7 +135,23 @@ export const DefaultContent = ({ hovered, xAxis, yAxis }) => {
107
135
  " ", target === null || target === void 0 ? void 0 :
108
136
  target.name,
109
137
  ": ",
110
- value)));
138
+ formattedValue)));
139
+ }
140
+ case 'radar': {
141
+ const radarSeries = series;
142
+ const seriesData = data;
143
+ const formattedValue = getFormattedValue({
144
+ value: seriesData.value,
145
+ format: valueFormat,
146
+ });
147
+ const value = (React.createElement(React.Fragment, null,
148
+ React.createElement("span", null,
149
+ radarSeries.name || radarSeries.id,
150
+ "\u00A0"),
151
+ React.createElement("span", null, formattedValue)));
152
+ return (React.createElement("div", { key: id, className: b('content-row') },
153
+ React.createElement("div", { className: b('color'), style: { backgroundColor: color } }),
154
+ React.createElement("div", null, closest ? React.createElement("b", null, value) : React.createElement("span", null, value))));
111
155
  }
112
156
  default: {
113
157
  return null;
@@ -23,5 +23,5 @@ export const Tooltip = (props) => {
23
23
  }, [left, top]);
24
24
  return (hovered === null || hovered === void 0 ? void 0 : hovered.length) ? (React.createElement(Popup, { anchorElement: anchor, className: b({ pinned: tooltipPinned }), disableTransition: true, floatingStyles: tooltipPinned ? undefined : { pointerEvents: 'none' }, offset: { mainAxis: 20 }, onOpenChange: tooltipPinned ? handleOnOpenChange : undefined, open: true, placement: ['right', 'left', 'top', 'bottom'] },
25
25
  React.createElement("div", { className: b('content') },
26
- React.createElement(ChartTooltipContent, { hovered: hovered, xAxis: xAxis, yAxis: yAxis, renderer: tooltip.renderer })))) : null;
26
+ React.createElement(ChartTooltipContent, { hovered: hovered, xAxis: xAxis, yAxis: yAxis, renderer: tooltip.renderer, valueFormat: tooltip.valueFormat })))) : null;
27
27
  };
@@ -89,6 +89,18 @@ export const seriesOptionsDefaults = {
89
89
  },
90
90
  },
91
91
  },
92
+ radar: {
93
+ states: {
94
+ hover: {
95
+ enabled: true,
96
+ brightness: 0.3,
97
+ },
98
+ inactive: {
99
+ enabled: true,
100
+ opacity: 0.5,
101
+ },
102
+ },
103
+ },
92
104
  waterfall: {
93
105
  barMaxWidth: 50,
94
106
  barPadding: 0.1,
@@ -10,6 +10,7 @@ export declare const SeriesType: {
10
10
  readonly Treemap: "treemap";
11
11
  readonly Waterfall: "waterfall";
12
12
  readonly Sankey: "sankey";
13
+ readonly Radar: "radar";
13
14
  };
14
15
  export declare enum DashStyle {
15
16
  Dash = "Dash",
@@ -10,6 +10,7 @@ export const SeriesType = {
10
10
  Treemap: 'treemap',
11
11
  Waterfall: 'waterfall',
12
12
  Sankey: 'sankey',
13
+ Radar: 'radar',
13
14
  };
14
15
  export var DashStyle;
15
16
  (function (DashStyle) {
@@ -28,7 +28,7 @@ export function prepareArea(args) {
28
28
  const defaultAreaWidth = get(seriesOptions, 'area.lineWidth', DEFAULT_LINE_WIDTH);
29
29
  const defaultOpacity = get(seriesOptions, 'area.opacity', 0.75);
30
30
  return seriesList.map((series) => {
31
- var _a, _b;
31
+ var _a, _b, _c;
32
32
  const id = getUniqId();
33
33
  const name = series.name || '';
34
34
  const color = series.color || colorScale(name);
@@ -53,6 +53,7 @@ export function prepareArea(args) {
53
53
  padding: get(series, 'dataLabels.padding', DEFAULT_DATALABELS_PADDING),
54
54
  allowOverlap: get(series, 'dataLabels.allowOverlap', false),
55
55
  html: get(series, 'dataLabels.html', false),
56
+ format: (_c = series.dataLabels) === null || _c === void 0 ? void 0 : _c.format,
56
57
  },
57
58
  marker: prepareMarker(series, seriesOptions),
58
59
  cursor: get(series, 'cursor', null),
@@ -5,7 +5,7 @@ import { getSeriesStackId, prepareLegendSymbol } from './utils';
5
5
  export function prepareBarXSeries(args) {
6
6
  const { colorScale, series: seriesList, seriesOptions, legend } = args;
7
7
  return seriesList.map((series) => {
8
- var _a, _b, _c, _d, _e;
8
+ var _a, _b, _c, _d, _e, _f;
9
9
  const name = series.name || '';
10
10
  const color = series.color || colorScale(name);
11
11
  return {
@@ -30,6 +30,7 @@ export function prepareBarXSeries(args) {
30
30
  allowOverlap: ((_e = series.dataLabels) === null || _e === void 0 ? void 0 : _e.allowOverlap) || false,
31
31
  padding: get(series, 'dataLabels.padding', DEFAULT_DATALABELS_PADDING),
32
32
  html: get(series, 'dataLabels.html', false),
33
+ format: (_f = series.dataLabels) === null || _f === void 0 ? void 0 : _f.format,
33
34
  },
34
35
  cursor: get(series, 'cursor', null),
35
36
  yAxis: get(series, 'yAxis', 0),
@@ -1,13 +1,16 @@
1
1
  import get from 'lodash/get';
2
2
  import { getLabelsSize, getUniqId } from '../../utils';
3
+ import { getFormattedValue } from '../../utils/chart/format';
3
4
  import { DEFAULT_DATALABELS_STYLE } from './constants';
4
5
  import { getSeriesStackId, prepareLegendSymbol } from './utils';
5
6
  function prepareDataLabels(series) {
6
- var _a;
7
+ var _a, _b;
7
8
  const enabled = get(series, 'dataLabels.enabled', false);
8
9
  const style = Object.assign({}, DEFAULT_DATALABELS_STYLE, (_a = series.dataLabels) === null || _a === void 0 ? void 0 : _a.style);
9
10
  const html = get(series, 'dataLabels.html', false);
10
- const labels = enabled ? series.data.map((d) => String(d.label || d.x)) : [];
11
+ const labels = enabled
12
+ ? series.data.map((d) => getFormattedValue(Object.assign({ value: d.x || d.label }, series.dataLabels)))
13
+ : [];
11
14
  const { maxHeight = 0, maxWidth = 0 } = getLabelsSize({
12
15
  labels,
13
16
  style,
@@ -21,6 +24,7 @@ function prepareDataLabels(series) {
21
24
  maxHeight,
22
25
  maxWidth,
23
26
  html,
27
+ format: (_b = series.dataLabels) === null || _b === void 0 ? void 0 : _b.format,
24
28
  };
25
29
  }
26
30
  export function prepareBarYSeries(args) {
@@ -46,7 +46,7 @@ export function prepareLineSeries(args) {
46
46
  const defaultLineWidth = get(seriesOptions, 'line.lineWidth', DEFAULT_LINE_WIDTH);
47
47
  const defaultDashStyle = get(seriesOptions, 'line.dashStyle', DEFAULT_DASH_STYLE);
48
48
  return seriesList.map((series) => {
49
- var _a, _b;
49
+ var _a, _b, _c;
50
50
  const id = getUniqId();
51
51
  const name = series.name || '';
52
52
  const color = series.color || colorScale(name);
@@ -69,6 +69,7 @@ export function prepareLineSeries(args) {
69
69
  padding: get(series, 'dataLabels.padding', DEFAULT_DATALABELS_PADDING),
70
70
  allowOverlap: get(series, 'dataLabels.allowOverlap', false),
71
71
  html: get(series, 'dataLabels.html', false),
72
+ format: (_c = series.dataLabels) === null || _c === void 0 ? void 0 : _c.format,
72
73
  },
73
74
  marker: prepareMarker(series, seriesOptions),
74
75
  dashStyle: dashStyle,
@@ -11,7 +11,7 @@ export function preparePieSeries(args) {
11
11
  const stackId = getUniqId();
12
12
  const seriesHoverState = get(seriesOptions, 'pie.states.hover');
13
13
  const preparedSeries = series.data.map((dataItem, i) => {
14
- var _a, _b, _c, _d, _e;
14
+ var _a, _b, _c, _d, _e, _f;
15
15
  const result = {
16
16
  type: 'pie',
17
17
  data: dataItem,
@@ -25,6 +25,7 @@ export function preparePieSeries(args) {
25
25
  distance: get(series, 'dataLabels.distance', 25),
26
26
  connectorCurve: get(series, 'dataLabels.connectorCurve', 'basic'),
27
27
  html: get(series, 'dataLabels.html', false),
28
+ format: (_b = series.dataLabels) === null || _b === void 0 ? void 0 : _b.format,
28
29
  },
29
30
  label: dataItem.label,
30
31
  value: dataItem.value,
@@ -38,9 +39,9 @@ export function preparePieSeries(args) {
38
39
  },
39
40
  center: series.center || ['50%', '50%'],
40
41
  borderColor: series.borderColor || '',
41
- borderRadius: (_b = series.borderRadius) !== null && _b !== void 0 ? _b : 0,
42
- borderWidth: (_c = series.borderWidth) !== null && _c !== void 0 ? _c : 1,
43
- radius: (_e = (_d = dataItem.radius) !== null && _d !== void 0 ? _d : series.radius) !== null && _e !== void 0 ? _e : '100%',
42
+ borderRadius: (_c = series.borderRadius) !== null && _c !== void 0 ? _c : 0,
43
+ borderWidth: (_d = series.borderWidth) !== null && _d !== void 0 ? _d : 1,
44
+ radius: (_f = (_e = dataItem.radius) !== null && _e !== void 0 ? _e : series.radius) !== null && _f !== void 0 ? _f : '100%',
44
45
  innerRadius: series.innerRadius || 0,
45
46
  stackId,
46
47
  states: {
@@ -0,0 +1,16 @@
1
+ import type { ChartSeriesOptions, RadarSeries } from '../../types';
2
+ import type { PreparedLegend, PreparedRadarSeries } from './types';
3
+ type PrepareRadarSeriesArgs = {
4
+ series: RadarSeries[];
5
+ seriesOptions?: ChartSeriesOptions;
6
+ legend: PreparedLegend;
7
+ };
8
+ export declare const DEFAULT_MARKER: {
9
+ enabled: boolean;
10
+ radius: number;
11
+ symbol: `${import("../../constants").SymbolType}`;
12
+ borderColor: string;
13
+ borderWidth: number;
14
+ };
15
+ export declare function prepareRadarSeries(args: PrepareRadarSeriesArgs): PreparedRadarSeries[];
16
+ export {};
@@ -0,0 +1,64 @@
1
+ import { scaleOrdinal } from 'd3';
2
+ import get from 'lodash/get';
3
+ import merge from 'lodash/merge';
4
+ import { DEFAULT_PALETTE } from '../../constants';
5
+ import { getUniqId } from '../../utils';
6
+ import { DEFAULT_DATALABELS_PADDING, DEFAULT_DATALABELS_STYLE, DEFAULT_HALO_OPTIONS, DEFAULT_POINT_MARKER_OPTIONS, } from './constants';
7
+ import { prepareLegendSymbol } from './utils';
8
+ export const DEFAULT_MARKER = Object.assign(Object.assign({}, DEFAULT_POINT_MARKER_OPTIONS), { enabled: true, radius: 2 });
9
+ function prepareMarker(series, seriesOptions) {
10
+ var _a;
11
+ const seriesHoverState = get(seriesOptions, 'radar.states.hover');
12
+ const markerNormalState = Object.assign({}, DEFAULT_MARKER, (_a = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions.radar) === null || _a === void 0 ? void 0 : _a.marker, series.marker);
13
+ const hoveredMarkerDefaultOptions = {
14
+ enabled: true,
15
+ radius: markerNormalState.radius + 1,
16
+ borderWidth: 1,
17
+ borderColor: '#ffffff',
18
+ halo: DEFAULT_HALO_OPTIONS,
19
+ };
20
+ return {
21
+ states: {
22
+ normal: markerNormalState,
23
+ hover: merge(hoveredMarkerDefaultOptions, seriesHoverState === null || seriesHoverState === void 0 ? void 0 : seriesHoverState.marker),
24
+ },
25
+ };
26
+ }
27
+ export function prepareRadarSeries(args) {
28
+ var _a, _b;
29
+ const { series: radarSeries, seriesOptions, legend } = args;
30
+ const colorScale = scaleOrdinal(radarSeries.map((s, index) => { var _a; return (_a = s.name) !== null && _a !== void 0 ? _a : `Series ${index + 1}`; }), DEFAULT_PALETTE);
31
+ const categories = (_b = (_a = radarSeries.find((s) => s.categories)) === null || _a === void 0 ? void 0 : _a.categories) !== null && _b !== void 0 ? _b : [];
32
+ return radarSeries.map((series, index) => {
33
+ var _a, _b, _c, _d, _e, _f;
34
+ const name = (_a = series.name) !== null && _a !== void 0 ? _a : `Series ${index + 1}`;
35
+ const color = (_b = series.color) !== null && _b !== void 0 ? _b : colorScale(name);
36
+ const preparedSeries = {
37
+ type: 'radar',
38
+ data: series.data,
39
+ categories,
40
+ id: getUniqId(),
41
+ name,
42
+ color,
43
+ visible: typeof series.visible === 'boolean' ? series.visible : true,
44
+ legend: {
45
+ enabled: get(series, 'legend.enabled', legend.enabled),
46
+ symbol: prepareLegendSymbol(series),
47
+ },
48
+ borderColor: series.borderColor || color,
49
+ borderWidth: (_c = series.borderWidth) !== null && _c !== void 0 ? _c : 1,
50
+ fillOpacity: (_d = series.fillOpacity) !== null && _d !== void 0 ? _d : 0.25,
51
+ dataLabels: {
52
+ enabled: get(series, 'dataLabels.enabled', true),
53
+ style: Object.assign({}, DEFAULT_DATALABELS_STYLE, (_e = series.dataLabels) === null || _e === void 0 ? void 0 : _e.style),
54
+ padding: get(series, 'dataLabels.padding', DEFAULT_DATALABELS_PADDING),
55
+ allowOverlap: get(series, 'dataLabels.allowOverlap', false),
56
+ html: get(series, 'dataLabels.html', false),
57
+ format: (_f = series.dataLabels) === null || _f === void 0 ? void 0 : _f.format,
58
+ },
59
+ cursor: get(series, 'cursor', null),
60
+ marker: prepareMarker(series, seriesOptions),
61
+ };
62
+ return preparedSeries;
63
+ });
64
+ }
@@ -5,7 +5,7 @@ import { prepareLegendSymbol } from './utils';
5
5
  export function prepareSankeySeries(args) {
6
6
  const { colorScale, legend, series } = args;
7
7
  return series.map((s) => {
8
- var _a;
8
+ var _a, _b;
9
9
  const id = getUniqId();
10
10
  const name = s.name || '';
11
11
  const color = colorScale(name);
@@ -22,6 +22,7 @@ export function prepareSankeySeries(args) {
22
22
  dataLabels: {
23
23
  enabled: get(s, 'dataLabels.enabled', true),
24
24
  style: Object.assign({}, DEFAULT_DATALABELS_STYLE, (_a = s.dataLabels) === null || _a === void 0 ? void 0 : _a.style),
25
+ format: (_b = s.dataLabels) === null || _b === void 0 ? void 0 : _b.format,
25
26
  },
26
27
  id,
27
28
  type: s.type,
@@ -6,7 +6,7 @@ import { prepareLegendSymbol } from './utils';
6
6
  export function prepareTreemap(args) {
7
7
  const { colorScale, legend, series } = args;
8
8
  return series.map((s) => {
9
- var _a;
9
+ var _a, _b;
10
10
  const id = getUniqId();
11
11
  const name = s.name || '';
12
12
  const color = s.color || colorScale(name);
@@ -20,6 +20,7 @@ export function prepareTreemap(args) {
20
20
  allowOverlap: get(s, 'dataLabels.allowOverlap', false),
21
21
  html: get(s, 'dataLabels.html', false),
22
22
  align: get(s, 'dataLabels.align', 'left'),
23
+ format: (_b = s.dataLabels) === null || _b === void 0 ? void 0 : _b.format,
23
24
  },
24
25
  id,
25
26
  type: s.type,
@@ -7,7 +7,7 @@ export function prepareWaterfallSeries(args) {
7
7
  const { colorScale, series: seriesList, legend } = args;
8
8
  const [, negativeColor, positiveColor] = DEFAULT_PALETTE;
9
9
  return seriesList.map((series) => {
10
- var _a, _b, _c;
10
+ var _a, _b, _c, _d;
11
11
  const name = series.name || '';
12
12
  const color = series.color || colorScale(name);
13
13
  const prepared = {
@@ -29,6 +29,7 @@ export function prepareWaterfallSeries(args) {
29
29
  allowOverlap: ((_c = series.dataLabels) === null || _c === void 0 ? void 0 : _c.allowOverlap) || false,
30
30
  padding: get(series, 'dataLabels.padding', DEFAULT_DATALABELS_PADDING),
31
31
  html: get(series, 'dataLabels.html', false),
32
+ format: (_d = series.dataLabels) === null || _d === void 0 ? void 0 : _d.format,
32
33
  },
33
34
  cursor: get(series, 'cursor', null),
34
35
  };
@@ -4,6 +4,7 @@ import { prepareBarXSeries } from './prepare-bar-x';
4
4
  import { prepareBarYSeries } from './prepare-bar-y';
5
5
  import { prepareLineSeries } from './prepare-line';
6
6
  import { preparePieSeries } from './prepare-pie';
7
+ import { prepareRadarSeries } from './prepare-radar';
7
8
  import { prepareSankeySeries } from './prepare-sankey';
8
9
  import { prepareScatterSeries } from './prepare-scatter';
9
10
  import { prepareTreemap } from './prepare-treemap';
@@ -75,6 +76,13 @@ export function prepareSeries(args) {
75
76
  legend,
76
77
  });
77
78
  }
79
+ case 'radar': {
80
+ return prepareRadarSeries({
81
+ series: series,
82
+ seriesOptions,
83
+ legend,
84
+ });
85
+ }
78
86
  default: {
79
87
  throw new ChartError({
80
88
  message: `Series type "${type}" does not support data preparation for series that do not support the presence of axes`,
@@ -1,5 +1,5 @@
1
1
  import type { DashStyle, LayoutAlgorithm, LineCap, SeriesOptionsDefaults, SymbolType } from '../../constants';
2
- import type { AreaSeries, AreaSeriesData, BarXSeries, BarXSeriesData, BarYSeries, BarYSeriesData, BaseTextStyle, ChartLegend, ConnectorCurve, ConnectorShape, LineSeries, LineSeriesData, PathLegendSymbolOptions, PieSeries, PieSeriesData, RectLegendSymbolOptions, SankeySeries, SankeySeriesData, ScatterSeries, ScatterSeriesData, SymbolLegendSymbolOptions, TreemapSeries, TreemapSeriesData, WaterfallSeries, WaterfallSeriesData } from '../../types';
2
+ import type { AreaSeries, AreaSeriesData, BarXSeries, BarXSeriesData, BarYSeries, BarYSeriesData, BaseTextStyle, ChartLegend, ConnectorCurve, ConnectorShape, LineSeries, LineSeriesData, PathLegendSymbolOptions, PieSeries, PieSeriesData, RadarSeries, RadarSeriesCategory, RadarSeriesData, RectLegendSymbolOptions, SankeySeries, SankeySeriesData, ScatterSeries, ScatterSeriesData, SymbolLegendSymbolOptions, TreemapSeries, TreemapSeriesData, ValueFormat, WaterfallSeries, WaterfallSeriesData } from '../../types';
3
3
  export type RectLegendSymbol = {
4
4
  shape: 'rect';
5
5
  } & Required<RectLegendSymbolOptions>;
@@ -106,6 +106,7 @@ export type PreparedBarXSeries = {
106
106
  allowOverlap: boolean;
107
107
  padding: number;
108
108
  html: boolean;
109
+ format?: ValueFormat;
109
110
  };
110
111
  borderRadius: number;
111
112
  yAxis: number;
@@ -122,6 +123,7 @@ export type PreparedBarYSeries = {
122
123
  maxHeight: number;
123
124
  maxWidth: number;
124
125
  html: boolean;
126
+ format?: ValueFormat;
125
127
  };
126
128
  borderRadius: number;
127
129
  } & BasePreparedSeries;
@@ -147,6 +149,7 @@ export type PreparedPieSeries = {
147
149
  distance: number;
148
150
  connectorCurve: ConnectorCurve;
149
151
  html: boolean;
152
+ format?: ValueFormat;
150
153
  };
151
154
  states: {
152
155
  hover: {
@@ -166,6 +169,7 @@ export type PreparedLineSeries = {
166
169
  padding: number;
167
170
  allowOverlap: boolean;
168
171
  html: boolean;
172
+ format?: ValueFormat;
169
173
  };
170
174
  marker: {
171
175
  states: {
@@ -203,6 +207,7 @@ export type PreparedAreaSeries = {
203
207
  padding: number;
204
208
  allowOverlap: boolean;
205
209
  html: boolean;
210
+ format?: ValueFormat;
206
211
  };
207
212
  marker: {
208
213
  states: {
@@ -234,6 +239,7 @@ export type PreparedTreemapSeries = {
234
239
  allowOverlap: boolean;
235
240
  html: boolean;
236
241
  align: Required<Required<TreemapSeries>['dataLabels']>['align'];
242
+ format?: ValueFormat;
237
243
  };
238
244
  layoutAlgorithm: `${LayoutAlgorithm}`;
239
245
  } & BasePreparedSeries & Omit<TreemapSeries, keyof BasePreparedSeries>;
@@ -246,6 +252,7 @@ export type PreparedWaterfallSeries = {
246
252
  allowOverlap: boolean;
247
253
  padding: number;
248
254
  html: boolean;
255
+ format?: ValueFormat;
249
256
  };
250
257
  positiveColor: string;
251
258
  negativeColor: string;
@@ -256,9 +263,44 @@ export type PreparedSankeySeries = {
256
263
  dataLabels: {
257
264
  enabled: boolean;
258
265
  style: BaseTextStyle;
266
+ format?: ValueFormat;
259
267
  };
260
268
  } & BasePreparedSeries & Omit<SankeySeries, keyof BasePreparedSeries>;
261
- export type PreparedSeries = PreparedScatterSeries | PreparedBarXSeries | PreparedBarYSeries | PreparedPieSeries | PreparedLineSeries | PreparedAreaSeries | PreparedTreemapSeries | PreparedWaterfallSeries | PreparedSankeySeries;
269
+ export type PreparedRadarSeries = {
270
+ type: RadarSeries['type'];
271
+ data: RadarSeriesData[];
272
+ categories: RadarSeriesCategory[];
273
+ borderColor: string;
274
+ borderWidth: number;
275
+ fillOpacity: number;
276
+ dataLabels: {
277
+ enabled: boolean;
278
+ style: BaseTextStyle;
279
+ padding: number;
280
+ allowOverlap: boolean;
281
+ html: boolean;
282
+ format?: ValueFormat;
283
+ };
284
+ marker: {
285
+ states: {
286
+ normal: {
287
+ symbol: `${SymbolType}`;
288
+ enabled: boolean;
289
+ radius: number;
290
+ borderWidth: number;
291
+ borderColor: string;
292
+ };
293
+ hover: {
294
+ enabled: boolean;
295
+ radius: number;
296
+ borderWidth: number;
297
+ borderColor: string;
298
+ halo: PreparedHaloOptions;
299
+ };
300
+ };
301
+ };
302
+ } & BasePreparedSeries;
303
+ export type PreparedSeries = PreparedScatterSeries | PreparedBarXSeries | PreparedBarYSeries | PreparedPieSeries | PreparedLineSeries | PreparedAreaSeries | PreparedTreemapSeries | PreparedWaterfallSeries | PreparedSankeySeries | PreparedRadarSeries;
262
304
  export type PreparedSeriesOptions = SeriesOptionsDefaults;
263
305
  export type StackedSeries = BarXSeries | AreaSeries | BarYSeries;
264
306
  export {};
@@ -1,8 +1,9 @@
1
1
  import { group, sort } from 'd3';
2
2
  import { getDataCategoryValue, getLabelsSize, getLeftPosition } from '../../../utils';
3
+ import { getFormattedValue } from '../../../utils/chart/format';
3
4
  import { getXValue, getYValue } from '../utils';
4
5
  function getLabelData(point, series, xMax) {
5
- const text = String(point.data.label || point.data.y);
6
+ const text = getFormattedValue(Object.assign({ value: point.data.label || point.data.y }, series.dataLabels));
6
7
  const style = series.dataLabels.style;
7
8
  const size = getLabelsSize({ labels: [text], style, html: series.dataLabels.html });
8
9
  const labelData = {
@@ -1,12 +1,13 @@
1
1
  import { ascending, descending, max, sort } from 'd3';
2
2
  import get from 'lodash/get';
3
3
  import { getDataCategoryValue, getLabelsSize } from '../../../utils';
4
+ import { getFormattedValue } from '../../../utils/chart/format';
4
5
  import { MIN_BAR_GAP, MIN_BAR_GROUP_GAP, MIN_BAR_WIDTH } from '../constants';
5
6
  function getLabelData(d) {
6
7
  if (!d.series.dataLabels.enabled) {
7
8
  return undefined;
8
9
  }
9
- const text = String(d.data.label || d.data.y);
10
+ const text = getFormattedValue(Object.assign({ value: d.data.label || d.data.y }, d.series.dataLabels));
10
11
  const style = d.series.dataLabels.style;
11
12
  const html = d.series.dataLabels.html;
12
13
  const { maxHeight: height, maxWidth: width } = getLabelsSize({
@@ -1,6 +1,7 @@
1
1
  import { ascending, descending, max, sort } from 'd3';
2
2
  import get from 'lodash/get';
3
3
  import { getDataCategoryValue, getLabelsSize } from '../../../utils';
4
+ import { getFormattedValue } from '../../../utils/chart/format';
4
5
  import { MIN_BAR_GAP, MIN_BAR_GROUP_GAP, MIN_BAR_WIDTH } from '../constants';
5
6
  const DEFAULT_LABEL_PADDING = 7;
6
7
  function groupByYValue(series, yAxis) {
@@ -54,7 +55,7 @@ function setLabel(prepared) {
54
55
  return;
55
56
  }
56
57
  const data = prepared.data;
57
- const content = String(data.label || data.x);
58
+ const content = getFormattedValue(Object.assign({ value: data.label || data.x }, dataLabels));
58
59
  const { maxHeight: height, maxWidth: width } = getLabelsSize({
59
60
  labels: [content],
60
61
  style: dataLabels.style,