@gravity-ui/chartkit 3.4.2 → 3.5.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.
- package/build/components/ChartKit.js +2 -2
- package/build/components/Loader/Loader.js +2 -2
- package/build/plugins/d3/renderer/D3Widget.js +3 -3
- package/build/plugins/d3/renderer/components/AxisX.js +2 -2
- package/build/plugins/d3/renderer/components/AxisY.js +2 -2
- package/build/plugins/d3/renderer/components/Chart.d.ts +3 -1
- package/build/plugins/d3/renderer/components/Chart.js +11 -6
- package/build/plugins/d3/renderer/components/Legend.js +80 -61
- package/build/plugins/d3/renderer/components/Title.js +2 -2
- package/build/plugins/d3/renderer/components/Tooltip/DefaultContent.js +12 -0
- package/build/plugins/d3/renderer/components/Tooltip/index.js +2 -2
- package/build/plugins/d3/renderer/components/styles.css +4 -13
- package/build/plugins/d3/renderer/hooks/index.d.ts +1 -1
- package/build/plugins/d3/renderer/hooks/index.js +1 -1
- package/build/plugins/d3/renderer/hooks/{useScales → useAxisScales}/index.d.ts +6 -3
- package/build/plugins/d3/renderer/hooks/useAxisScales/index.js +122 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/chart.js +19 -12
- package/build/plugins/d3/renderer/hooks/useChartOptions/index.d.ts +3 -1
- package/build/plugins/d3/renderer/hooks/useLegend/index.js +35 -4
- package/build/plugins/d3/renderer/hooks/useSeries/index.js +48 -10
- package/build/plugins/d3/renderer/hooks/useShapes/bar-x.d.ts +4 -1
- package/build/plugins/d3/renderer/hooks/useShapes/bar-x.js +7 -4
- package/build/plugins/d3/renderer/hooks/useShapes/index.d.ts +8 -3
- package/build/plugins/d3/renderer/hooks/useShapes/index.js +46 -21
- package/build/plugins/d3/renderer/hooks/useShapes/pie.d.ts +13 -0
- package/build/plugins/d3/renderer/hooks/useShapes/pie.js +51 -0
- package/build/plugins/d3/renderer/hooks/useShapes/scatter.d.ts +3 -1
- package/build/plugins/d3/renderer/hooks/useShapes/scatter.js +5 -4
- package/build/plugins/d3/renderer/hooks/useShapes/styles.css +16 -0
- package/build/plugins/d3/renderer/utils/index.d.ts +7 -1
- package/build/plugins/d3/renderer/utils/index.js +7 -12
- package/build/plugins/d3/renderer/utils/math.d.ts +23 -0
- package/build/plugins/d3/renderer/utils/math.js +43 -0
- package/build/plugins/highcharts/renderer/components/HighchartsComponent.js +1 -1
- package/build/plugins/highcharts/renderer/components/HighchartsReact.d.ts +18 -0
- package/build/plugins/highcharts/renderer/components/HighchartsReact.js +46 -0
- package/build/plugins/highcharts/renderer/components/StyledSplitPane/StyledSplitPane.js +2 -2
- package/build/plugins/highcharts/renderer/components/withSplitPane/withSplitPane.js +2 -2
- package/build/plugins/highcharts/renderer/helpers/config/config.js +2 -2
- package/build/plugins/highcharts/renderer/helpers/config/options.js +2 -2
- package/build/plugins/index.d.ts +1 -0
- package/build/plugins/index.js +1 -0
- package/build/plugins/indicator/renderer/IndicatorItem.js +2 -2
- package/build/plugins/indicator/renderer/IndicatorWidget.js +2 -2
- package/build/types/widget-data/bar-x.d.ts +1 -1
- package/build/types/widget-data/base.d.ts +3 -0
- package/build/types/widget-data/pie.d.ts +18 -1
- package/build/types/widget-data/scatter.d.ts +1 -1
- package/build/utils/cn.d.ts +3 -0
- package/build/utils/cn.js +4 -0
- package/package.json +4 -6
- package/build/plugins/d3/renderer/hooks/useScales/index.js +0 -109
package/build/plugins/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import block from '
|
|
3
|
-
const b = block('
|
|
2
|
+
import { block } from '../../../utils/cn';
|
|
3
|
+
const b = block('indicator');
|
|
4
4
|
export const IndicatorItem = (props) => {
|
|
5
5
|
const { formatNumber, content, color, defaultColor, size, title, nowrap } = props;
|
|
6
6
|
const mods = { size, nowrap };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import block from 'bem-cn-lite';
|
|
3
2
|
import { isEmpty } from 'lodash';
|
|
4
3
|
import { i18n } from '../../../i18n';
|
|
5
4
|
import { CHARTKIT_ERROR_CODE, ChartKitError } from '../../../libs';
|
|
6
5
|
import { CHARTKIT_SCROLLABLE_NODE_CLASSNAME } from '../../../constants';
|
|
7
6
|
import { getChartPerformanceDuration, getRandomCKId, markChartPerformance } from '../../../utils';
|
|
7
|
+
import { block } from '../../../utils/cn';
|
|
8
8
|
import { IndicatorItem } from './IndicatorItem';
|
|
9
9
|
import './IndicatorWidget.css';
|
|
10
|
-
const b = block('
|
|
10
|
+
const b = block('indicator');
|
|
11
11
|
const IndicatorWidget = React.forwardRef(
|
|
12
12
|
// _ref needs to avoid this React warning:
|
|
13
13
|
// "forwardRef render functions accept exactly two parameters: props and ref"
|
|
@@ -11,7 +11,7 @@ export type BarXSeriesData<T = any> = BaseSeriesData<T> & {
|
|
|
11
11
|
export type BarXSeries<T = any> = BaseSeries & {
|
|
12
12
|
type: 'bar-x';
|
|
13
13
|
data: BarXSeriesData<T>[];
|
|
14
|
-
/** The name of the series (used in legend) */
|
|
14
|
+
/** The name of the series (used in legend, tooltip etc) */
|
|
15
15
|
name: string;
|
|
16
16
|
/** The main color of the series (hex, rgba) */
|
|
17
17
|
color?: string;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import type { ChartKitWidgetLegend } from './legend';
|
|
1
2
|
export type BaseSeries = {
|
|
3
|
+
/** Individual series legend options. Has higher priority than legend options in widget data */
|
|
4
|
+
legend?: ChartKitWidgetLegend;
|
|
2
5
|
/** Initial visibility of the series */
|
|
3
6
|
visible?: boolean;
|
|
4
7
|
};
|
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
import type { BaseSeries, BaseSeriesData } from './base';
|
|
2
2
|
export type PieSeriesData<T = any> = BaseSeriesData<T> & {
|
|
3
|
+
/** The value of the pie segment. */
|
|
3
4
|
value: number;
|
|
4
|
-
|
|
5
|
+
/** The name of the pie segment (used in legend, tooltip etc). */
|
|
5
6
|
name: string;
|
|
7
|
+
/** Individual color for the pie segment. */
|
|
8
|
+
color?: string;
|
|
9
|
+
/** Initial visibility of the pie segment. */
|
|
10
|
+
visible?: boolean;
|
|
6
11
|
};
|
|
7
12
|
export type PieSeries<T = any> = BaseSeries & {
|
|
8
13
|
type: 'pie';
|
|
9
14
|
data: PieSeriesData<T>[];
|
|
15
|
+
/** The color of the border surrounding each segment. Default `--g-color-base-background` from @gravity-ui/uikit. */
|
|
16
|
+
borderColor?: string;
|
|
17
|
+
/** The width of the border surrounding each segment. Default 1px. */
|
|
18
|
+
borderWidth?: number;
|
|
19
|
+
/** The corner radius of the border surrounding each segment. Default 0. */
|
|
20
|
+
borderRadius?: number;
|
|
21
|
+
/** The center of the pie chart relative to the chart area. */
|
|
22
|
+
center?: [string | number | null, string | number | null];
|
|
23
|
+
/** The inner radius of the pie. Default 0. */
|
|
24
|
+
innerRadius?: string | number;
|
|
25
|
+
/** The radius of the pie relative to the chart area. The default behaviour is to scale to the chart area. */
|
|
26
|
+
radius?: string | number;
|
|
10
27
|
};
|
|
@@ -11,7 +11,7 @@ export type ScatterSeriesData<T = any> = BaseSeriesData<T> & {
|
|
|
11
11
|
export type ScatterSeries<T = any> = BaseSeries & {
|
|
12
12
|
type: 'scatter';
|
|
13
13
|
data: ScatterSeriesData<T>[];
|
|
14
|
-
/** The name of the series (used in legend) */
|
|
14
|
+
/** The name of the series (used in legend, tooltip etc) */
|
|
15
15
|
name: string;
|
|
16
16
|
/** The main color of the series (hex, rgba) */
|
|
17
17
|
color?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/chartkit",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
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",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"access": "public"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
+
"@bem-react/classname": "^1.6.0",
|
|
18
19
|
"@gravity-ui/date-utils": "^1.4.1",
|
|
19
|
-
"@gravity-ui/yagr": "^3.7.
|
|
20
|
-
"bem-cn-lite": "^4.1.0",
|
|
20
|
+
"@gravity-ui/yagr": "^3.7.10",
|
|
21
21
|
"d3": "^7.8.5",
|
|
22
22
|
"lodash": "^4.17.21",
|
|
23
23
|
"react-split-pane": "^0.1.92"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@gravity-ui/prettier-config": "^1.0.1",
|
|
32
32
|
"@gravity-ui/stylelint-config": "^1.0.1",
|
|
33
33
|
"@gravity-ui/tsconfig": "^1.0.0",
|
|
34
|
-
"@gravity-ui/uikit": "^5.
|
|
34
|
+
"@gravity-ui/uikit": "^5.6.0",
|
|
35
35
|
"@storybook/addon-essentials": "^7.0.26",
|
|
36
36
|
"@storybook/addon-knobs": "^7.0.2",
|
|
37
37
|
"@storybook/cli": "^7.0.26",
|
|
@@ -54,7 +54,6 @@
|
|
|
54
54
|
"gulp-replace": "^1.1.3",
|
|
55
55
|
"gulp-typescript": "^5.0.1",
|
|
56
56
|
"highcharts": "^8.2.2",
|
|
57
|
-
"highcharts-react-official": "^3.2.0",
|
|
58
57
|
"husky": "^4.2.5",
|
|
59
58
|
"jest": "^28.1.3",
|
|
60
59
|
"jest-environment-jsdom": "^28.1.2",
|
|
@@ -77,7 +76,6 @@
|
|
|
77
76
|
"peerDependencies": {
|
|
78
77
|
"@gravity-ui/uikit": "^5.0.0",
|
|
79
78
|
"highcharts": "^8.2.2",
|
|
80
|
-
"highcharts-react-official": "^3.2.0",
|
|
81
79
|
"react": "^16.0.0 || ^17.0.0 || ^18.0.0"
|
|
82
80
|
},
|
|
83
81
|
"scripts": {
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { scaleBand, scaleLinear, scaleUtc, extent } from 'd3';
|
|
3
|
-
import get from 'lodash/get';
|
|
4
|
-
import { getOnlyVisibleSeries, getDomainDataXBySeries, getDomainDataYBySeries } from '../../utils';
|
|
5
|
-
const isNumericalArrayData = (data) => {
|
|
6
|
-
return data.every((d) => typeof d === 'number' || d === null);
|
|
7
|
-
};
|
|
8
|
-
const filterCategoriesByVisibleSeries = (categories, series) => {
|
|
9
|
-
return categories.filter((category) => {
|
|
10
|
-
return series.some((s) => {
|
|
11
|
-
return s.data.some((d) => 'category' in d && d.category === category);
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
export const useScales = (args) => {
|
|
16
|
-
const { boundsWidth, boundsHeight, series, xAxis, yAxis } = args;
|
|
17
|
-
const scales = React.useMemo(() => {
|
|
18
|
-
const xMin = get(xAxis, 'min');
|
|
19
|
-
const xType = get(xAxis, 'type', 'linear');
|
|
20
|
-
const xCategories = get(xAxis, 'categories');
|
|
21
|
-
const xTimestamps = get(xAxis, 'timestamps');
|
|
22
|
-
const yType = get(yAxis[0], 'type', 'linear');
|
|
23
|
-
const yMin = get(yAxis[0], 'min');
|
|
24
|
-
const yCategories = get(yAxis[0], 'categories');
|
|
25
|
-
const yTimestamps = get(xAxis, 'timestamps');
|
|
26
|
-
let visibleSeries = getOnlyVisibleSeries(series);
|
|
27
|
-
// Reassign to all series in case of all series unselected,
|
|
28
|
-
// otherwise we will get an empty space without grid
|
|
29
|
-
visibleSeries = visibleSeries.length === 0 ? series : visibleSeries;
|
|
30
|
-
let xScale;
|
|
31
|
-
let yScale;
|
|
32
|
-
switch (xType) {
|
|
33
|
-
case 'linear': {
|
|
34
|
-
const domain = getDomainDataXBySeries(visibleSeries);
|
|
35
|
-
const range = [0, boundsWidth - boundsWidth * xAxis.maxPadding];
|
|
36
|
-
if (isNumericalArrayData(domain)) {
|
|
37
|
-
const [domainXMin, xMax] = extent(domain);
|
|
38
|
-
const xMinValue = typeof xMin === 'number' ? xMin : domainXMin;
|
|
39
|
-
xScale = scaleLinear().domain([xMinValue, xMax]).range(range).nice();
|
|
40
|
-
}
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
case 'category': {
|
|
44
|
-
if (xCategories) {
|
|
45
|
-
const filteredCategories = filterCategoriesByVisibleSeries(xCategories, visibleSeries);
|
|
46
|
-
xScale = scaleBand().domain(filteredCategories).range([0, boundsWidth]);
|
|
47
|
-
}
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
case 'datetime': {
|
|
51
|
-
const range = [0, boundsWidth - boundsWidth * xAxis.maxPadding];
|
|
52
|
-
if (xTimestamps) {
|
|
53
|
-
const [xMin, xMax] = extent(xTimestamps);
|
|
54
|
-
xScale = scaleUtc().domain([xMin, xMax]).range(range).nice();
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
const domain = getDomainDataXBySeries(visibleSeries);
|
|
58
|
-
if (isNumericalArrayData(domain)) {
|
|
59
|
-
const [xMin, xMax] = extent(domain);
|
|
60
|
-
xScale = scaleUtc().domain([xMin, xMax]).range(range).nice();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (!xScale) {
|
|
67
|
-
throw new Error('Failed to create xScale');
|
|
68
|
-
}
|
|
69
|
-
switch (yType) {
|
|
70
|
-
case 'linear': {
|
|
71
|
-
const domain = getDomainDataYBySeries(visibleSeries);
|
|
72
|
-
const range = [boundsHeight, boundsHeight * yAxis[0].maxPadding];
|
|
73
|
-
if (isNumericalArrayData(domain)) {
|
|
74
|
-
const [domainYMin, yMax] = extent(domain);
|
|
75
|
-
const yMinValue = typeof yMin === 'number' ? yMin : domainYMin;
|
|
76
|
-
yScale = scaleLinear().domain([yMinValue, yMax]).range(range).nice();
|
|
77
|
-
}
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
case 'category': {
|
|
81
|
-
if (yCategories) {
|
|
82
|
-
const filteredCategories = filterCategoriesByVisibleSeries(yCategories, visibleSeries);
|
|
83
|
-
yScale = scaleBand().domain(filteredCategories).range([boundsHeight, 0]);
|
|
84
|
-
}
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
case 'datetime': {
|
|
88
|
-
const range = [boundsHeight, boundsHeight * yAxis[0].maxPadding];
|
|
89
|
-
if (yTimestamps) {
|
|
90
|
-
const [yMin, yMax] = extent(yTimestamps);
|
|
91
|
-
yScale = scaleUtc().domain([yMin, yMax]).range(range).nice();
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
const domain = getDomainDataYBySeries(visibleSeries);
|
|
95
|
-
if (isNumericalArrayData(domain)) {
|
|
96
|
-
const [yMin, yMax] = extent(domain);
|
|
97
|
-
yScale = scaleUtc().domain([yMin, yMax]).range(range).nice();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (!yScale) {
|
|
104
|
-
throw new Error('Failed to create yScale');
|
|
105
|
-
}
|
|
106
|
-
return { xScale, yScale };
|
|
107
|
-
}, [boundsWidth, boundsHeight, series, xAxis, yAxis]);
|
|
108
|
-
return scales;
|
|
109
|
-
};
|