@cloud-ru/uikit-product-charts 0.13.12 → 0.13.14

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.
Files changed (156) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/dist/cjs/components/BagelChart/BagelChart.d.ts +9 -0
  3. package/dist/cjs/components/BagelChart/BagelChart.js +31 -0
  4. package/dist/cjs/components/BagelChart/index.d.ts +1 -0
  5. package/dist/cjs/components/BagelChart/index.js +17 -0
  6. package/dist/cjs/components/BagelChart/styles.module.css +39 -0
  7. package/dist/cjs/components/BagelChart/utils.d.ts +4 -0
  8. package/dist/cjs/components/BagelChart/utils.js +15 -0
  9. package/dist/cjs/components/HeatMapChart/HeatMapChart.d.ts +7 -0
  10. package/dist/cjs/components/HeatMapChart/HeatMapChart.js +89 -0
  11. package/dist/cjs/components/HeatMapChart/constants.d.ts +4 -0
  12. package/dist/cjs/components/HeatMapChart/constants.js +8 -0
  13. package/dist/cjs/components/HeatMapChart/helpers/constants.d.ts +6 -0
  14. package/dist/cjs/components/HeatMapChart/helpers/constants.js +9 -0
  15. package/dist/cjs/components/HeatMapChart/helpers/getComputedColor.d.ts +1 -0
  16. package/dist/cjs/components/HeatMapChart/helpers/getComputedColor.js +7 -0
  17. package/dist/cjs/components/HeatMapChart/helpers/getContrastColor.d.ts +5 -0
  18. package/dist/cjs/components/HeatMapChart/helpers/getContrastColor.js +11 -0
  19. package/dist/cjs/components/HeatMapChart/helpers/getStyles.d.ts +3 -0
  20. package/dist/cjs/components/HeatMapChart/helpers/getStyles.js +33 -0
  21. package/dist/cjs/components/HeatMapChart/helpers/getTickValues.d.ts +2 -0
  22. package/dist/cjs/components/HeatMapChart/helpers/getTickValues.js +68 -0
  23. package/dist/cjs/components/HeatMapChart/helpers/index.d.ts +4 -0
  24. package/dist/cjs/components/HeatMapChart/helpers/index.js +20 -0
  25. package/dist/cjs/components/HeatMapChart/index.d.ts +2 -0
  26. package/dist/cjs/components/HeatMapChart/index.js +5 -0
  27. package/dist/cjs/components/HeatMapChart/styles.module.css +98 -0
  28. package/dist/cjs/components/HeatMapChart/types.d.ts +35 -0
  29. package/dist/cjs/components/HeatMapChart/types.js +2 -0
  30. package/dist/cjs/components/InteractiveChart/InteractiveChart.d.ts +12 -0
  31. package/dist/cjs/components/InteractiveChart/InteractiveChart.js +48 -0
  32. package/dist/cjs/components/InteractiveChart/configurations/boxPlot.d.ts +5 -0
  33. package/dist/cjs/components/InteractiveChart/configurations/boxPlot.js +75 -0
  34. package/dist/cjs/components/InteractiveChart/configurations/defaultPlot.d.ts +5 -0
  35. package/dist/cjs/components/InteractiveChart/configurations/defaultPlot.js +66 -0
  36. package/dist/cjs/components/InteractiveChart/configurations/index.d.ts +2 -0
  37. package/dist/cjs/components/InteractiveChart/configurations/index.js +18 -0
  38. package/dist/cjs/components/InteractiveChart/constants.d.ts +17 -0
  39. package/dist/cjs/components/InteractiveChart/constants.js +20 -0
  40. package/dist/cjs/components/InteractiveChart/helpers/pathRenderer.d.ts +3 -0
  41. package/dist/cjs/components/InteractiveChart/helpers/pathRenderer.js +45 -0
  42. package/dist/cjs/components/InteractiveChart/hooks/useComputedColors.d.ts +2 -0
  43. package/dist/cjs/components/InteractiveChart/hooks/useComputedColors.js +24 -0
  44. package/dist/cjs/components/InteractiveChart/hooks/useLayer.d.ts +12 -0
  45. package/dist/cjs/components/InteractiveChart/hooks/useLayer.js +22 -0
  46. package/dist/cjs/components/InteractiveChart/index.d.ts +2 -0
  47. package/dist/cjs/components/InteractiveChart/index.js +18 -0
  48. package/dist/cjs/components/InteractiveChart/plugins/boxPlotPlugin.d.ts +12 -0
  49. package/dist/cjs/components/InteractiveChart/plugins/boxPlotPlugin.js +90 -0
  50. package/dist/cjs/components/InteractiveChart/plugins/columnHighlightPlugin.d.ts +12 -0
  51. package/dist/cjs/components/InteractiveChart/plugins/columnHighlightPlugin.js +65 -0
  52. package/dist/cjs/components/InteractiveChart/plugins/legendAsTooltipPlugin.d.ts +11 -0
  53. package/dist/cjs/components/InteractiveChart/plugins/legendAsTooltipPlugin.js +58 -0
  54. package/dist/cjs/components/InteractiveChart/plugins/wheelZoomPlugin.d.ts +5 -0
  55. package/dist/cjs/components/InteractiveChart/plugins/wheelZoomPlugin.js +96 -0
  56. package/dist/cjs/components/InteractiveChart/styles.module.css +25 -0
  57. package/dist/cjs/components/InteractiveChart/types.d.ts +5 -0
  58. package/dist/cjs/components/InteractiveChart/types.js +2 -0
  59. package/dist/cjs/components/PieChart/Legend/Legend.d.ts +21 -0
  60. package/dist/cjs/components/PieChart/Legend/Legend.js +18 -0
  61. package/dist/cjs/components/PieChart/Legend/index.d.ts +1 -0
  62. package/dist/cjs/components/PieChart/Legend/index.js +17 -0
  63. package/dist/cjs/components/PieChart/Legend/styles.module.css +50 -0
  64. package/dist/cjs/components/PieChart/Pie.d.ts +17 -0
  65. package/dist/cjs/components/PieChart/Pie.js +24 -0
  66. package/dist/cjs/components/PieChart/PieChart.d.ts +3 -0
  67. package/dist/cjs/components/PieChart/PieChart.js +68 -0
  68. package/dist/cjs/components/PieChart/index.d.ts +2 -0
  69. package/dist/cjs/components/PieChart/index.js +17 -0
  70. package/dist/cjs/components/PieChart/styles.module.css +52 -0
  71. package/dist/cjs/components/PieChart/types.d.ts +36 -0
  72. package/dist/cjs/components/PieChart/types.js +2 -0
  73. package/dist/cjs/components/index.d.ts +4 -0
  74. package/dist/cjs/components/index.js +20 -0
  75. package/dist/cjs/constants/colors.d.ts +36 -0
  76. package/dist/cjs/constants/colors.js +59 -0
  77. package/dist/cjs/index.d.ts +1 -0
  78. package/dist/cjs/index.js +17 -0
  79. package/dist/esm/components/BagelChart/BagelChart.d.ts +9 -0
  80. package/dist/esm/components/BagelChart/BagelChart.js +25 -0
  81. package/dist/esm/components/BagelChart/index.d.ts +1 -0
  82. package/dist/esm/components/BagelChart/index.js +1 -0
  83. package/dist/esm/components/BagelChart/styles.module.css +39 -0
  84. package/dist/esm/components/BagelChart/utils.d.ts +4 -0
  85. package/dist/esm/components/BagelChart/utils.js +12 -0
  86. package/dist/esm/components/HeatMapChart/HeatMapChart.d.ts +7 -0
  87. package/dist/esm/components/HeatMapChart/HeatMapChart.js +83 -0
  88. package/dist/esm/components/HeatMapChart/constants.d.ts +4 -0
  89. package/dist/esm/components/HeatMapChart/constants.js +5 -0
  90. package/dist/esm/components/HeatMapChart/helpers/constants.d.ts +6 -0
  91. package/dist/esm/components/HeatMapChart/helpers/constants.js +6 -0
  92. package/dist/esm/components/HeatMapChart/helpers/getComputedColor.d.ts +1 -0
  93. package/dist/esm/components/HeatMapChart/helpers/getComputedColor.js +4 -0
  94. package/dist/esm/components/HeatMapChart/helpers/getContrastColor.d.ts +5 -0
  95. package/dist/esm/components/HeatMapChart/helpers/getContrastColor.js +7 -0
  96. package/dist/esm/components/HeatMapChart/helpers/getStyles.d.ts +3 -0
  97. package/dist/esm/components/HeatMapChart/helpers/getStyles.js +29 -0
  98. package/dist/esm/components/HeatMapChart/helpers/getTickValues.d.ts +2 -0
  99. package/dist/esm/components/HeatMapChart/helpers/getTickValues.js +61 -0
  100. package/dist/esm/components/HeatMapChart/helpers/index.d.ts +4 -0
  101. package/dist/esm/components/HeatMapChart/helpers/index.js +4 -0
  102. package/dist/esm/components/HeatMapChart/index.d.ts +2 -0
  103. package/dist/esm/components/HeatMapChart/index.js +1 -0
  104. package/dist/esm/components/HeatMapChart/styles.module.css +98 -0
  105. package/dist/esm/components/HeatMapChart/types.d.ts +35 -0
  106. package/dist/esm/components/HeatMapChart/types.js +1 -0
  107. package/dist/esm/components/InteractiveChart/InteractiveChart.d.ts +12 -0
  108. package/dist/esm/components/InteractiveChart/InteractiveChart.js +42 -0
  109. package/dist/esm/components/InteractiveChart/configurations/boxPlot.d.ts +5 -0
  110. package/dist/esm/components/InteractiveChart/configurations/boxPlot.js +71 -0
  111. package/dist/esm/components/InteractiveChart/configurations/defaultPlot.d.ts +5 -0
  112. package/dist/esm/components/InteractiveChart/configurations/defaultPlot.js +59 -0
  113. package/dist/esm/components/InteractiveChart/configurations/index.d.ts +2 -0
  114. package/dist/esm/components/InteractiveChart/configurations/index.js +2 -0
  115. package/dist/esm/components/InteractiveChart/constants.d.ts +17 -0
  116. package/dist/esm/components/InteractiveChart/constants.js +17 -0
  117. package/dist/esm/components/InteractiveChart/helpers/pathRenderer.d.ts +3 -0
  118. package/dist/esm/components/InteractiveChart/helpers/pathRenderer.js +39 -0
  119. package/dist/esm/components/InteractiveChart/hooks/useComputedColors.d.ts +2 -0
  120. package/dist/esm/components/InteractiveChart/hooks/useComputedColors.js +21 -0
  121. package/dist/esm/components/InteractiveChart/hooks/useLayer.d.ts +12 -0
  122. package/dist/esm/components/InteractiveChart/hooks/useLayer.js +16 -0
  123. package/dist/esm/components/InteractiveChart/index.d.ts +2 -0
  124. package/dist/esm/components/InteractiveChart/index.js +2 -0
  125. package/dist/esm/components/InteractiveChart/plugins/boxPlotPlugin.d.ts +12 -0
  126. package/dist/esm/components/InteractiveChart/plugins/boxPlotPlugin.js +84 -0
  127. package/dist/esm/components/InteractiveChart/plugins/columnHighlightPlugin.d.ts +12 -0
  128. package/dist/esm/components/InteractiveChart/plugins/columnHighlightPlugin.js +59 -0
  129. package/dist/esm/components/InteractiveChart/plugins/legendAsTooltipPlugin.d.ts +11 -0
  130. package/dist/esm/components/InteractiveChart/plugins/legendAsTooltipPlugin.js +52 -0
  131. package/dist/esm/components/InteractiveChart/plugins/wheelZoomPlugin.d.ts +5 -0
  132. package/dist/esm/components/InteractiveChart/plugins/wheelZoomPlugin.js +93 -0
  133. package/dist/esm/components/InteractiveChart/styles.module.css +25 -0
  134. package/dist/esm/components/InteractiveChart/types.d.ts +5 -0
  135. package/dist/esm/components/InteractiveChart/types.js +1 -0
  136. package/dist/esm/components/PieChart/Legend/Legend.d.ts +21 -0
  137. package/dist/esm/components/PieChart/Legend/Legend.js +12 -0
  138. package/dist/esm/components/PieChart/Legend/index.d.ts +1 -0
  139. package/dist/esm/components/PieChart/Legend/index.js +1 -0
  140. package/dist/esm/components/PieChart/Legend/styles.module.css +50 -0
  141. package/dist/esm/components/PieChart/Pie.d.ts +17 -0
  142. package/dist/esm/components/PieChart/Pie.js +21 -0
  143. package/dist/esm/components/PieChart/PieChart.d.ts +3 -0
  144. package/dist/esm/components/PieChart/PieChart.js +62 -0
  145. package/dist/esm/components/PieChart/index.d.ts +2 -0
  146. package/dist/esm/components/PieChart/index.js +1 -0
  147. package/dist/esm/components/PieChart/styles.module.css +52 -0
  148. package/dist/esm/components/PieChart/types.d.ts +36 -0
  149. package/dist/esm/components/PieChart/types.js +1 -0
  150. package/dist/esm/components/index.d.ts +4 -0
  151. package/dist/esm/components/index.js +4 -0
  152. package/dist/esm/constants/colors.d.ts +36 -0
  153. package/dist/esm/constants/colors.js +56 -0
  154. package/dist/esm/index.d.ts +1 -0
  155. package/dist/esm/index.js +1 -0
  156. package/package.json +5 -4
