@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,498 @@
1
+ import { curveLinear, curveMonotoneX, curveMonotoneY, curveStepAfter, curveStepBefore, } from '@visx/curve';
2
+ import { themes } from '../style-config';
3
+ import { computeAxisProperties } from './axis';
4
+ import { accessor, accessorInvert, bisectIndex, createSubArrays, createSubPaths, getCoordinates, getLinesRenderer, getMarkerLabelProps, isMarkerLabelVisible, } from './lines';
5
+ describe('accessor()', () => {
6
+ it('should return an integer for linear scale', () => {
7
+ const axis = {
8
+ domain: [0, 100],
9
+ scaleType: 'linear',
10
+ orientation: 'top',
11
+ hideTickLabel: false,
12
+ tickFormat: undefined,
13
+ };
14
+ const cartesian = computeAxisProperties({
15
+ axis,
16
+ maxRangeX: 800,
17
+ maxRangeY: 600,
18
+ positionTop: 1,
19
+ positionRight: 2,
20
+ positionBottom: 3,
21
+ positionLeft: 4,
22
+ });
23
+ const res = accessor(cartesian, 'value', { value: 50 });
24
+ const exp = 400;
25
+ expect(res).toStrictEqual(exp);
26
+ });
27
+ it('should return an integer for time scale', () => {
28
+ const axis = {
29
+ domain: ['01-01-2020', '01-01-2022'],
30
+ scaleType: 'time',
31
+ orientation: 'top',
32
+ hideTickLabel: false,
33
+ tickFormat: undefined,
34
+ };
35
+ const cartesian = computeAxisProperties({
36
+ axis,
37
+ maxRangeX: 800,
38
+ maxRangeY: 600,
39
+ positionTop: 1,
40
+ positionRight: 2,
41
+ positionBottom: 3,
42
+ positionLeft: 4,
43
+ });
44
+ const res = accessor(cartesian, 'date', { date: '01-01-2021' });
45
+ const exp = 401;
46
+ expect(res).toStrictEqual(exp);
47
+ });
48
+ it('should return an integer for label scale', () => {
49
+ const axis = {
50
+ domain: ['01-01-2020', '01-01-2021', '01-01-2022'],
51
+ scaleType: 'label',
52
+ orientation: 'top',
53
+ hideTickLabel: false,
54
+ tickFormat: undefined,
55
+ };
56
+ const cartesian = computeAxisProperties({
57
+ axis,
58
+ maxRangeX: 800,
59
+ maxRangeY: 600,
60
+ positionTop: 1,
61
+ positionRight: 2,
62
+ positionBottom: 3,
63
+ positionLeft: 4,
64
+ });
65
+ const res = accessor(cartesian, 'date', { date: '01-01-2021' });
66
+ const exp = 400;
67
+ expect(res).toStrictEqual(exp);
68
+ });
69
+ it('should return undefined w/o datum', () => {
70
+ const axis = {
71
+ domain: ['01-01-2020', '01-01-2021', '01-01-2022'],
72
+ scaleType: 'label',
73
+ orientation: 'top',
74
+ hideTickLabel: false,
75
+ tickFormat: undefined,
76
+ };
77
+ const cartesian = computeAxisProperties({
78
+ axis,
79
+ maxRangeX: 800,
80
+ maxRangeY: 600,
81
+ positionTop: 1,
82
+ positionRight: 2,
83
+ positionBottom: 3,
84
+ positionLeft: 4,
85
+ });
86
+ const res = accessor(cartesian, 'date', { date: undefined });
87
+ const exp = undefined;
88
+ expect(res).toStrictEqual(exp);
89
+ });
90
+ });
91
+ describe('accessorInvert()', () => {
92
+ it('should return the correct value from domain - top axis', () => {
93
+ const axis = {
94
+ domain: [0, 100],
95
+ scaleType: 'linear',
96
+ orientation: 'top',
97
+ hideTickLabel: false,
98
+ tickFormat: undefined,
99
+ };
100
+ const cartesian = computeAxisProperties({
101
+ axis,
102
+ maxRangeX: 800,
103
+ maxRangeY: 600,
104
+ positionTop: 0,
105
+ positionRight: 2,
106
+ positionBottom: 3,
107
+ positionLeft: 4,
108
+ });
109
+ const res = accessorInvert(cartesian, 400);
110
+ const exp = 49.5;
111
+ expect(res).toStrictEqual(exp);
112
+ });
113
+ it('should return the correct value from domain - left axis', () => {
114
+ const axis = {
115
+ domain: [0, 100],
116
+ scaleType: 'linear',
117
+ orientation: 'left',
118
+ hideTickLabel: false,
119
+ tickFormat: undefined,
120
+ };
121
+ const cartesian = computeAxisProperties({
122
+ axis,
123
+ maxRangeX: 800,
124
+ maxRangeY: 600,
125
+ positionTop: 1,
126
+ positionRight: 2,
127
+ positionBottom: 3,
128
+ positionLeft: 4,
129
+ });
130
+ const res = accessorInvert(cartesian, 300);
131
+ const exp = 50;
132
+ expect(Math.round(res)).toStrictEqual(exp);
133
+ });
134
+ it('should return the correct value from domain - label/left', () => {
135
+ const axis = {
136
+ domain: ['a', 'b', 'c'],
137
+ scaleType: 'label',
138
+ orientation: 'left',
139
+ hideTickLabel: false,
140
+ tickFormat: undefined,
141
+ };
142
+ const cartesian = computeAxisProperties({
143
+ axis,
144
+ maxRangeX: 800,
145
+ maxRangeY: 600,
146
+ positionTop: 1,
147
+ positionRight: 2,
148
+ positionBottom: 3,
149
+ positionLeft: 4,
150
+ });
151
+ const res = accessorInvert(cartesian, 400);
152
+ const exp = 'c';
153
+ expect(res).toStrictEqual(exp);
154
+ });
155
+ it('should return the correct value from domain - label/top', () => {
156
+ const axis = {
157
+ domain: ['a', 'b', 'c'],
158
+ scaleType: 'label',
159
+ orientation: 'top',
160
+ hideTickLabel: false,
161
+ tickFormat: undefined,
162
+ };
163
+ const cartesian = computeAxisProperties({
164
+ axis,
165
+ maxRangeX: 800,
166
+ maxRangeY: 600,
167
+ positionTop: 1,
168
+ positionRight: 2,
169
+ positionBottom: 3,
170
+ positionLeft: 4,
171
+ });
172
+ const res = accessorInvert(cartesian, 350);
173
+ const exp = 'b';
174
+ expect(res).toStrictEqual(exp);
175
+ });
176
+ });
177
+ describe('bisectIndex()', () => {
178
+ it('should return correct data array index', () => {
179
+ const res = bisectIndex(['01-01-2020', '01-01-2021', '01-01-2022'], new Date('01-03-2021'), 0, 100);
180
+ const exp = 2;
181
+ expect(res).toStrictEqual(exp);
182
+ });
183
+ it('should return correct data array index', () => {
184
+ const res = bisectIndex(['01-01-2020', '01-01-2021', '01-01-2022'], new Date('01-01-2020'));
185
+ const exp = 1;
186
+ expect(res).toStrictEqual(exp);
187
+ });
188
+ });
189
+ describe('getCoordinates()', () => {
190
+ const indexAxis = {
191
+ domain: ['01-01-2020', '01-01-2023'],
192
+ scaleType: 'time',
193
+ orientation: 'bottom',
194
+ };
195
+ const seriesAxis = {
196
+ domain: [0, 100],
197
+ scaleType: 'linear',
198
+ orientation: 'left',
199
+ };
200
+ const i = computeAxisProperties({
201
+ axis: indexAxis,
202
+ maxRangeX: 800,
203
+ maxRangeY: 600,
204
+ positionTop: 1,
205
+ positionRight: 2,
206
+ positionBottom: 3,
207
+ positionLeft: 4,
208
+ });
209
+ const s = computeAxisProperties({
210
+ axis: seriesAxis,
211
+ maxRangeX: 800,
212
+ maxRangeY: 600,
213
+ positionTop: 1,
214
+ positionRight: 2,
215
+ positionBottom: 3,
216
+ positionLeft: 4,
217
+ });
218
+ it('should return data - horizontal', () => {
219
+ const res = getCoordinates({
220
+ datum: { date: '01-01-2021', value: 50 },
221
+ indexAxis: i,
222
+ indexDataKey: 'date',
223
+ otherAxis: s,
224
+ otherDataKey: 'value',
225
+ isHorizontal: true,
226
+ });
227
+ const exp = { x: 267, y: 300 };
228
+ expect(res).toStrictEqual(exp);
229
+ });
230
+ it('should return data - vertical', () => {
231
+ const res = getCoordinates({
232
+ datum: { date: '01-01-2021', value: 50 },
233
+ indexAxis: i,
234
+ indexDataKey: 'date',
235
+ otherAxis: s,
236
+ otherDataKey: 'value',
237
+ isHorizontal: false,
238
+ });
239
+ const exp = { x: 300, y: 267 };
240
+ expect(res).toStrictEqual(exp);
241
+ });
242
+ });
243
+ describe('getLinesRenderer()', () => {
244
+ it('should return curveLinear', () => {
245
+ const res = getLinesRenderer('lines', true);
246
+ const exp = curveLinear;
247
+ expect(res).toStrictEqual(exp);
248
+ });
249
+ it('should return curveMonotoneX', () => {
250
+ const res = getLinesRenderer('curves', true);
251
+ const exp = curveMonotoneX;
252
+ expect(res).toStrictEqual(exp);
253
+ });
254
+ it('should return curveMonotoneY', () => {
255
+ const res = getLinesRenderer('curves', false);
256
+ const exp = curveMonotoneY;
257
+ expect(res).toStrictEqual(exp);
258
+ });
259
+ it('should return curveStepAfter', () => {
260
+ const res = getLinesRenderer('steps', true);
261
+ const exp = curveStepAfter;
262
+ expect(res).toStrictEqual(exp);
263
+ });
264
+ it('should return curveStepBefore', () => {
265
+ const res = getLinesRenderer(undefined, false);
266
+ const exp = curveStepBefore;
267
+ expect(res).toStrictEqual(exp);
268
+ });
269
+ });
270
+ describe('isMarkerLabelVisible()', () => {
271
+ it('should return true for index 0 of 10 labels', () => {
272
+ const isVisible = isMarkerLabelVisible(0, 10, 12);
273
+ expect(isVisible).toBeTruthy();
274
+ });
275
+ it('should return true for index 19 of 20 labels', () => {
276
+ const isVisible = isMarkerLabelVisible(19, 20, 12);
277
+ expect(isVisible).not.toBeTruthy();
278
+ });
279
+ it('should return true if maxLabel is set to 0', () => {
280
+ const isVisible = isMarkerLabelVisible(19, 20, 0);
281
+ expect(isVisible).not.toBeTruthy();
282
+ });
283
+ it('should return true w/o maxLabel', () => {
284
+ const isVisible = isMarkerLabelVisible(19, 20);
285
+ expect(isVisible).not.toBeTruthy();
286
+ });
287
+ });
288
+ describe('getMarkerLabelProps()', () => {
289
+ it('shoult return a style configuration - horizontal/left', () => {
290
+ const res = getMarkerLabelProps({ x: 0, y: 0 }, { maxWidth: 800, maxHeight: 600 }, true, themes.light);
291
+ const exp = {
292
+ anchor: 'start',
293
+ background: 'hsl(220 16% 85%)',
294
+ backgroundProps: {
295
+ filter: 'opacity(0.7)', rx: 4, ry: 4, x: 4, y: 4,
296
+ },
297
+ fontColor: 'hsl(217 11% 14%)',
298
+ fontSize: 12,
299
+ fontWeight: 400,
300
+ padding: {
301
+ bottom: 2, left: 6, right: 6, top: 2,
302
+ },
303
+ titleProps: { textAnchor: 'start', x: 8, y: 6 },
304
+ verticalAnchor: 'start',
305
+ };
306
+ expect(res).toStrictEqual(exp);
307
+ });
308
+ it('shoult return a style configuration - horizontal/right', () => {
309
+ const res = getMarkerLabelProps({ x: 795, y: 0 }, { maxWidth: 800, maxHeight: 600 }, true, themes.light);
310
+ const exp = {
311
+ anchor: 'end',
312
+ background: 'hsl(220 16% 85%)',
313
+ backgroundProps: {
314
+ filter: 'opacity(0.7)', rx: 4, ry: 4, x: -4, y: 4,
315
+ },
316
+ fontColor: 'hsl(217 11% 14%)',
317
+ fontSize: 12,
318
+ fontWeight: 400,
319
+ padding: {
320
+ bottom: 2, left: 6, right: 6, top: 2,
321
+ },
322
+ titleProps: { textAnchor: 'start', x: 0, y: 6 },
323
+ verticalAnchor: 'start',
324
+ };
325
+ expect(res).toStrictEqual(exp);
326
+ });
327
+ it('shoult return a style configuration - horizontal/bottom', () => {
328
+ const res = getMarkerLabelProps({ x: 0, y: 595 }, { maxWidth: 800, maxHeight: 600 }, true, themes.light);
329
+ const exp = {
330
+ anchor: 'start',
331
+ background: 'hsl(220 16% 85%)',
332
+ backgroundProps: {
333
+ filter: 'opacity(0.7)', rx: 4, ry: 4, x: 4, y: -4,
334
+ },
335
+ fontColor: 'hsl(217 11% 14%)',
336
+ fontSize: 12,
337
+ fontWeight: 400,
338
+ padding: {
339
+ bottom: 2, left: 6, right: 6, top: 2,
340
+ },
341
+ titleProps: { textAnchor: 'start', x: 8, y: -2 },
342
+ verticalAnchor: 'end',
343
+ };
344
+ expect(res).toStrictEqual(exp);
345
+ });
346
+ it('shoult return a style configuration - vertical', () => {
347
+ const res = getMarkerLabelProps({ x: 0, y: 0 }, { maxWidth: 800, maxHeight: 600 }, false, themes.light);
348
+ const exp = {
349
+ anchor: 'start',
350
+ background: 'hsl(220 16% 85%)',
351
+ backgroundProps: {
352
+ filter: 'opacity(0.7)', rx: 4, ry: 4, x: 6, y: 4,
353
+ },
354
+ fontColor: 'hsl(217 11% 14%)',
355
+ fontSize: 12,
356
+ fontWeight: 400,
357
+ padding: {
358
+ bottom: 2, left: 6, right: 6, top: 2,
359
+ },
360
+ titleProps: { textAnchor: 'start', x: 10, y: 6 },
361
+ verticalAnchor: 'start',
362
+ };
363
+ expect(res).toStrictEqual(exp);
364
+ });
365
+ it('shoult return a style configuration - vertical/top', () => {
366
+ const res = getMarkerLabelProps({ x: 0, y: 595 }, { maxWidth: 800, maxHeight: 600 }, false, themes.light);
367
+ const exp = {
368
+ anchor: 'start',
369
+ background: 'hsl(220 16% 85%)',
370
+ backgroundProps: {
371
+ filter: 'opacity(0.7)', rx: 4, ry: 4, x: 6, y: -4,
372
+ },
373
+ fontColor: 'hsl(217 11% 14%)',
374
+ fontSize: 12,
375
+ fontWeight: 400,
376
+ padding: {
377
+ bottom: 2, left: 6, right: 6, top: 2,
378
+ },
379
+ titleProps: { textAnchor: 'start', x: 10, y: -2 },
380
+ verticalAnchor: 'end',
381
+ };
382
+ expect(res).toStrictEqual(exp);
383
+ });
384
+ it('shoult return a style configuration - vertical/bottom/right', () => {
385
+ const res = getMarkerLabelProps({ x: 795, y: 5 }, { maxWidth: 800, maxHeight: 600 }, false, themes.light);
386
+ const exp = {
387
+ anchor: 'end',
388
+ background: 'hsl(220 16% 85%)',
389
+ backgroundProps: {
390
+ filter: 'opacity(0.7)', rx: 4, ry: 4, x: 0, y: 4,
391
+ },
392
+ fontColor: 'hsl(217 11% 14%)',
393
+ fontSize: 12,
394
+ fontWeight: 400,
395
+ padding: {
396
+ bottom: 2, left: 6, right: 6, top: 2,
397
+ },
398
+ titleProps: { textAnchor: 'start', x: 4, y: 6 },
399
+ verticalAnchor: 'start',
400
+ };
401
+ expect(res).toStrictEqual(exp);
402
+ });
403
+ });
404
+ describe('createSubArrays()', () => {
405
+ it('should return an array of arrays - index 0', () => {
406
+ const input = [
407
+ { value: 0 },
408
+ { value: 1 },
409
+ { value: 1 },
410
+ { value: 1 }
411
+ ];
412
+ const condition = (d) => d.value === 0;
413
+ const res = createSubArrays(input, condition);
414
+ const exp = [[{ value: 1 }, { value: 1 }, { value: 1 }]];
415
+ expect(res).toStrictEqual(exp);
416
+ });
417
+ it('should return an array of arrays - index 1', () => {
418
+ const input = [
419
+ { value: 1 },
420
+ { value: 0 },
421
+ { value: 1 },
422
+ { value: 1 }
423
+ ];
424
+ const condition = (d) => d.value === 0;
425
+ const res = createSubArrays(input, condition);
426
+ const exp = [[{ value: 1 }], [], [{ value: 1 }, { value: 1 }]];
427
+ expect(res).toStrictEqual(exp);
428
+ });
429
+ it('should return an array of arrays - index -1', () => {
430
+ const input = [
431
+ { value: 1 },
432
+ { value: 1 },
433
+ { value: 1 },
434
+ { value: 0 }
435
+ ];
436
+ const condition = (d) => d.value === 0;
437
+ const res = createSubArrays(input, condition);
438
+ const exp = [[{ value: 1 }, { value: 1 }, { value: 1 }], []];
439
+ expect(res).toStrictEqual(exp);
440
+ });
441
+ });
442
+ describe('createSubPaths()', () => {
443
+ it('should return a sub path / last', () => {
444
+ const input = [
445
+ { value: 1 },
446
+ { value: 2 },
447
+ { value: 3 },
448
+ { value: 0 }
449
+ ];
450
+ const condition = (d) => d.value === 0;
451
+ const res = createSubPaths(input, condition);
452
+ const exp = [
453
+ [{ value: 1 }, { value: 2 }, { value: 3 }],
454
+ ];
455
+ expect(res).toStrictEqual(exp);
456
+ });
457
+ it('should return a sub path / nth', () => {
458
+ const input = [
459
+ { value: 1 },
460
+ { value: 0 },
461
+ { value: 2 },
462
+ { value: 3 },
463
+ ];
464
+ const condition = (d) => d.value === 0;
465
+ const res = createSubPaths(input, condition);
466
+ const exp = [
467
+ [{ value: 1 }],
468
+ [{ value: 1 }, { value: 2 }],
469
+ [{ value: 2 }, { value: 3 }],
470
+ ];
471
+ expect(res).toStrictEqual(exp);
472
+ });
473
+ it('should return a sub path / first', () => {
474
+ const input = [
475
+ { value: 0 },
476
+ { value: 1 },
477
+ { value: 2 },
478
+ { value: 3 },
479
+ ];
480
+ const condition = (d) => d.value === 0;
481
+ const res = createSubPaths(input, condition);
482
+ const exp = [
483
+ [{ value: 1 }, { value: 2 }, { value: 3 }],
484
+ ];
485
+ expect(res).toStrictEqual(exp);
486
+ });
487
+ it('should return a sub path / first', () => {
488
+ const input = [
489
+ { value: 1 },
490
+ { value: 2 },
491
+ { value: 3 },
492
+ ];
493
+ const condition = (d) => d.value === 0;
494
+ const res = createSubPaths(input, condition);
495
+ const exp = [[{ value: 1 }, { value: 2 }, { value: 3 }]];
496
+ expect(res).toStrictEqual(exp);
497
+ });
498
+ });
@@ -0,0 +1,13 @@
1
+ import { TickFormatter } from '@visx/axis/lib/types';
2
+ import { NumberValue } from '@visx/vendor/d3-scale';
3
+ import { ValidTypeOf } from '../types/main';
4
+ export declare const isArrayType: (arr: any[], type: ValidTypeOf | 'date') => boolean;
5
+ export declare const isArrayTypeObject: (arr: any[]) => boolean;
6
+ export declare const isArrayTypeString: (arr: any[]) => boolean;
7
+ export declare const isArrayTypeNumber: (arr: any[]) => boolean;
8
+ export declare const isArrayTypeDate: (arr: any[]) => boolean;
9
+ export declare const getMinMaxNumber: (values: number[]) => [number, number] | undefined;
10
+ export declare const getMinMaxDate: (values: Array<number | string | Date>) => Date[] | undefined;
11
+ export declare const getMaxCharactersNum: (domain: Array<string | number>, tickFormat?: TickFormatter<string | Date | NumberValue>) => number;
12
+ export declare const removeNilsFromDomain: (domain: Array<string | number | undefined>) => NonNullable<string | number>[];
13
+ //# sourceMappingURL=math.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../src/utils/math.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,eAAO,MAAM,WAAW,QACjB,GAAG,EAAE,QACJ,WAAW,GAAG,MAAM,YAa3B,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAAS,GAAG,EAAE,YAA+B,CAAC;AAC5E,eAAO,MAAM,iBAAiB,QAAS,GAAG,EAAE,YAA+B,CAAC;AAC5E,eAAO,MAAM,iBAAiB,QAAS,GAAG,EAAE,YAA+B,CAAC;AAC5E,eAAO,MAAM,eAAe,QAAS,GAAG,EAAE,YAA6B,CAAC;AAExE,eAAO,MAAM,eAAe,WAAY,MAAM,EAAE,KAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAGrE,CAAC;AAEF,eAAO,MAAM,aAAa,WAAY,MAAM,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,uBAsBlE,CAAC;AAEF,eAAO,MAAM,mBAAmB,WACtB,MAAM,MAAM,GAAG,MAAM,CAAC,eACjB,cAAc,MAAM,GAAG,IAAI,GAAG,WAAW,CAAC,WAiCxD,CAAC;AAEF,eAAO,MAAM,oBAAoB,WAAY,MAAM,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,mCACZ,CAAC"}
@@ -0,0 +1,89 @@
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 _ from 'lodash';
17
+ import { formatNumber } from './format';
18
+ export const isArrayType = (arr, type) => {
19
+ if (type === 'date') {
20
+ return Array.isArray(arr)
21
+ && arr.length > 0
22
+ && arr.every((el) => {
23
+ const toDate = new Date(el).toString();
24
+ return _.isDate(el) && toDate !== 'Invalid Date';
25
+ });
26
+ }
27
+ // eslint-disable-next-line valid-typeof
28
+ return Array.isArray(arr) && arr.length > 0 && arr.every(el => typeof el === type);
29
+ };
30
+ export const isArrayTypeObject = (arr) => isArrayType(arr, 'object');
31
+ export const isArrayTypeString = (arr) => isArrayType(arr, 'string');
32
+ export const isArrayTypeNumber = (arr) => isArrayType(arr, 'number');
33
+ export const isArrayTypeDate = (arr) => isArrayType(arr, 'date');
34
+ export const getMinMaxNumber = (values) => {
35
+ if (isArrayTypeNumber(values))
36
+ return [Math.min(...values), Math.max(...values)];
37
+ return undefined;
38
+ };
39
+ export const getMinMaxDate = (values) => {
40
+ const isNumbers = isArrayTypeNumber(values);
41
+ const isDates = isArrayTypeDate(values);
42
+ const isString = isArrayTypeString(values);
43
+ let dates;
44
+ if (isNumbers) {
45
+ dates = getMinMaxNumber(values);
46
+ }
47
+ if (isString) {
48
+ const n = values.map(s => new Date(s).getTime());
49
+ dates = getMinMaxNumber(n);
50
+ }
51
+ if (isDates) {
52
+ const v = values;
53
+ const n = v.map(date => date.getTime());
54
+ dates = getMinMaxNumber(n);
55
+ }
56
+ return dates && [new Date(dates[0]), new Date(dates[1])];
57
+ };
58
+ export const getMaxCharactersNum = (domain, tickFormat) => {
59
+ if (!domain.length)
60
+ return 0;
61
+ const isNumbers = isArrayTypeNumber(domain);
62
+ let maxLen = 0;
63
+ let diffLen = 0;
64
+ if (tickFormat) {
65
+ const formatObj = domain.map((e, i) => ({ value: e, index: i }));
66
+ const domainFormatted = domain.map((v, i) => tickFormat(v, i, formatObj));
67
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
68
+ const diff = domainFormatted.map((df, i) => (`${df}`).length - (`${domain[i]}`).length);
69
+ const [highest] = diff.sort((a, b) => b - a);
70
+ diffLen = highest;
71
+ }
72
+ if (isNumbers) {
73
+ const minMax = getMinMaxNumber(domain);
74
+ if (minMax !== undefined) {
75
+ const [low, high] = minMax;
76
+ const step = high / 10;
77
+ const lowLen = formatNumber(low).length;
78
+ const highLen = formatNumber(high).length;
79
+ const stepLen = formatNumber(step).length;
80
+ maxLen = Math.max(highLen, stepLen, lowLen);
81
+ }
82
+ }
83
+ else {
84
+ maxLen = domain.map(el => `${el}`).sort((a, b) => b.length - a.length)[0].length;
85
+ }
86
+ return maxLen + diffLen;
87
+ };
88
+ export const removeNilsFromDomain = (domain) => domain
89
+ .filter((el) => !_.isNil(el));
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=math.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math.test.d.ts","sourceRoot":"","sources":["../../src/utils/math.test.ts"],"names":[],"mappings":""}