@gravity-ui/chartkit 3.2.0-beta.2 → 3.3.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/libs/chartkit-error/__tests__/chartkit-error.js +27 -0
- package/build/libs/settings/__tests__/settings.test.d.ts +1 -0
- package/build/libs/settings/__tests__/settings.test.js +17 -0
- package/build/plugins/d3/__stories__/bar-x/category.stories.d.ts +4 -0
- package/build/plugins/d3/__stories__/bar-x/category.stories.js +75 -0
- package/build/plugins/d3/__stories__/bar-x/datetime.stories.d.ts +4 -0
- package/build/plugins/d3/__stories__/bar-x/datetime.stories.js +71 -0
- package/build/plugins/d3/__stories__/bar-x/linear.stories.d.ts +4 -0
- package/build/plugins/d3/__stories__/bar-x/linear.stories.js +78 -0
- package/build/plugins/d3/__stories__/penguins.json +3098 -0
- package/build/plugins/d3/__stories__/scatter/LinearCategories.stories.d.ts +4 -0
- package/build/plugins/d3/__stories__/scatter/LinearCategories.stories.js +100 -0
- package/build/plugins/d3/__stories__/scatter/Timestamp.stories.d.ts +4 -0
- package/build/plugins/d3/__stories__/scatter/Timestamp.stories.js +108 -0
- package/build/plugins/d3/renderer/components/AxisX.js +15 -5
- package/build/plugins/d3/renderer/components/AxisY.js +18 -8
- package/build/plugins/d3/renderer/hooks/useChartOptions/chart.js +15 -8
- package/build/plugins/d3/renderer/hooks/useChartOptions/types.d.ts +7 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/x-axis.js +8 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/y-axis.js +7 -0
- package/build/plugins/d3/renderer/hooks/useScales/index.js +13 -10
- package/build/plugins/d3/renderer/hooks/useShapes/{bar.d.ts → bar-x.d.ts} +3 -3
- package/build/plugins/d3/renderer/hooks/useShapes/{bar.js → bar-x.js} +1 -1
- package/build/plugins/d3/renderer/hooks/useShapes/index.js +3 -3
- package/build/plugins/highcharts/__stories__/Line.stories.d.ts +3 -0
- package/build/plugins/highcharts/__stories__/Line.stories.js +12 -0
- package/build/plugins/highcharts/__stories__/Pie.stories.d.ts +3 -0
- package/build/plugins/highcharts/__stories__/Pie.stories.js +12 -0
- package/build/plugins/highcharts/__stories__/area/Range.stories.d.ts +3 -0
- package/build/plugins/highcharts/__stories__/area/Range.stories.js +12 -0
- package/build/plugins/highcharts/__stories__/area/Stacked.stories.d.ts +3 -0
- package/build/plugins/highcharts/__stories__/area/Stacked.stories.js +12 -0
- package/build/plugins/highcharts/__stories__/column/HorizontalStacked.stories.d.ts +3 -0
- package/build/plugins/highcharts/__stories__/column/HorizontalStacked.stories.js +12 -0
- package/build/plugins/highcharts/__stories__/column/Vertical.stories.d.ts +3 -0
- package/build/plugins/highcharts/__stories__/column/Vertical.stories.js +12 -0
- package/build/plugins/highcharts/__stories__/column/VerticalStacked.stories.d.ts +3 -0
- package/build/plugins/highcharts/__stories__/column/VerticalStacked.stories.js +12 -0
- package/build/plugins/highcharts/__stories__/combined/ComboChartWithSameLegendValues.stories.d.ts +3 -0
- package/build/plugins/highcharts/__stories__/combined/ComboChartWithSameLegendValues.stories.js +12 -0
- package/build/plugins/highcharts/__stories__/complex/TwoAxis.stories.d.ts +3 -0
- package/build/plugins/highcharts/__stories__/complex/TwoAxis.stories.js +12 -0
- package/build/plugins/highcharts/__stories__/components/ChartStory.d.ts +12 -0
- package/build/plugins/highcharts/__stories__/components/ChartStory.js +28 -0
- package/build/plugins/highcharts/__stories__/constants/story-settings.d.ts +42 -0
- package/build/plugins/highcharts/__stories__/constants/story-settings.js +42 -0
- package/build/plugins/highcharts/__stories__/custom-error-render/custom-error-render.stories.d.ts +3 -0
- package/build/plugins/highcharts/__stories__/custom-error-render/custom-error-render.stories.js +41 -0
- package/build/plugins/highcharts/__stories__/no-data/no-data.stories.d.ts +3 -0
- package/build/plugins/highcharts/__stories__/no-data/no-data.stories.js +20 -0
- package/build/plugins/highcharts/__stories__/pie/WithTotals.stories.d.ts +3 -0
- package/build/plugins/highcharts/__stories__/pie/WithTotals.stories.js +12 -0
- package/build/plugins/highcharts/__tests__/prepare-data.test.d.ts +1 -0
- package/build/plugins/highcharts/__tests__/prepare-data.test.js +13 -0
- package/build/plugins/indicator/__stories__/Indicator.stories.d.ts +4 -0
- package/build/plugins/indicator/__stories__/Indicator.stories.js +45 -0
- package/build/plugins/yagr/__stories__/Yagr.stories.d.ts +6 -0
- package/build/plugins/yagr/__stories__/Yagr.stories.js +90 -0
- package/build/plugins/yagr/__stories__/mocks/line10.d.ts +53 -0
- package/build/plugins/yagr/__stories__/mocks/line10.js +78 -0
- package/build/plugins/yagr/__tests__/utils.test.d.ts +1 -0
- package/build/plugins/yagr/__tests__/utils.test.js +26 -0
- package/build/types/widget-data/axis.d.ts +18 -0
- package/build/types/widget-data/{bar.d.ts → bar-x.d.ts} +4 -4
- package/build/types/widget-data/bar-x.js +1 -0
- package/build/types/widget-data/index.d.ts +1 -1
- package/build/types/widget-data/index.js +1 -1
- package/build/types/widget-data/series.d.ts +3 -3
- package/build/utils/__tests__/common.test.d.ts +1 -0
- package/build/utils/__tests__/common.test.js +9 -0
- package/package.json +2 -7
- /package/build/{types/widget-data/bar.js → libs/chartkit-error/__tests__/chartkit-error.d.ts} +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import random from 'lodash/random';
|
|
3
|
+
import { withKnobs, select, radios, text } from '@storybook/addon-knobs';
|
|
4
|
+
import { Button } from '@gravity-ui/uikit';
|
|
5
|
+
import { settings } from '../../../../libs';
|
|
6
|
+
import { ChartKit } from '../../../../components/ChartKit';
|
|
7
|
+
import { D3Plugin } from '../..';
|
|
8
|
+
import penguins from '../penguins.json';
|
|
9
|
+
const shapeScatterSeriesData = (args) => {
|
|
10
|
+
const { data, groupBy, map } = args;
|
|
11
|
+
return data.reduce((acc, d) => {
|
|
12
|
+
const seriesName = d[groupBy];
|
|
13
|
+
if (!seriesName) {
|
|
14
|
+
return acc;
|
|
15
|
+
}
|
|
16
|
+
if (!acc[seriesName]) {
|
|
17
|
+
acc[seriesName] = [];
|
|
18
|
+
}
|
|
19
|
+
acc[seriesName].push(Object.assign({ x: d[map.x], y: d[map.y], radius: random(3, 6) }, (map.category && { category: d[map.category] })));
|
|
20
|
+
return acc;
|
|
21
|
+
}, {});
|
|
22
|
+
};
|
|
23
|
+
const shapeScatterSeries = (data) => {
|
|
24
|
+
return Object.keys(data).reduce((acc, name) => {
|
|
25
|
+
acc.push({
|
|
26
|
+
type: 'scatter',
|
|
27
|
+
data: data[name],
|
|
28
|
+
name,
|
|
29
|
+
});
|
|
30
|
+
return acc;
|
|
31
|
+
}, []);
|
|
32
|
+
};
|
|
33
|
+
const shapeScatterChartData = (series, categoriesType, categories) => {
|
|
34
|
+
let xAxis = {
|
|
35
|
+
title: {
|
|
36
|
+
text: text('X axis title', ''),
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
let yAxis = {
|
|
40
|
+
title: {
|
|
41
|
+
text: text('Y axis title', ''),
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
if (categories && categoriesType === 'x') {
|
|
45
|
+
xAxis = Object.assign(Object.assign({}, xAxis), { type: 'category', categories });
|
|
46
|
+
}
|
|
47
|
+
if (categories && categoriesType === 'y') {
|
|
48
|
+
yAxis = Object.assign(Object.assign({}, yAxis), { type: 'category', categories });
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
series: {
|
|
52
|
+
data: series,
|
|
53
|
+
},
|
|
54
|
+
xAxis,
|
|
55
|
+
yAxis: [yAxis],
|
|
56
|
+
title: {
|
|
57
|
+
text: text('title', 'Chart title'),
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const Template = () => {
|
|
62
|
+
const [shown, setShown] = React.useState(false);
|
|
63
|
+
const chartkitRef = React.useRef();
|
|
64
|
+
const x = select('x', ['culmen_length_mm', 'culmen_depth_mm', 'flipper_length_mm', 'body_mass_g'], 'culmen_length_mm');
|
|
65
|
+
const y = select('y', ['culmen_length_mm', 'culmen_depth_mm', 'flipper_length_mm', 'body_mass_g'], 'culmen_depth_mm');
|
|
66
|
+
const groupBy = select('groupBy', ['species', 'island', 'sex'], 'species');
|
|
67
|
+
const categoriesType = radios('categoriesType', { none: 'none', x: 'x', y: 'y' }, 'none');
|
|
68
|
+
const category = categoriesType === 'none'
|
|
69
|
+
? undefined
|
|
70
|
+
: select('category', ['species', 'island', 'sex'], 'island');
|
|
71
|
+
let categories;
|
|
72
|
+
if (categoriesType !== 'none' && category) {
|
|
73
|
+
categories = penguins.reduce((acc, p) => {
|
|
74
|
+
const cerrentCategory = p[category];
|
|
75
|
+
if (typeof cerrentCategory === 'string' && !acc.includes(cerrentCategory)) {
|
|
76
|
+
acc.push(cerrentCategory);
|
|
77
|
+
}
|
|
78
|
+
return acc;
|
|
79
|
+
}, []);
|
|
80
|
+
}
|
|
81
|
+
const shapedScatterSeriesData = shapeScatterSeriesData({
|
|
82
|
+
data: penguins,
|
|
83
|
+
groupBy,
|
|
84
|
+
map: { x, y, category },
|
|
85
|
+
});
|
|
86
|
+
const shapedScatterSeries = shapeScatterSeries(shapedScatterSeriesData);
|
|
87
|
+
const data = shapeScatterChartData(shapedScatterSeries, categoriesType, categories);
|
|
88
|
+
if (!shown) {
|
|
89
|
+
settings.set({ plugins: [D3Plugin] });
|
|
90
|
+
return React.createElement(Button, { onClick: () => setShown(true) }, "Show chart");
|
|
91
|
+
}
|
|
92
|
+
return (React.createElement("div", { style: { height: '80vh', width: '100%' } },
|
|
93
|
+
React.createElement(ChartKit, { ref: chartkitRef, type: "d3", data: data })));
|
|
94
|
+
};
|
|
95
|
+
export const LinearAndCategories = Template.bind({});
|
|
96
|
+
const meta = {
|
|
97
|
+
title: 'Plugins/D3/Scatter',
|
|
98
|
+
decorators: [withKnobs],
|
|
99
|
+
};
|
|
100
|
+
export default meta;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import random from 'lodash/random';
|
|
3
|
+
import { boolean, number } from '@storybook/addon-knobs';
|
|
4
|
+
import { dateTime } from '@gravity-ui/date-utils';
|
|
5
|
+
import { Button } from '@gravity-ui/uikit';
|
|
6
|
+
import { settings } from '../../../../libs';
|
|
7
|
+
import { ChartKit } from '../../../../components/ChartKit';
|
|
8
|
+
import { D3Plugin } from '../..';
|
|
9
|
+
const rowData = [
|
|
10
|
+
{
|
|
11
|
+
x: 1690686000000,
|
|
12
|
+
y: 86.71905594602345,
|
|
13
|
+
custom: 'green',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
x: 1690426800000,
|
|
17
|
+
y: 86.73089353359981,
|
|
18
|
+
custom: 'yellow',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
x: 1690254000000,
|
|
22
|
+
y: 86.53675705168267,
|
|
23
|
+
custom: 'red',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
x: 1690772400000,
|
|
27
|
+
y: 86.47880981408552,
|
|
28
|
+
custom: 'blue',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
x: 1690340400000,
|
|
32
|
+
y: 86.4108836764148,
|
|
33
|
+
custom: 'gray',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
x: 1690599600000,
|
|
37
|
+
y: 86.73440096266042,
|
|
38
|
+
custom: 'pink',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
x: 1690513200000,
|
|
42
|
+
y: 86.64935929597681,
|
|
43
|
+
custom: 'purple',
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
const shapeData = (data) => {
|
|
47
|
+
const scatterData = data.map((d) => ({
|
|
48
|
+
x: d.x,
|
|
49
|
+
y: d.y,
|
|
50
|
+
radius: random(3, 6),
|
|
51
|
+
custom: d.custom,
|
|
52
|
+
}));
|
|
53
|
+
const scatterSeries = {
|
|
54
|
+
type: 'scatter',
|
|
55
|
+
data: scatterData,
|
|
56
|
+
name: 'some-name',
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
series: {
|
|
60
|
+
data: [scatterSeries],
|
|
61
|
+
},
|
|
62
|
+
xAxis: {
|
|
63
|
+
type: 'datetime',
|
|
64
|
+
timestamps: data.map((d) => d.x),
|
|
65
|
+
grid: {
|
|
66
|
+
enabled: boolean('xAxis.grid.enabled', true),
|
|
67
|
+
},
|
|
68
|
+
labels: {
|
|
69
|
+
enabled: boolean('xAxis.labels.enabled', true),
|
|
70
|
+
},
|
|
71
|
+
ticks: {
|
|
72
|
+
pixelInterval: number('xAxis.ticks.pixelInterval', 100),
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
yAxis: [
|
|
76
|
+
{
|
|
77
|
+
grid: {
|
|
78
|
+
enabled: boolean('yAxis.grid.enabled', true),
|
|
79
|
+
},
|
|
80
|
+
labels: {
|
|
81
|
+
enabled: boolean('yAxis.labels.enabled', true),
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
tooltip: {
|
|
86
|
+
renderer: ({ hovered }) => {
|
|
87
|
+
const d = hovered.data;
|
|
88
|
+
return React.createElement("div", { style: { color: d.custom } }, dateTime({ input: d.x }).format('LL'));
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const Template = () => {
|
|
94
|
+
const [shown, setShown] = React.useState(false);
|
|
95
|
+
const chartkitRef = React.useRef();
|
|
96
|
+
const data = shapeData(rowData);
|
|
97
|
+
if (!shown) {
|
|
98
|
+
settings.set({ plugins: [D3Plugin] });
|
|
99
|
+
return React.createElement(Button, { onClick: () => setShown(true) }, "Show chart");
|
|
100
|
+
}
|
|
101
|
+
return (React.createElement("div", { style: { height: '300px', width: '100%' } },
|
|
102
|
+
React.createElement(ChartKit, { ref: chartkitRef, type: "d3", data: data })));
|
|
103
|
+
};
|
|
104
|
+
export const Timestamp = Template.bind({});
|
|
105
|
+
const meta = {
|
|
106
|
+
title: 'Plugins/D3/Scatter',
|
|
107
|
+
};
|
|
108
|
+
export default meta;
|
|
@@ -31,20 +31,30 @@ export const AxisX = ({ axis, width, height, scale }) => {
|
|
|
31
31
|
}
|
|
32
32
|
const svgElement = select(ref.current);
|
|
33
33
|
svgElement.selectAll('*').remove();
|
|
34
|
-
const
|
|
35
|
-
|
|
34
|
+
const tickSize = axis.grid.enabled ? height * -1 : 0;
|
|
35
|
+
let xAxisGenerator = axisBottom(scale)
|
|
36
|
+
.tickSize(tickSize)
|
|
36
37
|
.tickPadding(axis.labels.padding)
|
|
37
38
|
.tickFormat((value) => {
|
|
39
|
+
if (!axis.labels.enabled) {
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
38
42
|
return formatAxisTickLabel({
|
|
39
43
|
axisType: axis.type,
|
|
40
44
|
value,
|
|
41
|
-
dateFormat: axis.labels
|
|
42
|
-
numberFormat: axis.labels
|
|
45
|
+
dateFormat: axis.labels['dateFormat'],
|
|
46
|
+
numberFormat: axis.labels['numberFormat'],
|
|
43
47
|
});
|
|
44
48
|
});
|
|
49
|
+
if (axis.ticks.pixelInterval) {
|
|
50
|
+
const ticksCount = width / axis.ticks.pixelInterval;
|
|
51
|
+
xAxisGenerator = xAxisGenerator.ticks(ticksCount);
|
|
52
|
+
}
|
|
45
53
|
svgElement.call(xAxisGenerator).attr('class', b());
|
|
46
54
|
svgElement.select('.domain').attr('d', `M0,0V0H${width}`);
|
|
47
|
-
|
|
55
|
+
if (axis.labels.enabled) {
|
|
56
|
+
svgElement.selectAll('.tick text').style('font-size', axis.labels.style.fontSize);
|
|
57
|
+
}
|
|
48
58
|
const transformStyle = svgElement.select('.tick').attr('transform');
|
|
49
59
|
const { x } = parseTransformStyle(transformStyle);
|
|
50
60
|
if (x === 0) {
|
|
@@ -32,23 +32,33 @@ export const AxisY = ({ axises, width, height, scale }) => {
|
|
|
32
32
|
const axis = axises[0];
|
|
33
33
|
const svgElement = select(ref.current);
|
|
34
34
|
svgElement.selectAll('*').remove();
|
|
35
|
-
const
|
|
36
|
-
|
|
35
|
+
const tickSize = axis.grid.enabled ? width * -1 : 0;
|
|
36
|
+
let yAxisGenerator = axisLeft(scale)
|
|
37
|
+
.tickSize(tickSize)
|
|
37
38
|
.tickPadding(axis.labels.padding)
|
|
38
39
|
.tickFormat((value) => {
|
|
40
|
+
if (!axis.labels.enabled) {
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
39
43
|
return formatAxisTickLabel({
|
|
40
44
|
axisType: axis.type,
|
|
41
45
|
value,
|
|
42
|
-
dateFormat: axis.labels
|
|
43
|
-
numberFormat: axis.labels
|
|
46
|
+
dateFormat: axis.labels['dateFormat'],
|
|
47
|
+
numberFormat: axis.labels['numberFormat'],
|
|
44
48
|
});
|
|
45
49
|
});
|
|
50
|
+
if (axis.ticks.pixelInterval) {
|
|
51
|
+
const ticksCount = height / axis.ticks.pixelInterval;
|
|
52
|
+
yAxisGenerator = yAxisGenerator.ticks(ticksCount);
|
|
53
|
+
}
|
|
46
54
|
svgElement.call(yAxisGenerator).attr('class', b());
|
|
47
55
|
svgElement.select('.domain').attr('d', `M0,${height}H0V0`);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
if (axis.labels.enabled) {
|
|
57
|
+
svgElement
|
|
58
|
+
.selectAll('.tick text')
|
|
59
|
+
.style('font-size', axis.labels.style.fontSize)
|
|
60
|
+
.style('transform', 'translateY(-1px)');
|
|
61
|
+
}
|
|
52
62
|
const transformStyle = svgElement.select('.tick').attr('transform');
|
|
53
63
|
const { y } = parseTransformStyle(transformStyle);
|
|
54
64
|
if (y === height) {
|
|
@@ -24,12 +24,15 @@ const getAxisLabelMaxWidth = (args) => {
|
|
|
24
24
|
maxDomainValue = max(domain);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
let formattedValue = '';
|
|
28
|
+
if (axis.labels.enabled) {
|
|
29
|
+
formattedValue = formatAxisTickLabel({
|
|
30
|
+
axisType: axis.type,
|
|
31
|
+
value: maxDomainValue,
|
|
32
|
+
dateFormat: axis.labels['dateFormat'],
|
|
33
|
+
numberFormat: axis.labels['numberFormat'],
|
|
34
|
+
});
|
|
35
|
+
}
|
|
33
36
|
select(document.body)
|
|
34
37
|
.append('text')
|
|
35
38
|
.style('font-size', axis.labels.style.fontSize)
|
|
@@ -49,10 +52,14 @@ export const getPreparedChart = (args) => {
|
|
|
49
52
|
preparedY1Axis.labels.padding +
|
|
50
53
|
getAxisLabelMaxWidth({ axis: preparedY1Axis, series: series.data }) +
|
|
51
54
|
(preparedY1Axis.title.height || 0);
|
|
55
|
+
const marginTop = get(chart, 'margin.top', 0) +
|
|
56
|
+
getHorisontalSvgTextDimensions({ text: 'Tmp', style: preparedY1Axis.labels.style }) / 2;
|
|
57
|
+
const marginRight = get(chart, 'margin.right', 0) +
|
|
58
|
+
getAxisLabelMaxWidth({ axis: preparedXAxis, series: series.data }) / 2;
|
|
52
59
|
return {
|
|
53
60
|
margin: {
|
|
54
|
-
top:
|
|
55
|
-
right:
|
|
61
|
+
top: marginTop,
|
|
62
|
+
right: marginRight,
|
|
56
63
|
bottom: marginBottom,
|
|
57
64
|
left: marginLeft,
|
|
58
65
|
},
|
|
@@ -15,6 +15,13 @@ export type PreparedAxis = Omit<ChartKitWidgetAxis, 'type' | 'labels'> & {
|
|
|
15
15
|
style: BaseTextStyle;
|
|
16
16
|
};
|
|
17
17
|
min?: number;
|
|
18
|
+
grid: {
|
|
19
|
+
enabled: boolean;
|
|
20
|
+
};
|
|
21
|
+
maxPadding: number;
|
|
22
|
+
ticks: {
|
|
23
|
+
pixelInterval?: number;
|
|
24
|
+
};
|
|
18
25
|
};
|
|
19
26
|
export type PreparedTitle = ChartKitWidgetData['title'] & {
|
|
20
27
|
height: number;
|
|
@@ -24,6 +24,14 @@ export const getPreparedXAxis = ({ xAxis }) => {
|
|
|
24
24
|
? getHorisontalSvgTextDimensions({ text: titleText, style: titleStyle })
|
|
25
25
|
: 0,
|
|
26
26
|
},
|
|
27
|
+
min: get(xAxis, 'min'),
|
|
28
|
+
maxPadding: get(xAxis, 'maxPadding', 0.01),
|
|
29
|
+
grid: {
|
|
30
|
+
enabled: get(xAxis, 'grid.enabled', true),
|
|
31
|
+
},
|
|
32
|
+
ticks: {
|
|
33
|
+
pixelInterval: get(xAxis, 'ticks.pixelInterval'),
|
|
34
|
+
},
|
|
27
35
|
};
|
|
28
36
|
return preparedXAxis;
|
|
29
37
|
};
|
|
@@ -30,6 +30,13 @@ export const getPreparedYAxis = ({ yAxis }) => {
|
|
|
30
30
|
: 0,
|
|
31
31
|
},
|
|
32
32
|
min: get(yAxis1, 'min'),
|
|
33
|
+
maxPadding: get(yAxis1, 'maxPadding', 0.05),
|
|
34
|
+
grid: {
|
|
35
|
+
enabled: get(yAxis1, 'grid.enabled', true),
|
|
36
|
+
},
|
|
37
|
+
ticks: {
|
|
38
|
+
pixelInterval: get(yAxis1, 'ticks.pixelInterval'),
|
|
39
|
+
},
|
|
33
40
|
};
|
|
34
41
|
return [preparedY1Axis];
|
|
35
42
|
};
|
|
@@ -15,6 +15,7 @@ const filterCategoriesByVisibleSeries = (categories, series) => {
|
|
|
15
15
|
export const useScales = (args) => {
|
|
16
16
|
const { boundsWidth, boundsHeight, series, xAxis, yAxis } = args;
|
|
17
17
|
const scales = React.useMemo(() => {
|
|
18
|
+
const xMin = get(xAxis, 'min');
|
|
18
19
|
const xType = get(xAxis, 'type', 'linear');
|
|
19
20
|
const xCategories = get(xAxis, 'categories');
|
|
20
21
|
const xTimestamps = get(xAxis, 'timestamps');
|
|
@@ -31,9 +32,11 @@ export const useScales = (args) => {
|
|
|
31
32
|
switch (xType) {
|
|
32
33
|
case 'linear': {
|
|
33
34
|
const domain = getDomainDataXBySeries(visibleSeries);
|
|
35
|
+
const range = [0, boundsWidth - boundsWidth * xAxis.maxPadding];
|
|
34
36
|
if (isNumericalArrayData(domain)) {
|
|
35
|
-
const [
|
|
36
|
-
|
|
37
|
+
const [domainXMin, xMax] = extent(domain);
|
|
38
|
+
const xMinValue = typeof xMin === 'number' ? xMin : domainXMin;
|
|
39
|
+
xScale = scaleLinear().domain([xMinValue, xMax]).range(range).nice();
|
|
37
40
|
}
|
|
38
41
|
break;
|
|
39
42
|
}
|
|
@@ -45,15 +48,16 @@ export const useScales = (args) => {
|
|
|
45
48
|
break;
|
|
46
49
|
}
|
|
47
50
|
case 'datetime': {
|
|
51
|
+
const range = [0, boundsWidth - boundsWidth * xAxis.maxPadding];
|
|
48
52
|
if (xTimestamps) {
|
|
49
53
|
const [xMin, xMax] = extent(xTimestamps);
|
|
50
|
-
xScale = scaleUtc().domain([xMin, xMax]).range(
|
|
54
|
+
xScale = scaleUtc().domain([xMin, xMax]).range(range).nice();
|
|
51
55
|
}
|
|
52
56
|
else {
|
|
53
57
|
const domain = getDomainDataXBySeries(visibleSeries);
|
|
54
58
|
if (isNumericalArrayData(domain)) {
|
|
55
59
|
const [xMin, xMax] = extent(domain);
|
|
56
|
-
xScale = scaleUtc().domain([xMin, xMax]).range(
|
|
60
|
+
xScale = scaleUtc().domain([xMin, xMax]).range(range).nice();
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
break;
|
|
@@ -65,13 +69,11 @@ export const useScales = (args) => {
|
|
|
65
69
|
switch (yType) {
|
|
66
70
|
case 'linear': {
|
|
67
71
|
const domain = getDomainDataYBySeries(visibleSeries);
|
|
72
|
+
const range = [boundsHeight, boundsHeight * yAxis[0].maxPadding];
|
|
68
73
|
if (isNumericalArrayData(domain)) {
|
|
69
74
|
const [domainYMin, yMax] = extent(domain);
|
|
70
75
|
const yMinValue = typeof yMin === 'number' ? yMin : domainYMin;
|
|
71
|
-
yScale = scaleLinear()
|
|
72
|
-
.domain([yMinValue, yMax])
|
|
73
|
-
.range([boundsHeight, 0])
|
|
74
|
-
.nice();
|
|
76
|
+
yScale = scaleLinear().domain([yMinValue, yMax]).range(range).nice();
|
|
75
77
|
}
|
|
76
78
|
break;
|
|
77
79
|
}
|
|
@@ -83,15 +85,16 @@ export const useScales = (args) => {
|
|
|
83
85
|
break;
|
|
84
86
|
}
|
|
85
87
|
case 'datetime': {
|
|
88
|
+
const range = [boundsHeight, boundsHeight * yAxis[0].maxPadding];
|
|
86
89
|
if (yTimestamps) {
|
|
87
90
|
const [yMin, yMax] = extent(yTimestamps);
|
|
88
|
-
yScale = scaleUtc().domain([yMin, yMax]).range(
|
|
91
|
+
yScale = scaleUtc().domain([yMin, yMax]).range(range).nice();
|
|
89
92
|
}
|
|
90
93
|
else {
|
|
91
94
|
const domain = getDomainDataYBySeries(visibleSeries);
|
|
92
95
|
if (isNumericalArrayData(domain)) {
|
|
93
96
|
const [yMin, yMax] = extent(domain);
|
|
94
|
-
yScale = scaleUtc().domain([yMin, yMax]).range(
|
|
97
|
+
yScale = scaleUtc().domain([yMin, yMax]).range(range).nice();
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
100
|
break;
|
|
@@ -2,9 +2,9 @@ import React from 'react';
|
|
|
2
2
|
import { ChartOptions } from '../useChartOptions/types';
|
|
3
3
|
import { ChartScale } from '../useScales';
|
|
4
4
|
import { OnSeriesMouseLeave, OnSeriesMouseMove } from '../useTooltip/types';
|
|
5
|
-
import {
|
|
5
|
+
import { BarXSeries } from '../../../../../types/widget-data';
|
|
6
6
|
type Args = {
|
|
7
|
-
series:
|
|
7
|
+
series: BarXSeries[];
|
|
8
8
|
xAxis: ChartOptions['xAxis'];
|
|
9
9
|
xScale: ChartScale;
|
|
10
10
|
yAxis: ChartOptions['yAxis'];
|
|
@@ -12,5 +12,5 @@ type Args = {
|
|
|
12
12
|
onSeriesMouseMove?: OnSeriesMouseMove;
|
|
13
13
|
onSeriesMouseLeave?: OnSeriesMouseLeave;
|
|
14
14
|
};
|
|
15
|
-
export declare function
|
|
15
|
+
export declare function prepareBarXSeries(args: Args): React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
|
|
16
16
|
export {};
|
|
@@ -46,7 +46,7 @@ function minDiff(arr) {
|
|
|
46
46
|
}
|
|
47
47
|
return result;
|
|
48
48
|
}
|
|
49
|
-
export function
|
|
49
|
+
export function prepareBarXSeries(args) {
|
|
50
50
|
const { series, xAxis, xScale, yAxis, yScale, onSeriesMouseMove, onSeriesMouseLeave } = args;
|
|
51
51
|
const seriesData = series.map(({ data }) => data).flat(2);
|
|
52
52
|
const minPointDistance = minDiff(seriesData.map((item) => Number(item.x)));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { group } from 'd3';
|
|
3
3
|
import { getOnlyVisibleSeries } from '../../utils';
|
|
4
|
-
import {
|
|
4
|
+
import { prepareBarXSeries } from './bar-x';
|
|
5
5
|
import { prepareScatterSeries } from './scatter';
|
|
6
6
|
export const useShapes = (args) => {
|
|
7
7
|
const { series, xAxis, xScale, yAxis, yScale, svgContainer, onSeriesMouseMove, onSeriesMouseLeave, } = args;
|
|
@@ -11,8 +11,8 @@ export const useShapes = (args) => {
|
|
|
11
11
|
return Array.from(groupedSeries).reduce((acc, item) => {
|
|
12
12
|
const [seriesType, chartSeries] = item;
|
|
13
13
|
switch (seriesType) {
|
|
14
|
-
case 'bar': {
|
|
15
|
-
acc.push(...
|
|
14
|
+
case 'bar-x': {
|
|
15
|
+
acc.push(...prepareBarXSeries({
|
|
16
16
|
series: chartSeries,
|
|
17
17
|
xAxis,
|
|
18
18
|
xScale,
|
|
@@ -0,0 +1,3 @@
|
|
|
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>;
|
|
@@ -0,0 +1,12 @@
|
|
|
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({});
|
|
@@ -0,0 +1,3 @@
|
|
|
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>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ChartKit } from '../../../components/ChartKit';
|
|
3
|
+
import { data } from '../mocks/pie';
|
|
4
|
+
import { ChartStory } from './components/ChartStory';
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Plugins/Highcharts/Pie',
|
|
7
|
+
component: ChartKit,
|
|
8
|
+
};
|
|
9
|
+
const Template = () => {
|
|
10
|
+
return React.createElement(ChartStory, { data: data });
|
|
11
|
+
};
|
|
12
|
+
export const Pie = Template.bind({});
|
|
@@ -0,0 +1,3 @@
|
|
|
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 AreaRange: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, any>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ChartKit } from '../../../../components/ChartKit';
|
|
3
|
+
import { data } from '../../mocks/area-range';
|
|
4
|
+
import { ChartStory } from '../components/ChartStory';
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Plugins/Highcharts/Area',
|
|
7
|
+
component: ChartKit,
|
|
8
|
+
};
|
|
9
|
+
const Template = () => {
|
|
10
|
+
return React.createElement(ChartStory, { data: data });
|
|
11
|
+
};
|
|
12
|
+
export const AreaRange = Template.bind({});
|
|
@@ -0,0 +1,3 @@
|
|
|
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 AreaStacked: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, any>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ChartKit } from '../../../../components/ChartKit';
|
|
3
|
+
import { data } from '../../mocks/area-stacked';
|
|
4
|
+
import { ChartStory } from '../components/ChartStory';
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Plugins/Highcharts/Area',
|
|
7
|
+
component: ChartKit,
|
|
8
|
+
};
|
|
9
|
+
const Template = () => {
|
|
10
|
+
return React.createElement(ChartStory, { data: data, height: "500px" });
|
|
11
|
+
};
|
|
12
|
+
export const AreaStacked = Template.bind({});
|
|
@@ -0,0 +1,3 @@
|
|
|
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 HorizontalStacked: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, any>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ChartKit } from '../../../../components/ChartKit';
|
|
3
|
+
import { data } from '../../mocks/column-hor-stacked';
|
|
4
|
+
import { ChartStory } from '../components/ChartStory';
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Plugins/Highcharts/Column',
|
|
7
|
+
component: ChartKit,
|
|
8
|
+
};
|
|
9
|
+
const Template = () => {
|
|
10
|
+
return React.createElement(ChartStory, { data: data });
|
|
11
|
+
};
|
|
12
|
+
export const HorizontalStacked = Template.bind({});
|
|
@@ -0,0 +1,3 @@
|
|
|
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 Vertical: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, any>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ChartKit } from '../../../../components/ChartKit';
|
|
3
|
+
import { data } from '../../mocks/column-ver';
|
|
4
|
+
import { ChartStory } from '../components/ChartStory';
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Plugins/Highcharts/Column',
|
|
7
|
+
component: ChartKit,
|
|
8
|
+
};
|
|
9
|
+
const Template = () => {
|
|
10
|
+
return React.createElement(ChartStory, { data: data });
|
|
11
|
+
};
|
|
12
|
+
export const Vertical = Template.bind({});
|
|
@@ -0,0 +1,3 @@
|
|
|
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 VerticalStacked: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, any>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ChartKit } from '../../../../components/ChartKit';
|
|
3
|
+
import { data } from '../../mocks/column-ver-stacked';
|
|
4
|
+
import { ChartStory } from '../components/ChartStory';
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Plugins/Highcharts/Column',
|
|
7
|
+
component: ChartKit,
|
|
8
|
+
};
|
|
9
|
+
const Template = () => {
|
|
10
|
+
return React.createElement(ChartStory, { data: data });
|
|
11
|
+
};
|
|
12
|
+
export const VerticalStacked = Template.bind({});
|
package/build/plugins/highcharts/__stories__/combined/ComboChartWithSameLegendValues.stories.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
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 ComboChart: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, any>;
|