@wonderflow/charts 12.11.0 → 13.0.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.
Files changed (161) hide show
  1. package/dist/components/bar-chart/bar-chart.d.ts +33 -5
  2. package/dist/components/bar-chart/bar-chart.d.ts.map +1 -1
  3. package/dist/components/bar-chart/bar-chart.js +20 -45
  4. package/dist/components/bar-chart/bar-chart.test.js +7 -1
  5. package/dist/components/cartesian-base/cartesian-base-axis.d.ts.map +1 -1
  6. package/dist/components/cartesian-base/cartesian-base-axis.js +10 -11
  7. package/dist/components/cartesian-base/cartesian-base-legend.d.ts.map +1 -1
  8. package/dist/components/cartesian-base/cartesian-base-legend.js +3 -3
  9. package/dist/components/cartesian-base/cartesian-base.d.ts +27 -0
  10. package/dist/components/cartesian-base/cartesian-base.d.ts.map +1 -1
  11. package/dist/components/cartesian-base/cartesian-base.js +7 -3
  12. package/dist/components/cartesian-base/cartesian-base.module.css +1 -1
  13. package/dist/components/headings/headings.d.ts +19 -2
  14. package/dist/components/headings/headings.d.ts.map +1 -1
  15. package/dist/components/headings/headings.js +72 -6
  16. package/dist/components/headings/headings.module.css +1 -0
  17. package/dist/components/headings/headings.test.d.ts +1 -1
  18. package/dist/components/headings/headings.test.d.ts.map +1 -1
  19. package/dist/components/headings/headings.test.js +37 -3
  20. package/dist/components/line-chart/line-chart.d.ts +29 -13
  21. package/dist/components/line-chart/line-chart.d.ts.map +1 -1
  22. package/dist/components/line-chart/line-chart.js +4 -2
  23. package/dist/components/line-chart/line-chart.test.js +2 -2
  24. package/dist/components/loader/bar-chart-loader.d.ts.map +1 -1
  25. package/dist/components/loader/bar-chart-loader.js +1 -1
  26. package/dist/components/loader/loader.js +2 -2
  27. package/dist/components/loader/loader.test.js +4 -2
  28. package/dist/components/shapes/bars/bars-average.d.ts +3 -0
  29. package/dist/components/shapes/bars/bars-average.d.ts.map +1 -0
  30. package/dist/components/shapes/bars/bars-average.js +30 -0
  31. package/dist/components/shapes/bars/bars-overlay.d.ts +6 -0
  32. package/dist/components/shapes/bars/bars-overlay.d.ts.map +1 -0
  33. package/dist/components/shapes/bars/bars-overlay.js +59 -0
  34. package/dist/components/shapes/bars/bars-series.d.ts +6 -0
  35. package/dist/components/shapes/bars/bars-series.d.ts.map +1 -0
  36. package/dist/components/shapes/bars/bars-series.js +56 -0
  37. package/dist/components/shapes/bars/bars-tooltip.d.ts +3 -0
  38. package/dist/components/shapes/bars/bars-tooltip.d.ts.map +1 -0
  39. package/dist/components/shapes/bars/bars-tooltip.js +85 -0
  40. package/dist/components/shapes/bars/bars-trendline.d.ts +3 -0
  41. package/dist/components/shapes/bars/bars-trendline.d.ts.map +1 -0
  42. package/dist/components/shapes/bars/bars-trendline.js +43 -0
  43. package/dist/components/shapes/bars/bars.d.ts.map +1 -1
  44. package/dist/components/shapes/bars/bars.js +25 -18
  45. package/dist/components/shapes/bars/bars.module.css +1 -1
  46. package/dist/components/shapes/bars/bars.test.js +39 -8
  47. package/dist/components/shapes/bars/index.d.ts +5 -0
  48. package/dist/components/shapes/bars/index.d.ts.map +1 -1
  49. package/dist/components/shapes/bars/index.js +6 -1
  50. package/dist/components/shapes/lines/lines-average.d.ts.map +1 -1
  51. package/dist/components/shapes/lines/lines-average.js +8 -46
  52. package/dist/components/shapes/lines/lines-marker-labels.d.ts.map +1 -1
  53. package/dist/components/shapes/lines/lines-marker-labels.js +10 -10
  54. package/dist/components/shapes/lines/lines-overlay.d.ts.map +1 -1
  55. package/dist/components/shapes/lines/lines-overlay.js +21 -26
  56. package/dist/components/shapes/lines/lines-series.d.ts.map +1 -1
  57. package/dist/components/shapes/lines/lines-series.js +6 -19
  58. package/dist/components/shapes/lines/lines-tooltip.d.ts.map +1 -1
  59. package/dist/components/shapes/lines/lines-tooltip.js +20 -27
  60. package/dist/components/shapes/lines/lines-trendline.d.ts +3 -0
  61. package/dist/components/shapes/lines/lines-trendline.d.ts.map +1 -0
  62. package/dist/components/shapes/lines/lines-trendline.js +43 -0
  63. package/dist/components/shapes/lines/lines.d.ts.map +1 -1
  64. package/dist/components/shapes/lines/lines.js +2 -1
  65. package/dist/components/shapes/lines/lines.test.js +29 -8
  66. package/dist/hooks/hooks.test.d.ts.map +1 -1
  67. package/dist/hooks/hooks.test.js +157 -5
  68. package/dist/hooks/index.d.ts +4 -0
  69. package/dist/hooks/index.d.ts.map +1 -1
  70. package/dist/hooks/index.js +4 -0
  71. package/dist/hooks/useAverage.d.ts +82 -0
  72. package/dist/hooks/useAverage.d.ts.map +1 -0
  73. package/dist/hooks/useAverage.js +83 -0
  74. package/dist/hooks/useBarChart.d.ts +16 -0
  75. package/dist/hooks/useBarChart.d.ts.map +1 -0
  76. package/dist/hooks/useBarChart.js +104 -0
  77. package/dist/hooks/useBars.d.ts +52 -0
  78. package/dist/hooks/useBars.d.ts.map +1 -0
  79. package/dist/hooks/useBars.js +82 -0
  80. package/dist/hooks/useCartesian.d.ts +11 -2
  81. package/dist/hooks/useCartesian.d.ts.map +1 -1
  82. package/dist/hooks/useCartesian.js +16 -5
  83. package/dist/hooks/useLineChart.d.ts +3 -27
  84. package/dist/hooks/useLineChart.d.ts.map +1 -1
  85. package/dist/hooks/useLineChart.js +22 -13
  86. package/dist/hooks/useLines.d.ts +48 -0
  87. package/dist/hooks/useLines.d.ts.map +1 -0
  88. package/dist/hooks/useLines.js +70 -0
  89. package/dist/hooks/useTrendline.d.ts +56 -0
  90. package/dist/hooks/useTrendline.d.ts.map +1 -0
  91. package/dist/hooks/useTrendline.js +84 -0
  92. package/dist/providers/cartesian.d.ts +5 -1
  93. package/dist/providers/cartesian.d.ts.map +1 -1
  94. package/dist/providers/cartesian.js +19 -3
  95. package/dist/providers/data.d.ts +6 -7
  96. package/dist/providers/data.d.ts.map +1 -1
  97. package/dist/providers/data.js +4 -3
  98. package/dist/style-config/axis.js +3 -3
  99. package/dist/style-config/bars.d.ts +3 -0
  100. package/dist/style-config/bars.d.ts.map +1 -0
  101. package/dist/style-config/bars.js +33 -0
  102. package/dist/style-config/cartesian.d.ts.map +1 -1
  103. package/dist/style-config/cartesian.js +2 -0
  104. package/dist/style-config/colors.d.ts +1 -4
  105. package/dist/style-config/colors.d.ts.map +1 -1
  106. package/dist/style-config/colors.js +30 -36
  107. package/dist/style-config/headings.d.ts.map +1 -1
  108. package/dist/style-config/headings.js +16 -1
  109. package/dist/style-config/lines.d.ts.map +1 -1
  110. package/dist/style-config/lines.js +6 -0
  111. package/dist/style-config/themes.d.ts.map +1 -1
  112. package/dist/style-config/themes.js +18 -0
  113. package/dist/types/bar-chart.d.ts +20 -15
  114. package/dist/types/bar-chart.d.ts.map +1 -1
  115. package/dist/types/bar-chart.js +1 -39
  116. package/dist/types/bars.d.ts +29 -0
  117. package/dist/types/bars.d.ts.map +1 -0
  118. package/dist/types/bars.js +16 -0
  119. package/dist/types/cartesian.d.ts +3 -0
  120. package/dist/types/cartesian.d.ts.map +1 -1
  121. package/dist/types/headings.d.ts +15 -0
  122. package/dist/types/headings.d.ts.map +1 -1
  123. package/dist/types/headings.js +1 -1
  124. package/dist/types/index.d.ts +3 -0
  125. package/dist/types/index.d.ts.map +1 -1
  126. package/dist/types/index.js +4 -1
  127. package/dist/types/line-chart.d.ts +12 -12
  128. package/dist/types/line-chart.d.ts.map +1 -1
  129. package/dist/types/lines.d.ts +6 -0
  130. package/dist/types/lines.d.ts.map +1 -1
  131. package/dist/types/main.d.ts +14 -1
  132. package/dist/types/main.d.ts.map +1 -1
  133. package/dist/types/themes.d.ts +9 -0
  134. package/dist/types/themes.d.ts.map +1 -1
  135. package/dist/utils/axis.d.ts +12 -2
  136. package/dist/utils/axis.d.ts.map +1 -1
  137. package/dist/utils/axis.js +52 -15
  138. package/dist/utils/axis.test.js +72 -8
  139. package/dist/utils/bars.d.ts +15 -0
  140. package/dist/utils/bars.d.ts.map +1 -0
  141. package/dist/utils/bars.js +71 -0
  142. package/dist/utils/bars.test.d.ts +2 -0
  143. package/dist/utils/bars.test.d.ts.map +1 -0
  144. package/dist/utils/bars.test.js +95 -0
  145. package/dist/utils/data.d.ts +9 -6
  146. package/dist/utils/data.d.ts.map +1 -1
  147. package/dist/utils/data.js +87 -15
  148. package/dist/utils/data.test.js +173 -80
  149. package/dist/utils/format.d.ts +1 -0
  150. package/dist/utils/format.d.ts.map +1 -1
  151. package/dist/utils/format.js +2 -1
  152. package/dist/utils/index.d.ts +1 -0
  153. package/dist/utils/index.d.ts.map +1 -1
  154. package/dist/utils/index.js +2 -1
  155. package/dist/utils/lines.test.js +25 -0
  156. package/dist/utils/metadata.d.ts +7 -8
  157. package/dist/utils/metadata.d.ts.map +1 -1
  158. package/dist/utils/metadata.js +3 -20
  159. package/dist/utils/metadata.test.js +3 -56
  160. package/dist/utils/viewport.test.js +8 -0
  161. package/package.json +4 -2
