@gravity-ui/chartkit 3.1.2 → 3.2.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/plugins/d3/__stories__/LinearCategories.stories.d.ts +4 -0
- package/build/plugins/d3/__stories__/LinearCategories.stories.js +101 -0
- package/build/plugins/d3/__stories__/Timestamp.stories.d.ts +4 -0
- package/build/plugins/d3/__stories__/Timestamp.stories.js +89 -0
- package/build/plugins/d3/__stories__/penguins.json +3098 -0
- package/build/plugins/d3/index.d.ts +7 -0
- package/build/plugins/d3/index.js +10 -0
- package/build/plugins/d3/renderer/D3Widget.d.ts +15 -0
- package/build/plugins/d3/renderer/D3Widget.js +40 -0
- package/build/plugins/d3/renderer/components/AxisX.d.ts +10 -0
- package/build/plugins/d3/renderer/components/AxisX.js +68 -0
- package/build/plugins/d3/renderer/components/AxisY.d.ts +10 -0
- package/build/plugins/d3/renderer/components/AxisY.js +73 -0
- package/build/plugins/d3/renderer/components/Chart.d.ts +10 -0
- package/build/plugins/d3/renderer/components/Chart.js +64 -0
- package/build/plugins/d3/renderer/components/Legend.d.ts +12 -0
- package/build/plugins/d3/renderer/components/Legend.js +66 -0
- package/build/plugins/d3/renderer/components/Title.d.ts +7 -0
- package/build/plugins/d3/renderer/components/Title.js +8 -0
- package/build/plugins/d3/renderer/components/Tooltip/DefaultContent.d.ts +10 -0
- package/build/plugins/d3/renderer/components/Tooltip/DefaultContent.js +21 -0
- package/build/plugins/d3/renderer/components/Tooltip/index.d.ts +12 -0
- package/build/plugins/d3/renderer/components/Tooltip/index.js +53 -0
- package/build/plugins/d3/renderer/components/index.d.ts +1 -0
- package/build/plugins/d3/renderer/components/index.js +1 -0
- package/build/plugins/d3/renderer/components/styles.css +61 -0
- package/build/plugins/d3/renderer/constants.d.ts +1 -0
- package/build/plugins/d3/renderer/constants.js +22 -0
- package/build/plugins/d3/renderer/hooks/index.d.ts +10 -0
- package/build/plugins/d3/renderer/hooks/index.js +10 -0
- package/build/plugins/d3/renderer/hooks/useChartDimensions/index.d.ts +17 -0
- package/build/plugins/d3/renderer/hooks/useChartDimensions/index.js +13 -0
- package/build/plugins/d3/renderer/hooks/useChartEvents/index.d.ts +5 -0
- package/build/plugins/d3/renderer/hooks/useChartEvents/index.js +15 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/chart.d.ts +8 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/chart.js +60 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/constants.d.ts +3 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/constants.js +3 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/index.d.ts +3 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/index.js +32 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/legend.d.ts +6 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/legend.js +5 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/title.d.ts +5 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/title.js +17 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/tooltip.d.ts +5 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/tooltip.js +5 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/types.d.ts +32 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/types.js +1 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/utils.d.ts +5 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/utils.js +18 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/x-axis.d.ts +5 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/x-axis.js +29 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/y-axis.d.ts +5 -0
- package/build/plugins/d3/renderer/hooks/useChartOptions/y-axis.js +34 -0
- package/build/plugins/d3/renderer/hooks/useLegend/index.d.ts +13 -0
- package/build/plugins/d3/renderer/hooks/useLegend/index.js +28 -0
- package/build/plugins/d3/renderer/hooks/useScales/index.d.ts +17 -0
- package/build/plugins/d3/renderer/hooks/useScales/index.js +101 -0
- package/build/plugins/d3/renderer/hooks/useSeries/index.d.ts +14 -0
- package/build/plugins/d3/renderer/hooks/useSeries/index.js +23 -0
- package/build/plugins/d3/renderer/hooks/useShapes/index.d.ts +19 -0
- package/build/plugins/d3/renderer/hooks/useShapes/index.js +73 -0
- package/build/plugins/d3/renderer/hooks/useTooltip/index.d.ts +13 -0
- package/build/plugins/d3/renderer/hooks/useTooltip/index.js +19 -0
- package/build/plugins/d3/renderer/hooks/useTooltip/types.d.ts +7 -0
- package/build/plugins/d3/renderer/hooks/useTooltip/types.js +1 -0
- package/build/plugins/d3/renderer/utils/index.d.ts +18 -0
- package/build/plugins/d3/renderer/utils/index.js +71 -0
- package/build/plugins/d3/types.d.ts +4 -0
- package/build/plugins/d3/types.js +1 -0
- package/build/types/widget-data/axis.d.ts +22 -0
- package/build/types/widget-data/axis.js +1 -0
- package/build/types/widget-data/base.d.ts +15 -0
- package/build/types/widget-data/base.js +1 -0
- package/build/types/widget-data/chart.d.ts +9 -0
- package/build/types/widget-data/chart.js +1 -0
- package/build/types/widget-data/index.d.ts +24 -0
- package/build/types/widget-data/index.js +9 -0
- package/build/types/widget-data/legend.d.ts +3 -0
- package/build/types/widget-data/legend.js +1 -0
- package/build/types/widget-data/pie.d.ts +10 -0
- package/build/types/widget-data/pie.js +1 -0
- package/build/types/widget-data/scatter.d.ts +20 -0
- package/build/types/widget-data/scatter.js +1 -0
- package/build/types/widget-data/series.d.ts +4 -0
- package/build/types/widget-data/series.js +1 -0
- package/build/types/widget-data/title.d.ts +5 -0
- package/build/types/widget-data/title.js +1 -0
- package/build/types/widget-data/tooltip.d.ts +12 -0
- package/build/types/widget-data/tooltip.js +1 -0
- package/build/types/widget.d.ts +5 -0
- package/package.json +4 -2
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
labels: {
|
|
36
|
+
enabled: false,
|
|
37
|
+
},
|
|
38
|
+
title: {
|
|
39
|
+
text: text('X axis title', ''),
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
let yAxis = {
|
|
43
|
+
title: {
|
|
44
|
+
text: text('Y axis title', ''),
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
if (categories && categoriesType === 'x') {
|
|
48
|
+
xAxis = Object.assign(Object.assign({}, xAxis), { type: 'category', categories });
|
|
49
|
+
}
|
|
50
|
+
if (categories && categoriesType === 'y') {
|
|
51
|
+
yAxis = Object.assign(Object.assign({}, yAxis), { type: 'category', categories });
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
series,
|
|
55
|
+
xAxis,
|
|
56
|
+
yAxis: [yAxis],
|
|
57
|
+
title: {
|
|
58
|
+
text: text('title', 'Chart title'),
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
const Template = () => {
|
|
63
|
+
const [shown, setShown] = React.useState(false);
|
|
64
|
+
const chartkitRef = React.useRef();
|
|
65
|
+
const x = select('x', ['culmen_length_mm', 'culmen_depth_mm', 'flipper_length_mm', 'body_mass_g'], 'culmen_length_mm');
|
|
66
|
+
const y = select('y', ['culmen_length_mm', 'culmen_depth_mm', 'flipper_length_mm', 'body_mass_g'], 'culmen_depth_mm');
|
|
67
|
+
const groupBy = select('groupBy', ['species', 'island', 'sex'], 'species');
|
|
68
|
+
const categoriesType = radios('categoriesType', { none: 'none', x: 'x', y: 'y' }, 'none');
|
|
69
|
+
const category = categoriesType === 'none'
|
|
70
|
+
? undefined
|
|
71
|
+
: select('category', ['species', 'island', 'sex'], 'island');
|
|
72
|
+
let categories;
|
|
73
|
+
if (categoriesType !== 'none' && category) {
|
|
74
|
+
categories = penguins.reduce((acc, p) => {
|
|
75
|
+
const cerrentCategory = p[category];
|
|
76
|
+
if (typeof cerrentCategory === 'string' && !acc.includes(cerrentCategory)) {
|
|
77
|
+
acc.push(cerrentCategory);
|
|
78
|
+
}
|
|
79
|
+
return acc;
|
|
80
|
+
}, []);
|
|
81
|
+
}
|
|
82
|
+
const shapedScatterSeriesData = shapeScatterSeriesData({
|
|
83
|
+
data: penguins,
|
|
84
|
+
groupBy,
|
|
85
|
+
map: { x, y, category },
|
|
86
|
+
});
|
|
87
|
+
const shapedScatterSeries = shapeScatterSeries(shapedScatterSeriesData);
|
|
88
|
+
const data = shapeScatterChartData(shapedScatterSeries, categoriesType, categories);
|
|
89
|
+
if (!shown) {
|
|
90
|
+
settings.set({ plugins: [D3Plugin] });
|
|
91
|
+
return React.createElement(Button, { onClick: () => setShown(true) }, "Show chart");
|
|
92
|
+
}
|
|
93
|
+
return (React.createElement("div", { style: { height: '80vh', width: '100%' } },
|
|
94
|
+
React.createElement(ChartKit, { ref: chartkitRef, type: "d3", data: data })));
|
|
95
|
+
};
|
|
96
|
+
export const LinearAndCategories = Template.bind({});
|
|
97
|
+
const meta = {
|
|
98
|
+
title: 'Plugins/D3',
|
|
99
|
+
decorators: [withKnobs],
|
|
100
|
+
};
|
|
101
|
+
export default meta;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import random from 'lodash/random';
|
|
3
|
+
import { dateTime } from '@gravity-ui/date-utils';
|
|
4
|
+
import { Button } from '@gravity-ui/uikit';
|
|
5
|
+
import { settings } from '../../../libs';
|
|
6
|
+
import { ChartKit } from '../../../components/ChartKit';
|
|
7
|
+
import { D3Plugin } from '..';
|
|
8
|
+
const rowData = [
|
|
9
|
+
{
|
|
10
|
+
x: 1690686000000,
|
|
11
|
+
y: 86.71905594602345,
|
|
12
|
+
custom: 'green',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
x: 1690426800000,
|
|
16
|
+
y: 86.73089353359981,
|
|
17
|
+
custom: 'yellow',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
x: 1690254000000,
|
|
21
|
+
y: 86.53675705168267,
|
|
22
|
+
custom: 'red',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
x: 1690772400000,
|
|
26
|
+
y: 86.47880981408552,
|
|
27
|
+
custom: 'blue',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
x: 1690340400000,
|
|
31
|
+
y: 86.4108836764148,
|
|
32
|
+
custom: 'gray',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
x: 1690599600000,
|
|
36
|
+
y: 86.73440096266042,
|
|
37
|
+
custom: 'pink',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
x: 1690513200000,
|
|
41
|
+
y: 86.64935929597681,
|
|
42
|
+
custom: 'purple',
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
const shapeData = (data) => {
|
|
46
|
+
const scatterData = data.map((d) => ({
|
|
47
|
+
x: d.x,
|
|
48
|
+
y: d.y,
|
|
49
|
+
radius: random(3, 6),
|
|
50
|
+
custom: d.custom,
|
|
51
|
+
}));
|
|
52
|
+
const scatterSeries = {
|
|
53
|
+
type: 'scatter',
|
|
54
|
+
data: scatterData,
|
|
55
|
+
name: 'some-name',
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
series: [scatterSeries],
|
|
59
|
+
xAxis: {
|
|
60
|
+
type: 'datetime',
|
|
61
|
+
timestamps: data.map((d) => d.x),
|
|
62
|
+
},
|
|
63
|
+
tooltip: {
|
|
64
|
+
renderer: ({ hovered }) => {
|
|
65
|
+
const d = hovered.data;
|
|
66
|
+
return React.createElement("div", { style: { color: d.custom } }, dateTime({ input: d.x }).format('LL'));
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
title: {
|
|
70
|
+
text: 'Chart title',
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const Template = () => {
|
|
75
|
+
const [shown, setShown] = React.useState(false);
|
|
76
|
+
const chartkitRef = React.useRef();
|
|
77
|
+
const data = shapeData(rowData);
|
|
78
|
+
if (!shown) {
|
|
79
|
+
settings.set({ plugins: [D3Plugin] });
|
|
80
|
+
return React.createElement(Button, { onClick: () => setShown(true) }, "Show chart");
|
|
81
|
+
}
|
|
82
|
+
return (React.createElement("div", { style: { height: '300px', width: '100%' } },
|
|
83
|
+
React.createElement(ChartKit, { ref: chartkitRef, type: "d3", data: data })));
|
|
84
|
+
};
|
|
85
|
+
export const Timestamp = Template.bind({});
|
|
86
|
+
const meta = {
|
|
87
|
+
title: 'Plugins/D3',
|
|
88
|
+
};
|
|
89
|
+
export default meta;
|