@wonderflow/charts 12.8.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 (259) hide show
  1. package/dist/components/cartesian-base/cartesian-base-axis.d.ts +15 -0
  2. package/dist/components/cartesian-base/cartesian-base-axis.d.ts.map +1 -0
  3. package/dist/components/cartesian-base/cartesian-base-axis.js +53 -0
  4. package/dist/components/cartesian-base/cartesian-base-grid.d.ts +23 -0
  5. package/dist/components/cartesian-base/cartesian-base-grid.d.ts.map +1 -0
  6. package/dist/components/cartesian-base/cartesian-base-grid.js +35 -0
  7. package/dist/components/cartesian-base/cartesian-base-legend.d.ts +7 -0
  8. package/dist/components/cartesian-base/cartesian-base-legend.d.ts.map +1 -0
  9. package/dist/components/cartesian-base/cartesian-base-legend.js +35 -0
  10. package/dist/components/cartesian-base/cartesian-base.d.ts +78 -0
  11. package/dist/components/cartesian-base/cartesian-base.d.ts.map +1 -0
  12. package/dist/components/cartesian-base/cartesian-base.js +98 -0
  13. package/dist/components/cartesian-base/cartesian-base.module.css +1 -0
  14. package/dist/components/cartesian-base/cartesian-base.test.d.ts +2 -0
  15. package/dist/components/cartesian-base/cartesian-base.test.d.ts.map +1 -0
  16. package/dist/components/cartesian-base/cartesian-base.test.js +51 -0
  17. package/dist/components/cartesian-base/index.d.ts +3 -0
  18. package/dist/components/cartesian-base/index.d.ts.map +1 -0
  19. package/dist/components/cartesian-base/index.js +16 -0
  20. package/dist/components/empty-state/empty-state.d.ts +16 -0
  21. package/dist/components/empty-state/empty-state.d.ts.map +1 -0
  22. package/dist/components/empty-state/empty-state.js +31 -0
  23. package/dist/components/empty-state/empty-state.test.d.ts +2 -0
  24. package/dist/components/empty-state/empty-state.test.d.ts.map +1 -0
  25. package/dist/components/empty-state/empty-state.test.js +67 -0
  26. package/dist/components/empty-state/index.d.ts +2 -0
  27. package/dist/components/empty-state/index.d.ts.map +1 -0
  28. package/dist/components/empty-state/index.js +16 -0
  29. package/dist/components/headings/headings.d.ts +27 -0
  30. package/dist/components/headings/headings.d.ts.map +1 -0
  31. package/dist/components/headings/headings.js +31 -0
  32. package/dist/components/headings/headings.test.d.ts +2 -0
  33. package/dist/components/headings/headings.test.d.ts.map +1 -0
  34. package/dist/components/headings/headings.test.js +14 -0
  35. package/dist/components/headings/index.d.ts +3 -0
  36. package/dist/components/headings/index.d.ts.map +1 -0
  37. package/dist/components/headings/index.js +16 -0
  38. package/dist/components/index.d.ts +7 -0
  39. package/dist/components/index.d.ts.map +1 -0
  40. package/dist/components/index.js +21 -0
  41. package/dist/components/line-chart/index.d.ts +3 -0
  42. package/dist/components/line-chart/index.d.ts.map +1 -0
  43. package/dist/components/line-chart/index.js +16 -0
  44. package/dist/components/line-chart/line-chart.d.ts +57 -0
  45. package/dist/components/line-chart/line-chart.d.ts.map +1 -0
  46. package/dist/components/line-chart/line-chart.js +68 -0
  47. package/dist/components/line-chart/line-chart.test.d.ts +2 -0
  48. package/dist/components/line-chart/line-chart.test.d.ts.map +1 -0
  49. package/dist/components/line-chart/line-chart.test.js +20 -0
  50. package/dist/components/loader/bar-chart-loader.d.ts +11 -0
  51. package/dist/components/loader/bar-chart-loader.d.ts.map +1 -0
  52. package/dist/components/loader/bar-chart-loader.js +3 -0
  53. package/dist/components/loader/index.d.ts +2 -0
  54. package/dist/components/loader/index.d.ts.map +1 -0
  55. package/dist/components/loader/index.js +16 -0
  56. package/dist/components/loader/line-chart-loader.d.ts +11 -0
  57. package/dist/components/loader/line-chart-loader.d.ts.map +1 -0
  58. package/dist/components/loader/line-chart-loader.js +3 -0
  59. package/dist/components/loader/loader.d.ts +10 -0
  60. package/dist/components/loader/loader.d.ts.map +1 -0
  61. package/dist/components/loader/loader.js +35 -0
  62. package/dist/components/loader/loader.test.d.ts +2 -0
  63. package/dist/components/loader/loader.test.d.ts.map +1 -0
  64. package/dist/components/loader/loader.test.js +50 -0
  65. package/dist/components/placeholder/index.d.ts +3 -0
  66. package/dist/components/placeholder/index.d.ts.map +1 -0
  67. package/dist/components/placeholder/index.js +16 -0
  68. package/dist/components/placeholder/placeholder.d.ts +9 -0
  69. package/dist/components/placeholder/placeholder.d.ts.map +1 -0
  70. package/dist/components/placeholder/placeholder.js +19 -0
  71. package/dist/components/placeholder/placeholder.test.d.ts +2 -0
  72. package/dist/components/placeholder/placeholder.test.d.ts.map +1 -0
  73. package/dist/components/placeholder/placeholder.test.js +15 -0
  74. package/dist/components/shapes/index.d.ts +2 -0
  75. package/dist/components/shapes/index.d.ts.map +1 -0
  76. package/dist/components/shapes/index.js +16 -0
  77. package/dist/components/shapes/lines/index.d.ts +2 -0
  78. package/dist/components/shapes/lines/index.d.ts.map +1 -0
  79. package/dist/components/shapes/lines/index.js +16 -0
  80. package/dist/components/shapes/lines/lines-marker-labels.d.ts +3 -0
  81. package/dist/components/shapes/lines/lines-marker-labels.d.ts.map +1 -0
  82. package/dist/components/shapes/lines/lines-marker-labels.js +72 -0
  83. package/dist/components/shapes/lines/lines-overlay.d.ts +3 -0
  84. package/dist/components/shapes/lines/lines-overlay.d.ts.map +1 -0
  85. package/dist/components/shapes/lines/lines-overlay.js +52 -0
  86. package/dist/components/shapes/lines/lines-series.d.ts +3 -0
  87. package/dist/components/shapes/lines/lines-series.d.ts.map +1 -0
  88. package/dist/components/shapes/lines/lines-series.js +58 -0
  89. package/dist/components/shapes/lines/lines-tooltip.d.ts +3 -0
  90. package/dist/components/shapes/lines/lines-tooltip.d.ts.map +1 -0
  91. package/dist/components/shapes/lines/lines-tooltip.js +107 -0
  92. package/dist/components/shapes/lines/lines.d.ts +3 -0
  93. package/dist/components/shapes/lines/lines.d.ts.map +1 -0
  94. package/dist/components/shapes/lines/lines.js +28 -0
  95. package/dist/components/shapes/lines/lines.module.css +1 -0
  96. package/dist/components/shapes/lines/lines.test.d.ts +2 -0
  97. package/dist/components/shapes/lines/lines.test.d.ts.map +1 -0
  98. package/dist/components/shapes/lines/lines.test.js +142 -0
  99. package/dist/components/tooltip/index.d.ts +3 -0
  100. package/dist/components/tooltip/index.d.ts.map +1 -0
  101. package/dist/components/tooltip/index.js +16 -0
  102. package/dist/components/tooltip/tooltip.d.ts +35 -0
  103. package/dist/components/tooltip/tooltip.d.ts.map +1 -0
  104. package/dist/components/tooltip/tooltip.js +37 -0
  105. package/dist/components/tooltip/tooltip.module.css +1 -0
  106. package/dist/components/tooltip/tooltip.test.d.ts +2 -0
  107. package/dist/components/tooltip/tooltip.test.d.ts.map +1 -0
  108. package/dist/components/tooltip/tooltip.test.js +20 -0
  109. package/dist/index.d.ts +5 -0
  110. package/dist/index.d.ts.map +1 -0
  111. package/dist/index.js +19 -0
  112. package/dist/providers/cartesian.d.ts +20 -0
  113. package/dist/providers/cartesian.d.ts.map +1 -0
  114. package/dist/providers/cartesian.js +43 -0
  115. package/dist/providers/data.d.ts +11 -0
  116. package/dist/providers/data.d.ts.map +1 -0
  117. package/dist/providers/data.js +32 -0
  118. package/dist/providers/index.d.ts +6 -0
  119. package/dist/providers/index.d.ts.map +1 -0
  120. package/dist/providers/index.js +20 -0
  121. package/dist/providers/layout.d.ts +14 -0
  122. package/dist/providers/layout.d.ts.map +1 -0
  123. package/dist/providers/layout.js +34 -0
  124. package/dist/providers/style-config.d.ts +11 -0
  125. package/dist/providers/style-config.d.ts.map +1 -0
  126. package/dist/providers/style-config.js +29 -0
  127. package/dist/providers/theme.d.ts +10 -0
  128. package/dist/providers/theme.d.ts.map +1 -0
  129. package/dist/providers/theme.js +29 -0
  130. package/dist/style-config/axis.d.ts +3 -0
  131. package/dist/style-config/axis.d.ts.map +1 -0
  132. package/dist/style-config/axis.js +86 -0
  133. package/dist/style-config/cartesian.d.ts +3 -0
  134. package/dist/style-config/cartesian.d.ts.map +1 -0
  135. package/dist/style-config/cartesian.js +31 -0
  136. package/dist/style-config/colors.d.ts +9 -0
  137. package/dist/style-config/colors.d.ts.map +1 -0
  138. package/dist/style-config/colors.js +271 -0
  139. package/dist/style-config/grid.d.ts +7 -0
  140. package/dist/style-config/grid.d.ts.map +1 -0
  141. package/dist/style-config/grid.js +24 -0
  142. package/dist/style-config/headings.d.ts +3 -0
  143. package/dist/style-config/headings.d.ts.map +1 -0
  144. package/dist/style-config/headings.js +39 -0
  145. package/dist/style-config/index.d.ts +10 -0
  146. package/dist/style-config/index.d.ts.map +1 -0
  147. package/dist/style-config/index.js +24 -0
  148. package/dist/style-config/legend.d.ts +3 -0
  149. package/dist/style-config/legend.d.ts.map +1 -0
  150. package/dist/style-config/legend.js +18 -0
  151. package/dist/style-config/linear-gradient.d.ts +3 -0
  152. package/dist/style-config/linear-gradient.d.ts.map +1 -0
  153. package/dist/style-config/linear-gradient.js +20 -0
  154. package/dist/style-config/lines.d.ts +3 -0
  155. package/dist/style-config/lines.d.ts.map +1 -0
  156. package/dist/style-config/lines.js +39 -0
  157. package/dist/style-config/themes.d.ts +5 -0
  158. package/dist/style-config/themes.d.ts.map +1 -0
  159. package/dist/style-config/themes.js +86 -0
  160. package/dist/style-config/tooltip.d.ts +8 -0
  161. package/dist/style-config/tooltip.d.ts.map +1 -0
  162. package/dist/style-config/tooltip.js +56 -0
  163. package/dist/style-config/viewport.d.ts +3 -0
  164. package/dist/style-config/viewport.d.ts.map +1 -0
  165. package/dist/style-config/viewport.js +30 -0
  166. package/dist/types/axis.d.ts +108 -0
  167. package/dist/types/axis.d.ts.map +1 -0
  168. package/dist/types/axis.js +16 -0
  169. package/dist/types/cartesian.d.ts +58 -0
  170. package/dist/types/cartesian.d.ts.map +1 -0
  171. package/dist/types/cartesian.js +20 -0
  172. package/dist/types/colors.d.ts +9 -0
  173. package/dist/types/colors.d.ts.map +1 -0
  174. package/dist/types/colors.js +16 -0
  175. package/dist/types/grid.d.ts +14 -0
  176. package/dist/types/grid.d.ts.map +1 -0
  177. package/dist/types/grid.js +1 -0
  178. package/dist/types/headings.d.ts +26 -0
  179. package/dist/types/headings.d.ts.map +1 -0
  180. package/dist/types/headings.js +16 -0
  181. package/dist/types/index.d.ts +13 -0
  182. package/dist/types/index.d.ts.map +1 -0
  183. package/dist/types/index.js +27 -0
  184. package/dist/types/legend.d.ts +4 -0
  185. package/dist/types/legend.d.ts.map +1 -0
  186. package/dist/types/legend.js +16 -0
  187. package/dist/types/line-chart.d.ts +53 -0
  188. package/dist/types/line-chart.d.ts.map +1 -0
  189. package/dist/types/line-chart.js +16 -0
  190. package/dist/types/linear-gradient.d.ts +5 -0
  191. package/dist/types/linear-gradient.d.ts.map +1 -0
  192. package/dist/types/linear-gradient.js +16 -0
  193. package/dist/types/lines.d.ts +25 -0
  194. package/dist/types/lines.d.ts.map +1 -0
  195. package/dist/types/lines.js +16 -0
  196. package/dist/types/main.d.ts +11 -0
  197. package/dist/types/main.d.ts.map +1 -0
  198. package/dist/types/main.js +20 -0
  199. package/dist/types/themes.d.ts +31 -0
  200. package/dist/types/themes.d.ts.map +1 -0
  201. package/dist/types/themes.js +16 -0
  202. package/dist/types/tooltip.d.ts +23 -0
  203. package/dist/types/tooltip.d.ts.map +1 -0
  204. package/dist/types/tooltip.js +16 -0
  205. package/dist/types/viewport.d.ts +8 -0
  206. package/dist/types/viewport.d.ts.map +1 -0
  207. package/dist/types/viewport.js +16 -0
  208. package/dist/utils/axis.d.ts +60 -0
  209. package/dist/utils/axis.d.ts.map +1 -0
  210. package/dist/utils/axis.js +401 -0
  211. package/dist/utils/axis.test.d.ts +2 -0
  212. package/dist/utils/axis.test.d.ts.map +1 -0
  213. package/dist/utils/axis.test.js +1071 -0
  214. package/dist/utils/colors.d.ts +8 -0
  215. package/dist/utils/colors.d.ts.map +1 -0
  216. package/dist/utils/colors.js +33 -0
  217. package/dist/utils/colors.test.d.ts +2 -0
  218. package/dist/utils/colors.test.d.ts.map +1 -0
  219. package/dist/utils/colors.test.js +31 -0
  220. package/dist/utils/data.d.ts +14 -0
  221. package/dist/utils/data.d.ts.map +1 -0
  222. package/dist/utils/data.js +116 -0
  223. package/dist/utils/data.test.d.ts +2 -0
  224. package/dist/utils/data.test.d.ts.map +1 -0
  225. package/dist/utils/data.test.js +371 -0
  226. package/dist/utils/format.d.ts +15 -0
  227. package/dist/utils/format.d.ts.map +1 -0
  228. package/dist/utils/format.js +41 -0
  229. package/dist/utils/format.test.d.ts +2 -0
  230. package/dist/utils/format.test.d.ts.map +1 -0
  231. package/dist/utils/format.test.js +101 -0
  232. package/dist/utils/index.d.ts +8 -0
  233. package/dist/utils/index.d.ts.map +1 -0
  234. package/dist/utils/index.js +22 -0
  235. package/dist/utils/lines.d.ts +52 -0
  236. package/dist/utils/lines.d.ts.map +1 -0
  237. package/dist/utils/lines.js +190 -0
  238. package/dist/utils/lines.test.d.ts +2 -0
  239. package/dist/utils/lines.test.d.ts.map +1 -0
  240. package/dist/utils/lines.test.js +498 -0
  241. package/dist/utils/math.d.ts +13 -0
  242. package/dist/utils/math.d.ts.map +1 -0
  243. package/dist/utils/math.js +89 -0
  244. package/dist/utils/math.test.d.ts +2 -0
  245. package/dist/utils/math.test.d.ts.map +1 -0
  246. package/dist/utils/math.test.js +142 -0
  247. package/dist/utils/metadata.d.ts +6 -0
  248. package/dist/utils/metadata.d.ts.map +1 -0
  249. package/dist/utils/metadata.js +36 -0
  250. package/dist/utils/metadata.test.d.ts +2 -0
  251. package/dist/utils/metadata.test.d.ts.map +1 -0
  252. package/dist/utils/metadata.test.js +102 -0
  253. package/dist/utils/viewport.d.ts +3 -0
  254. package/dist/utils/viewport.d.ts.map +1 -0
  255. package/dist/utils/viewport.js +29 -0
  256. package/dist/utils/viewport.test.d.ts +2 -0
  257. package/dist/utils/viewport.test.d.ts.map +1 -0
  258. package/dist/utils/viewport.test.js +63 -0
  259. package/package.json +106 -0
