@megafon/ui-lk-vas 0.3.0 → 0.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/dist/es/components/Charts/Chart/Chart.css +73 -0
- package/dist/es/components/Charts/Chart/Chart.d.ts +5 -0
- package/dist/es/components/Charts/Chart/Chart.js +104 -0
- package/dist/es/components/Charts/Chart/components/_ChartBar/ChartBar.css +27 -0
- package/dist/es/components/Charts/Chart/components/_ChartBar/ChartBar.d.ts +9 -0
- package/dist/es/components/Charts/Chart/components/_ChartBar/ChartBar.js +107 -0
- package/dist/es/components/Charts/Chart/components/_ChartBase/ChartBase.d.ts +12 -0
- package/dist/es/components/Charts/Chart/components/_ChartBase/ChartBase.js +41 -0
- package/dist/es/components/Charts/Chart/components/_ChartBase/helpers.d.ts +2 -0
- package/dist/es/components/Charts/Chart/components/_ChartBase/helpers.js +49 -0
- package/dist/es/components/Charts/Chart/components/_ChartDoughnut/ChartDoughnut.css +26 -0
- package/dist/es/components/Charts/Chart/components/_ChartDoughnut/ChartDoughnut.d.ts +9 -0
- package/dist/es/components/Charts/Chart/components/_ChartDoughnut/ChartDoughnut.js +65 -0
- package/dist/es/components/Charts/Chart/components/_ChartLegend/ChartLegend.css +58 -0
- package/dist/es/components/Charts/Chart/components/_ChartLegend/ChartLegend.d.ts +12 -0
- package/dist/es/components/Charts/Chart/components/_ChartLegend/ChartLegend.js +29 -0
- package/dist/es/components/Charts/Chart/components/_ChartLine/ChartLine.css +27 -0
- package/dist/es/components/Charts/Chart/components/_ChartLine/ChartLine.d.ts +9 -0
- package/dist/es/components/Charts/Chart/components/_ChartLine/ChartLine.js +112 -0
- package/dist/es/components/Charts/Chart/components/chartColors.d.ts +13 -0
- package/dist/es/components/Charts/Chart/components/chartColors.js +31 -0
- package/dist/es/components/Charts/Chart/img/chart.png +0 -0
- package/dist/es/components/Charts/Chart/types.d.ts +40 -0
- package/dist/es/components/Charts/Chart/types.js +1 -0
- package/dist/es/hooks/useCssVariable.d.ts +2 -0
- package/dist/es/hooks/useCssVariable.js +22 -0
- package/dist/es/index.d.ts +7 -5
- package/dist/es/index.js +8 -6
- package/dist/lib/components/Charts/Chart/Chart.css +73 -0
- package/dist/lib/components/Charts/Chart/Chart.d.ts +5 -0
- package/dist/lib/components/Charts/Chart/Chart.js +113 -0
- package/dist/lib/components/Charts/Chart/components/_ChartBar/ChartBar.css +27 -0
- package/dist/lib/components/Charts/Chart/components/_ChartBar/ChartBar.d.ts +9 -0
- package/dist/lib/components/Charts/Chart/components/_ChartBar/ChartBar.js +116 -0
- package/dist/lib/components/Charts/Chart/components/_ChartBase/ChartBase.d.ts +12 -0
- package/dist/lib/components/Charts/Chart/components/_ChartBase/ChartBase.js +51 -0
- package/dist/lib/components/Charts/Chart/components/_ChartBase/helpers.d.ts +2 -0
- package/dist/lib/components/Charts/Chart/components/_ChartBase/helpers.js +55 -0
- package/dist/lib/components/Charts/Chart/components/_ChartDoughnut/ChartDoughnut.css +26 -0
- package/dist/lib/components/Charts/Chart/components/_ChartDoughnut/ChartDoughnut.d.ts +9 -0
- package/dist/lib/components/Charts/Chart/components/_ChartDoughnut/ChartDoughnut.js +74 -0
- package/dist/lib/components/Charts/Chart/components/_ChartLegend/ChartLegend.css +58 -0
- package/dist/lib/components/Charts/Chart/components/_ChartLegend/ChartLegend.d.ts +12 -0
- package/dist/lib/components/Charts/Chart/components/_ChartLegend/ChartLegend.js +37 -0
- package/dist/lib/components/Charts/Chart/components/_ChartLine/ChartLine.css +27 -0
- package/dist/lib/components/Charts/Chart/components/_ChartLine/ChartLine.d.ts +9 -0
- package/dist/lib/components/Charts/Chart/components/_ChartLine/ChartLine.js +121 -0
- package/dist/lib/components/Charts/Chart/components/chartColors.d.ts +13 -0
- package/dist/lib/components/Charts/Chart/components/chartColors.js +37 -0
- package/dist/lib/components/Charts/Chart/img/chart.png +0 -0
- package/dist/lib/components/Charts/Chart/types.d.ts +40 -0
- package/dist/lib/components/Charts/Chart/types.js +5 -0
- package/dist/lib/hooks/useCssVariable.d.ts +2 -0
- package/dist/lib/hooks/useCssVariable.js +29 -0
- package/dist/lib/index.d.ts +7 -5
- package/dist/lib/index.js +45 -31
- package/package.json +5 -4
- package/dist/es/components/UploadForm/UploadField/UploadField.css +0 -27
- package/dist/es/components/UploadForm/UploadField/UploadField.d.ts +0 -22
- package/dist/es/components/UploadForm/UploadField/UploadField.js +0 -56
- package/dist/es/components/UploadForm/UploadField/components/_UploadFieldDropArea/UploadFieldDropArea.css +0 -83
- package/dist/es/components/UploadForm/UploadField/components/_UploadFieldDropArea/UploadFieldDropArea.d.ts +0 -21
- package/dist/es/components/UploadForm/UploadField/components/_UploadFieldDropArea/UploadFieldDropArea.js +0 -50
- package/dist/es/components/UploadForm/UploadField/components/useDragAndDrop.d.ts +0 -3
- package/dist/es/components/UploadForm/UploadField/components/useDragAndDrop.js +0 -50
- package/dist/es/components/UploadForm/UploadFileItem/UploadFileItem.css +0 -112
- package/dist/es/components/UploadForm/UploadFileItem/UploadFileItem.d.ts +0 -25
- package/dist/es/components/UploadForm/UploadFileItem/UploadFileItem.js +0 -86
- package/dist/es/components/UploadForm/UploadFileItem/components/_UploadFileItemIcon/UploadFileItemIcon.d.ts +0 -7
- package/dist/es/components/UploadForm/UploadFileItem/components/_UploadFileItemIcon/UploadFileItemIcon.js +0 -279
- package/dist/es/components/UploadForm/UploadFileItem/helpers.d.ts +0 -5
- package/dist/es/components/UploadForm/UploadFileItem/helpers.js +0 -27
- package/dist/lib/components/UploadForm/UploadField/UploadField.css +0 -27
- package/dist/lib/components/UploadForm/UploadField/UploadField.d.ts +0 -22
- package/dist/lib/components/UploadForm/UploadField/UploadField.js +0 -65
- package/dist/lib/components/UploadForm/UploadField/components/_UploadFieldDropArea/UploadFieldDropArea.css +0 -83
- package/dist/lib/components/UploadForm/UploadField/components/_UploadFieldDropArea/UploadFieldDropArea.d.ts +0 -21
- package/dist/lib/components/UploadForm/UploadField/components/_UploadFieldDropArea/UploadFieldDropArea.js +0 -59
- package/dist/lib/components/UploadForm/UploadField/components/useDragAndDrop.d.ts +0 -3
- package/dist/lib/components/UploadForm/UploadField/components/useDragAndDrop.js +0 -57
- package/dist/lib/components/UploadForm/UploadFileItem/UploadFileItem.css +0 -112
- package/dist/lib/components/UploadForm/UploadFileItem/UploadFileItem.d.ts +0 -25
- package/dist/lib/components/UploadForm/UploadFileItem/UploadFileItem.js +0 -95
- package/dist/lib/components/UploadForm/UploadFileItem/components/_UploadFileItemIcon/UploadFileItemIcon.d.ts +0 -7
- package/dist/lib/components/UploadForm/UploadFileItem/components/_UploadFileItemIcon/UploadFileItemIcon.js +0 -289
- package/dist/lib/components/UploadForm/UploadFileItem/helpers.d.ts +0 -5
- package/dist/lib/components/UploadForm/UploadFileItem/helpers.js +0 -33
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
h1,
|
|
2
|
+
h2,
|
|
3
|
+
h3,
|
|
4
|
+
h4,
|
|
5
|
+
h5 {
|
|
6
|
+
margin: 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.mfui-lkvas-chart {
|
|
10
|
+
display: -webkit-box;
|
|
11
|
+
display: -ms-flexbox;
|
|
12
|
+
display: flex;
|
|
13
|
+
-webkit-box-orient: vertical;
|
|
14
|
+
-webkit-box-direction: normal;
|
|
15
|
+
-ms-flex-direction: column;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
gap: 24px;
|
|
18
|
+
-webkit-box-align: center;
|
|
19
|
+
-ms-flex-align: center;
|
|
20
|
+
align-items: center;
|
|
21
|
+
-webkit-box-sizing: border-box;
|
|
22
|
+
box-sizing: border-box;
|
|
23
|
+
width: 100%;
|
|
24
|
+
height: -webkit-fit-content;
|
|
25
|
+
height: -moz-fit-content;
|
|
26
|
+
height: fit-content;
|
|
27
|
+
padding: 24px 32px 32px 32px;
|
|
28
|
+
border-radius: 12px;
|
|
29
|
+
background-color: var(--base);
|
|
30
|
+
-webkit-box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
|
|
31
|
+
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
|
|
32
|
+
}
|
|
33
|
+
.mfui-lkvas-chart__header {
|
|
34
|
+
display: grid;
|
|
35
|
+
grid-template-columns: 1fr auto minmax(-webkit-min-content, 1fr);
|
|
36
|
+
grid-template-columns: 1fr auto minmax(min-content, 1fr);
|
|
37
|
+
gap: 20px;
|
|
38
|
+
-webkit-box-align: center;
|
|
39
|
+
-ms-flex-align: center;
|
|
40
|
+
align-items: center;
|
|
41
|
+
width: 100%;
|
|
42
|
+
}
|
|
43
|
+
.mfui-lkvas-chart__title {
|
|
44
|
+
font-weight: 500;
|
|
45
|
+
font-size: 18px;
|
|
46
|
+
line-height: 24px;
|
|
47
|
+
letter-spacing: 0.5px;
|
|
48
|
+
grid-column-start: 2;
|
|
49
|
+
text-align: center;
|
|
50
|
+
}
|
|
51
|
+
@media screen and (min-width: 1280px) {
|
|
52
|
+
.mfui-lkvas-chart__title {
|
|
53
|
+
font-size: 20px;
|
|
54
|
+
line-height: 28px;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
.mfui-lkvas-chart__button {
|
|
58
|
+
grid-column-start: 3;
|
|
59
|
+
justify-self: end;
|
|
60
|
+
}
|
|
61
|
+
.mfui-lkvas-chart__image {
|
|
62
|
+
display: block;
|
|
63
|
+
width: 96px;
|
|
64
|
+
height: 96px;
|
|
65
|
+
background-image: url("./img/chart.png");
|
|
66
|
+
background-repeat: no-repeat;
|
|
67
|
+
background-size: cover;
|
|
68
|
+
}
|
|
69
|
+
.mfui-lkvas-chart__empty-text {
|
|
70
|
+
font-size: 15px;
|
|
71
|
+
line-height: 24px;
|
|
72
|
+
font-weight: 400;
|
|
73
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { Button } from '@megafon/ui-core';
|
|
5
|
+
import { cnCreate, filterDataAttrs } from '@megafon/ui-helpers';
|
|
6
|
+
import useCssVariable from "../../../hooks/useCssVariable";
|
|
7
|
+
import ChartBar from "./components/_ChartBar/ChartBar";
|
|
8
|
+
import ChartDoughnut from "./components/_ChartDoughnut/ChartDoughnut";
|
|
9
|
+
import ChartLine from "./components/_ChartLine/ChartLine";
|
|
10
|
+
import "./Chart.css";
|
|
11
|
+
var DownloadIcon = function DownloadIcon(props) {
|
|
12
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
13
|
+
viewBox: "0 0 32 32"
|
|
14
|
+
}, props), /*#__PURE__*/React.createElement("path", {
|
|
15
|
+
d: "M15.04 5.99L14.97 17l-1.26-1.49-1.42 1.41L15.37 20h1.26l3.08-3.08-1.42-1.41-1.32 1.55.07-11.05-2-.02z"
|
|
16
|
+
}), /*#__PURE__*/React.createElement("path", {
|
|
17
|
+
d: "M8 17H6a10 10 0 0020 0h-2a8 8 0 01-16 0z"
|
|
18
|
+
}));
|
|
19
|
+
};
|
|
20
|
+
var cn = cnCreate('mfui-lkvas-chart');
|
|
21
|
+
var Chart = function Chart(_ref) {
|
|
22
|
+
var className = _ref.className,
|
|
23
|
+
type = _ref.type,
|
|
24
|
+
title = _ref.title,
|
|
25
|
+
labels = _ref.labels,
|
|
26
|
+
datasets = _ref.datasets,
|
|
27
|
+
scales = _ref.scales,
|
|
28
|
+
downloadLink = _ref.downloadLink,
|
|
29
|
+
_ref$hideLegend = _ref.hideLegend,
|
|
30
|
+
hideLegend = _ref$hideLegend === void 0 ? false : _ref$hideLegend,
|
|
31
|
+
dataAttrs = _ref.dataAttrs;
|
|
32
|
+
var _React$useState = React.useState(),
|
|
33
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
34
|
+
bgColor = _React$useState2[0],
|
|
35
|
+
setBgColor = _React$useState2[1];
|
|
36
|
+
var rootRef = React.useRef(null);
|
|
37
|
+
var ticksColor = useCssVariable('--content');
|
|
38
|
+
var scaleColor = useCssVariable('--spbSky1');
|
|
39
|
+
var scalesColor = {
|
|
40
|
+
ticksColor: ticksColor,
|
|
41
|
+
scaleColor: scaleColor
|
|
42
|
+
};
|
|
43
|
+
var showChart = !!datasets.length && !!labels.length;
|
|
44
|
+
React.useEffect(function () {
|
|
45
|
+
if (type === 'doughnut' && rootRef.current) {
|
|
46
|
+
var rootNodeStyle = window.getComputedStyle(rootRef.current);
|
|
47
|
+
setBgColor(rootNodeStyle.getPropertyValue('background-color'));
|
|
48
|
+
}
|
|
49
|
+
}, [type]);
|
|
50
|
+
var renderChart = function renderChart() {
|
|
51
|
+
if (type === 'line') {
|
|
52
|
+
return /*#__PURE__*/React.createElement(ChartLine, {
|
|
53
|
+
type: type,
|
|
54
|
+
datasets: datasets,
|
|
55
|
+
labels: labels,
|
|
56
|
+
scales: scales,
|
|
57
|
+
hideLegend: hideLegend,
|
|
58
|
+
scalesColors: scalesColor
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (type === 'bar') {
|
|
62
|
+
return /*#__PURE__*/React.createElement(ChartBar, {
|
|
63
|
+
type: type,
|
|
64
|
+
datasets: datasets,
|
|
65
|
+
labels: labels,
|
|
66
|
+
scales: scales,
|
|
67
|
+
hideLegend: hideLegend,
|
|
68
|
+
scalesColors: scalesColor
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return /*#__PURE__*/React.createElement(ChartDoughnut, {
|
|
72
|
+
type: type,
|
|
73
|
+
datasets: datasets,
|
|
74
|
+
labels: labels,
|
|
75
|
+
hideLegend: hideLegend,
|
|
76
|
+
bgColor: bgColor
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
var emptyContent = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
80
|
+
className: cn('image')
|
|
81
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
82
|
+
className: cn('empty-text')
|
|
83
|
+
}, "\u0414\u0430\u043D\u043D\u044B\u0445 \u043D\u0435\u0442"));
|
|
84
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
85
|
+
className: cn([className])
|
|
86
|
+
}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
|
|
87
|
+
ref: rootRef
|
|
88
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
89
|
+
className: cn('header')
|
|
90
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
91
|
+
className: cn('title')
|
|
92
|
+
}, title), !!downloadLink && /*#__PURE__*/React.createElement(Button, {
|
|
93
|
+
className: cn('button'),
|
|
94
|
+
theme: "green",
|
|
95
|
+
type: "text",
|
|
96
|
+
href: downloadLink,
|
|
97
|
+
download: true,
|
|
98
|
+
icon: /*#__PURE__*/React.createElement(DownloadIcon, null),
|
|
99
|
+
dataAttrs: {
|
|
100
|
+
root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.downloadButton
|
|
101
|
+
}
|
|
102
|
+
}, "\u0421\u043A\u0430\u0447\u0430\u0442\u044C")), showChart ? renderChart() : emptyContent);
|
|
103
|
+
};
|
|
104
|
+
export default Chart;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
h1,
|
|
2
|
+
h2,
|
|
3
|
+
h3,
|
|
4
|
+
h4,
|
|
5
|
+
h5 {
|
|
6
|
+
margin: 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.mfui-lkvas-chart-bar {
|
|
10
|
+
display: -webkit-box;
|
|
11
|
+
display: -ms-flexbox;
|
|
12
|
+
display: flex;
|
|
13
|
+
-webkit-box-orient: vertical;
|
|
14
|
+
-webkit-box-direction: normal;
|
|
15
|
+
-ms-flex-direction: column;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
gap: 24px;
|
|
18
|
+
-webkit-box-align: center;
|
|
19
|
+
-ms-flex-align: center;
|
|
20
|
+
align-items: center;
|
|
21
|
+
width: 100%;
|
|
22
|
+
}
|
|
23
|
+
.mfui-lkvas-chart-bar__chart {
|
|
24
|
+
width: 100%;
|
|
25
|
+
height: 230px;
|
|
26
|
+
cursor: pointer;
|
|
27
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { IChart, IScalesColors } from '../../types';
|
|
3
|
+
import './ChartBar.scss';
|
|
4
|
+
interface IChartBar extends Pick<IChart, 'datasets' | 'labels' | 'hideLegend' | 'scales'> {
|
|
5
|
+
type: 'bar';
|
|
6
|
+
scalesColors: IScalesColors;
|
|
7
|
+
}
|
|
8
|
+
declare const ChartBar: React.FC<IChartBar>;
|
|
9
|
+
export default ChartBar;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import "core-js/modules/es.array.map.js";
|
|
3
|
+
import "core-js/modules/es.array.reduce.js";
|
|
4
|
+
import "core-js/modules/es.object.to-string.js";
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import { cnCreate } from '@megafon/ui-helpers';
|
|
7
|
+
import ChartBase from "../_ChartBase/ChartBase";
|
|
8
|
+
import ChartLegend from "../_ChartLegend/ChartLegend";
|
|
9
|
+
import { CHART_BAR_COLORS, SCALES_COLORS, POINT_BORDER_COLOR } from "../chartColors";
|
|
10
|
+
import "./ChartBar.css";
|
|
11
|
+
var cn = cnCreate('mfui-lkvas-chart-bar');
|
|
12
|
+
var ChartBar = function ChartBar(_ref) {
|
|
13
|
+
var type = _ref.type,
|
|
14
|
+
datasets = _ref.datasets,
|
|
15
|
+
labels = _ref.labels,
|
|
16
|
+
_ref$scales = _ref.scales,
|
|
17
|
+
_ref$scales2 = _ref$scales === void 0 ? {} : _ref$scales,
|
|
18
|
+
_ref$scales2$skipTick = _ref$scales2.skipTicksX,
|
|
19
|
+
skipTicksX = _ref$scales2$skipTick === void 0 ? 1 : _ref$scales2$skipTick,
|
|
20
|
+
_ref$scales2$skipTick2 = _ref$scales2.skipTicksY,
|
|
21
|
+
skipTicksY = _ref$scales2$skipTick2 === void 0 ? 1 : _ref$scales2$skipTick2,
|
|
22
|
+
_ref$hideLegend = _ref.hideLegend,
|
|
23
|
+
hideLegend = _ref$hideLegend === void 0 ? false : _ref$hideLegend,
|
|
24
|
+
_ref$scalesColors = _ref.scalesColors,
|
|
25
|
+
_ref$scalesColors$tic = _ref$scalesColors.ticksColor,
|
|
26
|
+
ticksColor = _ref$scalesColors$tic === void 0 ? SCALES_COLORS.ticks : _ref$scalesColors$tic,
|
|
27
|
+
_ref$scalesColors$sca = _ref$scalesColors.scaleColor,
|
|
28
|
+
scaleColor = _ref$scalesColors$sca === void 0 ? SCALES_COLORS.scale : _ref$scalesColors$sca;
|
|
29
|
+
var chartData = {
|
|
30
|
+
labels: labels,
|
|
31
|
+
datasets: datasets.map(function (dataset, index) {
|
|
32
|
+
return _extends(_extends({}, dataset), {
|
|
33
|
+
backgroundColor: CHART_BAR_COLORS[index],
|
|
34
|
+
categoryPercentage: 0.5,
|
|
35
|
+
pointBorderColor: POINT_BORDER_COLOR
|
|
36
|
+
});
|
|
37
|
+
})
|
|
38
|
+
};
|
|
39
|
+
var chartOptions = {
|
|
40
|
+
responsive: true,
|
|
41
|
+
maintainAspectRatio: false,
|
|
42
|
+
scales: {
|
|
43
|
+
y: {
|
|
44
|
+
display: true,
|
|
45
|
+
beginAtZero: true,
|
|
46
|
+
type: 'linear',
|
|
47
|
+
position: 'left',
|
|
48
|
+
grid: {
|
|
49
|
+
color: scaleColor
|
|
50
|
+
},
|
|
51
|
+
border: {
|
|
52
|
+
color: scaleColor
|
|
53
|
+
},
|
|
54
|
+
ticks: {
|
|
55
|
+
autoSkip: true,
|
|
56
|
+
maxRotation: 0,
|
|
57
|
+
color: ticksColor,
|
|
58
|
+
callback: function callback(value, index) {
|
|
59
|
+
return index % skipTicksY === 0 ? value : '';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
x: {
|
|
64
|
+
grid: {
|
|
65
|
+
display: false
|
|
66
|
+
},
|
|
67
|
+
border: {
|
|
68
|
+
color: scaleColor
|
|
69
|
+
},
|
|
70
|
+
ticks: {
|
|
71
|
+
autoSkip: true,
|
|
72
|
+
maxRotation: 0,
|
|
73
|
+
color: ticksColor,
|
|
74
|
+
callback: function callback(_value, index) {
|
|
75
|
+
return index % skipTicksX === 0 ? labels[index] : '';
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
var legendItems = datasets.map(function (_ref2, index) {
|
|
82
|
+
var _ref2$label = _ref2.label,
|
|
83
|
+
label = _ref2$label === void 0 ? '' : _ref2$label,
|
|
84
|
+
data = _ref2.data,
|
|
85
|
+
unit = _ref2.unit;
|
|
86
|
+
var sumValue = data.reduce(function (sum, current) {
|
|
87
|
+
return sum + current;
|
|
88
|
+
}, 0);
|
|
89
|
+
return {
|
|
90
|
+
title: label,
|
|
91
|
+
value: unit ? sumValue + unit : sumValue,
|
|
92
|
+
color: CHART_BAR_COLORS[index]
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
96
|
+
className: cn()
|
|
97
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
98
|
+
className: cn('chart')
|
|
99
|
+
}, /*#__PURE__*/React.createElement(ChartBase, {
|
|
100
|
+
type: type,
|
|
101
|
+
data: chartData,
|
|
102
|
+
options: chartOptions
|
|
103
|
+
})), !hideLegend && /*#__PURE__*/React.createElement(ChartLegend, {
|
|
104
|
+
items: legendItems
|
|
105
|
+
}));
|
|
106
|
+
};
|
|
107
|
+
export default ChartBar;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ChartOptions, ChartData, ChartType, UpdateMode } from 'chart.js';
|
|
3
|
+
export interface IChartBase {
|
|
4
|
+
data: ChartData;
|
|
5
|
+
options: ChartOptions;
|
|
6
|
+
type: ChartType;
|
|
7
|
+
updateMode?: UpdateMode;
|
|
8
|
+
height?: number;
|
|
9
|
+
width?: number;
|
|
10
|
+
}
|
|
11
|
+
declare const ChartBase: React.FC<IChartBase>;
|
|
12
|
+
export default ChartBase;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useCallback } from 'react';
|
|
2
|
+
import { cnCreate } from '@megafon/ui-helpers';
|
|
3
|
+
import { ArcElement, BarController, BarElement, CategoryScale, Chart, DoughnutController, LinearScale, LineController, LineElement, PointElement, Tooltip } from 'chart.js';
|
|
4
|
+
import setChartDefaultSettings from "./helpers";
|
|
5
|
+
Chart.register(ArcElement, BarController, BarElement, CategoryScale, DoughnutController, LinearScale, LineController, LineElement, PointElement, Tooltip);
|
|
6
|
+
setChartDefaultSettings();
|
|
7
|
+
var cn = cnCreate('mfui-lkvas-chart-base');
|
|
8
|
+
var ChartBase = function ChartBase(_ref) {
|
|
9
|
+
var data = _ref.data,
|
|
10
|
+
options = _ref.options,
|
|
11
|
+
type = _ref.type,
|
|
12
|
+
updateMode = _ref.updateMode,
|
|
13
|
+
height = _ref.height,
|
|
14
|
+
width = _ref.width;
|
|
15
|
+
var chartInstance = useRef(null);
|
|
16
|
+
useEffect(function () {
|
|
17
|
+
if (chartInstance.current) {
|
|
18
|
+
chartInstance.current.data = data;
|
|
19
|
+
chartInstance.current.options = options;
|
|
20
|
+
chartInstance.current.update(updateMode);
|
|
21
|
+
}
|
|
22
|
+
}, [data, options, updateMode]);
|
|
23
|
+
var nodeRef = useCallback(function (node) {
|
|
24
|
+
var _a;
|
|
25
|
+
(_a = chartInstance.current) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
26
|
+
if (node) {
|
|
27
|
+
chartInstance.current = new Chart(node, {
|
|
28
|
+
type: type,
|
|
29
|
+
data: data,
|
|
30
|
+
options: options
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}, [data, options, type]);
|
|
34
|
+
return /*#__PURE__*/React.createElement("canvas", {
|
|
35
|
+
className: cn(),
|
|
36
|
+
ref: nodeRef,
|
|
37
|
+
height: height,
|
|
38
|
+
width: width
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
export default ChartBase;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Chart } from 'chart.js';
|
|
2
|
+
import { TOOLTIP_COLORS } from "../chartColors";
|
|
3
|
+
var FONT_FAMILY = 'Graphik, Arial, sans-serif';
|
|
4
|
+
var setChartDefaultSettings = function setChartDefaultSettings() {
|
|
5
|
+
Chart.defaults.responsive = true;
|
|
6
|
+
Chart.defaults.font.family = FONT_FAMILY;
|
|
7
|
+
Chart.defaults.scales.category.ticks.autoSkip = true;
|
|
8
|
+
Chart.defaults.scales.category.ticks.maxRotation = 0;
|
|
9
|
+
Chart.defaults.scales.category.ticks.font = {
|
|
10
|
+
size: 12
|
|
11
|
+
};
|
|
12
|
+
Chart.defaults.scales.linear.type = 'linear';
|
|
13
|
+
Chart.defaults.scales.linear.position = 'left';
|
|
14
|
+
Chart.defaults.scales.linear.beginAtZero = true;
|
|
15
|
+
Chart.defaults.scales.linear.ticks.autoSkip = true;
|
|
16
|
+
Chart.defaults.scales.linear.ticks.maxRotation = 0;
|
|
17
|
+
Chart.defaults.scales.linear.ticks.font = {
|
|
18
|
+
size: 12
|
|
19
|
+
};
|
|
20
|
+
Chart.defaults.plugins.tooltip.enabled = true;
|
|
21
|
+
Chart.defaults.plugins.tooltip.backgroundColor = TOOLTIP_COLORS.background;
|
|
22
|
+
Chart.defaults.plugins.tooltip.titleColor = TOOLTIP_COLORS.titleColor;
|
|
23
|
+
Chart.defaults.plugins.tooltip.titleFont = {
|
|
24
|
+
weight: '400'
|
|
25
|
+
};
|
|
26
|
+
Chart.defaults.plugins.tooltip.bodyFont = {
|
|
27
|
+
weight: '500'
|
|
28
|
+
};
|
|
29
|
+
Chart.defaults.plugins.tooltip.bodyAlign = 'left';
|
|
30
|
+
Chart.defaults.plugins.tooltip.padding = {
|
|
31
|
+
top: 8,
|
|
32
|
+
left: 12,
|
|
33
|
+
bottom: 6,
|
|
34
|
+
right: 12
|
|
35
|
+
};
|
|
36
|
+
Chart.defaults.plugins.tooltip.cornerRadius = 8;
|
|
37
|
+
Chart.defaults.plugins.tooltip.displayColors = true;
|
|
38
|
+
Chart.defaults.plugins.tooltip.boxWidth = 8;
|
|
39
|
+
Chart.defaults.plugins.tooltip.boxHeight = 8;
|
|
40
|
+
Chart.defaults.plugins.tooltip.boxPadding = 4;
|
|
41
|
+
Chart.defaults.plugins.tooltip.usePointStyle = true;
|
|
42
|
+
Chart.defaults.plugins.tooltip.callbacks.labelPointStyle = function () {
|
|
43
|
+
return {
|
|
44
|
+
pointStyle: 'circle',
|
|
45
|
+
rotation: 0
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export default setChartDefaultSettings;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
h1,
|
|
2
|
+
h2,
|
|
3
|
+
h3,
|
|
4
|
+
h4,
|
|
5
|
+
h5 {
|
|
6
|
+
margin: 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.mfui-lkvas-chart-doughnut {
|
|
10
|
+
display: -webkit-box;
|
|
11
|
+
display: -ms-flexbox;
|
|
12
|
+
display: flex;
|
|
13
|
+
-webkit-box-orient: vertical;
|
|
14
|
+
-webkit-box-direction: normal;
|
|
15
|
+
-ms-flex-direction: column;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
gap: 24px;
|
|
18
|
+
-webkit-box-align: center;
|
|
19
|
+
-ms-flex-align: center;
|
|
20
|
+
align-items: center;
|
|
21
|
+
width: 100%;
|
|
22
|
+
}
|
|
23
|
+
.mfui-lkvas-chart-doughnut__chart {
|
|
24
|
+
margin: -4px;
|
|
25
|
+
pointer-events: none;
|
|
26
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { IChart } from '../../types';
|
|
3
|
+
import './ChartDoughnut.scss';
|
|
4
|
+
interface IChartDoughnut extends Pick<IChart, 'datasets' | 'labels' | 'hideLegend'> {
|
|
5
|
+
type: 'doughnut';
|
|
6
|
+
bgColor?: string;
|
|
7
|
+
}
|
|
8
|
+
declare const ChartDoughnut: React.FC<IChartDoughnut>;
|
|
9
|
+
export default ChartDoughnut;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import "core-js/modules/es.array.map.js";
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { cnCreate } from '@megafon/ui-helpers';
|
|
6
|
+
import ChartBase from "../_ChartBase/ChartBase";
|
|
7
|
+
import ChartLegend from "../_ChartLegend/ChartLegend";
|
|
8
|
+
import CHART_COLORS, { DOUGHNUT_BORDER_COLOR } from "../chartColors";
|
|
9
|
+
import "./ChartDoughnut.css";
|
|
10
|
+
var DOUGHNUT_SIZE = 220;
|
|
11
|
+
var cn = cnCreate('mfui-lkvas-chart-doughnut');
|
|
12
|
+
var ChartDoughnut = function ChartDoughnut(_ref) {
|
|
13
|
+
var type = _ref.type,
|
|
14
|
+
datasets = _ref.datasets,
|
|
15
|
+
labels = _ref.labels,
|
|
16
|
+
_ref$hideLegend = _ref.hideLegend,
|
|
17
|
+
hideLegend = _ref$hideLegend === void 0 ? false : _ref$hideLegend,
|
|
18
|
+
_ref$bgColor = _ref.bgColor,
|
|
19
|
+
bgColor = _ref$bgColor === void 0 ? DOUGHNUT_BORDER_COLOR : _ref$bgColor;
|
|
20
|
+
var _datasets = _slicedToArray(datasets, 1),
|
|
21
|
+
_datasets$ = _datasets[0],
|
|
22
|
+
data = _datasets$.data,
|
|
23
|
+
unit = _datasets$.unit;
|
|
24
|
+
var legendItems = data.map(function (value, index) {
|
|
25
|
+
return {
|
|
26
|
+
title: labels[index],
|
|
27
|
+
value: unit ? value + unit : value,
|
|
28
|
+
color: CHART_COLORS[index]
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
var chartData = {
|
|
32
|
+
labels: labels,
|
|
33
|
+
datasets: datasets.map(function (dataset) {
|
|
34
|
+
return _extends(_extends({}, dataset), {
|
|
35
|
+
backgroundColor: CHART_COLORS,
|
|
36
|
+
borderColor: bgColor,
|
|
37
|
+
borderWidth: 4
|
|
38
|
+
});
|
|
39
|
+
})
|
|
40
|
+
};
|
|
41
|
+
var chartOptions = {
|
|
42
|
+
events: [],
|
|
43
|
+
responsive: false,
|
|
44
|
+
cutout: 70,
|
|
45
|
+
plugins: {
|
|
46
|
+
tooltip: {
|
|
47
|
+
enabled: false
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
52
|
+
className: cn()
|
|
53
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
54
|
+
className: cn('chart')
|
|
55
|
+
}, /*#__PURE__*/React.createElement(ChartBase, {
|
|
56
|
+
type: type,
|
|
57
|
+
data: chartData,
|
|
58
|
+
options: chartOptions,
|
|
59
|
+
height: DOUGHNUT_SIZE,
|
|
60
|
+
width: DOUGHNUT_SIZE
|
|
61
|
+
})), !hideLegend && /*#__PURE__*/React.createElement(ChartLegend, {
|
|
62
|
+
items: legendItems
|
|
63
|
+
}));
|
|
64
|
+
};
|
|
65
|
+
export default ChartDoughnut;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
h1,
|
|
2
|
+
h2,
|
|
3
|
+
h3,
|
|
4
|
+
h4,
|
|
5
|
+
h5 {
|
|
6
|
+
margin: 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.mfui-lkvas-chart-legend {
|
|
10
|
+
display: -webkit-box;
|
|
11
|
+
display: -ms-flexbox;
|
|
12
|
+
display: flex;
|
|
13
|
+
-ms-flex-wrap: wrap;
|
|
14
|
+
flex-wrap: wrap;
|
|
15
|
+
gap: 12px;
|
|
16
|
+
-webkit-box-pack: space-evenly;
|
|
17
|
+
-ms-flex-pack: space-evenly;
|
|
18
|
+
justify-content: space-evenly;
|
|
19
|
+
-webkit-box-sizing: border-box;
|
|
20
|
+
box-sizing: border-box;
|
|
21
|
+
width: 100%;
|
|
22
|
+
padding: 12px;
|
|
23
|
+
border: 1px solid var(--spbSky1);
|
|
24
|
+
border-radius: 12px;
|
|
25
|
+
}
|
|
26
|
+
.mfui-lkvas-chart-legend__item {
|
|
27
|
+
display: -webkit-box;
|
|
28
|
+
display: -ms-flexbox;
|
|
29
|
+
display: flex;
|
|
30
|
+
gap: 12px;
|
|
31
|
+
}
|
|
32
|
+
.mfui-lkvas-chart-legend__item-point {
|
|
33
|
+
-ms-flex-negative: 0;
|
|
34
|
+
flex-shrink: 0;
|
|
35
|
+
width: 12px;
|
|
36
|
+
height: 12px;
|
|
37
|
+
margin-top: 6px;
|
|
38
|
+
border-radius: 50%;
|
|
39
|
+
}
|
|
40
|
+
.mfui-lkvas-chart-legend__item-title {
|
|
41
|
+
font-size: 15px;
|
|
42
|
+
line-height: 24px;
|
|
43
|
+
font-weight: 400;
|
|
44
|
+
display: block;
|
|
45
|
+
}
|
|
46
|
+
.mfui-lkvas-chart-legend__item-value {
|
|
47
|
+
font-weight: 500;
|
|
48
|
+
font-size: 18px;
|
|
49
|
+
line-height: 24px;
|
|
50
|
+
letter-spacing: 0.5px;
|
|
51
|
+
display: block;
|
|
52
|
+
}
|
|
53
|
+
@media screen and (min-width: 1280px) {
|
|
54
|
+
.mfui-lkvas-chart-legend__item-value {
|
|
55
|
+
font-size: 20px;
|
|
56
|
+
line-height: 28px;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import './ChartLegend.scss';
|
|
3
|
+
export type ChartLegendItemType = {
|
|
4
|
+
title: string;
|
|
5
|
+
value: number | string;
|
|
6
|
+
color: string;
|
|
7
|
+
};
|
|
8
|
+
export interface IChartLegend {
|
|
9
|
+
items: ChartLegendItemType[];
|
|
10
|
+
}
|
|
11
|
+
declare const ChartLegend: React.FC<IChartLegend>;
|
|
12
|
+
export default ChartLegend;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import "core-js/modules/es.array.map.js";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { cnCreate } from '@megafon/ui-helpers';
|
|
4
|
+
import "./ChartLegend.css";
|
|
5
|
+
var cn = cnCreate('mfui-lkvas-chart-legend');
|
|
6
|
+
var ChartLegend = function ChartLegend(_ref) {
|
|
7
|
+
var items = _ref.items;
|
|
8
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
9
|
+
className: cn()
|
|
10
|
+
}, items.map(function (_ref2, index) {
|
|
11
|
+
var title = _ref2.title,
|
|
12
|
+
value = _ref2.value,
|
|
13
|
+
color = _ref2.color;
|
|
14
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
15
|
+
key: title + index,
|
|
16
|
+
className: cn('item')
|
|
17
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
18
|
+
className: cn('item-point'),
|
|
19
|
+
style: {
|
|
20
|
+
backgroundColor: color
|
|
21
|
+
}
|
|
22
|
+
}), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
|
|
23
|
+
className: cn('item-title')
|
|
24
|
+
}, title), !!value && /*#__PURE__*/React.createElement("span", {
|
|
25
|
+
className: cn('item-value')
|
|
26
|
+
}, value)));
|
|
27
|
+
}));
|
|
28
|
+
};
|
|
29
|
+
export default ChartLegend;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
h1,
|
|
2
|
+
h2,
|
|
3
|
+
h3,
|
|
4
|
+
h4,
|
|
5
|
+
h5 {
|
|
6
|
+
margin: 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.mfui-lkvas-chart-line {
|
|
10
|
+
display: -webkit-box;
|
|
11
|
+
display: -ms-flexbox;
|
|
12
|
+
display: flex;
|
|
13
|
+
-webkit-box-orient: vertical;
|
|
14
|
+
-webkit-box-direction: normal;
|
|
15
|
+
-ms-flex-direction: column;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
gap: 24px;
|
|
18
|
+
-webkit-box-align: center;
|
|
19
|
+
-ms-flex-align: center;
|
|
20
|
+
align-items: center;
|
|
21
|
+
width: 100%;
|
|
22
|
+
}
|
|
23
|
+
.mfui-lkvas-chart-line__chart {
|
|
24
|
+
width: 100%;
|
|
25
|
+
height: 230px;
|
|
26
|
+
cursor: pointer;
|
|
27
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { IScalesColors, IChart } from '../../types';
|
|
3
|
+
import './ChartLine.scss';
|
|
4
|
+
interface IChartLine extends Pick<IChart, 'datasets' | 'labels' | 'hideLegend' | 'scales'> {
|
|
5
|
+
type: 'line';
|
|
6
|
+
scalesColors: IScalesColors;
|
|
7
|
+
}
|
|
8
|
+
declare const ChartLine: React.FC<IChartLine>;
|
|
9
|
+
export default ChartLine;
|