@gravity-ui/chartkit 3.1.3 → 3.2.0-beta.2

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 (132) hide show
  1. package/build/plugins/d3/index.d.ts +7 -0
  2. package/build/plugins/d3/index.js +10 -0
  3. package/build/plugins/d3/renderer/D3Widget.d.ts +15 -0
  4. package/build/plugins/d3/renderer/D3Widget.js +40 -0
  5. package/build/plugins/d3/renderer/components/AxisX.d.ts +10 -0
  6. package/build/plugins/d3/renderer/components/AxisX.js +68 -0
  7. package/build/plugins/d3/renderer/components/AxisY.d.ts +10 -0
  8. package/build/plugins/d3/renderer/components/AxisY.js +73 -0
  9. package/build/plugins/d3/renderer/components/Chart.d.ts +10 -0
  10. package/build/plugins/d3/renderer/components/Chart.js +64 -0
  11. package/build/plugins/d3/renderer/components/Legend.d.ts +12 -0
  12. package/build/plugins/d3/renderer/components/Legend.js +66 -0
  13. package/build/plugins/d3/renderer/components/Title.d.ts +7 -0
  14. package/build/plugins/d3/renderer/components/Title.js +8 -0
  15. package/build/plugins/d3/renderer/components/Tooltip/DefaultContent.d.ts +10 -0
  16. package/build/plugins/d3/renderer/components/Tooltip/DefaultContent.js +21 -0
  17. package/build/plugins/d3/renderer/components/Tooltip/index.d.ts +12 -0
  18. package/build/plugins/d3/renderer/components/Tooltip/index.js +53 -0
  19. package/build/plugins/d3/renderer/components/index.d.ts +1 -0
  20. package/build/plugins/d3/renderer/components/index.js +1 -0
  21. package/build/plugins/d3/renderer/components/styles.css +61 -0
  22. package/build/plugins/d3/renderer/constants.d.ts +1 -0
  23. package/build/plugins/d3/renderer/constants.js +22 -0
  24. package/build/plugins/d3/renderer/hooks/index.d.ts +10 -0
  25. package/build/plugins/d3/renderer/hooks/index.js +10 -0
  26. package/build/plugins/d3/renderer/hooks/useChartDimensions/index.d.ts +17 -0
  27. package/build/plugins/d3/renderer/hooks/useChartDimensions/index.js +13 -0
  28. package/build/plugins/d3/renderer/hooks/useChartEvents/index.d.ts +5 -0
  29. package/build/plugins/d3/renderer/hooks/useChartEvents/index.js +15 -0
  30. package/build/plugins/d3/renderer/hooks/useChartOptions/chart.d.ts +8 -0
  31. package/build/plugins/d3/renderer/hooks/useChartOptions/chart.js +60 -0
  32. package/build/plugins/d3/renderer/hooks/useChartOptions/constants.d.ts +3 -0
  33. package/build/plugins/d3/renderer/hooks/useChartOptions/constants.js +3 -0
  34. package/build/plugins/d3/renderer/hooks/useChartOptions/index.d.ts +3 -0
  35. package/build/plugins/d3/renderer/hooks/useChartOptions/index.js +32 -0
  36. package/build/plugins/d3/renderer/hooks/useChartOptions/legend.d.ts +6 -0
  37. package/build/plugins/d3/renderer/hooks/useChartOptions/legend.js +7 -0
  38. package/build/plugins/d3/renderer/hooks/useChartOptions/title.d.ts +5 -0
  39. package/build/plugins/d3/renderer/hooks/useChartOptions/title.js +17 -0
  40. package/build/plugins/d3/renderer/hooks/useChartOptions/tooltip.d.ts +5 -0
  41. package/build/plugins/d3/renderer/hooks/useChartOptions/tooltip.js +5 -0
  42. package/build/plugins/d3/renderer/hooks/useChartOptions/types.d.ts +33 -0
  43. package/build/plugins/d3/renderer/hooks/useChartOptions/utils.d.ts +5 -0
  44. package/build/plugins/d3/renderer/hooks/useChartOptions/utils.js +18 -0
  45. package/build/plugins/d3/renderer/hooks/useChartOptions/x-axis.d.ts +5 -0
  46. package/build/plugins/d3/renderer/hooks/useChartOptions/x-axis.js +29 -0
  47. package/build/plugins/d3/renderer/hooks/useChartOptions/y-axis.d.ts +5 -0
  48. package/build/plugins/d3/renderer/hooks/useChartOptions/y-axis.js +35 -0
  49. package/build/plugins/d3/renderer/hooks/useLegend/index.d.ts +13 -0
  50. package/build/plugins/d3/renderer/hooks/useLegend/index.js +28 -0
  51. package/build/plugins/d3/renderer/hooks/useScales/index.d.ts +17 -0
  52. package/build/plugins/d3/renderer/hooks/useScales/index.js +106 -0
  53. package/build/plugins/d3/renderer/hooks/useSeries/index.d.ts +14 -0
  54. package/build/plugins/d3/renderer/hooks/useSeries/index.js +23 -0
  55. package/build/plugins/d3/renderer/hooks/useShapes/bar.d.ts +16 -0
  56. package/build/plugins/d3/renderer/hooks/useShapes/bar.js +75 -0
  57. package/build/plugins/d3/renderer/hooks/useShapes/index.d.ts +19 -0
  58. package/build/plugins/d3/renderer/hooks/useShapes/index.js +44 -0
  59. package/build/plugins/d3/renderer/hooks/useShapes/scatter.d.ts +18 -0
  60. package/build/plugins/d3/renderer/hooks/useShapes/scatter.js +62 -0
  61. package/build/plugins/d3/renderer/hooks/useTooltip/index.d.ts +13 -0
  62. package/build/plugins/d3/renderer/hooks/useTooltip/index.js +19 -0
  63. package/build/plugins/d3/renderer/hooks/useTooltip/types.d.ts +7 -0
  64. package/build/plugins/d3/renderer/utils/index.d.ts +18 -0
  65. package/build/plugins/d3/renderer/utils/index.js +71 -0
  66. package/build/plugins/d3/types.d.ts +4 -0
  67. package/build/types/widget-data/axis.d.ts +24 -0
  68. package/build/types/widget-data/bar.d.ts +31 -0
  69. package/build/types/widget-data/base.d.ts +15 -0
  70. package/build/types/widget-data/base.js +1 -0
  71. package/build/types/widget-data/chart.d.ts +9 -0
  72. package/build/types/widget-data/chart.js +1 -0
  73. package/build/types/widget-data/index.d.ts +28 -0
  74. package/build/types/widget-data/index.js +10 -0
  75. package/build/types/widget-data/legend.d.ts +3 -0
  76. package/build/types/widget-data/legend.js +1 -0
  77. package/build/types/widget-data/pie.d.ts +10 -0
  78. package/build/types/widget-data/pie.js +1 -0
  79. package/build/types/widget-data/scatter.d.ts +20 -0
  80. package/build/types/widget-data/scatter.js +1 -0
  81. package/build/types/widget-data/series.d.ts +18 -0
  82. package/build/types/widget-data/series.js +1 -0
  83. package/build/types/widget-data/title.d.ts +5 -0
  84. package/build/types/widget-data/title.js +1 -0
  85. package/build/types/widget-data/tooltip.d.ts +12 -0
  86. package/build/types/widget-data/tooltip.js +1 -0
  87. package/build/types/widget.d.ts +5 -0
  88. package/package.json +10 -3
  89. package/build/libs/chartkit-error/__tests__/chartkit-error.js +0 -27
  90. package/build/libs/settings/__tests__/settings.test.js +0 -17
  91. package/build/plugins/highcharts/__stories__/Line.stories.d.ts +0 -3
  92. package/build/plugins/highcharts/__stories__/Line.stories.js +0 -12
  93. package/build/plugins/highcharts/__stories__/Pie.stories.d.ts +0 -3
  94. package/build/plugins/highcharts/__stories__/Pie.stories.js +0 -12
  95. package/build/plugins/highcharts/__stories__/area/Range.stories.d.ts +0 -3
  96. package/build/plugins/highcharts/__stories__/area/Range.stories.js +0 -12
  97. package/build/plugins/highcharts/__stories__/area/Stacked.stories.d.ts +0 -3
  98. package/build/plugins/highcharts/__stories__/area/Stacked.stories.js +0 -12
  99. package/build/plugins/highcharts/__stories__/column/HorizontalStacked.stories.d.ts +0 -3
  100. package/build/plugins/highcharts/__stories__/column/HorizontalStacked.stories.js +0 -12
  101. package/build/plugins/highcharts/__stories__/column/Vertical.stories.d.ts +0 -3
  102. package/build/plugins/highcharts/__stories__/column/Vertical.stories.js +0 -12
  103. package/build/plugins/highcharts/__stories__/column/VerticalStacked.stories.d.ts +0 -3
  104. package/build/plugins/highcharts/__stories__/column/VerticalStacked.stories.js +0 -12
  105. package/build/plugins/highcharts/__stories__/combined/ComboChartWithSameLegendValues.stories.d.ts +0 -3
  106. package/build/plugins/highcharts/__stories__/combined/ComboChartWithSameLegendValues.stories.js +0 -12
  107. package/build/plugins/highcharts/__stories__/complex/TwoAxis.stories.d.ts +0 -3
  108. package/build/plugins/highcharts/__stories__/complex/TwoAxis.stories.js +0 -12
  109. package/build/plugins/highcharts/__stories__/components/ChartStory.d.ts +0 -12
  110. package/build/plugins/highcharts/__stories__/components/ChartStory.js +0 -28
  111. package/build/plugins/highcharts/__stories__/constants/story-settings.d.ts +0 -42
  112. package/build/plugins/highcharts/__stories__/constants/story-settings.js +0 -42
  113. package/build/plugins/highcharts/__stories__/custom-error-render/custom-error-render.stories.d.ts +0 -3
  114. package/build/plugins/highcharts/__stories__/custom-error-render/custom-error-render.stories.js +0 -41
  115. package/build/plugins/highcharts/__stories__/no-data/no-data.stories.d.ts +0 -3
  116. package/build/plugins/highcharts/__stories__/no-data/no-data.stories.js +0 -20
  117. package/build/plugins/highcharts/__stories__/pie/WithTotals.stories.d.ts +0 -3
  118. package/build/plugins/highcharts/__stories__/pie/WithTotals.stories.js +0 -12
  119. package/build/plugins/highcharts/__tests__/prepare-data.test.js +0 -13
  120. package/build/plugins/indicator/__stories__/Indicator.stories.d.ts +0 -4
  121. package/build/plugins/indicator/__stories__/Indicator.stories.js +0 -45
  122. package/build/plugins/yagr/__stories__/Yagr.stories.d.ts +0 -6
  123. package/build/plugins/yagr/__stories__/Yagr.stories.js +0 -90
  124. package/build/plugins/yagr/__stories__/mocks/line10.d.ts +0 -53
  125. package/build/plugins/yagr/__stories__/mocks/line10.js +0 -78
  126. package/build/plugins/yagr/__tests__/utils.test.js +0 -26
  127. package/build/utils/__tests__/common.test.js +0 -9
  128. /package/build/{libs/chartkit-error/__tests__/chartkit-error.d.ts → plugins/d3/renderer/hooks/useChartOptions/types.js} +0 -0
  129. /package/build/{libs/settings/__tests__/settings.test.d.ts → plugins/d3/renderer/hooks/useTooltip/types.js} +0 -0
  130. /package/build/plugins/{highcharts/__tests__/prepare-data.test.d.ts → d3/types.js} +0 -0
  131. /package/build/{plugins/yagr/__tests__/utils.test.d.ts → types/widget-data/axis.js} +0 -0
  132. /package/build/{utils/__tests__/common.test.d.ts → types/widget-data/bar.js} +0 -0
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import type { ChartOptions } from '../useChartOptions/types';
3
+ import type { ChartScale } from '../useScales';
4
+ import type { ChartSeries } from '../useSeries';
5
+ import type { OnSeriesMouseMove, OnSeriesMouseLeave } from '../useTooltip/types';
6
+ type Args = {
7
+ series: ChartSeries[];
8
+ xAxis: ChartOptions['xAxis'];
9
+ xScale: ChartScale;
10
+ yAxis: ChartOptions['yAxis'];
11
+ yScale: ChartScale;
12
+ svgContainer: SVGSVGElement | null;
13
+ onSeriesMouseMove?: OnSeriesMouseMove;
14
+ onSeriesMouseLeave?: OnSeriesMouseLeave;
15
+ };
16
+ export declare const useShapes: (args: Args) => {
17
+ shapes: React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
18
+ };
19
+ export {};
@@ -0,0 +1,44 @@
1
+ import React from 'react';
2
+ import { group } from 'd3';
3
+ import { getOnlyVisibleSeries } from '../../utils';
4
+ import { prepareBarSeries } from './bar';
5
+ import { prepareScatterSeries } from './scatter';
6
+ export const useShapes = (args) => {
7
+ const { series, xAxis, xScale, yAxis, yScale, svgContainer, onSeriesMouseMove, onSeriesMouseLeave, } = args;
8
+ const shapes = React.useMemo(() => {
9
+ const visibleSeries = getOnlyVisibleSeries(series);
10
+ const groupedSeries = group(visibleSeries, (item) => item.type);
11
+ return Array.from(groupedSeries).reduce((acc, item) => {
12
+ const [seriesType, chartSeries] = item;
13
+ switch (seriesType) {
14
+ case 'bar': {
15
+ acc.push(...prepareBarSeries({
16
+ series: chartSeries,
17
+ xAxis,
18
+ xScale,
19
+ yAxis,
20
+ yScale,
21
+ onSeriesMouseMove,
22
+ onSeriesMouseLeave,
23
+ }));
24
+ break;
25
+ }
26
+ case 'scatter': {
27
+ acc.push(...prepareScatterSeries({
28
+ series: chartSeries,
29
+ xAxis,
30
+ xScale,
31
+ yAxis,
32
+ yScale,
33
+ onSeriesMouseMove,
34
+ onSeriesMouseLeave,
35
+ svgContainer,
36
+ }));
37
+ break;
38
+ }
39
+ }
40
+ return acc;
41
+ }, []);
42
+ }, [series, xAxis, xScale, yAxis, yScale, svgContainer, onSeriesMouseMove, onSeriesMouseLeave]);
43
+ return { shapes };
44
+ };
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { ChartOptions } from '../useChartOptions/types';
3
+ import { ChartScale } from '../useScales';
4
+ import { OnSeriesMouseLeave, OnSeriesMouseMove } from '../useTooltip/types';
5
+ import { ScatterSeries } from '../../../../../types/widget-data';
6
+ type PrepareScatterSeriesArgs = {
7
+ series: ScatterSeries[];
8
+ xAxis: ChartOptions['xAxis'];
9
+ xScale: ChartScale;
10
+ yAxis: ChartOptions['yAxis'];
11
+ yScale: ChartScale;
12
+ svgContainer: SVGSVGElement | null;
13
+ onSeriesMouseMove?: OnSeriesMouseMove;
14
+ onSeriesMouseLeave?: OnSeriesMouseLeave;
15
+ key?: string;
16
+ };
17
+ export declare function prepareScatterSeries(args: PrepareScatterSeriesArgs): React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
18
+ export {};
@@ -0,0 +1,62 @@
1
+ import { pointer } from 'd3';
2
+ import React from 'react';
3
+ import block from 'bem-cn-lite';
4
+ const b = block('chartkit-d3-scatter');
5
+ const DEFAULT_SCATTER_POINT_RADIUS = 4;
6
+ const prepareCategoricalScatterData = (data) => {
7
+ return data.filter((d) => typeof d.category === 'string');
8
+ };
9
+ const prepareLinearScatterData = (data) => {
10
+ return data.filter((d) => typeof d.x === 'number' && typeof d.y === 'number');
11
+ };
12
+ const getPointProperties = (args) => {
13
+ const { point, xAxis, xScale, yAxis, yScale } = args;
14
+ const r = point.radius || DEFAULT_SCATTER_POINT_RADIUS;
15
+ let cx;
16
+ let cy;
17
+ if (xAxis.type === 'category') {
18
+ const xBandScale = xScale;
19
+ cx = (xBandScale(point.category) || 0) + xBandScale.step() / 2;
20
+ }
21
+ else {
22
+ const xLinearScale = xScale;
23
+ cx = xLinearScale(point.x);
24
+ }
25
+ if (yAxis[0].type === 'category') {
26
+ const yBandScale = yScale;
27
+ cy = (yBandScale(point.category) || 0) + yBandScale.step() / 2;
28
+ }
29
+ else {
30
+ const yLinearScale = yScale;
31
+ cy = yLinearScale(point.y);
32
+ }
33
+ return { r, cx, cy };
34
+ };
35
+ export function prepareScatterSeries(args) {
36
+ const { series, xAxis, xScale, yAxis, yScale, onSeriesMouseMove, onSeriesMouseLeave, key, svgContainer, } = args;
37
+ return series.reduce((result, s) => {
38
+ var _a;
39
+ const preparedData = xAxis.type === 'category' || ((_a = yAxis[0]) === null || _a === void 0 ? void 0 : _a.type) === 'category'
40
+ ? prepareCategoricalScatterData(s.data)
41
+ : prepareLinearScatterData(s.data);
42
+ result.push(...preparedData.map((point, i) => {
43
+ const pointProps = getPointProperties({
44
+ point,
45
+ xAxis,
46
+ xScale,
47
+ yAxis,
48
+ yScale,
49
+ });
50
+ return (React.createElement("circle", Object.assign({ key: `${i}-${key}`, className: b('point'), fill: s.color }, pointProps, { onMouseMove: function (e) {
51
+ onSeriesMouseMove === null || onSeriesMouseMove === void 0 ? void 0 : onSeriesMouseMove({
52
+ hovered: {
53
+ data: point,
54
+ series: s,
55
+ },
56
+ pointerPosition: pointer(e, svgContainer),
57
+ });
58
+ }, onMouseLeave: onSeriesMouseLeave })));
59
+ }));
60
+ return result;
61
+ }, []);
62
+ }
@@ -0,0 +1,13 @@
1
+ import type { TooltipHoveredData } from '../../../../../types/widget-data';
2
+ import { PreparedTooltip } from '../useChartOptions/types';
3
+ import type { PointerPosition, OnSeriesMouseMove, OnSeriesMouseLeave } from './types';
4
+ type Args = {
5
+ tooltip: PreparedTooltip;
6
+ };
7
+ export declare const useTooltip: ({ tooltip }: Args) => {
8
+ hovered: TooltipHoveredData<any> | undefined;
9
+ pointerPosition: PointerPosition | undefined;
10
+ handleSeriesMouseMove: OnSeriesMouseMove | undefined;
11
+ handleSeriesMouseLeave: OnSeriesMouseLeave | undefined;
12
+ };
13
+ export {};
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ export const useTooltip = ({ tooltip }) => {
3
+ const [hovered, setTooltipHoveredData] = React.useState();
4
+ const [pointerPosition, setPointerPosition] = React.useState();
5
+ const handleSeriesMouseMove = React.useCallback(({ pointerPosition: nextPointerPosition, hovered: nextHovered }) => {
6
+ setTooltipHoveredData(nextHovered);
7
+ setPointerPosition(nextPointerPosition);
8
+ }, []);
9
+ const handleSeriesMouseLeave = React.useCallback(() => {
10
+ setTooltipHoveredData(undefined);
11
+ setPointerPosition(undefined);
12
+ }, []);
13
+ return {
14
+ hovered,
15
+ pointerPosition,
16
+ handleSeriesMouseMove: tooltip.enabled ? handleSeriesMouseMove : undefined,
17
+ handleSeriesMouseLeave: tooltip.enabled ? handleSeriesMouseLeave : undefined,
18
+ };
19
+ };
@@ -0,0 +1,7 @@
1
+ import type { TooltipHoveredData } from '../../../../../types/widget-data';
2
+ export type PointerPosition = [number, number];
3
+ export type OnSeriesMouseMove = (args: {
4
+ hovered: TooltipHoveredData;
5
+ pointerPosition?: PointerPosition;
6
+ }) => void;
7
+ export type OnSeriesMouseLeave = () => void;
@@ -0,0 +1,18 @@
1
+ import type { AxisDomain } from 'd3';
2
+ import type { ChartKitWidgetSeries, ChartKitWidgetAxisType, ChartKitWidgetAxisLabels } from '../../../../types/widget-data';
3
+ export declare const isAxisRelatedSeries: (series: ChartKitWidgetSeries) => boolean;
4
+ export declare const getDomainDataXBySeries: (series: ChartKitWidgetSeries[]) => unknown[];
5
+ export declare const getDomainDataYBySeries: (series: ChartKitWidgetSeries[]) => unknown[];
6
+ export declare const getSeriesNames: (series: ChartKitWidgetSeries[]) => string[];
7
+ export declare const getVisibleSeriesNames: (series: ChartKitWidgetSeries[]) => string[];
8
+ export declare const getOnlyVisibleSeries: <T extends ChartKitWidgetSeries<any>>(series: T[]) => T[];
9
+ export declare const parseTransformStyle: (style: string | null) => {
10
+ x?: number | undefined;
11
+ y?: number | undefined;
12
+ };
13
+ export declare const formatAxisTickLabel: (args: {
14
+ axisType: ChartKitWidgetAxisType;
15
+ value: AxisDomain;
16
+ dateFormat?: ChartKitWidgetAxisLabels['dateFormat'];
17
+ numberFormat?: ChartKitWidgetAxisLabels['numberFormat'];
18
+ }) => string;
@@ -0,0 +1,71 @@
1
+ import { dateTime } from '@gravity-ui/date-utils';
2
+ import { formatNumber } from '../../../shared';
3
+ const CHARTS_WITHOUT_AXIS = ['pie'];
4
+ // Сhecks whether the series should be drawn with axes
5
+ export const isAxisRelatedSeries = (series) => {
6
+ return !CHARTS_WITHOUT_AXIS.includes(series.type);
7
+ };
8
+ export const getDomainDataXBySeries = (series) => {
9
+ return series.filter(isAxisRelatedSeries).reduce((acc, s) => {
10
+ acc.push(...s.data.map((d) => 'x' in d && d.x));
11
+ return acc;
12
+ }, []);
13
+ };
14
+ export const getDomainDataYBySeries = (series) => {
15
+ return series.filter(isAxisRelatedSeries).reduce((acc, s) => {
16
+ acc.push(...s.data.map((d) => 'y' in d && d.y));
17
+ return acc;
18
+ }, []);
19
+ };
20
+ // Uses to get all series names array (except `pie` charts)
21
+ export const getSeriesNames = (series) => {
22
+ return series.reduce((acc, s) => {
23
+ if ('name' in s && typeof s.name === 'string') {
24
+ acc.push(s.name);
25
+ }
26
+ return acc;
27
+ }, []);
28
+ };
29
+ // Uses to get all visible series names array (except `pie` charts)
30
+ export const getVisibleSeriesNames = (series) => {
31
+ return series.reduce((acc, s) => {
32
+ var _a;
33
+ const visible = (_a = s.visible) !== null && _a !== void 0 ? _a : true;
34
+ if ('name' in s && typeof s.name === 'string' && visible) {
35
+ acc.push(s.name);
36
+ }
37
+ return acc;
38
+ }, []);
39
+ };
40
+ export const getOnlyVisibleSeries = (series) => {
41
+ return series.filter((s) => s.visible);
42
+ };
43
+ export const parseTransformStyle = (style) => {
44
+ var _a;
45
+ if (!style) {
46
+ return {};
47
+ }
48
+ const stringifiedValue = ((_a = style.match(/\((.*?)\)/)) === null || _a === void 0 ? void 0 : _a[1]) || '';
49
+ const [xString, yString] = stringifiedValue.split(',');
50
+ const x = Number.isNaN(Number(xString)) ? undefined : Number(xString);
51
+ const y = Number.isNaN(Number(yString)) ? undefined : Number(yString);
52
+ return { x, y };
53
+ };
54
+ const defaultFormatNumberOptions = {
55
+ precision: 0,
56
+ };
57
+ export const formatAxisTickLabel = (args) => {
58
+ const { axisType, value, dateFormat = 'DD.MM.YY', numberFormat = defaultFormatNumberOptions, } = args;
59
+ switch (axisType) {
60
+ case 'category': {
61
+ return value;
62
+ }
63
+ case 'datetime': {
64
+ return dateTime({ input: value }).format(dateFormat);
65
+ }
66
+ case 'linear':
67
+ default: {
68
+ return formatNumber(value, numberFormat);
69
+ }
70
+ }
71
+ };
@@ -0,0 +1,4 @@
1
+ import type { ChartKitWidgetData } from '../../types/widget-data';
2
+ export type D3WidgetData = {
3
+ data: ChartKitWidgetData;
4
+ };
@@ -0,0 +1,24 @@
1
+ import type { FormatNumberOptions } from '../../plugins/shared';
2
+ import type { BaseTextStyle } from './base';
3
+ export type ChartKitWidgetAxisType = 'category' | 'datetime' | 'linear';
4
+ export type ChartKitWidgetAxisLabels = {
5
+ /** Enable or disable the axis labels */
6
+ enabled?: boolean;
7
+ /** The pixel padding for axis labels */
8
+ padding?: number;
9
+ dateFormat?: string;
10
+ numberFormat?: FormatNumberOptions;
11
+ style?: Partial<BaseTextStyle>;
12
+ };
13
+ export type ChartKitWidgetAxis = {
14
+ categories?: string[];
15
+ timestamps?: number[];
16
+ type?: ChartKitWidgetAxisType;
17
+ /** The axis labels show the number or category for each tick */
18
+ labels?: ChartKitWidgetAxisLabels;
19
+ title?: {
20
+ text?: string;
21
+ };
22
+ /** The minimum value of the axis. If undefined the min value is automatically calculate */
23
+ min?: number;
24
+ };
@@ -0,0 +1,31 @@
1
+ import type { BaseSeries, BaseSeriesData } from './base';
2
+ import type { ChartKitWidgetSeriesOptions } from './series';
3
+ export type BarSeriesData<T = any> = BaseSeriesData<T> & {
4
+ /** The x value of the point */
5
+ x?: number;
6
+ /** The y value of the point */
7
+ y?: number;
8
+ /** Corresponding value of axis category */
9
+ category?: string;
10
+ };
11
+ export type BarSeries<T = any> = BaseSeries & {
12
+ type: 'bar';
13
+ data: BarSeriesData<T>[];
14
+ /** The name of the series (used in legend) */
15
+ name: string;
16
+ /** The main color of the series (hex, rgba) */
17
+ color?: string;
18
+ stacking?: 'normal' | 'percent';
19
+ /** This option allows grouping series in a stacked chart */
20
+ stackId?: string;
21
+ /** Whether to group non-stacked columns or to let them render independent of each other.
22
+ * When false columns will be laid out individually and overlap each other.
23
+ *
24
+ * @default true
25
+ * */
26
+ grouping?: boolean;
27
+ dataLabels?: ChartKitWidgetSeriesOptions['dataLabels'] & {
28
+ /** Whether to align the data label inside the box or to the actual value point */
29
+ inside?: boolean;
30
+ };
31
+ };
@@ -0,0 +1,15 @@
1
+ export type BaseSeries = {
2
+ /** Initial visibility of the series */
3
+ visible?: boolean;
4
+ };
5
+ export type BaseSeriesData<T = any> = {
6
+ /**
7
+ * A reserved subspace to store options and values for customized functionality
8
+ *
9
+ * Here you can add additional data for your own event callbacks and formatter callbacks
10
+ */
11
+ custom?: T;
12
+ };
13
+ export type BaseTextStyle = {
14
+ fontSize: string;
15
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ export type ChartMargin = {
2
+ top: number;
3
+ right: number;
4
+ bottom: number;
5
+ left: number;
6
+ };
7
+ export type ChartKitWidgetChart = {
8
+ margin?: Partial<ChartMargin>;
9
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ import type { ChartKitWidgetAxis } from './axis';
2
+ import type { ChartKitWidgetChart } from './chart';
3
+ import type { ChartKitWidgetLegend } from './legend';
4
+ import type { ChartKitWidgetSeries, ChartKitWidgetSeriesOptions } from './series';
5
+ import type { ChartKitWidgetTitle } from './title';
6
+ import type { ChartKitWidgetTooltip } from './tooltip';
7
+ export * from './axis';
8
+ export * from './base';
9
+ export * from './chart';
10
+ export * from './legend';
11
+ export * from './pie';
12
+ export * from './scatter';
13
+ export * from './bar';
14
+ export * from './series';
15
+ export * from './title';
16
+ export * from './tooltip';
17
+ export type ChartKitWidgetData<T = any> = {
18
+ chart?: ChartKitWidgetChart;
19
+ legend?: ChartKitWidgetLegend;
20
+ series: {
21
+ data: ChartKitWidgetSeries<T>[];
22
+ options?: ChartKitWidgetSeriesOptions;
23
+ };
24
+ title?: ChartKitWidgetTitle;
25
+ tooltip?: ChartKitWidgetTooltip<T>;
26
+ xAxis?: ChartKitWidgetAxis;
27
+ yAxis?: ChartKitWidgetAxis[];
28
+ };
@@ -0,0 +1,10 @@
1
+ export * from './axis';
2
+ export * from './base';
3
+ export * from './chart';
4
+ export * from './legend';
5
+ export * from './pie';
6
+ export * from './scatter';
7
+ export * from './bar';
8
+ export * from './series';
9
+ export * from './title';
10
+ export * from './tooltip';
@@ -0,0 +1,3 @@
1
+ export type ChartKitWidgetLegend = {
2
+ enabled?: boolean;
3
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { BaseSeries, BaseSeriesData } from './base';
2
+ export type PieSeriesData<T = any> = BaseSeriesData<T> & {
3
+ value: number;
4
+ color: string;
5
+ name: string;
6
+ };
7
+ export type PieSeries<T = any> = BaseSeries & {
8
+ type: 'pie';
9
+ data: PieSeriesData<T>[];
10
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ import type { BaseSeries, BaseSeriesData } from './base';
2
+ export type ScatterSeriesData<T = any> = BaseSeriesData<T> & {
3
+ /** The x value of the point */
4
+ x?: number;
5
+ /** The y value of the point */
6
+ y?: number;
7
+ /** Corresponding value of axis category */
8
+ category?: string;
9
+ radius?: number;
10
+ };
11
+ export type ScatterSeries<T = any> = BaseSeries & {
12
+ type: 'scatter';
13
+ data: ScatterSeriesData<T>[];
14
+ /** The name of the series (used in legend) */
15
+ name: string;
16
+ /** The main color of the series (hex, rgba) */
17
+ color?: string;
18
+ /** A predefined shape or symbol for the dot */
19
+ symbol?: string;
20
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ import type { PieSeries, PieSeriesData } from './pie';
2
+ import type { ScatterSeries, ScatterSeriesData } from './scatter';
3
+ import type { BarSeries, BarSeriesData } from './bar';
4
+ import React from 'react';
5
+ export type ChartKitWidgetSeries<T = any> = ScatterSeries<T> | PieSeries<T> | BarSeries<T>;
6
+ export type ChartKitWidgetSeriesData<T = any> = ScatterSeriesData<T> | PieSeriesData<T> | BarSeriesData<T>;
7
+ export type DataLabelRendererData<T = any> = {
8
+ data: ChartKitWidgetSeriesData<T>;
9
+ };
10
+ export type ChartKitWidgetSeriesOptions = {
11
+ /** Individual data label for each point. */
12
+ dataLabels?: {
13
+ /** Enable or disable the data labels */
14
+ enabled?: boolean;
15
+ /** Callback function to render the data label */
16
+ renderer?: (args: DataLabelRendererData) => React.SVGTextElementAttributes<SVGTextElement>;
17
+ };
18
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { BaseTextStyle } from './base';
2
+ export type ChartKitWidgetTitle = {
3
+ text: string;
4
+ style?: Partial<BaseTextStyle>;
5
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import type { ChartKitWidgetSeries, ChartKitWidgetSeriesData } from './series';
3
+ export type TooltipHoveredData<T = any> = {
4
+ data: ChartKitWidgetSeriesData<T>;
5
+ series: ChartKitWidgetSeries;
6
+ };
7
+ export type ChartKitWidgetTooltip<T = any> = {
8
+ enabled?: boolean;
9
+ renderer?: (data: {
10
+ hovered: TooltipHoveredData<T>;
11
+ }) => React.ReactElement;
12
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -2,6 +2,7 @@
2
2
  import type { CustomTooltipProps, Yagr, YagrWidgetData } from '../plugins/yagr/types';
3
3
  import type { IndicatorWidgetData } from '../plugins/indicator/types';
4
4
  import type { Highcharts, HighchartsWidgetData, StringParams } from '../plugins/highcharts/types';
5
+ import type { ChartKitWidgetData } from './widget-data';
5
6
  export interface ChartKitWidget {
6
7
  yagr: {
7
8
  data: YagrWidgetData;
@@ -28,4 +29,8 @@ export interface ChartKitWidget {
28
29
  forceUpdate: boolean;
29
30
  }, callExternalOnChange?: boolean) => void;
30
31
  };
32
+ d3: {
33
+ data: ChartKitWidgetData;
34
+ widget: never;
35
+ };
31
36
  }
package/package.json CHANGED
@@ -1,21 +1,27 @@
1
1
  {
2
2
  "name": "@gravity-ui/chartkit",
3
- "version": "3.1.3",
3
+ "version": "3.2.0-beta.2",
4
4
  "description": "React component used to render charts based on any sources you need",
5
5
  "license": "MIT",
6
6
  "repository": "git@github.com:gravity-ui/ChartKit.git",
7
7
  "main": "build/index.js",
8
8
  "typings": "build/index.d.ts",
9
9
  "files": [
10
- "build"
10
+ "build",
11
+ "!**/__tests__/**",
12
+ "!**/__stories__/**"
11
13
  ],
12
14
  "publishConfig": {
13
15
  "access": "public"
14
16
  },
17
+ "sideEffects": [
18
+ "*.css"
19
+ ],
15
20
  "dependencies": {
16
21
  "@gravity-ui/date-utils": "^1.4.1",
17
- "@gravity-ui/yagr": "^3.7.7",
22
+ "@gravity-ui/yagr": "^3.7.8",
18
23
  "bem-cn-lite": "^4.1.0",
24
+ "d3": "^7.8.5",
19
25
  "lodash": "^4.17.21",
20
26
  "react-split-pane": "^0.1.92"
21
27
  },
@@ -35,6 +41,7 @@
35
41
  "@storybook/preset-scss": "^1.0.3",
36
42
  "@storybook/react": "^7.0.26",
37
43
  "@storybook/react-webpack5": "^7.0.26",
44
+ "@types/d3": "^7.4.0",
38
45
  "@types/jest": "^28.1.3",
39
46
  "@types/lodash": "^4.14.177",
40
47
  "@types/node": "^18.0.0",
@@ -1,27 +0,0 @@
1
- import { CHARTKIT_ERROR_CODE, ChartKitError, isChartKitError } from '../chartkit-error';
2
- describe('libs/chartkit-error', () => {
3
- test.each([
4
- [new ChartKitError(), true],
5
- [new Error(), false],
6
- [null, false],
7
- [undefined, false],
8
- ])('isChartKitError (args: %j)', (error, expected) => {
9
- const result = isChartKitError(error);
10
- expect(result).toEqual(expected);
11
- });
12
- test.each([
13
- [undefined, CHARTKIT_ERROR_CODE.UNKNOWN],
14
- [{ code: CHARTKIT_ERROR_CODE.NO_DATA }, CHARTKIT_ERROR_CODE.NO_DATA],
15
- ])('check ChartKitError code (args: %j)', (args, expected) => {
16
- let result = '';
17
- try {
18
- throw new ChartKitError(args);
19
- }
20
- catch (error) {
21
- if (isChartKitError(error)) {
22
- result = error.code;
23
- }
24
- }
25
- expect(result).toEqual(expected);
26
- });
27
- });
@@ -1,17 +0,0 @@
1
- import { settings } from '../settings';
2
- const resetSettings = () => settings.set({ lang: 'en' });
3
- describe('libs/settings', () => {
4
- it('Default lang should be equal to en', () => {
5
- const result = settings.get('lang');
6
- expect(result).toBe('en');
7
- });
8
- it('Changed lang should be equal to ru', () => {
9
- settings.set({
10
- lang: 'ru',
11
- });
12
- const result = settings.get('lang');
13
- expect(result).toBe('ru');
14
- });
15
- beforeAll(resetSettings);
16
- afterEach(resetSettings);
17
- });
@@ -1,3 +0,0 @@
1
- declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react/dist/types-0a347bb9").R, import("@storybook/types").Args>;
2
- export default _default;
3
- export declare const Line: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, any>;
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import { ChartKit } from '../../../components/ChartKit';
3
- import { data } from '../mocks/line';
4
- import { ChartStory } from './components/ChartStory';
5
- export default {
6
- title: 'Plugins/Highcharts/Line',
7
- component: ChartKit,
8
- };
9
- const Template = () => {
10
- return React.createElement(ChartStory, { data: data });
11
- };
12
- export const Line = Template.bind({});
@@ -1,3 +0,0 @@
1
- declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react/dist/types-0a347bb9").R, import("@storybook/types").Args>;
2
- export default _default;
3
- export declare const Pie: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, any>;