@@ -0,0 +1,25 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import cn from 'classnames';
14
+ import { PieChart } from 'react-minimal-pie-chart';
15
+ import { themeVars } from '@sbercloud/figma-tokens-cloud-platform';
16
+ import { NumberFormatter } from '@sbercloud/uikit-product-localization';
17
+ import { error, extractSupportProps } from '@sbercloud/uikit-product-utils';
18
+ import styles from './styles.module.css';
19
+ import { getSegmentColor } from './utils';
20
+ export function BagelChart(_a) {
21
+ var { value, total, title, className } = _a, rest = __rest(_a, ["value", "total", "title", "className"]);
22
+ error('Value is too long', value > 9999999);
23
+ error('Total is too long', total > 999999999);
24
+ return (_jsxs("div", Object.assign({ className: cn(styles.wrapper, className) }, extractSupportProps(rest), { children: [title && _jsx("div", { className: styles.titleWrapper, children: title }), _jsx(PieChart, { data: [{ value, color: getSegmentColor({ value, total }) }], totalValue: total, background: themeVars.sys.neutral.decorDefault, startAngle: 270, lineWidth: 15, label: () => (_jsxs(_Fragment, { children: [_jsx("text", { className: styles.value, x: 50, y: 45, children: _jsx(NumberFormatter, { value: value }) }), _jsx("text", { className: styles.limit, x: 50, y: 65, children: _jsx(NumberFormatter, { value: total }) })] })), labelPosition: 0 })] })));
25
+ }
@@ -0,0 +1 @@
1
+ export * from './BagelChart';
@@ -0,0 +1 @@
1
+ export * from './BagelChart';
@@ -0,0 +1,39 @@
1
+ .wrapper{
2
+ min-width:100px;
3
+ }
4
+
5
+ .titleWrapper{
6
+ font-family:var(--sans-title-m-font-family, SB Sans Interface);
7
+ font-weight:var(--sans-title-m-font-weight, Semibold);
8
+ line-height:var(--sans-title-m-line-height, 24px);
9
+ font-size:var(--sans-title-m-font-size, 16px);
10
+ letter-spacing:var(--sans-title-m-letter-spacing, 0.15px);
11
+ paragraph-spacing:var(--sans-title-m-paragraph-spacing, 8.8px);
12
+ color:var(--sys-neutral-text-support, #6d707f);
13
+ margin-bottom:8px;
14
+ display:flex;
15
+ justify-content:center;
16
+ gap:4px;
17
+ }
18
+
19
+ .value{
20
+ font-family:var(--sans-title-m-font-family, SB Sans Interface);
21
+ font-weight:var(--sans-title-m-font-weight, Semibold);
22
+ line-height:var(--sans-title-m-line-height, 24px);
23
+ font-size:var(--sans-title-m-font-size, 16px);
24
+ letter-spacing:var(--sans-title-m-letter-spacing, 0.15px);
25
+ paragraph-spacing:var(--sans-title-m-paragraph-spacing, 8.8px);
26
+ fill:var(--sys-neutral-text-main, #41424e);
27
+ text-anchor:middle;
28
+ }
29
+
30
+ .limit{
31
+ font-family:var(--sans-body-m-font-family, SB Sans Interface);
32
+ font-weight:var(--sans-body-m-font-weight, Regular);
33
+ line-height:var(--sans-body-m-line-height, 20px);
34
+ font-size:var(--sans-body-m-font-size, 14px);
35
+ letter-spacing:var(--sans-body-m-letter-spacing, 0.1px);
36
+ paragraph-spacing:var(--sans-body-m-paragraph-spacing, 7.7px);
37
+ fill:var(--sys-neutral-text-support, #6d707f);
38
+ text-anchor:middle;
39
+ }
@@ -0,0 +1,4 @@
1
+ export declare function getSegmentColor({ value, total }: {
2
+ value: number;
3
+ total: number;
4
+ }): string;
@@ -0,0 +1,12 @@
1
+ import { themeVars } from '@sbercloud/figma-tokens-cloud-platform';
2
+ export function getSegmentColor({ value, total }) {
3
+ const occupancyPercent = (value / total) * 100;
4
+ let segmentColor = themeVars.sys.green.accentDefault;
5
+ if (occupancyPercent > 50 && occupancyPercent <= 75) {
6
+ segmentColor = themeVars.sys.yellow.accentDefault;
7
+ }
8
+ else if (occupancyPercent > 75) {
9
+ segmentColor = themeVars.sys.red.accentDefault;
10
+ }
11
+ return segmentColor;
12
+ }
@@ -0,0 +1,7 @@
1
+ import { WithSupportProps } from '@sbercloud/uikit-product-utils';
2
+ import { XAxisPosition } from './constants';
3
+ import { HeatMapChartProps } from './types';
4
+ export declare function HeatMapChart({ data, options, className, ...rest }: WithSupportProps<HeatMapChartProps>): import("react/jsx-runtime").JSX.Element;
5
+ export declare namespace HeatMapChart {
6
+ var xAxisPositions: typeof XAxisPosition;
7
+ }
@@ -0,0 +1,83 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import cn from 'classnames';
14
+ import { scaleLinear } from 'd3-scale';
15
+ import { useCallback, useMemo, useRef, useState } from 'react';
16
+ import { HeatMapGrid } from 'react-grid-heatmap';
17
+ import { themeVars } from '@sbercloud/figma-tokens-cloud-platform';
18
+ import { extractSupportProps, useTheme } from '@sbercloud/uikit-product-utils';
19
+ import { Divider } from '@snack-uikit/divider';
20
+ import { useLayoutEffect } from '@snack-uikit/utils';
21
+ import { XAxisPosition } from './constants';
22
+ import { getComputedColor, getContrastColor, getStyles, getTickValues } from './helpers';
23
+ import { DEFAULT_CHART_HEIGHT, LEGEND_HEIGHT, TICKS_SIZE, TITLE_HEIGHT, X_AXIS_LABEL_HEIGHT, } from './helpers/constants';
24
+ import styles from './styles.module.css';
25
+ export function HeatMapChart(_a) {
26
+ var _b;
27
+ var { data, options, className } = _a, rest = __rest(_a, ["data", "options", "className"]);
28
+ const { title, height = DEFAULT_CHART_HEIGHT, axes = {}, formatter, legend, domain, cellRender, styles: stylesProp, } = options;
29
+ const { xAxis, yAxis } = axes;
30
+ const xAxisPosition = (xAxis === null || xAxis === void 0 ? void 0 : xAxis.position) || XAxisPosition.Bottom;
31
+ const isLegendEnabled = (_b = legend === null || legend === void 0 ? void 0 : legend.show) !== null && _b !== void 0 ? _b : true;
32
+ const colorContainerRef = useRef(null);
33
+ // TODO https://jira.sbercloud.tech/browse/FF-6024
34
+ const { theme } = useTheme();
35
+ const [colorRange, setColorRange] = useState(['#ffffff', '#000000']);
36
+ const [lightTextColor, setLightTextColor] = useState('#ffffff');
37
+ const [darkTextColor, setDarkTextColor] = useState('#000000');
38
+ useLayoutEffect(() => {
39
+ if (!colorContainerRef.current) {
40
+ return;
41
+ }
42
+ const rangeStart = getComputedColor(colorContainerRef.current, '--range-start');
43
+ const rangeEnd = getComputedColor(colorContainerRef.current, '--range-end');
44
+ const lightTextColor = getComputedColor(colorContainerRef.current, '--light-text');
45
+ const darkTextColor = getComputedColor(colorContainerRef.current, '--dark-text');
46
+ setColorRange([rangeStart, rangeEnd]);
47
+ setLightTextColor(lightTextColor);
48
+ setDarkTextColor(darkTextColor);
49
+ }, [theme]);
50
+ const colorScale = useMemo(() => scaleLinear(colorRange).domain(domain), [colorRange, domain]);
51
+ const commonStyles = useMemo(() => getStyles(colorScale, data), [colorScale, data]);
52
+ const legendTicks = useMemo(() => getTickValues(domain), [domain]);
53
+ const cellHeight = useMemo(() => {
54
+ var _a;
55
+ const titleHeight = title ? TITLE_HEIGHT : 0;
56
+ const xLabelsHeight = ((_a = xAxis === null || xAxis === void 0 ? void 0 : xAxis.ticks) === null || _a === void 0 ? void 0 : _a.length) ? TICKS_SIZE : 0;
57
+ const xAxisLabelHeight = (yAxis === null || yAxis === void 0 ? void 0 : yAxis.ticks) ? X_AXIS_LABEL_HEIGHT : 0;
58
+ const legendHeight = isLegendEnabled ? LEGEND_HEIGHT : 0;
59
+ const chartHeight = height - 48 - titleHeight - xLabelsHeight - xAxisLabelHeight - legendHeight;
60
+ return `${chartHeight / data.length}px`;
61
+ }, [data, height, title, xAxis, yAxis, isLegendEnabled]);
62
+ const gradient = useMemo(() => {
63
+ const parts = colorRange.map((color, i) => `${color} ${i * (100 / (colorRange.length - 1))}%`);
64
+ return `linear-gradient(90deg, ${parts})`;
65
+ }, [colorRange]);
66
+ const formatValue = useCallback((value) => (formatter && typeof formatter === 'function' ? formatter(value) : value), [formatter]);
67
+ return (_jsxs("div", Object.assign({ className: cn(styles.wrapper, className) }, extractSupportProps(rest), { ref: colorContainerRef, style: {
68
+ '--range-start': themeVars.sys.primary.decorDisabled,
69
+ '--range-end': themeVars.sys.primary.accentDefault,
70
+ '--light-text': themeVars.ref.brand['90'],
71
+ '--dark-text': themeVars.ref.brand['30'],
72
+ }, children: [title && _jsx("h3", { className: styles.title, children: title }), (xAxis === null || xAxis === void 0 ? void 0 : xAxis.label) && xAxisPosition === XAxisPosition.Top && _jsx("div", { className: styles.xAxisLabel, children: xAxis.label }), _jsxs("div", { className: styles.gridWrapper, "data-grid": Boolean(yAxis === null || yAxis === void 0 ? void 0 : yAxis.label) || undefined, children: [(yAxis === null || yAxis === void 0 ? void 0 : yAxis.label) && (_jsx("div", { className: styles.yAxisLabel, "data-x-axis-position": xAxisPosition, children: yAxis.label })), _jsx(HeatMapGrid, { data: data, xLabels: xAxis === null || xAxis === void 0 ? void 0 : xAxis.ticks, yLabels: yAxis === null || yAxis === void 0 ? void 0 : yAxis.ticks, xLabelsPos: xAxisPosition, yLabelsPos: 'left', cellRender:
73
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
+ cellRender ||
75
+ ((x, y, value) => (_jsx("h5", { className: styles.cell, title: String(value), style: {
76
+ '--color': getContrastColor({
77
+ lightColor: lightTextColor,
78
+ darkColor: darkTextColor,
79
+ rgb: colorScale(value),
80
+ }),
81
+ }, children: formatValue(value) }))), xLabelsStyle: (stylesProp === null || stylesProp === void 0 ? void 0 : stylesProp.xLabelsStyle) || commonStyles.xLabelsStyle, yLabelsStyle: (stylesProp === null || stylesProp === void 0 ? void 0 : stylesProp.yLabelsStyle) || commonStyles.yLabelsStyle, cellStyle: (stylesProp === null || stylesProp === void 0 ? void 0 : stylesProp.cellStyle) || commonStyles.cellStyle, cellHeight: cellHeight })] }), (xAxis === null || xAxis === void 0 ? void 0 : xAxis.label) && xAxisPosition === XAxisPosition.Bottom && _jsx("div", { className: styles.xAxisLabel, children: xAxis.label }), isLegendEnabled && (_jsxs("div", { className: styles.legend, children: [_jsx(Divider, {}), _jsx("div", { className: styles.gradient, style: { '--gradient': gradient } }), _jsx("div", { className: styles.legendTicksWrapper, children: legendTicks.map((tick) => (_jsx("span", { className: styles.tick, children: tick }, tick))) })] }))] })));
82
+ }
83
+ HeatMapChart.xAxisPositions = XAxisPosition;
@@ -0,0 +1,4 @@
1
+ export declare enum XAxisPosition {
2
+ Top = "top",
3
+ Bottom = "bottom"
4
+ }
@@ -0,0 +1,5 @@
1
+ export var XAxisPosition;
2
+ (function (XAxisPosition) {
3
+ XAxisPosition["Top"] = "top";
4
+ XAxisPosition["Bottom"] = "bottom";
5
+ })(XAxisPosition || (XAxisPosition = {}));
@@ -0,0 +1,6 @@
1
+ export declare const TITLE_HEIGHT = 74;
2
+ export declare const TICKS_SIZE = 34;
3
+ export declare const X_AXIS_LABEL_HEIGHT = 32;
4
+ export declare const LEGEND_HEIGHT = 94;
5
+ export declare const DEFAULT_CHART_HEIGHT = 700;
6
+ export declare const DEFAULT_LEGEND_TICKS_NUM = 5;
@@ -0,0 +1,6 @@
1
+ export const TITLE_HEIGHT = 74;
2
+ export const TICKS_SIZE = 34;
3
+ export const X_AXIS_LABEL_HEIGHT = 32;
4
+ export const LEGEND_HEIGHT = 94;
5
+ export const DEFAULT_CHART_HEIGHT = 700;
6
+ export const DEFAULT_LEGEND_TICKS_NUM = 5;
@@ -0,0 +1 @@
1
+ export declare function getComputedColor(el: HTMLElement, prop: string): string;
@@ -0,0 +1,4 @@
1
+ export function getComputedColor(el, prop) {
2
+ const styles = getComputedStyle(el);
3
+ return styles.getPropertyValue(prop);
4
+ }
@@ -0,0 +1,5 @@
1
+ export declare const getContrastColor: ({ rgb, darkColor, lightColor, }: {
2
+ rgb: string;
3
+ lightColor: string;
4
+ darkColor: string;
5
+ }) => string;
@@ -0,0 +1,7 @@
1
+ export const getContrastColor = ({ rgb, darkColor, lightColor, }) => {
2
+ // https://gomakethings.com/dynamically-changing-the-text-color-based-on-background-color-contrast-with-vanilla-js/
3
+ const bgColor = rgb.split(/\(([^)]+)\)/)[1].replace(/ /g, '');
4
+ const [r, g, b] = bgColor.split(',');
5
+ const yiq = (Math.round(parseInt(r) * 299) + Math.round(parseInt(g) * 587) + Math.round(parseInt(b) * 114)) / 1000;
6
+ return yiq >= 152 ? darkColor : lightColor;
7
+ };
@@ -0,0 +1,3 @@
1
+ import { ScaleLinear } from 'd3-scale';
2
+ import { HeatMapChartStyles } from '../types';
3
+ export declare const getStyles: (colorScale: ScaleLinear<string, string>, data: number[][]) => HeatMapChartStyles;
@@ -0,0 +1,29 @@
1
+ import { themeVars } from '@sbercloud/figma-tokens-cloud-platform';
2
+ import { TICKS_SIZE } from './constants';
3
+ export const getStyles = (colorScale, data) => ({
4
+ cellStyle: (x, y) => ({
5
+ backgroundColor: colorScale(data[x][y]),
6
+ display: 'flex',
7
+ alignItems: 'center',
8
+ justifyContent: 'center',
9
+ borderRadius: '4px',
10
+ padding: '4px',
11
+ borderColor: themeVars.sys.neutral.background1Level,
12
+ }),
13
+ xLabelsStyle: () => ({
14
+ fontSize: '12px',
15
+ lineHeight: '10px',
16
+ fontWeight: 400,
17
+ marginTop: '12px',
18
+ color: themeVars.sys.neutral.textSupport,
19
+ padding: 0,
20
+ height: `${TICKS_SIZE - 12}px`,
21
+ }),
22
+ yLabelsStyle: () => ({
23
+ width: `${TICKS_SIZE - 8}px`,
24
+ fontSize: '12px',
25
+ marginRight: '8px',
26
+ padding: '0',
27
+ color: themeVars.sys.neutral.textSupport,
28
+ }),
29
+ });
@@ -0,0 +1,2 @@
1
+ import { HeatMapChartOptions } from '../types';
2
+ export declare const getTickValues: (domain: HeatMapChartOptions["domain"]) => string[];
@@ -0,0 +1,61 @@
1
+ import range from 'lodash.range';
2
+ import { DEFAULT_LEGEND_TICKS_NUM } from './constants';
3
+ /**
4
+ * Returns a "nice" number approximately equal to range Rounds
5
+ * the number if round = true Takes the ceiling if round = false.
6
+ *
7
+ * @param range the data range
8
+ * @param round whether to round the result
9
+ * @return a "nice" number to be used for the data range
10
+ */
11
+ const niceNum = (range, round) => {
12
+ let niceFraction;
13
+ const exponent = Math.floor(Math.log10(range));
14
+ const fraction = range / Math.pow(10, exponent);
15
+ if (round) {
16
+ if (fraction < 1.5)
17
+ niceFraction = 1;
18
+ else if (fraction < 3)
19
+ niceFraction = 2;
20
+ else if (fraction < 7)
21
+ niceFraction = 5;
22
+ else
23
+ niceFraction = 10;
24
+ }
25
+ else {
26
+ if (fraction <= 1)
27
+ niceFraction = 1;
28
+ else if (fraction <= 2)
29
+ niceFraction = 2;
30
+ else if (fraction <= 5)
31
+ niceFraction = 5;
32
+ else
33
+ niceFraction = 10;
34
+ }
35
+ return niceFraction * Math.pow(10, exponent);
36
+ };
37
+ /**
38
+ * Calculate and update values for tick spacing and nice
39
+ * minimum and maximum data points on the axis.
40
+ */
41
+ const calculateTicks = (maxTicks, minPoint, maxPoint) => {
42
+ const range = niceNum(maxPoint - minPoint, false);
43
+ const tickSpacing = niceNum(range / (maxTicks - 1), true);
44
+ const niceMin = Math.floor(minPoint / tickSpacing) * tickSpacing;
45
+ const niceMax = Math.ceil(maxPoint / tickSpacing) * tickSpacing;
46
+ return [tickSpacing, niceMin, niceMax];
47
+ };
48
+ export const getTickValues = (domain) => {
49
+ const [min, max] = domain;
50
+ const [tickSpacing, niceMin, niceMax] = calculateTicks(DEFAULT_LEGEND_TICKS_NUM, min, max);
51
+ const rangeValues = range(niceMin, niceMax, tickSpacing).filter(v => (v > 1 ? Math.floor(v) > min : v > min));
52
+ return [...new Set([min, ...rangeValues, max])].map(value => {
53
+ if (value === 0) {
54
+ return '0';
55
+ }
56
+ if (value < 1) {
57
+ return value.toFixed(1);
58
+ }
59
+ return String(Math.floor(value));
60
+ });
61
+ };
@@ -0,0 +1,4 @@
1
+ export * from './getComputedColor';
2
+ export * from './getContrastColor';
3
+ export * from './getStyles';
4
+ export * from './getTickValues';
@@ -0,0 +1,4 @@
1
+ export * from './getComputedColor';
2
+ export * from './getContrastColor';
3
+ export * from './getStyles';
4
+ export * from './getTickValues';
@@ -0,0 +1,2 @@
1
+ export { HeatMapChart } from './HeatMapChart';
2
+ export type { HeatMapChartProps } from './types';
@@ -0,0 +1 @@
1
+ export { HeatMapChart } from './HeatMapChart';
@@ -0,0 +1,98 @@
1
+ .wrapper{
2
+ padding:24px;
3
+ background-color:var(--sys-neutral-background1-level, #fdfdfd);
4
+ border-radius:8px;
5
+ }
6
+
7
+ .gridWrapper{
8
+ position:relative;
9
+ display:block;
10
+ }
11
+ .gridWrapper[data-grid]{
12
+ display:grid;
13
+ grid-auto-rows:minmax(min-content, max-content);
14
+ grid-template-columns:auto 1fr;
15
+ }
16
+
17
+ .title{
18
+ font-family:var(--sans-title-m-font-family, SB Sans Interface);
19
+ font-weight:var(--sans-title-m-font-weight, Semibold);
20
+ line-height:var(--sans-title-m-line-height, 24px);
21
+ font-size:var(--sans-title-m-font-size, 16px);
22
+ letter-spacing:var(--sans-title-m-letter-spacing, 0.15px);
23
+ paragraph-spacing:var(--sans-title-m-paragraph-spacing, 8.8px);
24
+ margin-bottom:24px;
25
+ font-size:20px;
26
+ font-weight:bold;
27
+ color:var(--sys-neutral-text-main, #41424e);
28
+ height:50px;
29
+ }
30
+
31
+ .legend{
32
+ margin-top:24px;
33
+ height:70px;
34
+ }
35
+
36
+ .gradient{
37
+ height:20px;
38
+ margin:24px 0 8px;
39
+ background:var(--gradient);
40
+ background-color:var(--sys-red-accent-default, #cb3f3e) !important;
41
+ border-radius:4px;
42
+ }
43
+
44
+ .legendTicksWrapper{
45
+ display:flex;
46
+ justify-content:space-between;
47
+ }
48
+
49
+ .tick{
50
+ font-family:var(--sans-body-m-font-family, SB Sans Interface);
51
+ font-weight:var(--sans-body-m-font-weight, Regular);
52
+ line-height:var(--sans-body-m-line-height, 20px);
53
+ font-size:var(--sans-body-m-font-size, 14px);
54
+ letter-spacing:var(--sans-body-m-letter-spacing, 0.1px);
55
+ paragraph-spacing:var(--sans-body-m-paragraph-spacing, 7.7px);
56
+ color:var(--sys-neutral-text-support, #6d707f);
57
+ font-size:12px;
58
+ }
59
+
60
+ .cell{
61
+ font-family:var(--sans-body-s-font-family, SB Sans Interface);
62
+ font-weight:var(--sans-body-s-font-weight, Regular);
63
+ line-height:var(--sans-body-s-line-height, 16px);
64
+ font-size:var(--sans-body-s-font-size, 12px);
65
+ letter-spacing:var(--sans-body-s-letter-spacing, 0.1px);
66
+ paragraph-spacing:var(--sans-body-s-paragraph-spacing, 6.6px);
67
+ color:var(--color);
68
+ text-overflow:ellipsis;
69
+ overflow:hidden;
70
+ }
71
+
72
+ .xAxisLabel{
73
+ display:flex;
74
+ justify-content:center;
75
+ margin-top:8px;
76
+ color:var(--sys-neutral-text-support, #6d707f);
77
+ font-size:12px;
78
+ font-weight:600;
79
+ height:24px;
80
+ margin-left:6px;
81
+ }
82
+
83
+ .yAxisLabel{
84
+ margin-right:16px;
85
+ transform:rotate(180deg);
86
+ transform-origin:right, top;
87
+ writing-mode:vertical-rl;
88
+ text-align:center;
89
+ font-size:12px;
90
+ font-weight:600;
91
+ color:var(--sys-neutral-text-support, #6d707f);
92
+ }
93
+ .yAxisLabel[data-x-axis-position=top]{
94
+ margin-top:34px;
95
+ }
96
+ .yAxisLabel[data-x-axis-position=bottom]{
97
+ margin-bottom:34px;
98
+ }
@@ -0,0 +1,35 @@
1
+ import { ReactNode } from 'react';
2
+ import { XAxisPosition } from './constants';
3
+ export type HeatMapChartAxisOptions = {
4
+ label?: string;
5
+ ticks?: string[];
6
+ };
7
+ export type HeatMapChartLegendOptions = {
8
+ show?: boolean;
9
+ };
10
+ export type HeatMapChartAxesOptions = {
11
+ xAxis?: HeatMapChartAxisOptions & {
12
+ position?: XAxisPosition;
13
+ };
14
+ yAxis?: HeatMapChartAxisOptions;
15
+ };
16
+ export type HeatMapChartStyles = {
17
+ xLabelsStyle: (index: number) => Record<string, string | number>;
18
+ yLabelsStyle: (index: number) => Record<string, string | number>;
19
+ cellStyle: (x: number, y: number, ratio: number) => Record<string, string | number>;
20
+ };
21
+ export type HeatMapChartOptions = {
22
+ title?: string;
23
+ height?: number;
24
+ formatter?: (value: number) => string;
25
+ axes?: HeatMapChartAxesOptions;
26
+ domain: [number, number];
27
+ cellRender?: (x: number, y: number, value: number) => ReactNode;
28
+ legend?: HeatMapChartLegendOptions;
29
+ styles?: Partial<HeatMapChartStyles>;
30
+ };
31
+ export type HeatMapChartProps = {
32
+ data: number[][];
33
+ options: HeatMapChartOptions;
34
+ className?: string;
35
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import 'uplot/dist/uPlot.min.css';
2
+ import './styles.module.scss';
3
+ import uPlot from 'uplot';
4
+ import { WithSupportProps } from '@sbercloud/uikit-product-utils';
5
+ import { PlotType } from './types';
6
+ export type InteractiveChartProps = {
7
+ data: uPlot.AlignedData;
8
+ options?: Partial<uPlot.Options>;
9
+ type?: PlotType;
10
+ className?: string;
11
+ };
12
+ export declare function InteractiveChart({ data, options, type, className, ...rest }: WithSupportProps<InteractiveChartProps>): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,42 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import 'uplot/dist/uPlot.min.css';
14
+ import './styles.module.css';
15
+ import cn from 'classnames';
16
+ import merge from 'lodash.merge';
17
+ import { useMemo } from 'react';
18
+ import UPlotReact from 'uplot-react';
19
+ import { extractSupportProps } from '@sbercloud/uikit-product-utils';
20
+ import { CHART_OTHER_COLORS, CHART_SERIES_COLORS, COLOR_CONTAINER_CLASSNAME, } from '../../constants/colors';
21
+ import { getBoxPlotOptions, getDefaultPlotOptions } from './configurations';
22
+ import { PLOT_TYPES } from './constants';
23
+ import { useComputedColors } from './hooks/useComputedColors';
24
+ function chooseBaseOptions({ type, computedColors, }) {
25
+ switch (type) {
26
+ case PLOT_TYPES.BoxPlot:
27
+ return getBoxPlotOptions({ computedColors });
28
+ case PLOT_TYPES.Default:
29
+ default:
30
+ return getDefaultPlotOptions({ computedColors });
31
+ }
32
+ }
33
+ export function InteractiveChart(_a) {
34
+ var { data, options, type = PLOT_TYPES.Default, className } = _a, rest = __rest(_a, ["data", "options", "type", "className"]);
35
+ const style = useMemo(() => Object.entries(Object.assign(Object.assign({}, CHART_SERIES_COLORS), CHART_OTHER_COLORS)).reduce((styles, [key, value]) => {
36
+ styles[`--${key}`] = value;
37
+ return styles;
38
+ }, {}), []);
39
+ const computedColors = useComputedColors();
40
+ const resultOptions = useMemo(() => merge({}, chooseBaseOptions({ type, computedColors }), options), [computedColors, options, type]);
41
+ return (_jsx("div", Object.assign({}, extractSupportProps(rest), { className: cn(COLOR_CONTAINER_CLASSNAME, className), style: style, children: _jsx(UPlotReact, { options: resultOptions, data: data }) })));
42
+ }
@@ -0,0 +1,5 @@
1
+ import uPlot from 'uplot';
2
+ import { ColorMap } from '../../../constants/colors';
3
+ export declare const getBoxPlotOptions: ({ computedColors }: {
4
+ computedColors: ColorMap;
5
+ }) => uPlot.Options;
@@ -0,0 +1,71 @@
1
+ import { boxPlotPlugin } from '../plugins/boxPlotPlugin';
2
+ import { columnHighlightPlugin } from '../plugins/columnHighlightPlugin';
3
+ import { legendAsTooltipPlugin } from '../plugins/legendAsTooltipPlugin';
4
+ export const getBoxPlotOptions = ({ computedColors }) => ({
5
+ id: 'boxPlot',
6
+ title: 'Distribution of object predictions by bin',
7
+ width: 800,
8
+ height: 600,
9
+ cursor: {
10
+ drag: {
11
+ x: false,
12
+ y: false,
13
+ },
14
+ },
15
+ plugins: [
16
+ boxPlotPlugin({ computedColors }),
17
+ columnHighlightPlugin({ computedColors }),
18
+ legendAsTooltipPlugin({ computedColors }),
19
+ ],
20
+ series: [
21
+ {
22
+ label: 'bin',
23
+ },
24
+ {
25
+ label: 'X1',
26
+ },
27
+ {
28
+ label: 'Q1',
29
+ },
30
+ {
31
+ label: 'Median',
32
+ },
33
+ {
34
+ label: 'Q3',
35
+ },
36
+ {
37
+ label: 'X2',
38
+ },
39
+ ],
40
+ scales: {
41
+ x: {
42
+ distr: 2,
43
+ time: false,
44
+ range: (self, fromMin, fromMax) => [fromMin - 1, fromMax + 1],
45
+ },
46
+ y: {
47
+ time: false,
48
+ auto: true,
49
+ },
50
+ },
51
+ axes: [
52
+ {
53
+ label: 'Bin Number',
54
+ labelSize: 30,
55
+ stroke: '#808080',
56
+ grid: {
57
+ stroke: 'rgba(128, 128, 128, 0.15)',
58
+ width: 1 / devicePixelRatio,
59
+ },
60
+ },
61
+ {
62
+ label: 'Prediction',
63
+ labelSize: 30,
64
+ stroke: '#808080',
65
+ grid: {
66
+ stroke: 'rgba(128, 128, 128, 0.15)',
67
+ width: 1 / devicePixelRatio,
68
+ },
69
+ },
70
+ ],
71
+ });
@@ -0,0 +1,5 @@
1
+ import uPlot from 'uplot';
2
+ import { ColorMap } from '../../../constants/colors';
3
+ export declare const getDefaultPlotOptions: ({ computedColors }: {
4
+ computedColors: ColorMap;
5
+ }) => uPlot.Options;