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

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 +14 -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,59 @@
1
+ import Color from 'color';
2
+ import { OTHER_COLORS } from '../../../constants/colors';
3
+ import { wheelZoomPlugin } from '../plugins/wheelZoomPlugin';
4
+ export const getDefaultPlotOptions = ({ computedColors }) => {
5
+ const axisColor = new Color(computedColors[OTHER_COLORS.AxisColor]).alpha(0.8).rgb().string();
6
+ const labelColor = computedColors[OTHER_COLORS.LabelColor];
7
+ return {
8
+ id: 'defaultPlot',
9
+ title: 'Title',
10
+ width: 800,
11
+ height: 600,
12
+ cursor: {
13
+ drag: {
14
+ x: true,
15
+ y: true,
16
+ dist: 10,
17
+ uni: 10,
18
+ },
19
+ },
20
+ plugins: [wheelZoomPlugin({ factor: 0.75 })],
21
+ series: [
22
+ {
23
+ label: 'x',
24
+ },
25
+ ],
26
+ scales: {
27
+ x: {
28
+ time: false,
29
+ auto: true,
30
+ },
31
+ y: {
32
+ time: false,
33
+ auto: true,
34
+ },
35
+ },
36
+ axes: [
37
+ {
38
+ show: true,
39
+ label: 'x',
40
+ labelSize: 30,
41
+ stroke: labelColor,
42
+ grid: {
43
+ stroke: axisColor,
44
+ width: 1 / devicePixelRatio,
45
+ },
46
+ },
47
+ {
48
+ show: true,
49
+ label: 'y',
50
+ labelSize: 30,
51
+ stroke: labelColor,
52
+ grid: {
53
+ stroke: axisColor,
54
+ width: 1 / devicePixelRatio,
55
+ },
56
+ },
57
+ ],
58
+ };
59
+ };
@@ -0,0 +1,2 @@
1
+ export * from './boxPlot';
2
+ export * from './defaultPlot';
@@ -0,0 +1,2 @@
1
+ export * from './boxPlot';
2
+ export * from './defaultPlot';
@@ -0,0 +1,17 @@
1
+ export declare const PLOT_TYPES: {
2
+ readonly BoxPlot: "boxPlot";
3
+ readonly Default: "default";
4
+ };
5
+ export declare const LINE_INTERPOLATIONS: {
6
+ readonly Linear: "linear";
7
+ readonly StepAfter: "stepAfter";
8
+ readonly StepBefore: "stepBefore";
9
+ readonly Spline: "spline";
10
+ };
11
+ export declare const DRAW_STYLES: {
12
+ readonly Line: "line";
13
+ readonly Bars: "bars";
14
+ readonly Points: "points";
15
+ readonly BarsLeft: "barsLeft";
16
+ readonly BarsRight: "barsRight";
17
+ };
@@ -0,0 +1,17 @@
1
+ export const PLOT_TYPES = {
2
+ BoxPlot: 'boxPlot',
3
+ Default: 'default',
4
+ };
5
+ export const LINE_INTERPOLATIONS = {
6
+ Linear: 'linear',
7
+ StepAfter: 'stepAfter',
8
+ StepBefore: 'stepBefore',
9
+ Spline: 'spline',
10
+ };
11
+ export const DRAW_STYLES = {
12
+ Line: 'line',
13
+ Bars: 'bars',
14
+ Points: 'points',
15
+ BarsLeft: 'barsLeft',
16
+ BarsRight: 'barsRight',
17
+ };
@@ -0,0 +1,3 @@
1
+ import uPlot from 'uplot';
2
+ import { DrawStyle, LineInterpolation } from '../types';
3
+ export declare function getPathRenderer(drawStyle: DrawStyle, lineInterpolation?: LineInterpolation): (self: uPlot, seriesIdx: number, idx0: number, idx1: number) => uPlot.Series.Paths | null;
@@ -0,0 +1,39 @@
1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts-nocheck
3
+ /* eslint-disable */
4
+ import uPlot from 'uplot';
5
+ import { LINE_INTERPOLATIONS, DRAW_STYLES } from '../constants';
6
+ const { linear, stepped, bars, spline } = uPlot.paths;
7
+ const _bars60_100 = bars({ size: [0.6, 100] });
8
+ const _bars100Left = bars({ size: [1], align: 1 });
9
+ const _bars100Right = bars({ size: [1], align: -1 });
10
+ const _stepBefore = stepped({ align: -1 });
11
+ const _stepAfter = stepped({ align: 1 });
12
+ const _linear = linear();
13
+ const _spline = spline();
14
+ export function getPathRenderer(drawStyle, lineInterpolation) {
15
+ return function pathRenderer(self, seriesIdx, idx0, idx1) {
16
+ const style = drawStyle;
17
+ const interp = lineInterpolation;
18
+ const renderer = style === DRAW_STYLES.Line
19
+ ? interp === LINE_INTERPOLATIONS.Linear
20
+ ? _linear
21
+ : interp === LINE_INTERPOLATIONS.StepAfter
22
+ ? _stepAfter
23
+ : interp === LINE_INTERPOLATIONS.StepBefore
24
+ ? _stepBefore
25
+ : interp === LINE_INTERPOLATIONS.Spline
26
+ ? _spline
27
+ : null
28
+ : style === DRAW_STYLES.Bars
29
+ ? _bars60_100
30
+ : style === DRAW_STYLES.BarsLeft
31
+ ? _bars100Left
32
+ : style === DRAW_STYLES.BarsRight
33
+ ? _bars100Right
34
+ : style === DRAW_STYLES.Points
35
+ ? () => null
36
+ : () => null;
37
+ return renderer(self, seriesIdx, idx0, idx1);
38
+ };
39
+ }
@@ -0,0 +1,2 @@
1
+ import { SeriesColorMap } from '../../../constants/colors';
2
+ export declare function useComputedColors(): SeriesColorMap;
@@ -0,0 +1,21 @@
1
+ import { useState } from 'react';
2
+ import { useTheme } from '@sbercloud/uikit-product-utils';
3
+ import { useLayoutEffect } from '@snack-uikit/utils';
4
+ import { COLOR_CONTAINER_CLASSNAME, OTHER_COLORS, SERIES_COLORS } from '../../../constants/colors';
5
+ const EMPTY_COLORS = {};
6
+ export function useComputedColors() {
7
+ const { theme } = useTheme();
8
+ const [computedColors, setComputedColors] = useState(EMPTY_COLORS);
9
+ useLayoutEffect(() => {
10
+ const colorContainer = document.querySelector('.' + COLOR_CONTAINER_CLASSNAME);
11
+ if (!colorContainer) {
12
+ return;
13
+ }
14
+ const styles = getComputedStyle(colorContainer);
15
+ setComputedColors(Object.values(Object.assign(Object.assign({}, SERIES_COLORS), OTHER_COLORS)).reduce((colors, color) => {
16
+ colors[color] = styles.getPropertyValue(`--${color}`);
17
+ return colors;
18
+ }, {}));
19
+ }, [theme]);
20
+ return computedColors;
21
+ }
@@ -0,0 +1,12 @@
1
+ import { Series } from 'uplot';
2
+ import { SeriesColor } from '../../../constants/colors';
3
+ import { DrawStyle, LineInterpolation } from '../types';
4
+ type Layer = Partial<Series>;
5
+ type UseLayerProps = {
6
+ label: string;
7
+ color: SeriesColor;
8
+ drawStyle: DrawStyle;
9
+ lineInterpolation?: LineInterpolation;
10
+ };
11
+ export declare function useLayer({ label, color, drawStyle, lineInterpolation }: UseLayerProps): Layer;
12
+ export {};
@@ -0,0 +1,16 @@
1
+ import Color from 'color';
2
+ import { useMemo } from 'react';
3
+ import { getPathRenderer } from '../helpers/pathRenderer';
4
+ import { useComputedColors } from './useComputedColors';
5
+ export function useLayer({ label, color, drawStyle, lineInterpolation }) {
6
+ const computedColors = useComputedColors();
7
+ const stroke = computedColors[color];
8
+ const fill = new Color(stroke).alpha(0.1).rgb().string();
9
+ return useMemo(() => ({
10
+ label,
11
+ stroke,
12
+ fill,
13
+ width: 2,
14
+ paths: getPathRenderer(drawStyle, lineInterpolation),
15
+ }), [drawStyle, label, stroke, fill, lineInterpolation]);
16
+ }
@@ -0,0 +1,2 @@
1
+ export * from './InteractiveChart';
2
+ export * from './hooks/useLayer';
@@ -0,0 +1,2 @@
1
+ export * from './InteractiveChart';
2
+ export * from './hooks/useLayer';
@@ -0,0 +1,12 @@
1
+ import { ColorMap } from '../../../constants/colors';
2
+ export declare function boxPlotPlugin({ gap, bodyMaxWidth, shadowWidth, computedColors, }: {
3
+ gap?: number;
4
+ bodyMaxWidth?: number;
5
+ shadowWidth?: number;
6
+ computedColors: ColorMap;
7
+ }): {
8
+ opts: (u: any, opts: any) => void;
9
+ hooks: {
10
+ draw: (u: any) => void;
11
+ };
12
+ };
@@ -0,0 +1,84 @@
1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts-nocheck
3
+ /* eslint-disable */
4
+ import Color from 'color';
5
+ import uPlot from 'uplot';
6
+ import { SERIES_COLORS, OTHER_COLORS } from '../../../constants/colors';
7
+ export function boxPlotPlugin({ gap = 5, bodyMaxWidth = 60, shadowWidth = 3, computedColors, }) {
8
+ const shadowColor = computedColors[OTHER_COLORS.ShadowColor];
9
+ const lineColor = new Color(computedColors[OTHER_COLORS.LineColor]).alpha(0.5).rgb().string();
10
+ function roundRect(ctx, x, y, width, height, radius) {
11
+ ctx.beginPath();
12
+ ctx.moveTo(x + radius, y);
13
+ ctx.lineTo(x + width - radius, y);
14
+ ctx.quadraticCurveTo(x + width, y, x + width, y - radius);
15
+ ctx.lineTo(x + width, y + height + radius);
16
+ ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
17
+ ctx.lineTo(x + radius, y + height);
18
+ ctx.quadraticCurveTo(x, y + height, x, y + height + radius);
19
+ ctx.lineTo(x, y - radius);
20
+ ctx.quadraticCurveTo(x, y, x + radius, y);
21
+ ctx.closePath();
22
+ ctx.fill();
23
+ }
24
+ function drawBoxes(u) {
25
+ u.ctx.save();
26
+ const offset = (shadowWidth % 2) / 2;
27
+ u.ctx.translate(offset, offset);
28
+ const [iMin, iMax] = u.series[0].idxs;
29
+ for (let i = iMin; i <= iMax; i++) {
30
+ const xVal = u.scales.x.distr === 2 ? i : u.data[0][i];
31
+ const open = u.data[1][i];
32
+ const low = u.data[2][i];
33
+ const median = u.data[3][i];
34
+ const high = u.data[4][i];
35
+ const close = u.data[5][i];
36
+ const timeAsX = u.valToPos(xVal, 'x', true);
37
+ const openAsY = u.valToPos(open, 'y', true);
38
+ const lowAsY = u.valToPos(low, 'y', true);
39
+ const medianAsY = u.valToPos(median, 'y', true);
40
+ const highAsY = u.valToPos(high, 'y', true);
41
+ const closeAsY = u.valToPos(close, 'y', true);
42
+ // moustache
43
+ const shadowHeight = closeAsY - openAsY;
44
+ const shadowX = timeAsX - shadowWidth / 2;
45
+ const shadowY = openAsY;
46
+ const columnWidth = u.bbox.width / (iMax - iMin + 2);
47
+ const bodyWidth = Math.min(bodyMaxWidth, columnWidth - gap);
48
+ u.ctx.fillStyle = shadowColor;
49
+ u.ctx.fillRect(Math.round(shadowX), Math.round(shadowY), Math.round(shadowWidth), Math.round(shadowHeight));
50
+ u.ctx.fillRect(Math.round(timeAsX - bodyWidth / 4), Math.round(shadowY - shadowWidth / 2), Math.round(bodyWidth / 2), Math.round(shadowWidth));
51
+ u.ctx.fillRect(Math.round(timeAsX - bodyWidth / 4), Math.round(shadowY + shadowHeight - shadowWidth / 2), Math.round(bodyWidth / 2), Math.round(shadowWidth));
52
+ // body rect
53
+ const bodyHeight = highAsY - lowAsY;
54
+ const bodyX = timeAsX - bodyWidth / 2;
55
+ const bodyY = lowAsY;
56
+ if (Math.abs(bodyHeight) > 8) {
57
+ u.ctx.fillStyle = computedColors === null || computedColors === void 0 ? void 0 : computedColors[Object.values(SERIES_COLORS)[i % Object.keys(SERIES_COLORS).length]];
58
+ roundRect(u.ctx, Math.round(bodyX), Math.round(bodyY), Math.round(bodyWidth), Math.round(bodyHeight), 8, true, true);
59
+ u.ctx.fillStyle = lineColor;
60
+ u.ctx.fillRect(Math.round(bodyX), medianAsY - shadowWidth / 2, Math.round(bodyWidth), Math.round(shadowWidth));
61
+ }
62
+ }
63
+ u.ctx.translate(-offset, -offset);
64
+ u.ctx.restore();
65
+ }
66
+ return {
67
+ opts: (u, opts) => {
68
+ uPlot.assign(opts, {
69
+ cursor: {
70
+ points: {
71
+ show: false,
72
+ },
73
+ },
74
+ });
75
+ opts.series.forEach(series => {
76
+ series.paths = () => null;
77
+ series.points = { show: false };
78
+ });
79
+ },
80
+ hooks: {
81
+ draw: drawBoxes,
82
+ },
83
+ };
84
+ }
@@ -0,0 +1,12 @@
1
+ import uPlot from 'uplot';
2
+ import { ColorMap } from '../../../constants/colors';
3
+ export declare function columnHighlightPlugin({ className, computedColors, }: {
4
+ className?: string;
5
+ computedColors: ColorMap;
6
+ }): {
7
+ opts: (u: any, opts: any) => void;
8
+ hooks: {
9
+ init: (u: uPlot) => void;
10
+ setCursor: (u: any) => void;
11
+ };
12
+ };
@@ -0,0 +1,59 @@
1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts-nocheck
3
+ /* eslint-disable */
4
+ import Color from 'color';
5
+ import uPlot from 'uplot';
6
+ import { OTHER_COLORS } from '../../../constants/colors';
7
+ export function columnHighlightPlugin({ className = '', computedColors, }) {
8
+ const backgroundColor = new Color(computedColors[OTHER_COLORS.ColumnHighlightColor]).alpha(0.5).rgb().string();
9
+ let underEl, overEl, currIdx;
10
+ function init(u) {
11
+ underEl = u.under;
12
+ overEl = u.over;
13
+ const highlightEl = document.createElement('div');
14
+ className && highlightEl.classList.add(className);
15
+ uPlot.assign(highlightEl.style, {
16
+ pointerEvents: 'none',
17
+ display: 'none',
18
+ position: 'absolute',
19
+ left: 0,
20
+ top: 0,
21
+ height: '100%',
22
+ backgroundColor,
23
+ });
24
+ underEl.appendChild(highlightEl);
25
+ u._highlightEl = highlightEl;
26
+ // show/hide highlight on enter/exit
27
+ overEl.addEventListener('mouseenter', () => {
28
+ highlightEl.style.display = null;
29
+ });
30
+ overEl.addEventListener('mouseleave', () => {
31
+ highlightEl.style.display = 'none';
32
+ });
33
+ }
34
+ function update(u) {
35
+ if (currIdx !== u.cursor.idx) {
36
+ currIdx = u.cursor.idx;
37
+ const highlightEl = u._highlightEl;
38
+ const dx = u.scales.x.max - u.scales.x.min;
39
+ const width = u.bbox.width / dx / devicePixelRatio;
40
+ const left = u.valToPos(currIdx, 'x') - width / 2;
41
+ highlightEl.style.transform = 'translateX(' + Math.round(left) + 'px)';
42
+ highlightEl.style.width = Math.round(width) + 'px';
43
+ }
44
+ }
45
+ return {
46
+ opts: (u, opts) => {
47
+ uPlot.assign(opts, {
48
+ cursor: {
49
+ x: false,
50
+ y: false,
51
+ },
52
+ });
53
+ },
54
+ hooks: {
55
+ init: init,
56
+ setCursor: update,
57
+ },
58
+ };
59
+ }
@@ -0,0 +1,11 @@
1
+ import uPlot from 'uplot';
2
+ import { ColorMap } from '../../../constants/colors';
3
+ export declare function legendAsTooltipPlugin({ className, computedColors, }: {
4
+ className?: string;
5
+ computedColors: ColorMap;
6
+ }): {
7
+ hooks: {
8
+ init: (u: uPlot, opts: any) => void;
9
+ setCursor: (u: any) => void;
10
+ };
11
+ };
@@ -0,0 +1,52 @@
1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts-nocheck
3
+ /* eslint-disable */
4
+ import uPlot from 'uplot';
5
+ import { OTHER_COLORS } from '../../../constants/colors';
6
+ export function legendAsTooltipPlugin({ className = '', computedColors, }) {
7
+ const backgroundColor = computedColors[OTHER_COLORS.TooltipBackgroundColor];
8
+ const color = computedColors[OTHER_COLORS.TooltipColor];
9
+ function init(u, opts) {
10
+ const legendEl = u.root.querySelector(`.u-legend`);
11
+ legendEl.classList.remove('u-inline');
12
+ className && legendEl.classList.add(className);
13
+ uPlot.assign(legendEl.style, {
14
+ borderRadius: '4px',
15
+ textAlign: 'left',
16
+ pointerEvents: 'none',
17
+ display: 'none',
18
+ position: 'absolute',
19
+ left: 0,
20
+ top: 0,
21
+ zIndex: 100,
22
+ backgroundColor,
23
+ color,
24
+ });
25
+ // hide series color markers
26
+ const idents = legendEl.querySelectorAll('.u-marker');
27
+ for (let i = 0; i < idents.length; i++)
28
+ idents[i].style.display = 'none';
29
+ const overEl = u.over;
30
+ overEl.style.overflow = 'visible';
31
+ // move legend into plot bounds
32
+ overEl.appendChild(legendEl);
33
+ // show/hide tooltip on enter/exit
34
+ overEl.addEventListener('mouseenter', () => {
35
+ legendEl.style.display = null;
36
+ });
37
+ overEl.addEventListener('mouseleave', () => {
38
+ legendEl.style.display = 'none';
39
+ });
40
+ }
41
+ function update(u) {
42
+ const { left, top } = u.cursor;
43
+ const legendEl = u.root.querySelector(`.u-legend`);
44
+ legendEl.style.transform = 'translate(' + (left + 15) + 'px, ' + top + 'px)';
45
+ }
46
+ return {
47
+ hooks: {
48
+ init: init,
49
+ setCursor: update,
50
+ },
51
+ };
52
+ }
@@ -0,0 +1,5 @@
1
+ export declare function wheelZoomPlugin(opts: any): {
2
+ hooks: {
3
+ ready: (u: any) => void;
4
+ };
5
+ };
@@ -0,0 +1,93 @@
1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts-nocheck
3
+ /* eslint-disable */
4
+ export function wheelZoomPlugin(opts) {
5
+ const factor = opts.factor || 0.75;
6
+ let xMin, xMax, yMin, yMax, xRange, yRange;
7
+ function clamp(nRange, nMin, nMax, fRange, fMin, fMax) {
8
+ if (nRange > fRange) {
9
+ nMin = fMin;
10
+ nMax = fMax;
11
+ }
12
+ else if (nMin < fMin) {
13
+ nMin = fMin;
14
+ nMax = fMin + nRange;
15
+ }
16
+ else if (nMax > fMax) {
17
+ nMax = fMax;
18
+ nMin = fMax - nRange;
19
+ }
20
+ return [nMin, nMax];
21
+ }
22
+ return {
23
+ hooks: {
24
+ ready: u => {
25
+ xMin = u.scales.x.min;
26
+ xMax = u.scales.x.max;
27
+ yMin = u.scales.y.min;
28
+ yMax = u.scales.y.max;
29
+ xRange = xMax - xMin;
30
+ yRange = yMax - yMin;
31
+ const plot = u.root.querySelector('.u-over');
32
+ const rect = plot.getBoundingClientRect();
33
+ // wheel drag pan
34
+ plot.addEventListener('mousedown', e => {
35
+ if (e.button == 1) {
36
+ // plot.style.cursor = "move";
37
+ e.preventDefault();
38
+ const left0 = e.clientX;
39
+ // let top0 = e.clientY;
40
+ const scXMin0 = u.scales.x.min;
41
+ const scXMax0 = u.scales.x.max;
42
+ const xUnitsPerPx = u.posToVal(1, 'x') - u.posToVal(0, 'x');
43
+ function onmove(e) {
44
+ e.preventDefault();
45
+ const left1 = e.clientX;
46
+ // let top1 = e.clientY;
47
+ const dx = xUnitsPerPx * (left1 - left0);
48
+ u.setScale('x', {
49
+ min: scXMin0 - dx,
50
+ max: scXMax0 - dx,
51
+ });
52
+ }
53
+ function onup(e) {
54
+ document.removeEventListener('mousemove', onmove);
55
+ document.removeEventListener('mouseup', onup);
56
+ }
57
+ document.addEventListener('mousemove', onmove);
58
+ document.addEventListener('mouseup', onup);
59
+ }
60
+ });
61
+ // wheel scroll zoom
62
+ plot.addEventListener('wheel', e => {
63
+ e.preventDefault();
64
+ const { left, top } = u.cursor;
65
+ const leftPct = left / rect.width;
66
+ const btmPct = 1 - top / rect.height;
67
+ const xVal = u.posToVal(left, 'x');
68
+ const yVal = u.posToVal(top, 'y');
69
+ const oxRange = u.scales.x.max - u.scales.x.min;
70
+ const oyRange = u.scales.y.max - u.scales.y.min;
71
+ const nxRange = e.deltaY < 0 ? oxRange * factor : oxRange / factor;
72
+ let nxMin = xVal - leftPct * nxRange;
73
+ let nxMax = nxMin + nxRange;
74
+ [nxMin, nxMax] = clamp(nxRange, nxMin, nxMax, xRange, xMin, xMax);
75
+ const nyRange = e.deltaY < 0 ? oyRange * factor : oyRange / factor;
76
+ let nyMin = yVal - btmPct * nyRange;
77
+ let nyMax = nyMin + nyRange;
78
+ [nyMin, nyMax] = clamp(nyRange, nyMin, nyMax, yRange, yMin, yMax);
79
+ u.batch(() => {
80
+ u.setScale('x', {
81
+ min: nxMin,
82
+ max: nxMax,
83
+ });
84
+ u.setScale('y', {
85
+ min: nyMin,
86
+ max: nyMax,
87
+ });
88
+ });
89
+ });
90
+ },
91
+ },
92
+ };
93
+ }
@@ -0,0 +1,25 @@
1
+ :global .interactive-chart-wrapper{
2
+ }
3
+ :global .interactive-chart-wrapper .uplot{
4
+ font-family:inherit;
5
+ background-color:var(--sys-neutral-background1-level, #fdfdfd);
6
+ padding:16px 0;
7
+ border-radius:8px;
8
+ color:var(--sys-neutral-text-main, #41424e);
9
+ }
10
+ :global .interactive-chart-wrapper .uplot .u-title{
11
+ font-size:20px;
12
+ text-align:unset;
13
+ padding-left:24px;
14
+ }
15
+ :global .interactive-chart-wrapper .u-hz .u-cursor-x, :global .interactive-chart-wrapper .u-vt .u-cursor-y, :global .interactive-chart-wrapper .u-hz .u-cursor-y, :global .interactive-chart-wrapper .u-vt .u-cursor-x{
16
+ border-color:var(--sys-neutral-decor-default, #dde0ea);
17
+ }
18
+ :global .interactive-chart-wrapper .u-select{
19
+ background-color:var(--sys-neutral-decor-disabled, #e6e8ef);
20
+ }
21
+ :global .interactive-chart-wrapper table .u-series .u-marker{
22
+ width:16px;
23
+ height:16px;
24
+ border-radius:16px;
25
+ }
@@ -0,0 +1,5 @@
1
+ import { ValueOf } from '@snack-uikit/utils';
2
+ import { DRAW_STYLES, LINE_INTERPOLATIONS, PLOT_TYPES } from './constants';
3
+ export type PlotType = ValueOf<typeof PLOT_TYPES>;
4
+ export type LineInterpolation = ValueOf<typeof LINE_INTERPOLATIONS>;
5
+ export type DrawStyle = ValueOf<typeof DRAW_STYLES>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import { MouseEvent } from 'react';
2
+ import { TextLike } from '../types';
3
+ type LegendItem = {
4
+ label: TextLike;
5
+ value: TextLike;
6
+ color?: string;
7
+ id?: string;
8
+ };
9
+ type LegendItemProps = LegendItem & {
10
+ size: 's' | 'm' | 'l';
11
+ onItemClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
12
+ };
13
+ declare function LegendItem({ color, label, value, size, onItemClick }: LegendItemProps): import("react/jsx-runtime").JSX.Element;
14
+ type LegendProps = {
15
+ data: Array<LegendItem>;
16
+ typographySize: 's' | 'm' | 'l';
17
+ legendTitle?: string;
18
+ onItemClick?: (event: MouseEvent<HTMLAnchorElement>, data: LegendItem) => void;
19
+ };
20
+ export declare function Legend({ data, legendTitle, typographySize, onItemClick }: LegendProps): import("react/jsx-runtime").JSX.Element;
21
+ export {};
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Fragment } from 'react';
3
+ import { Divider } from '@snack-uikit/divider';
4
+ import { Link } from '@snack-uikit/link';
5
+ import { Typography } from '@snack-uikit/typography';
6
+ import styles from './styles.module.css';
7
+ function LegendItem({ color, label, value, size, onItemClick }) {
8
+ return (_jsxs("div", { className: styles.legendItemWrapper, children: [_jsxs("span", { className: styles.legendItemTitle, children: [color && _jsx("span", { className: styles.dot, style: { '--color': color } }), _jsx(Link, { onClick: onItemClick, text: String(label), size: size })] }), _jsx("span", { className: styles.legendValue, children: value })] }));
9
+ }
10
+ export function Legend({ data, legendTitle, typographySize, onItemClick }) {
11
+ return (_jsxs("div", { className: styles.legend, children: [legendTitle && (_jsxs(_Fragment, { children: [_jsx(Typography, { purpose: 'label', family: 'sans', size: typographySize, children: legendTitle }), _jsx("div", { className: styles.legendDividerWrapper, children: _jsx(Divider, {}) })] })), data.map((item, index) => (_jsxs(Fragment, { children: [_jsx(LegendItem, Object.assign({}, item, { size: typographySize, onItemClick: onItemClick ? event => onItemClick(event, item) : undefined })), index !== data.length - 1 && (_jsx("div", { className: styles.legendDividerWrapper, children: _jsx(Divider, {}) }))] }, `legend_${item.label}_${index}`)))] }));
12
+ }
@@ -0,0 +1 @@
1
+ export * from './Legend';
@@ -0,0 +1 @@
1
+ export * from './Legend';