@@ -0,0 +1,15 @@
1
+ import { CartesianAxis } from '../types/axis';
2
+ import { BarChartMetadata } from '../types/bar-chart';
3
+ import { Bar, BarsStyleConfig } from '../types/bars';
4
+ import { Data } from '../types/main';
5
+ export declare const getBarSize: (bar: Bar, axis: CartesianAxis, isHorizontal: boolean) => number;
6
+ export declare const getBarPosition: (bar: Bar, axis: CartesianAxis, isHorizontal: boolean) => number;
7
+ export declare const getBarSizeAndPosition: (bar: Bar, axis: CartesianAxis, isHorizontal: boolean) => {
8
+ x: number | undefined;
9
+ y: number | undefined;
10
+ width: number | undefined;
11
+ height: number | undefined;
12
+ };
13
+ export declare const getBarThickness: (thickness: number, maxSize: number, fixedBarSize: boolean) => number;
14
+ export declare const getHeightForVerticalChartWithFixedBarSize: (config: BarsStyleConfig, data: Data, metadata: BarChartMetadata) => number;
15
+ //# sourceMappingURL=bars.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bars.d.ts","sourceRoot":"","sources":["../../src/utils/bars.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAGrC,eAAO,MAAM,UAAU,QAAS,GAAG,QAAQ,aAAa,gBAAgB,OAAO,WAgB9E,CAAC;AAEF,eAAO,MAAM,cAAc,QAAS,GAAG,QAAQ,aAAa,gBAAgB,OAAO,WAYlF,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAAS,GAAG,QAAQ,aAAa,gBAAgB,OAAO;;;;;CASzF,CAAC;AAEF,eAAO,MAAM,eAAe,cACf,MAAM,WACR,MAAM,gBACD,OAAO,WAOtB,CAAC;AAEF,eAAO,MAAM,yCAAyC,WAC5C,eAAe,wBAEb,gBAAgB,WAoB3B,CAAC"}
@@ -0,0 +1,71 @@
1
+ /*
2
+ * Copyright 2024 Wonderflow Design Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import _ from 'lodash';
17
+ import { clampLinearDomain } from './axis';
18
+ export const getBarSize = (bar, axis, isHorizontal) => {
19
+ const clampedDomain = clampLinearDomain(axis.domain);
20
+ const min = _.min(clampedDomain);
21
+ const scaleZero = axis.scale(0) ?? 0;
22
+ const scaleMin = axis.scale(min) ?? 0;
23
+ const diffNegative = scaleMin - scaleZero;
24
+ if (isHorizontal) {
25
+ return (bar.value >= 0)
26
+ ? (bar.height - diffNegative)
27
+ : (diffNegative - bar.height);
28
+ }
29
+ return (bar.value >= 0)
30
+ ? (bar.width + diffNegative)
31
+ : Math.abs(bar.width + diffNegative);
32
+ };
33
+ export const getBarPosition = (bar, axis, isHorizontal) => {
34
+ const scaleZero = axis.scale(0) ?? 0;
35
+ if (isHorizontal) {
36
+ return (bar.value >= 0)
37
+ ? bar.y
38
+ : scaleZero;
39
+ }
40
+ return (bar.value >= 0)
41
+ ? scaleZero
42
+ : bar.width;
43
+ };
44
+ export const getBarSizeAndPosition = (bar, axis, isHorizontal) => {
45
+ const size = getBarSize(bar, axis, isHorizontal);
46
+ const position = getBarPosition(bar, axis, isHorizontal);
47
+ return {
48
+ x: isHorizontal ? undefined : position,
49
+ y: isHorizontal ? position : undefined,
50
+ width: isHorizontal ? undefined : size,
51
+ height: isHorizontal ? size : undefined,
52
+ };
53
+ };
54
+ export const getBarThickness = (thickness, maxSize, fixedBarSize) => {
55
+ if (fixedBarSize) {
56
+ return _.clamp(thickness, 2, maxSize);
57
+ }
58
+ return thickness;
59
+ };
60
+ export const getHeightForVerticalChartWithFixedBarSize = (config, data, metadata) => {
61
+ const { series, overlay } = metadata;
62
+ const indexLen = data.length;
63
+ const seriesBarsNum = series.dataKey.length;
64
+ const overlayBarsNum = overlay.dataKey?.length ?? 0;
65
+ const totalBarsNum = seriesBarsNum + overlayBarsNum;
66
+ const { maxSize, paddingInnerGroup, paddingOuterGroup, paddingInner, paddingOuter, } = config;
67
+ const barGroup = totalBarsNum * maxSize * (1 + paddingInnerGroup) * (1 + paddingOuterGroup);
68
+ const allGroups = (indexLen + 2) * barGroup * (1 + paddingInner) + barGroup * (2 + paddingOuter);
69
+ const h = _.round(allGroups);
70
+ return h;
71
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=bars.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bars.test.d.ts","sourceRoot":"","sources":["../../src/utils/bars.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,95 @@
1
+ import { getBarSize, getHeightForVerticalChartWithFixedBarSize } from './bars';
2
+ describe('getBarSize()', () => {
3
+ const bar = {
4
+ color: 'red',
5
+ height: 60,
6
+ index: 1,
7
+ key: 'name',
8
+ value: 15,
9
+ width: 24,
10
+ x: 20,
11
+ y: 35,
12
+ };
13
+ const axis = {
14
+ top: 0,
15
+ left: 0,
16
+ domain: [-100, 100],
17
+ scaleType: 'linear',
18
+ orientation: 'left',
19
+ scale: () => 10,
20
+ };
21
+ it('should return for positive values', () => {
22
+ const res = getBarSize(bar, axis, true);
23
+ const exp = 60;
24
+ expect(res).toStrictEqual(exp);
25
+ });
26
+ it('should return for vertical layout', () => {
27
+ const res = getBarSize(bar, { ...axis, scale: (x) => -x }, false);
28
+ const exp = 124;
29
+ expect(res).toStrictEqual(exp);
30
+ });
31
+ it('should return for negative value', () => {
32
+ const res = getBarSize({ ...bar, value: -60 }, { ...axis, scale: (x) => -x }, false);
33
+ const exp = 124;
34
+ expect(res).toStrictEqual(exp);
35
+ });
36
+ });
37
+ describe('getBarPosition()', () => {
38
+ const bar = {
39
+ color: 'red',
40
+ height: 60,
41
+ index: 1,
42
+ key: 'name',
43
+ value: 15,
44
+ width: 24,
45
+ x: 20,
46
+ y: 35,
47
+ };
48
+ const axis = {
49
+ top: 0,
50
+ left: 0,
51
+ domain: [-100, 100],
52
+ scaleType: 'linear',
53
+ orientation: 'left',
54
+ scale: () => 50,
55
+ };
56
+ it('should return position, positive true', () => {
57
+ const res = getBarSize(bar, axis, true);
58
+ const exp = 60;
59
+ expect(res).toStrictEqual(exp);
60
+ });
61
+ it('should return position, positive false', () => {
62
+ const res = getBarSize(bar, axis, false);
63
+ const exp = 24;
64
+ expect(res).toStrictEqual(exp);
65
+ });
66
+ it('should return position, negative true', () => {
67
+ const res = getBarSize({ ...bar, value: -50 }, axis, false);
68
+ const exp = 24;
69
+ expect(res).toStrictEqual(exp);
70
+ });
71
+ it('should return position, negative false', () => {
72
+ const res = getBarSize({ ...bar, value: -50 }, axis, true);
73
+ const exp = -60;
74
+ expect(res).toStrictEqual(exp);
75
+ });
76
+ });
77
+ describe('getHeightForVerticalChartWithFixedBarSize()', () => {
78
+ const config = {
79
+ maxSize: 24,
80
+ paddingInnerGroup: 0.1,
81
+ paddingOuterGroup: 0.1,
82
+ paddingInner: 0.2,
83
+ paddingOuter: 1,
84
+ };
85
+ const data = [
86
+ { date: '2024', value: 100 },
87
+ { date: '2023', value: 100 },
88
+ ];
89
+ const metadata = {
90
+ series: { dataKey: ['value'] },
91
+ overlay: { dataKey: undefined },
92
+ };
93
+ const res = getHeightForVerticalChartWithFixedBarSize(config, data, metadata);
94
+ expect(res).toStrictEqual(227);
95
+ });
@@ -1,17 +1,20 @@
1
1
  import { Except } from 'type-fest';
2
- import { AverageType, AxisProps, Data, LineChartIndex, LineChartOverlay, LineChartSeries, SortingType } from '../types';
3
- import { BarChartIndex, BarChartOverlay, BarChartSeries } from '../types/bar-chart';
2
+ import { AverageType, AxisProps, Bar, Data, LineChartIndex, LineChartSeries, SortingType, TrendlineType } from '../types';
3
+ import { BarChartIndex, BarChartSeries } from '../types/bar-chart';
4
4
  export declare const getValueFromObjectByPath: (object: Record<string, unknown>, path: string) => unknown;
5
5
  export declare const getPrimitiveFromObjectByPath: (object: Record<string, unknown>, path: string) => string | number | undefined;
6
6
  export declare const getLabelFromPath: (path: string) => string;
7
7
  export declare const getPrimitivesFromObjectArrayByPath: (arr: Array<Record<string, unknown>>, path: string) => (string | number | undefined)[];
8
8
  export declare const removeKeysFromObject: (obj: Record<string, unknown>, keys: string[]) => Record<string, unknown>;
9
- export declare const handleAxisDomainAndScaleType: (data: Data, axis: LineChartIndex | LineChartSeries | LineChartOverlay | BarChartIndex | BarChartSeries | BarChartOverlay) => Except<AxisProps, 'orientation'>;
10
- export declare const handleChartDomainAndScaleType: (data: Data, index: LineChartIndex | BarChartIndex, series: LineChartSeries | BarChartSeries, overlay?: LineChartOverlay | BarChartOverlay) => {
9
+ export declare const mirrorDomain: (domain: Array<NonNullable<string | number>>) => NonNullable<string | number>[] | (number | undefined)[];
10
+ export declare const handleAxisDomainAndScaleType: <T extends BarChartIndex | BarChartSeries | LineChartIndex | LineChartSeries>(data: Data, axis: T) => Except<AxisProps, 'orientation'>;
11
+ export declare const handleChartDomainAndScaleType: <T extends BarChartIndex | LineChartIndex, U extends BarChartSeries | LineChartSeries>(data: Data, index: T, series: U, overlay?: U | undefined) => {
11
12
  index: Except<AxisProps, "orientation">;
12
13
  series: Except<AxisProps, "orientation">;
13
14
  overlay: Except<AxisProps, "orientation"> | undefined;
14
15
  };
15
- export declare const sortBy: (datum: Record<string, string | number | undefined | null>, dataKey: string[], sorting: SortingType) => string[];
16
- export declare const computeAverage: (data: Data, dataKeys: string[]) => AverageType;
16
+ export declare const extractBarValueFromNestedKey: (barGroup: any, index: number, data: Data, scale: (value: any) => number | undefined, maxSize: number, isHorizontal: boolean) => any;
17
+ export declare const sortBarsBy: (bars: Bar[], sorting: SortingType, isHorizontal: boolean) => Bar[];
18
+ export declare const computeAverage: (data: Data, dataKeys: string[]) => AverageType | undefined;
19
+ export declare const computeTrendline: (data: Data, dataKeys: string[]) => TrendlineType[];
17
20
  //# sourceMappingURL=data.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/utils/data.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EACL,WAAW,EACX,SAAS,EACT,IAAI,EAAE,cAAc,EAAE,gBAAgB,EAAE,eAAe,EAAE,WAAW,EACrE,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAQpF,eAAO,MAAM,wBAAwB,WAAY,OAAO,MAAM,EAAE,OAAO,CAAC,QAAQ,MAAM,YAA0B,CAAC;AAEjH,eAAO,MAAM,4BAA4B,WAAY,OAAO,MAAM,EAAE,OAAO,CAAC,QAAQ,MAAM,gCAGzF,CAAC;AAEF,eAAO,MAAM,gBAAgB,SAAU,MAAM,WAc5C,CAAC;AAEF,eAAO,MAAM,kCAAkC,QACxC,MAAM,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC,QAC7B,MAAM,oCAC0C,CAAC;AAEzD,eAAO,MAAM,oBAAoB,QAAS,OAAO,MAAM,EAAE,OAAO,CAAC,QAAQ,MAAM,EAAE,4BAQhF,CAAC;AAEF,eAAO,MAAM,4BAA4B,qBAEjC,cAAc,GAAG,eAAe,GAAG,gBAAgB,GAAG,aAAa,GAAG,cAAc,GAAG,eAAe,KAC3G,OAAO,SAAS,EAAE,aAAa,CAgEjC,CAAC;AAEF,eAAO,MAAM,6BAA6B,sBAEjC,cAAc,GAAG,aAAa,UAC7B,eAAe,GAAG,cAAc,YAC9B,gBAAgB,GAAG,eAAe;;;;CAa7C,CAAC;AAEF,eAAO,MAAM,MAAM,UACV,OAAO,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAE,WACjD,MAAM,EAAE,WACR,WAAW,KACnB,MAAM,EAkBR,CAAC;AAEF,eAAO,MAAM,cAAc,yBAEf,MAAM,EAAE,KACjB,WAWF,CAAC"}
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/utils/data.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EACL,WAAW,EACX,SAAS,EACT,GAAG,EACH,IAAI,EAAE,cAAc,EACpB,eAAe,EAAE,WAAW,EAAE,aAAa,EAC5C,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAQnE,eAAO,MAAM,wBAAwB,WAAY,OAAO,MAAM,EAAE,OAAO,CAAC,QAAQ,MAAM,YAA0B,CAAC;AAEjH,eAAO,MAAM,4BAA4B,WAAY,OAAO,MAAM,EAAE,OAAO,CAAC,QAAQ,MAAM,gCAGzF,CAAC;AAEF,eAAO,MAAM,gBAAgB,SAAU,MAAM,WAc5C,CAAC;AAEF,eAAO,MAAM,kCAAkC,QACxC,MAAM,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC,QAC7B,MAAM,oCAC0C,CAAC;AAEzD,eAAO,MAAM,oBAAoB,QAAS,OAAO,MAAM,EAAE,OAAO,CAAC,QAAQ,MAAM,EAAE,4BAQhF,CAAC;AAEF,eAAO,MAAM,YAAY,WAAY,MAAM,YAAY,MAAM,GAAG,MAAM,CAAC,CAAC,4DAcvE,CAAC;AAEF,eAAO,MAAM,4BAA4B,wGAM3B,OAAO,SAAS,EAAE,aAAa,CAmE5C,CAAC;AAEF,eAAO,MAAM,6BAA6B;;;;CAmBzC,CAAC;AAEF,eAAO,MAAM,4BAA4B,aAC7B,GAAG,SACN,MAAM,6BAEE,GAAG,KAAK,MAAM,GAAG,SAAS,WAChC,MAAM,gBACD,OAAO,QAsBrB,CAAC;AAEH,eAAO,MAAM,UAAU,SACf,GAAG,EAAE,WACF,WAAW,gBACN,OAAO,UAgCtB,CAAC;AAEF,eAAO,MAAM,cAAc,yBAEf,MAAM,EAAE,KACjB,WAAW,GAAG,SAWhB,CAAC;AAEF,eAAO,MAAM,gBAAgB,yBAEjB,MAAM,EAAE,KACjB,aAAa,EAoCd,CAAC"}
@@ -14,8 +14,9 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import _ from 'lodash';
17
+ import { SimpleLinearRegression } from 'ml-regression-simple-linear';
17
18
  import { inferScaleTypeFromDomain } from './axis';
18
- import { formatDate } from './format';
19
+ import { formatDate, maxPrecision } from './format';
19
20
  import { getMinMaxDate, getMinMaxNumber, removeNilsFromDomain, } from './math';
20
21
  export const getValueFromObjectByPath = (object, path) => _.at(object, path)[0];
21
22
  export const getPrimitiveFromObjectByPath = (object, path) => {
@@ -43,8 +44,19 @@ export const removeKeysFromObject = (obj, keys) => {
43
44
  });
44
45
  return copy;
45
46
  };
47
+ export const mirrorDomain = (domain) => {
48
+ const max = _.max(domain) ?? 0;
49
+ const min = _.min(domain) ?? 0;
50
+ if (typeof max === 'number' && typeof min === 'number') {
51
+ const absMax = Math.abs(max);
52
+ const absMin = Math.abs(min);
53
+ const absMinMax = _.max([absMax, absMin]);
54
+ return [-absMinMax, absMinMax];
55
+ }
56
+ return domain;
57
+ };
46
58
  export const handleAxisDomainAndScaleType = (data, axis) => {
47
- const hasData = !!data.length;
59
+ const hasData = Boolean(data.length);
48
60
  let res = {
49
61
  ...axis,
50
62
  hideTickLabel: true,
@@ -58,7 +70,7 @@ export const handleAxisDomainAndScaleType = (data, axis) => {
58
70
  const domainData = _.flattenDeep(primitivesFromArray);
59
71
  let ownDomain = removeNilsFromDomain(domainData);
60
72
  const st = inferScaleTypeFromDomain(domainData, scaleType);
61
- const hasCustomDomain = !!domain?.length;
73
+ const hasCustomDomain = !!(domain?.length);
62
74
  if (hasCustomDomain) {
63
75
  if (st === 'time') {
64
76
  const minMaxDate = getMinMaxDate(ownDomain);
@@ -114,20 +126,50 @@ export const handleChartDomainAndScaleType = (data, index, series, overlay) => {
114
126
  overlay: o,
115
127
  };
116
128
  };
117
- export const sortBy = (datum, dataKey, sorting) => {
129
+ export const extractBarValueFromNestedKey = (barGroup, index, data, scale, maxSize, isHorizontal) => barGroup.bars.map((bar) => {
130
+ if (!bar.value) {
131
+ const newValue = getPrimitiveFromObjectByPath(data[index], bar.key);
132
+ const scaled = scale(newValue) ?? 0;
133
+ if (isHorizontal) {
134
+ return {
135
+ ...bar,
136
+ value: newValue,
137
+ height: maxSize - scaled,
138
+ y: scaled,
139
+ };
140
+ }
141
+ return {
142
+ ...bar,
143
+ value: newValue,
144
+ width: scaled,
145
+ };
146
+ }
147
+ return bar;
148
+ });
149
+ export const sortBarsBy = (bars, sorting, isHorizontal) => {
150
+ let res = [];
151
+ let isReverse = false;
118
152
  if (sorting === 'as-is')
119
- return dataKey;
120
- let isAscending = false;
121
- let order = ['key', 'value'];
122
- if (sorting === 'ascending-key' || sorting === 'ascending-value') {
123
- isAscending = true;
153
+ res = bars;
154
+ if (sorting === 'ascending-key' || sorting === 'ascending-value')
155
+ isReverse = true;
156
+ if (sorting.includes('key')) {
157
+ const withSort = _.sortBy(bars, 'key');
158
+ const withReverse = isReverse ? _.reverse(withSort) : withSort;
159
+ res = withReverse.map((el, i) => {
160
+ const { x, y } = bars[i];
161
+ return isHorizontal ? ({ ...el, x }) : ({ ...el, x, y });
162
+ });
124
163
  }
125
- if (sorting === 'descending-value' || sorting === 'ascending-value') {
126
- order = ['value', 'key'];
164
+ if (sorting.includes('value')) {
165
+ const withSort = _.sortBy(bars, 'value');
166
+ const withReverse = isReverse ? _.reverse(withSort) : withSort;
167
+ res = withReverse.map((el, i) => {
168
+ const { x, y } = bars[i];
169
+ return isHorizontal ? ({ ...el, x }) : ({ ...el, x, y });
170
+ });
127
171
  }
128
- const entries = Object.entries(datum).filter(e => dataKey.includes(e[0])).map(e => ({ key: e[0], value: e[1] }));
129
- const orderedKeys = _.orderBy(entries, order).map(e => e.key);
130
- return isAscending ? orderedKeys.reverse() : orderedKeys;
172
+ return res;
131
173
  };
132
174
  export const computeAverage = (data, dataKeys) => {
133
175
  const dataKey = dataKeys.map((k) => ({
@@ -137,5 +179,35 @@ export const computeAverage = (data, dataKeys) => {
137
179
  .filter((d) => typeof d === 'number')),
138
180
  }));
139
181
  const all = _.mean(dataKey.map(k => k.average));
140
- return _.isNaN(all) ? undefined : { average: all, dataKey };
182
+ return _.isNaN(all) ? undefined : { average: maxPrecision(all, 2), dataKey };
141
183
  };
184
+ export const computeTrendline = (data, dataKeys) => dataKeys.map((k) => {
185
+ const dataPoints = data
186
+ .map(d => getPrimitiveFromObjectByPath(d, k))
187
+ .filter((d) => typeof d === 'number');
188
+ const index = Array(dataPoints.length).fill('').map((_, i) => i);
189
+ const regression = new SimpleLinearRegression(index, dataPoints);
190
+ const { slope, intercept, coefficients } = regression;
191
+ const score = regression.score(index, dataPoints);
192
+ const trendline = data.map((_, i) => {
193
+ const val = slope * i + intercept;
194
+ return maxPrecision(val, 2);
195
+ });
196
+ const from = trendline[0];
197
+ const to = trendline[trendline.length - 1];
198
+ return {
199
+ name: k,
200
+ slope: maxPrecision(slope, 2),
201
+ intercept: maxPrecision(intercept, 2),
202
+ coefficients: coefficients.map(c => maxPrecision(c, 2)),
203
+ score: {
204
+ r: maxPrecision(score.r, 2),
205
+ r2: maxPrecision(score.r2, 2),
206
+ chi2: maxPrecision(score.chi2, 2),
207
+ rmsd: maxPrecision(score.rmsd, 2),
208
+ },
209
+ trendline,
210
+ from,
211
+ to,
212
+ };
213
+ });
@@ -1,4 +1,4 @@
1
- import { computeAverage, getLabelFromPath, getPrimitiveFromObjectByPath, getPrimitivesFromObjectArrayByPath, getValueFromObjectByPath, handleAxisDomainAndScaleType, handleChartDomainAndScaleType, sortBy, } from './data';
1
+ import { computeAverage, computeTrendline, extractBarValueFromNestedKey, getLabelFromPath, getPrimitiveFromObjectByPath, getPrimitivesFromObjectArrayByPath, getValueFromObjectByPath, handleAxisDomainAndScaleType, handleChartDomainAndScaleType, mirrorDomain, sortBarsBy, } from './data';
2
2
  const data = [
3
3
  {
4
4
  user: 'joe',
@@ -312,7 +312,7 @@ describe('handleChartDomainAndScaleType()', () => {
312
312
  ];
313
313
  const index = { dataKey: 'date' };
314
314
  const series = { dataKey: ['value', 'percentage'] };
315
- const overlay = { dataKey: 'overlay' };
315
+ const overlay = { dataKey: ['overlay'] };
316
316
  const res = handleChartDomainAndScaleType(data, index, series, overlay);
317
317
  const exp = {
318
318
  index: {
@@ -369,84 +369,6 @@ describe('handleChartDomainAndScaleType()', () => {
369
369
  expect(res).toStrictEqual(exp);
370
370
  });
371
371
  });
372
- describe('sortBy()', () => {
373
- it('should return an unmodified array of datakeys', () => {
374
- const datum = { a: 2, b: 3, c: 1 };
375
- const datakey = ['a', 'b', 'c'];
376
- const res = sortBy(datum, datakey, 'as-is');
377
- const exp = ['a', 'b', 'c'];
378
- expect(res).toStrictEqual(exp);
379
- });
380
- it('should return alphabetical ordered datakeys', () => {
381
- const datum = { a: 2, b: 3, c: 1 };
382
- const datakey = ['c', 'a', 'b'];
383
- const res = sortBy(datum, datakey, 'descending-key');
384
- const exp = ['a', 'b', 'c'];
385
- expect(res).toStrictEqual(exp);
386
- });
387
- it('should return reversed alphabetical ordered datakeys', () => {
388
- const datum = { a: 2, b: 3, c: 1 };
389
- const datakey = ['c', 'a', 'b'];
390
- const res = sortBy(datum, datakey, 'ascending-key');
391
- const exp = ['c', 'b', 'a'];
392
- expect(res).toStrictEqual(exp);
393
- });
394
- it('should return keys sorted by descending numerical dataValue', () => {
395
- const datum = { a: 2, b: 3, c: 1 };
396
- const datakey = ['a', 'b', 'c'];
397
- const res = sortBy(datum, datakey, 'descending-value');
398
- const exp = ['c', 'a', 'b'];
399
- expect(res).toStrictEqual(exp);
400
- });
401
- it('should return keys sorted by ascending numerical dataValue', () => {
402
- const datum = { a: 2, b: 3, c: 1 };
403
- const datakey = ['a', 'b', 'c'];
404
- const res = sortBy(datum, datakey, 'ascending-value');
405
- const exp = ['b', 'a', 'c'];
406
- expect(res).toStrictEqual(exp);
407
- });
408
- it('should return keys sorted by descending alphabetical dataValue', () => {
409
- const datum = { a: 'xyz', b: 'jki', c: 'abc' };
410
- const datakey = ['b', 'c', 'a'];
411
- const res = sortBy(datum, datakey, 'descending-value');
412
- const exp = ['c', 'b', 'a'];
413
- expect(res).toStrictEqual(exp);
414
- });
415
- it('should return keys sorted by ascending alphabetical dataValue', () => {
416
- const datum = { a: 'xyz', b: 'jki', c: 'abc' };
417
- const datakey = ['b', 'c', 'a'];
418
- const res = sortBy(datum, datakey, 'ascending-value');
419
- const exp = ['a', 'b', 'c'];
420
- expect(res).toStrictEqual(exp);
421
- });
422
- it('should return keys sorted by descending alphabetical dataValue with undefined value', () => {
423
- const datum = {
424
- a: 'xyz', b: undefined, c: 'abc', d: undefined,
425
- };
426
- const datakey = ['b', 'c', 'a', 'd'];
427
- const res = sortBy(datum, datakey, 'descending-value');
428
- const exp = ['c', 'a', 'b', 'd'];
429
- expect(res).toStrictEqual(exp);
430
- });
431
- it('should return keys sorted by descending alphabetical dataValue with undefined value', () => {
432
- const datum = {
433
- a: 'xyz', b: undefined, c: 'abc', d: undefined,
434
- };
435
- const datakey = ['b', 'c', 'a', 'd'];
436
- const res = sortBy(datum, datakey, 'descending-value');
437
- const exp = ['c', 'a', 'b', 'd'];
438
- expect(res).toStrictEqual(exp);
439
- });
440
- it('should return keys sorted by descending alphabetical dataValue with undefined value and less keys', () => {
441
- const datum = {
442
- a: 'xyz', b: undefined, c: 'abc', d: undefined,
443
- };
444
- const datakey = ['b', 'c'];
445
- const res = sortBy(datum, datakey, 'descending-value');
446
- const exp = ['c', 'b'];
447
- expect(res).toStrictEqual(exp);
448
- });
449
- });
450
372
  describe('computeAverage()', () => {
451
373
  it('should return undefined when average is NaN', () => {
452
374
  const data = [];
@@ -477,3 +399,174 @@ describe('computeAverage()', () => {
477
399
  expect(res).toStrictEqual(exp);
478
400
  });
479
401
  });
402
+ describe('computeTrendline()', () => {
403
+ it('should return values for single data key', () => {
404
+ const data = [
405
+ { datakey: 0.5 },
406
+ { datakey: 1 },
407
+ { datakey: 1.5 },
408
+ { datakey: 2 },
409
+ { datakey: 2.5 },
410
+ ];
411
+ const res = computeTrendline(data, ['datakey']);
412
+ const exp = [{
413
+ name: 'datakey',
414
+ slope: 0.5,
415
+ intercept: 0.5,
416
+ coefficients: [0.5, 0.5],
417
+ score: {
418
+ r: 1, r2: 1, chi2: 0, rmsd: 0,
419
+ },
420
+ trendline: [0.5, 1, 1.5, 2, 2.5],
421
+ from: 0.5,
422
+ to: 2.5,
423
+ }];
424
+ expect(res).toStrictEqual(exp);
425
+ });
426
+ it('should return values for single data key', () => {
427
+ const data = [
428
+ { datakey: 1 },
429
+ { datakey: 3 },
430
+ { datakey: 0.5 },
431
+ { datakey: 2.5 },
432
+ { datakey: 0.25 },
433
+ ];
434
+ const res = computeTrendline(data, ['datakey']);
435
+ const exp = [{
436
+ name: 'datakey',
437
+ slope: -0.2,
438
+ intercept: 1.85,
439
+ coefficients: [1.85, -0.2],
440
+ score: {
441
+ r: 0.26,
442
+ r2: 0.07,
443
+ chi2: 6.32,
444
+ rmsd: 1.06,
445
+ },
446
+ trendline: [
447
+ 1.85,
448
+ 1.65,
449
+ 1.45,
450
+ 1.25,
451
+ 1.05
452
+ ],
453
+ from: 1.85,
454
+ to: 1.05,
455
+ }];
456
+ expect(res).toStrictEqual(exp);
457
+ });
458
+ });
459
+ describe('extractBarValueFromNestedKey()', () => {
460
+ const barGroup = {
461
+ bars: [{
462
+ color: 'red',
463
+ height: 60,
464
+ index: 1,
465
+ key: 'name.test',
466
+ value: undefined,
467
+ width: 24,
468
+ x: 20,
469
+ y: 35,
470
+ }],
471
+ };
472
+ const data = [{ name: { test: 15 } }];
473
+ const scale = () => 10;
474
+ it('should return for horizontal layout', () => {
475
+ const res = extractBarValueFromNestedKey(barGroup, 0, data, scale, 24, true);
476
+ expect(res).toStrictEqual([{
477
+ color: 'red',
478
+ height: 14,
479
+ index: 1,
480
+ key: 'name.test',
481
+ value: 15,
482
+ width: 24,
483
+ x: 20,
484
+ y: 10,
485
+ }]);
486
+ });
487
+ it('should return for vertical layout', () => {
488
+ const res = extractBarValueFromNestedKey(barGroup, 0, data, scale, 24, false);
489
+ expect(res).toStrictEqual([{
490
+ color: 'red',
491
+ height: 60,
492
+ index: 1,
493
+ key: 'name.test',
494
+ value: 15,
495
+ width: 10,
496
+ x: 20,
497
+ y: 35,
498
+ }]);
499
+ });
500
+ });
501
+ describe('sortBarsBy()', () => {
502
+ const bars = [
503
+ {
504
+ color: 'red',
505
+ height: 60,
506
+ index: 1,
507
+ key: 'A',
508
+ value: 20,
509
+ width: 24,
510
+ x: 20,
511
+ y: 35,
512
+ },
513
+ {
514
+ color: 'red',
515
+ height: 60,
516
+ index: 1,
517
+ key: 'B',
518
+ value: 10,
519
+ width: 24,
520
+ x: 20,
521
+ y: 35,
522
+ }
523
+ ];
524
+ it('should return same order for "as-is"', () => {
525
+ const res = sortBarsBy(bars, 'as-is', true);
526
+ const exp = { key: 'A', value: 20 };
527
+ expect(res[0].key).toStrictEqual(exp.key);
528
+ expect(res[0].value).toStrictEqual(exp.value);
529
+ });
530
+ it('should return right order for "descending-key"', () => {
531
+ const res = sortBarsBy(bars, 'descending-key', true);
532
+ expect(res[0].key).toStrictEqual('A');
533
+ expect(res[1].key).toStrictEqual('B');
534
+ });
535
+ it('should return right order for "ascending-key"', () => {
536
+ const res = sortBarsBy(bars, 'ascending-key', true);
537
+ expect(res[0].key).toStrictEqual('B');
538
+ expect(res[1].key).toStrictEqual('A');
539
+ });
540
+ it('should return right order for "descending-value"', () => {
541
+ const res = sortBarsBy(bars, 'descending-value', true);
542
+ expect(res[0].value).toStrictEqual(10);
543
+ expect(res[1].value).toStrictEqual(20);
544
+ });
545
+ it('should return right order for "ascending-value"', () => {
546
+ const res = sortBarsBy(bars, 'ascending-value', true);
547
+ expect(res[0].value).toStrictEqual(20);
548
+ expect(res[1].value).toStrictEqual(10);
549
+ });
550
+ it('should return right order for "descending-key"', () => {
551
+ const res = sortBarsBy(bars, 'descending-key', false);
552
+ expect(res[0].key).toStrictEqual('A');
553
+ expect(res[1].key).toStrictEqual('B');
554
+ });
555
+ });
556
+ describe('mirrorDomain()', () => {
557
+ it('should return the right mirrored domain for numbers', () => {
558
+ const res = mirrorDomain([0, 100]);
559
+ const exp = [-100, 100];
560
+ expect(res).toStrictEqual(exp);
561
+ });
562
+ it('should return the same domain for other than number', () => {
563
+ const res = mirrorDomain(['0', '100']);
564
+ const exp = ['0', '100'];
565
+ expect(res).toStrictEqual(exp);
566
+ });
567
+ it('should return 0,0 for NaN values', () => {
568
+ const res = mirrorDomain([NaN, NaN]);
569
+ const exp = [-0, 0];
570
+ expect(res).toStrictEqual(exp);
571
+ });
572
+ });
@@ -12,4 +12,5 @@ export declare const truncate: (text: string | undefined, options?: {
12
12
  omission?: string;
13
13
  separator?: RegExp | string;
14
14
  }) => string;
15
+ export declare const maxPrecision: (value: number, precision: number) => number;
15
16
  //# sourceMappingURL=format.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/utils/format.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAKpD,eAAO,MAAM,UAAU,UACd,MAAM,GAAG,MAAM,EAAE,gCAEvB,MAAM,EASR,CAAC;AAEF,eAAO,MAAM,YAAY,UAChB,MAAM;;YAGuD,CAAC;AAEvE,eAAO,MAAM,UAAU,UACd,IAAI,4CAGgF,CAAC;AAE9F,eAAO,MAAM,WAAW,UACf,MAAM,GAAG,WAAW,GAAG,IAAI,8BAExB,GAAG;;CAKd,CAAC;AAEF,eAAO,MAAM,QAAQ,SACb,MAAM,GAAG,SAAS,YACf;IACP,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B,WAI2B,CAAC"}
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/utils/format.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAKpD,eAAO,MAAM,UAAU,UACd,MAAM,GAAG,MAAM,EAAE,gCAEvB,MAAM,EASR,CAAC;AAEF,eAAO,MAAM,YAAY,UAChB,MAAM;;YAGuD,CAAC;AAEvE,eAAO,MAAM,UAAU,UACd,IAAI,4CAGgF,CAAC;AAE9F,eAAO,MAAM,WAAW,UACf,MAAM,GAAG,WAAW,GAAG,IAAI,8BAExB,GAAG;;CAKd,CAAC;AAEF,eAAO,MAAM,QAAQ,SACb,MAAM,GAAG,SAAS,YACf;IACP,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B,WAI2B,CAAC;AAE/B,eAAO,MAAM,YAAY,UAAW,MAAM,aAAa,MAAM,WAA8B,CAAC"}
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2023 Wonderflow Design Team
2
+ * Copyright 2023-2024 Wonderflow Design Team
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -39,3 +39,4 @@ export const truncate = (text, options = {
39
39
  length: axisStyleConfig.formatting.maxCharactersLength,
40
40
  omission: axisStyleConfig.formatting.omission,
41
41
  }) => _.truncate(text, options);
42
+ export const maxPrecision = (value, precision) => _.round(value, precision);