@@ -0,0 +1,101 @@
1
+ import { formatDate, formatNumber, formatValue, getLocales, truncate, } from './format';
2
+ describe('getLocales()', () => {
3
+ it('should return the corresponding locales ["it-IT"]', () => {
4
+ const res = getLocales('it-it');
5
+ const exp = ['it-IT'];
6
+ expect(res).toStrictEqual(exp);
7
+ });
8
+ it('should return the corresponding multiple locales ["it-IT", "en-US"]', () => {
9
+ const res = getLocales(['it-it', 'en-us']);
10
+ const exp = ['it-IT', 'en-US'];
11
+ expect(res).toStrictEqual(exp);
12
+ });
13
+ it('should return the corresponding the default locales ["en-US"]', () => {
14
+ const res = getLocales(['it-it-en-us']);
15
+ const exp = ['en-US'];
16
+ expect(res).toStrictEqual(exp);
17
+ });
18
+ });
19
+ describe('formatNumber()', () => {
20
+ it('should return the value for the default locales', () => {
21
+ const res = formatNumber(1000);
22
+ const exp = '1,000';
23
+ expect(res).toStrictEqual(exp);
24
+ });
25
+ it('should return the value for it-IT locales', () => {
26
+ const res = formatNumber(1000, 'it-IT');
27
+ const exp = '1.000';
28
+ expect(res).toStrictEqual(exp);
29
+ });
30
+ it('should return the value for en-UK locales', () => {
31
+ const res = formatNumber(1000, 'en-UK');
32
+ const exp = '1,000';
33
+ expect(res).toStrictEqual(exp);
34
+ });
35
+ it('should return the value for the default locales for decimals', () => {
36
+ const res = formatNumber(0.1);
37
+ const exp = '0.1';
38
+ expect(res).toStrictEqual(exp);
39
+ });
40
+ it('should return the value for it-IT locales for decimals', () => {
41
+ const res = formatNumber(0.1, 'it-IT');
42
+ const exp = '0,1';
43
+ expect(res).toStrictEqual(exp);
44
+ });
45
+ it('should return the value for en-UK locales for decimals', () => {
46
+ const res = formatNumber(0.1, 'en-UK');
47
+ const exp = '0.1';
48
+ expect(res).toStrictEqual(exp);
49
+ });
50
+ });
51
+ describe('formatDate()', () => {
52
+ it('should return the formatted date', () => {
53
+ const res = formatDate(new Date('12-13-2023'));
54
+ const exp = '12-13-2023';
55
+ expect(res).toStrictEqual(exp);
56
+ });
57
+ it('should return the formatted date', () => {
58
+ const res = formatDate(new Date('2023-12-13'));
59
+ const exp = '12-13-2023';
60
+ expect(res).toStrictEqual(exp);
61
+ });
62
+ it('should return the formatted date for UK', () => {
63
+ const res = formatDate(new Date('2023-12-13'), 'en-UK');
64
+ const exp = '13-12-2023';
65
+ expect(res).toStrictEqual(exp);
66
+ });
67
+ it('should return the formatted date for IT', () => {
68
+ const res = formatDate(new Date('12-13-2023'), 'it-IT');
69
+ const exp = '13-12-2023';
70
+ expect(res).toStrictEqual(exp);
71
+ });
72
+ });
73
+ describe('formatValue()', () => {
74
+ it('should return the value for number', () => {
75
+ const res = formatValue(1000);
76
+ const exp = '1,000';
77
+ expect(res).toStrictEqual(exp);
78
+ });
79
+ it('should return the value for date', () => {
80
+ const res = formatValue(new Date('12-13-2023'));
81
+ const exp = '12-13-2023';
82
+ expect(res).toStrictEqual(exp);
83
+ });
84
+ it('should return the value for string', () => {
85
+ const res = formatValue('test');
86
+ const exp = 'test';
87
+ expect(res).toStrictEqual(exp);
88
+ });
89
+ });
90
+ describe('truncate()', () => {
91
+ it('should return truncated text', () => {
92
+ const res = truncate('abcdefghijklmnopqrstuvwxyz');
93
+ const exp = 'abcdefghijklmnopq...';
94
+ expect(res).toStrictEqual(exp);
95
+ });
96
+ it('should return untruncated text', () => {
97
+ const res = truncate('12345678901234567890');
98
+ const exp = '12345678901234567890';
99
+ expect(res).toStrictEqual(exp);
100
+ });
101
+ });
@@ -0,0 +1,8 @@
1
+ export * from './axis';
2
+ export * from './colors';
3
+ export * from './data';
4
+ export * from './format';
5
+ export * from './lines';
6
+ export * from './math';
7
+ export * from './metadata';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAgBA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC"}
@@ -0,0 +1,22 @@
1
+ /*
2
+ * Copyright 2023 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
+ export * from './axis';
17
+ export * from './colors';
18
+ export * from './data';
19
+ export * from './format';
20
+ export * from './lines';
21
+ export * from './math';
22
+ export * from './metadata';
@@ -0,0 +1,52 @@
1
+ import { CartesianAxis, Data, LineChartRenderType, Theme } from '../types';
2
+ export declare const accessor: (axis: CartesianAxis, dataKey: string, datum?: Record<string, unknown>) => number | undefined;
3
+ export declare const accessorInvert: (axis?: CartesianAxis, value?: number) => string | number | Date | undefined;
4
+ export declare const bisectIndex: (array: ArrayLike<string | number>, x: Date, lo?: number | undefined, hi?: number | undefined) => number;
5
+ export declare const getCoordinates: ({ datum, indexAxis, indexDataKey, otherAxis, otherDataKey, isHorizontal, }: {
6
+ datum: Record<string, any>;
7
+ indexAxis: CartesianAxis;
8
+ indexDataKey: string;
9
+ otherAxis: CartesianAxis;
10
+ otherDataKey: string;
11
+ isHorizontal: boolean;
12
+ }) => {
13
+ x: number | undefined;
14
+ y: number | undefined;
15
+ };
16
+ export declare const getLinesRenderer: (renderAs: LineChartRenderType | undefined, isHorizontal: boolean) => import("d3-shape").CurveFactory;
17
+ export declare const isMarkerLabelVisible: (index: number, totalLabels: number, maxLabels?: number) => boolean;
18
+ export declare const getMarkerLabelProps: (pos: {
19
+ x: number | undefined;
20
+ y: number | undefined;
21
+ }, dimension: {
22
+ maxWidth: number;
23
+ maxHeight: number;
24
+ }, isHorizontal: boolean, theme: Theme) => {
25
+ anchor: "end" | "middle" | "start" | "inherit" | undefined;
26
+ verticalAnchor: "end" | "middle" | "start" | undefined;
27
+ fontColor: string;
28
+ fontSize: number;
29
+ fontWeight: number;
30
+ background: string;
31
+ padding: {
32
+ top: number;
33
+ right: number;
34
+ bottom: number;
35
+ left: number;
36
+ };
37
+ titleProps: {
38
+ x: number;
39
+ y: number;
40
+ textAnchor: "end" | "middle" | "start" | "inherit" | undefined;
41
+ };
42
+ backgroundProps: {
43
+ rx: number;
44
+ ry: number;
45
+ x: number;
46
+ y: number;
47
+ filter: string;
48
+ };
49
+ };
50
+ export declare const createSubArrays: (arr: Array<Record<string, any>>, condition: (d: Record<string, any>) => boolean) => Record<string, any>[][];
51
+ export declare const createSubPaths: (data: Data, condition: (d: Record<string, any>) => boolean) => Record<string, any>[][];
52
+ //# sourceMappingURL=lines.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lines.d.ts","sourceRoot":"","sources":["../../src/utils/lines.ts"],"names":[],"mappings":"AAuBA,OAAO,EACL,aAAa,EAAE,IAAI,EAAE,mBAAmB,EAAE,KAAK,EAChD,MAAM,UAAU,CAAC;AAGlB,eAAO,MAAM,QAAQ,SAAU,aAAa,WAAW,MAAM,UAAU,OAAO,MAAM,EAAE,OAAO,CAAC,uBAU7F,CAAC;AAEF,eAAO,MAAM,cAAc,UAAW,aAAa,UAAU,MAAM,uCA8BlE,CAAC;AAEF,eAAO,MAAM,WAAW,0GAA8D,CAAC;AAEvF,eAAO,MAAM,cAAc;WAShB,OAAO,MAAM,EAAE,GAAG,CAAC;eACf,aAAa;kBACV,MAAM;eACT,aAAa;kBACV,MAAM;kBACN,OAAO;;;;CASxB,CAAC;AAEF,eAAO,MAAM,gBAAgB,aAAc,mBAAmB,GAAG,SAAS,gBAAgB,OAAO,oCAOhG,CAAC;AAEF,eAAO,MAAM,oBAAoB,UAAW,MAAM,eAAe,MAAM,gCAStE,CAAC;AAEF,eAAO,MAAM,mBAAmB,QACzB;IAAE,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,aAC1C;IAAE,QAAQ,EAAE,MAAM,CAAE;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,gBACrC,OAAO,SACd,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;CA2Eb,CAAC;AAEF,eAAO,MAAM,eAAe,QACrB,MAAM,OAAO,MAAM,EAAE,GAAG,CAAC,CAAC,iBAChB,OAAO,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,4BAgBL,CAAC;AAE5C,eAAO,MAAM,cAAc,8BAEV,OAAO,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,4BA6B/C,CAAC"}
@@ -0,0 +1,190 @@
1
+ /*
2
+ * Copyright 2023 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 { curveLinear, curveMonotoneX, curveMonotoneY, curveStepAfter, curveStepBefore, } from '@visx/curve';
17
+ import { bisector } from '@visx/vendor/d3-array';
18
+ import _ from 'lodash';
19
+ import { getPrimitiveFromObjectByPath } from './data';
20
+ export const accessor = (axis, dataKey, datum) => {
21
+ if (axis.scale && datum) {
22
+ const d = getPrimitiveFromObjectByPath(datum, dataKey);
23
+ if (!_.isNil(d)) {
24
+ const t = axis.scaleType === 'time' ? new Date(d) : d;
25
+ return axis.scale(t);
26
+ }
27
+ }
28
+ return undefined;
29
+ };
30
+ export const accessorInvert = (axis, value) => {
31
+ let res;
32
+ if (axis && value) {
33
+ const { orientation, top, left, scale, scaleType, } = axis;
34
+ const isVertical = orientation === 'left' || orientation === 'right';
35
+ const offset = isVertical ? top : left;
36
+ const num = value - offset;
37
+ if (scaleType !== 'label') {
38
+ const s = scale;
39
+ res = s.invert(num);
40
+ }
41
+ else {
42
+ const [from, to] = scale.range();
43
+ const min = Math.min(from, to);
44
+ const max = Math.max(from, to);
45
+ const divider = axis.numTicks ?? axis.domain.length;
46
+ const bandwidth = (max - min) / divider;
47
+ // @ts-expect-error: method not expected
48
+ const padding = scale.padding() ? bandwidth / 2 : 0;
49
+ const i = Math.round((num - padding) / bandwidth);
50
+ const len = axis.domain.length;
51
+ res = isVertical ? axis.domain[len - i] : axis.domain[i];
52
+ }
53
+ }
54
+ return res;
55
+ };
56
+ export const bisectIndex = bisector((index) => new Date(index)).right;
57
+ export const getCoordinates = ({ datum, indexAxis, indexDataKey, otherAxis, otherDataKey, isHorizontal, }) => {
58
+ const i = accessor(indexAxis, indexDataKey, datum);
59
+ const o = accessor(otherAxis, otherDataKey, datum);
60
+ return isHorizontal
61
+ ? { x: i, y: o }
62
+ : { x: o, y: i };
63
+ };
64
+ export const getLinesRenderer = (renderAs, isHorizontal) => {
65
+ const whichMonotone = isHorizontal ? curveMonotoneX : curveMonotoneY;
66
+ const whichStep = isHorizontal ? curveStepAfter : curveStepBefore;
67
+ if (renderAs === 'curves')
68
+ return whichMonotone;
69
+ if (renderAs === 'lines')
70
+ return curveLinear;
71
+ return whichStep;
72
+ };
73
+ export const isMarkerLabelVisible = (index, totalLabels, maxLabels = 12) => {
74
+ const divider = maxLabels > 1 ? maxLabels : 1;
75
+ const step = Math.ceil(totalLabels / divider);
76
+ const half = Math.round(totalLabels / 2);
77
+ const leftIndex = [];
78
+ for (let i = 0; i < half; i += step)
79
+ leftIndex.push(i);
80
+ const rightIndex = leftIndex.map(e => totalLabels - e);
81
+ const allIndex = leftIndex.concat(rightIndex).sort((a, b) => a - b);
82
+ return allIndex.includes(index);
83
+ };
84
+ export const getMarkerLabelProps = (pos, dimension, isHorizontal, theme) => {
85
+ const { maxWidth, maxHeight } = dimension;
86
+ const main = {
87
+ anchor: 'middle',
88
+ verticalAnchor: 'end',
89
+ fontColor: theme.markerLabel.fontColor,
90
+ fontSize: 12,
91
+ fontWeight: 400,
92
+ background: theme.markerLabel.background,
93
+ padding: {
94
+ top: 2, right: 6, bottom: 2, left: 6,
95
+ },
96
+ titleProps: {
97
+ x: 4,
98
+ y: 2,
99
+ textAnchor: 'start',
100
+ },
101
+ backgroundProps: {
102
+ rx: 4,
103
+ ry: 4,
104
+ x: 0,
105
+ y: 0,
106
+ filter: 'opacity(0.7)',
107
+ },
108
+ };
109
+ if (!_.isNil(pos.x) && !_.isNil(pos.y)) {
110
+ const isLeft = pos.x < (maxWidth * 0.075);
111
+ const isRigth = pos.x > (maxWidth * 0.9);
112
+ const isTop = pos.y < (maxHeight * 0.075);
113
+ const isBottom = pos.y > (maxHeight * 0.9);
114
+ if (isHorizontal) {
115
+ if (isLeft) {
116
+ main.anchor = 'start';
117
+ main.backgroundProps.x = 4;
118
+ }
119
+ if (isRigth) {
120
+ main.anchor = 'end';
121
+ main.backgroundProps.x = -4;
122
+ }
123
+ if (isBottom) {
124
+ main.backgroundProps.y = -4;
125
+ }
126
+ else {
127
+ main.verticalAnchor = 'start';
128
+ main.backgroundProps.y = 4;
129
+ }
130
+ }
131
+ else {
132
+ main.anchor = 'start';
133
+ if (isTop) {
134
+ main.verticalAnchor = 'start';
135
+ main.backgroundProps.y = 4;
136
+ }
137
+ else {
138
+ main.backgroundProps.y = -4;
139
+ }
140
+ if (isLeft) {
141
+ main.backgroundProps.x = 6;
142
+ }
143
+ if (isRigth) {
144
+ main.anchor = 'end';
145
+ }
146
+ }
147
+ main.titleProps.x += main.backgroundProps.x;
148
+ main.titleProps.y += main.backgroundProps.y;
149
+ }
150
+ return main;
151
+ };
152
+ export const createSubArrays = (arr, condition) => arr.reduce((acc, cur) => {
153
+ const items = acc.length;
154
+ const lastIndex = acc.length - 1;
155
+ if (condition(cur)) {
156
+ if (items > 0 && acc[lastIndex].length > 0) {
157
+ acc.push([]);
158
+ }
159
+ }
160
+ else if (items === 0 || acc[lastIndex].length === 0) {
161
+ acc.push([cur]);
162
+ }
163
+ else {
164
+ acc[lastIndex].push(cur);
165
+ }
166
+ return acc;
167
+ }, []);
168
+ export const createSubPaths = (data, condition) => {
169
+ const subArray = createSubArrays(data, condition);
170
+ if (!subArray[0].length)
171
+ subArray.shift();
172
+ if (!subArray[subArray.length - 1].length)
173
+ subArray.pop();
174
+ if (subArray.length > 1) {
175
+ return subArray.map((a, i) => {
176
+ const len = a.length;
177
+ const prev = i - 1;
178
+ const post = i + 1;
179
+ if (!len) {
180
+ const arrPrev = subArray[prev];
181
+ const arrPrevLast = arrPrev.length - 1;
182
+ const fromPrev = arrPrev[arrPrevLast];
183
+ const fromPost = subArray[post][0];
184
+ return [fromPrev, fromPost];
185
+ }
186
+ return a;
187
+ });
188
+ }
189
+ return subArray;
190
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=lines.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lines.test.d.ts","sourceRoot":"","sources":["../../src/utils/lines.test.ts"],"names":[],"mappings":""}