@spaced-out/ui-design-system 0.1.85 → 0.1.87-beta.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/.cspell/custom-words.txt +5 -1
- package/.storybook/preview-head.html +4 -0
- package/CHANGELOG.md +14 -0
- package/design-tokens/color/app-color.json +26 -0
- package/design-tokens/font/base-font.json +1 -1
- package/design-tokens/size/base-size.json +12 -0
- package/lib/components/ChartWrapper/ChartWrapper.js +124 -0
- package/lib/components/ChartWrapper/ChartWrapper.js.flow +156 -0
- package/lib/components/ChartWrapper/ChartWrapper.module.css +19 -0
- package/lib/components/ChartWrapper/index.js +16 -0
- package/lib/components/ChartWrapper/index.js.flow +3 -0
- package/lib/components/Charts/ChartTooltip.js +18 -0
- package/lib/components/Charts/ChartTooltip.js.flow +15 -0
- package/lib/components/Charts/ChartTooltip.module.css +36 -0
- package/lib/components/Charts/index.js +71 -0
- package/lib/components/Charts/index.js.flow +8 -0
- package/lib/components/ColumnChart/ColumnChart.js +79 -0
- package/lib/components/ColumnChart/ColumnChart.js.flow +108 -0
- package/lib/components/ColumnChart/ColumnChart.module.css +12 -0
- package/lib/components/ColumnChart/index.js +16 -0
- package/lib/components/ColumnChart/index.js.flow +3 -0
- package/lib/components/DonutChart/DonutChart.js +94 -0
- package/lib/components/DonutChart/DonutChart.js.flow +146 -0
- package/lib/components/DonutChart/DonutChart.module.css +65 -0
- package/lib/components/DonutChart/index.js +16 -0
- package/lib/components/DonutChart/index.js.flow +3 -0
- package/lib/components/Grid/Grid.js +19 -8
- package/lib/components/Grid/Grid.js.flow +24 -7
- package/lib/components/Grid/Grid.module.css +1 -2
- package/lib/components/Icon/index.js +31 -25
- package/lib/components/Icon/index.js.flow +3 -6
- package/lib/components/LineChart/LineChart.js +64 -0
- package/lib/components/LineChart/LineChart.js.flow +85 -0
- package/lib/components/LineChart/LineChart.module.css +17 -0
- package/lib/components/LineChart/index.js +16 -0
- package/lib/components/LineChart/index.js.flow +3 -0
- package/lib/components/SpiderChart/SpiderChart.js +88 -0
- package/lib/components/SpiderChart/SpiderChart.js.flow +123 -0
- package/lib/components/SpiderChart/SpiderChart.module.css +17 -0
- package/lib/components/SpiderChart/index.js +16 -0
- package/lib/components/SpiderChart/index.js.flow +3 -0
- package/lib/components/index.js +11 -0
- package/lib/components/index.js.flow +1 -0
- package/lib/styles/index.css +25 -1
- package/lib/styles/index.js +28 -4
- package/lib/styles/index.js.flow +25 -1
- package/lib/styles/variables/_color.css +16 -0
- package/lib/styles/variables/_color.js +17 -1
- package/lib/styles/variables/_color.js.flow +16 -0
- package/lib/styles/variables/_font.css +1 -1
- package/lib/styles/variables/_font.js +1 -1
- package/lib/styles/variables/_font.js.flow +1 -1
- package/lib/styles/variables/_size.css +8 -0
- package/lib/styles/variables/_size.js +9 -1
- package/lib/styles/variables/_size.js.flow +8 -0
- package/lib/types/charts.js +0 -0
- package/lib/types/charts.js.flow +151 -0
- package/lib/utils/charts/charts.js +71 -0
- package/lib/utils/charts/charts.js.flow +89 -0
- package/lib/utils/charts/columnChart.js +55 -0
- package/lib/utils/charts/columnChart.js.flow +59 -0
- package/lib/utils/charts/donutChart.js +114 -0
- package/lib/utils/charts/donutChart.js.flow +138 -0
- package/lib/utils/charts/helpers.js +65 -0
- package/lib/utils/charts/helpers.js.flow +68 -0
- package/lib/utils/charts/index.js +82 -0
- package/lib/utils/charts/index.js.flow +9 -0
- package/lib/utils/charts/lineChart.js +47 -0
- package/lib/utils/charts/lineChart.js.flow +49 -0
- package/lib/utils/charts/spiderChart.js +59 -0
- package/lib/utils/charts/spiderChart.js.flow +72 -0
- package/lib/utils/charts/typography.js +59 -0
- package/lib/utils/charts/typography.js.flow +67 -0
- package/package.json +4 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ColumnChart = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _highcharts = _interopRequireDefault(require("highcharts"));
|
|
9
|
+
var _highchartsReactOfficial = _interopRequireDefault(require("highcharts-react-official"));
|
|
10
|
+
var _charts = require("../../utils/charts");
|
|
11
|
+
var _classify = _interopRequireDefault(require("../../utils/classify"));
|
|
12
|
+
var _ChartWrapper = require("../ChartWrapper");
|
|
13
|
+
var _ColumnChartModule = _interopRequireDefault(require("./ColumnChart.module.css"));
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
16
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
+
|
|
18
|
+
//$FlowFixMe[untyped-import]
|
|
19
|
+
|
|
20
|
+
//$FlowFixMe[untyped-import]
|
|
21
|
+
|
|
22
|
+
const ColumnChart = _ref => {
|
|
23
|
+
let {
|
|
24
|
+
classNames,
|
|
25
|
+
cardTitle,
|
|
26
|
+
customExportOptions,
|
|
27
|
+
series,
|
|
28
|
+
drilldown,
|
|
29
|
+
headerActions,
|
|
30
|
+
...userOptions
|
|
31
|
+
} = _ref;
|
|
32
|
+
const chartRef = /*#__PURE__*/React.createRef();
|
|
33
|
+
const columnChartSeries = series.map((seriesItem, index) => ({
|
|
34
|
+
...seriesItem,
|
|
35
|
+
name: seriesItem.name,
|
|
36
|
+
data: seriesItem.data,
|
|
37
|
+
color: (0, _charts.getDataVizColor)(index),
|
|
38
|
+
pointWidth: _charts.columnPlotWidth
|
|
39
|
+
}));
|
|
40
|
+
const addColorToDrilldownSeries = series => series?.map(seriesItem => ({
|
|
41
|
+
...seriesItem,
|
|
42
|
+
data: seriesItem.data.map((dataItem, index) => ({
|
|
43
|
+
...dataItem,
|
|
44
|
+
color: (0, _charts.getDataVizColor)(index),
|
|
45
|
+
pointWidth: _charts.columnPlotWidth
|
|
46
|
+
}))
|
|
47
|
+
}));
|
|
48
|
+
const columnDrilldown = drilldown ? {
|
|
49
|
+
...drilldown,
|
|
50
|
+
series: addColorToDrilldownSeries(drilldown.series)
|
|
51
|
+
} : {};
|
|
52
|
+
const defaultColumnChartOptions = (0, _charts.getColumnChartOptions)();
|
|
53
|
+
|
|
54
|
+
//$FlowFixMe[cannot-spread-inexact]
|
|
55
|
+
const chartOptions = (0, _charts.mergeChartUserOptions)(defaultColumnChartOptions, {
|
|
56
|
+
series: columnChartSeries,
|
|
57
|
+
drilldown: columnDrilldown,
|
|
58
|
+
...userOptions
|
|
59
|
+
});
|
|
60
|
+
const {
|
|
61
|
+
highChart,
|
|
62
|
+
...wrapperClassNames
|
|
63
|
+
} = classNames || {};
|
|
64
|
+
return /*#__PURE__*/React.createElement(_ChartWrapper.ChartWrapper, {
|
|
65
|
+
title: cardTitle,
|
|
66
|
+
ref: chartRef,
|
|
67
|
+
classNames: wrapperClassNames,
|
|
68
|
+
customExportOptions: customExportOptions,
|
|
69
|
+
headerActions: headerActions
|
|
70
|
+
}, /*#__PURE__*/React.createElement(_highchartsReactOfficial.default, {
|
|
71
|
+
highcharts: _highcharts.default,
|
|
72
|
+
containerProps: {
|
|
73
|
+
className: (0, _classify.default)(_ColumnChartModule.default.columnChartContainer, highChart)
|
|
74
|
+
},
|
|
75
|
+
ref: chartRef,
|
|
76
|
+
options: chartOptions
|
|
77
|
+
}));
|
|
78
|
+
};
|
|
79
|
+
exports.ColumnChart = ColumnChart;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// @flow strict
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
//$FlowFixMe[untyped-import]
|
|
5
|
+
import Highcharts from 'highcharts';
|
|
6
|
+
//$FlowFixMe[untyped-import]
|
|
7
|
+
import HighchartsReact from 'highcharts-react-official';
|
|
8
|
+
|
|
9
|
+
import type {Drilldown} from '../../types/charts';
|
|
10
|
+
import {
|
|
11
|
+
columnPlotWidth,
|
|
12
|
+
getColumnChartOptions,
|
|
13
|
+
getDataVizColor,
|
|
14
|
+
mergeChartUserOptions,
|
|
15
|
+
} from '../../utils/charts';
|
|
16
|
+
import classify from '../../utils/classify';
|
|
17
|
+
import type {ChartWrapperClassNames, ExportOptionType} from '../ChartWrapper';
|
|
18
|
+
import {ChartWrapper} from '../ChartWrapper';
|
|
19
|
+
|
|
20
|
+
import css from './ColumnChart.module.css';
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
type ClassNames = $ReadOnly<{
|
|
24
|
+
...ChartWrapperClassNames,
|
|
25
|
+
highChart?: string,
|
|
26
|
+
}>;
|
|
27
|
+
|
|
28
|
+
type ColumnSeriesItem = {
|
|
29
|
+
name: string,
|
|
30
|
+
data: [],
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type ColumnChartProps = {
|
|
34
|
+
classNames?: ClassNames,
|
|
35
|
+
cardTitle?: string,
|
|
36
|
+
customExportOptions?: Array<ExportOptionType> | null,
|
|
37
|
+
series: Array<ColumnSeriesItem>,
|
|
38
|
+
drilldown: Drilldown,
|
|
39
|
+
headerActions?: React.Node,
|
|
40
|
+
...
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const ColumnChart = ({
|
|
44
|
+
classNames,
|
|
45
|
+
cardTitle,
|
|
46
|
+
customExportOptions,
|
|
47
|
+
series,
|
|
48
|
+
drilldown,
|
|
49
|
+
headerActions,
|
|
50
|
+
...userOptions
|
|
51
|
+
}: ColumnChartProps): React.Node => {
|
|
52
|
+
const chartRef = React.createRef();
|
|
53
|
+
|
|
54
|
+
const columnChartSeries = series.map((seriesItem, index) => ({
|
|
55
|
+
...seriesItem,
|
|
56
|
+
name: seriesItem.name,
|
|
57
|
+
data: seriesItem.data,
|
|
58
|
+
color: getDataVizColor(index),
|
|
59
|
+
pointWidth: columnPlotWidth,
|
|
60
|
+
}));
|
|
61
|
+
|
|
62
|
+
const addColorToDrilldownSeries = (series) =>
|
|
63
|
+
series?.map((seriesItem) => ({
|
|
64
|
+
...seriesItem,
|
|
65
|
+
data: seriesItem.data.map((dataItem, index) => ({
|
|
66
|
+
...dataItem,
|
|
67
|
+
color: getDataVizColor(index),
|
|
68
|
+
pointWidth: columnPlotWidth,
|
|
69
|
+
})),
|
|
70
|
+
}));
|
|
71
|
+
|
|
72
|
+
const columnDrilldown = drilldown
|
|
73
|
+
? {
|
|
74
|
+
...drilldown,
|
|
75
|
+
series: addColorToDrilldownSeries(drilldown.series),
|
|
76
|
+
}
|
|
77
|
+
: {};
|
|
78
|
+
|
|
79
|
+
const defaultColumnChartOptions = getColumnChartOptions();
|
|
80
|
+
|
|
81
|
+
//$FlowFixMe[cannot-spread-inexact]
|
|
82
|
+
const chartOptions = mergeChartUserOptions(defaultColumnChartOptions, {
|
|
83
|
+
series: columnChartSeries,
|
|
84
|
+
drilldown: columnDrilldown,
|
|
85
|
+
...userOptions,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const {highChart, ...wrapperClassNames} = classNames || {};
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<ChartWrapper
|
|
92
|
+
title={cardTitle}
|
|
93
|
+
ref={chartRef}
|
|
94
|
+
classNames={wrapperClassNames}
|
|
95
|
+
customExportOptions={customExportOptions}
|
|
96
|
+
headerActions={headerActions}
|
|
97
|
+
>
|
|
98
|
+
<HighchartsReact
|
|
99
|
+
highcharts={Highcharts}
|
|
100
|
+
containerProps={{
|
|
101
|
+
className: classify(css.columnChartContainer, highChart),
|
|
102
|
+
}}
|
|
103
|
+
ref={chartRef}
|
|
104
|
+
options={chartOptions}
|
|
105
|
+
/>
|
|
106
|
+
</ChartWrapper>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
@value (colorFillPrimary) from '../../styles/variables/_color.css';
|
|
2
|
+
@value (size400, size660, sizeFluid) from '../../styles/variables/_size.css';
|
|
3
|
+
|
|
4
|
+
.columnChartContainer {
|
|
5
|
+
width: sizeFluid;
|
|
6
|
+
min-width: size660;
|
|
7
|
+
min-height: size400;
|
|
8
|
+
max-height: size400;
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
justify-content: center;
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _ColumnChart = require("./ColumnChart");
|
|
7
|
+
Object.keys(_ColumnChart).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _ColumnChart[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _ColumnChart[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DonutChart = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _highcharts = _interopRequireDefault(require("highcharts"));
|
|
9
|
+
var _highchartsReactOfficial = _interopRequireDefault(require("highcharts-react-official"));
|
|
10
|
+
var _charts = require("../../utils/charts");
|
|
11
|
+
var _classify = _interopRequireDefault(require("../../utils/classify"));
|
|
12
|
+
var _ChartWrapper = require("../ChartWrapper");
|
|
13
|
+
var _typographyModule = _interopRequireDefault(require("../../styles/typography.module.css"));
|
|
14
|
+
var _DonutChartModule = _interopRequireDefault(require("./DonutChart.module.css"));
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
18
|
+
|
|
19
|
+
//$FlowFixMe[untyped-import]
|
|
20
|
+
|
|
21
|
+
//$FlowFixMe[untyped-import]
|
|
22
|
+
|
|
23
|
+
const DonutChart = _ref => {
|
|
24
|
+
let {
|
|
25
|
+
classNames,
|
|
26
|
+
cardTitle,
|
|
27
|
+
customExportOptions,
|
|
28
|
+
headerActions,
|
|
29
|
+
series,
|
|
30
|
+
drilldown,
|
|
31
|
+
legend,
|
|
32
|
+
centerText,
|
|
33
|
+
centerSubtext,
|
|
34
|
+
...userOptions
|
|
35
|
+
} = _ref;
|
|
36
|
+
const chartRef = React.useRef();
|
|
37
|
+
const {
|
|
38
|
+
highChart,
|
|
39
|
+
subtitleClassNames,
|
|
40
|
+
...wrapperClassNames
|
|
41
|
+
} = classNames || {};
|
|
42
|
+
const defaultCenterHTML = `<span class=${(0, _classify.default)(_DonutChartModule.default.subtitleWrap, subtitleClassNames?.wrapper)}>
|
|
43
|
+
<span class="${(0, _classify.default)(_typographyModule.default.jumboMedium, _DonutChartModule.default.subtitleText, subtitleClassNames?.text)}">
|
|
44
|
+
${centerText ? centerText : ''}
|
|
45
|
+
</span>
|
|
46
|
+
<span class="${(0, _classify.default)(_typographyModule.default.bodySmall, _DonutChartModule.default.subtitleSubtext, subtitleClassNames?.subtext)}">
|
|
47
|
+
${centerSubtext ? centerSubtext : ''}
|
|
48
|
+
</span>
|
|
49
|
+
<span>`;
|
|
50
|
+
const donutChartSeries = series.map(seriesItem => ({
|
|
51
|
+
...seriesItem,
|
|
52
|
+
data: seriesItem.data.map((dataItem, index) => ({
|
|
53
|
+
...dataItem,
|
|
54
|
+
color: (0, _charts.getDataVizColor)(index)
|
|
55
|
+
}))
|
|
56
|
+
}));
|
|
57
|
+
const addColorToDrilldownSeries = series => series?.map(seriesItem => ({
|
|
58
|
+
...seriesItem,
|
|
59
|
+
data: seriesItem.data.map((dataItem, index) => ({
|
|
60
|
+
...dataItem,
|
|
61
|
+
color: (0, _charts.getDataVizColor)(index)
|
|
62
|
+
}))
|
|
63
|
+
}));
|
|
64
|
+
const donutDrilldown = drilldown ? {
|
|
65
|
+
...drilldown,
|
|
66
|
+
series: addColorToDrilldownSeries(drilldown.series)
|
|
67
|
+
} : {};
|
|
68
|
+
const defaultLineChartOptions = (0, _charts.getDonutChartOptions)({
|
|
69
|
+
legend,
|
|
70
|
+
defaultCenterHTML
|
|
71
|
+
});
|
|
72
|
+
const chartOptions = (0, _charts.mergeChartUserOptions)(defaultLineChartOptions, {
|
|
73
|
+
series: donutChartSeries,
|
|
74
|
+
drilldown: donutDrilldown,
|
|
75
|
+
...userOptions
|
|
76
|
+
});
|
|
77
|
+
return /*#__PURE__*/React.createElement(_ChartWrapper.ChartWrapper, {
|
|
78
|
+
title: cardTitle
|
|
79
|
+
//$FlowFixMe[incompatible-type]
|
|
80
|
+
,
|
|
81
|
+
ref: chartRef,
|
|
82
|
+
customExportOptions: customExportOptions,
|
|
83
|
+
headerActions: headerActions,
|
|
84
|
+
classNames: wrapperClassNames
|
|
85
|
+
}, /*#__PURE__*/React.createElement(_highchartsReactOfficial.default, {
|
|
86
|
+
highcharts: _highcharts.default,
|
|
87
|
+
containerProps: {
|
|
88
|
+
className: (0, _classify.default)(_DonutChartModule.default.donutChartContainer, highChart)
|
|
89
|
+
},
|
|
90
|
+
ref: chartRef,
|
|
91
|
+
options: chartOptions
|
|
92
|
+
}));
|
|
93
|
+
};
|
|
94
|
+
exports.DonutChart = DonutChart;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// @flow strict
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
//$FlowFixMe[untyped-import]
|
|
5
|
+
import Highcharts from 'highcharts';
|
|
6
|
+
//$FlowFixMe[untyped-import]
|
|
7
|
+
import HighchartsReact from 'highcharts-react-official';
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
Drilldown,
|
|
11
|
+
LegendOptionsType,
|
|
12
|
+
SeriesOptionsType,
|
|
13
|
+
} from '../../types/charts';
|
|
14
|
+
import {
|
|
15
|
+
getDataVizColor,
|
|
16
|
+
getDonutChartOptions,
|
|
17
|
+
mergeChartUserOptions,
|
|
18
|
+
} from '../../utils/charts';
|
|
19
|
+
import classify from '../../utils/classify';
|
|
20
|
+
import type {ChartWrapperClassNames, ExportOptionType} from '../ChartWrapper';
|
|
21
|
+
import {ChartWrapper} from '../ChartWrapper';
|
|
22
|
+
|
|
23
|
+
import typographyCss from '../../styles/typography.module.css';
|
|
24
|
+
import css from './DonutChart.module.css';
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
type ClassNames = $ReadOnly<{
|
|
28
|
+
...ChartWrapperClassNames,
|
|
29
|
+
highChart?: string,
|
|
30
|
+
subtitleClassNames?: SubtitleClassNames,
|
|
31
|
+
}>;
|
|
32
|
+
type DonutChartData = {
|
|
33
|
+
name: string,
|
|
34
|
+
value: number,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type SubtitleClassNames = {
|
|
38
|
+
wrapper?: string,
|
|
39
|
+
text?: string,
|
|
40
|
+
subtext?: string,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type DonutChartProps = {
|
|
44
|
+
classNames?: ClassNames,
|
|
45
|
+
cardTitle?: React.Node,
|
|
46
|
+
customExportOptions?: Array<ExportOptionType> | null,
|
|
47
|
+
headerActions?: React.Node,
|
|
48
|
+
centerText?: string,
|
|
49
|
+
centerSubtext?: string,
|
|
50
|
+
series: Array<SeriesOptionsType>,
|
|
51
|
+
drilldown: Drilldown,
|
|
52
|
+
legend?: LegendOptionsType,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const DonutChart = ({
|
|
56
|
+
classNames,
|
|
57
|
+
cardTitle,
|
|
58
|
+
customExportOptions,
|
|
59
|
+
headerActions,
|
|
60
|
+
series,
|
|
61
|
+
drilldown,
|
|
62
|
+
legend,
|
|
63
|
+
centerText,
|
|
64
|
+
centerSubtext,
|
|
65
|
+
...userOptions
|
|
66
|
+
}: DonutChartProps): React.Node => {
|
|
67
|
+
const chartRef = React.useRef();
|
|
68
|
+
|
|
69
|
+
const {highChart, subtitleClassNames, ...wrapperClassNames} =
|
|
70
|
+
classNames || {};
|
|
71
|
+
|
|
72
|
+
const defaultCenterHTML = `<span class=${classify(
|
|
73
|
+
css.subtitleWrap,
|
|
74
|
+
subtitleClassNames?.wrapper,
|
|
75
|
+
)}>
|
|
76
|
+
<span class="${classify(
|
|
77
|
+
typographyCss.jumboMedium,
|
|
78
|
+
css.subtitleText,
|
|
79
|
+
subtitleClassNames?.text,
|
|
80
|
+
)}">
|
|
81
|
+
${centerText ? centerText : ''}
|
|
82
|
+
</span>
|
|
83
|
+
<span class="${classify(
|
|
84
|
+
typographyCss.bodySmall,
|
|
85
|
+
css.subtitleSubtext,
|
|
86
|
+
subtitleClassNames?.subtext,
|
|
87
|
+
)}">
|
|
88
|
+
${centerSubtext ? centerSubtext : ''}
|
|
89
|
+
</span>
|
|
90
|
+
<span>`;
|
|
91
|
+
|
|
92
|
+
const donutChartSeries = series.map((seriesItem) => ({
|
|
93
|
+
...seriesItem,
|
|
94
|
+
data: seriesItem.data.map((dataItem, index) => ({
|
|
95
|
+
...dataItem,
|
|
96
|
+
color: getDataVizColor(index),
|
|
97
|
+
})),
|
|
98
|
+
}));
|
|
99
|
+
|
|
100
|
+
const addColorToDrilldownSeries = (series) =>
|
|
101
|
+
series?.map((seriesItem) => ({
|
|
102
|
+
...seriesItem,
|
|
103
|
+
data: seriesItem.data.map((dataItem, index) => ({
|
|
104
|
+
...dataItem,
|
|
105
|
+
color: getDataVizColor(index),
|
|
106
|
+
})),
|
|
107
|
+
}));
|
|
108
|
+
|
|
109
|
+
const donutDrilldown = drilldown
|
|
110
|
+
? {
|
|
111
|
+
...drilldown,
|
|
112
|
+
series: addColorToDrilldownSeries(drilldown.series),
|
|
113
|
+
}
|
|
114
|
+
: {};
|
|
115
|
+
|
|
116
|
+
const defaultLineChartOptions = getDonutChartOptions({
|
|
117
|
+
legend,
|
|
118
|
+
defaultCenterHTML,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const chartOptions = mergeChartUserOptions(defaultLineChartOptions, {
|
|
122
|
+
series: donutChartSeries,
|
|
123
|
+
drilldown: donutDrilldown,
|
|
124
|
+
...userOptions,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<ChartWrapper
|
|
129
|
+
title={cardTitle}
|
|
130
|
+
//$FlowFixMe[incompatible-type]
|
|
131
|
+
ref={chartRef}
|
|
132
|
+
customExportOptions={customExportOptions}
|
|
133
|
+
headerActions={headerActions}
|
|
134
|
+
classNames={wrapperClassNames}
|
|
135
|
+
>
|
|
136
|
+
<HighchartsReact
|
|
137
|
+
highcharts={Highcharts}
|
|
138
|
+
containerProps={{
|
|
139
|
+
className: classify(css.donutChartContainer, highChart),
|
|
140
|
+
}}
|
|
141
|
+
ref={chartRef}
|
|
142
|
+
options={chartOptions}
|
|
143
|
+
/>
|
|
144
|
+
</ChartWrapper>
|
|
145
|
+
);
|
|
146
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
@value (
|
|
2
|
+
fontSize12,
|
|
3
|
+
fontSize36,
|
|
4
|
+
fontWeightMedium,
|
|
5
|
+
fontWeightBook,
|
|
6
|
+
fontLineHeight100,
|
|
7
|
+
fontLineHeight130,
|
|
8
|
+
fontLetterSpacingMinus3,
|
|
9
|
+
fontLetterSpacing4
|
|
10
|
+
) from '../../styles/variables/_font.css';
|
|
11
|
+
|
|
12
|
+
@value (colorTextPrimary, colorTextSecondary) from '../../styles/variables/_color.css';
|
|
13
|
+
@value (size240, size300, size400, size500, sizeFluid) from '../../styles/variables/_size.css';
|
|
14
|
+
|
|
15
|
+
@value (spaceNone, spaceXSmall) from '../../styles/variables/_space.css';
|
|
16
|
+
|
|
17
|
+
.wrapper {
|
|
18
|
+
display: flex;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.donutChartContainer {
|
|
22
|
+
width: sizeFluid;
|
|
23
|
+
min-width: size500;
|
|
24
|
+
min-height: size300;
|
|
25
|
+
display: block;
|
|
26
|
+
align-items: center;
|
|
27
|
+
justify-content: center;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.subtitleWrap {
|
|
31
|
+
display: flex;
|
|
32
|
+
gap: spaceXSmall;
|
|
33
|
+
flex-direction: column;
|
|
34
|
+
align-items: center;
|
|
35
|
+
justify-content: center;
|
|
36
|
+
overflow: hidden;
|
|
37
|
+
text-overflow: ellipsis;
|
|
38
|
+
width: sizeFluid;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.subtitleText {
|
|
42
|
+
margin: spaceNone;
|
|
43
|
+
color: colorTextPrimary;
|
|
44
|
+
|
|
45
|
+
text-align: center;
|
|
46
|
+
|
|
47
|
+
width: sizeFluid;
|
|
48
|
+
overflow: hidden;
|
|
49
|
+
white-space: nowrap;
|
|
50
|
+
text-overflow: ellipsis;
|
|
51
|
+
display: block;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.subtitleSubtext {
|
|
55
|
+
margin: spaceNone;
|
|
56
|
+
color: colorTextSecondary;
|
|
57
|
+
|
|
58
|
+
text-align: center;
|
|
59
|
+
|
|
60
|
+
width: sizeFluid;
|
|
61
|
+
overflow: hidden;
|
|
62
|
+
display: block;
|
|
63
|
+
white-space: nowrap;
|
|
64
|
+
text-overflow: ellipsis;
|
|
65
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _DonutChart = require("./DonutChart");
|
|
7
|
+
Object.keys(_DonutChart).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _DonutChart[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _DonutChart[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -14,16 +14,18 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
14
14
|
const GRID_SYSTEM_MAP = {
|
|
15
15
|
small: 24,
|
|
16
16
|
medium: 12,
|
|
17
|
-
large: 6
|
|
17
|
+
large: 6,
|
|
18
|
+
autoFill: 'auto-fill'
|
|
18
19
|
};
|
|
19
20
|
const Row = _ref => {
|
|
20
21
|
let {
|
|
21
22
|
className,
|
|
22
23
|
children,
|
|
23
24
|
span = 1,
|
|
24
|
-
gridType = 'medium'
|
|
25
|
+
gridType = 'medium',
|
|
26
|
+
repeatTracks = '1fr'
|
|
25
27
|
} = _ref;
|
|
26
|
-
const
|
|
28
|
+
const gridRepeatCount = GRID_SYSTEM_MAP[gridType];
|
|
27
29
|
let columnSpanCount = 0;
|
|
28
30
|
let lastChildColCount = 0;
|
|
29
31
|
const childrenWithProps = React.Children.map(children, child => {
|
|
@@ -42,21 +44,30 @@ const Row = _ref => {
|
|
|
42
44
|
}
|
|
43
45
|
lastChildColCount = columnSpanCount;
|
|
44
46
|
columnSpanCount = lastChildColCount + offset + span;
|
|
45
|
-
|
|
47
|
+
let gridColumnStart = 0,
|
|
48
|
+
gridColumnEnd = 0;
|
|
49
|
+
if (gridType === 'autoFill') {
|
|
50
|
+
gridColumnStart = 'auto';
|
|
46
51
|
return /*#__PURE__*/React.cloneElement(child, {
|
|
47
|
-
gridColumnStart
|
|
52
|
+
gridColumnStart,
|
|
53
|
+
gridColumnEnd: `span ${span}`
|
|
54
|
+
});
|
|
55
|
+
} else if (typeof gridRepeatCount === 'number' && columnSpanCount <= gridRepeatCount) {
|
|
56
|
+
gridColumnStart = lastChildColCount + offset + 1;
|
|
57
|
+
return /*#__PURE__*/React.cloneElement(child, {
|
|
58
|
+
gridColumnStart,
|
|
48
59
|
gridColumnEnd: `span ${span}`
|
|
49
60
|
});
|
|
50
61
|
} else {
|
|
51
|
-
console.error(`number of column exceed ${
|
|
62
|
+
console.error(`number of column exceed ${gridRepeatCount}`);
|
|
52
63
|
}
|
|
53
64
|
}
|
|
54
65
|
});
|
|
55
66
|
return /*#__PURE__*/React.createElement("div", {
|
|
56
67
|
"data-testid": "Grid",
|
|
57
|
-
className: (0, _classify.classify)(_GridModule.default.gridRow,
|
|
68
|
+
className: (0, _classify.classify)(_GridModule.default.gridRow, className),
|
|
58
69
|
style: {
|
|
59
|
-
gridTemplateColumns: `repeat(${
|
|
70
|
+
gridTemplateColumns: `repeat(${gridRepeatCount}, ${repeatTracks})`
|
|
60
71
|
}
|
|
61
72
|
}, childrenWithProps);
|
|
62
73
|
};
|
|
@@ -11,13 +11,15 @@ export type RowProps = {
|
|
|
11
11
|
children?: React.Node,
|
|
12
12
|
span?: number,
|
|
13
13
|
offset?: number,
|
|
14
|
-
gridType?: 'small' | 'medium' | 'large',
|
|
14
|
+
gridType?: 'small' | 'medium' | 'large' | 'autoFill',
|
|
15
|
+
repeatTracks?: string,
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
const GRID_SYSTEM_MAP = {
|
|
18
19
|
small: 24,
|
|
19
20
|
medium: 12,
|
|
20
21
|
large: 6,
|
|
22
|
+
autoFill: 'auto-fill',
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
export const Row = ({
|
|
@@ -25,8 +27,9 @@ export const Row = ({
|
|
|
25
27
|
children,
|
|
26
28
|
span = 1,
|
|
27
29
|
gridType = 'medium',
|
|
30
|
+
repeatTracks = '1fr',
|
|
28
31
|
}: RowProps): React.Node => {
|
|
29
|
-
const
|
|
32
|
+
const gridRepeatCount = GRID_SYSTEM_MAP[gridType];
|
|
30
33
|
let columnSpanCount = 0;
|
|
31
34
|
let lastChildColCount = 0;
|
|
32
35
|
const childrenWithProps = React.Children.map(children, (child) => {
|
|
@@ -42,13 +45,25 @@ export const Row = ({
|
|
|
42
45
|
}
|
|
43
46
|
lastChildColCount = columnSpanCount;
|
|
44
47
|
columnSpanCount = lastChildColCount + offset + span;
|
|
45
|
-
|
|
48
|
+
let gridColumnStart = 0,
|
|
49
|
+
gridColumnEnd = 0;
|
|
50
|
+
if (gridType === 'autoFill') {
|
|
51
|
+
gridColumnStart = 'auto';
|
|
46
52
|
return React.cloneElement(child, {
|
|
47
|
-
gridColumnStart
|
|
53
|
+
gridColumnStart,
|
|
54
|
+
gridColumnEnd: `span ${span}`,
|
|
55
|
+
});
|
|
56
|
+
} else if (
|
|
57
|
+
typeof gridRepeatCount === 'number' &&
|
|
58
|
+
columnSpanCount <= gridRepeatCount
|
|
59
|
+
) {
|
|
60
|
+
gridColumnStart = lastChildColCount + offset + 1;
|
|
61
|
+
return React.cloneElement(child, {
|
|
62
|
+
gridColumnStart,
|
|
48
63
|
gridColumnEnd: `span ${span}`,
|
|
49
64
|
});
|
|
50
65
|
} else {
|
|
51
|
-
console.error(`number of column exceed ${
|
|
66
|
+
console.error(`number of column exceed ${gridRepeatCount}`);
|
|
52
67
|
}
|
|
53
68
|
}
|
|
54
69
|
});
|
|
@@ -56,8 +71,10 @@ export const Row = ({
|
|
|
56
71
|
return (
|
|
57
72
|
<div
|
|
58
73
|
data-testid="Grid"
|
|
59
|
-
className={classify(css.gridRow,
|
|
60
|
-
style={{
|
|
74
|
+
className={classify(css.gridRow, className)}
|
|
75
|
+
style={{
|
|
76
|
+
gridTemplateColumns: `repeat(${gridRepeatCount}, ${repeatTracks})`,
|
|
77
|
+
}}
|
|
61
78
|
>
|
|
62
79
|
{childrenWithProps}
|
|
63
80
|
</div>
|