@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,1071 @@
1
+ import { cartesianStyleConfig, viewportStyleConfig } from '../style-config';
2
+ import { computeAxisOffset, computeAxisProperties, computeAxisStyleConfig, computeAxisSystemOffset, computeAxisSystemProperties, getAxisOffset, getLabelOffset, getTickLabelSize, handleChartAxisLayout, handleNumberOfTicks, handleTickFormat, handleVerticalTickLabelOffset, handleVerticalTickLabelTransform, hasVerticalTickLabel, inferScaleTypeFromDomain, scaleDomainToAxis, } from './axis';
3
+ describe('getAxisOffset()', () => {
4
+ it('should return offset for top axis', () => {
5
+ const res = getAxisOffset({
6
+ orientation: 'top',
7
+ tick: 10,
8
+ tickOffset: -10,
9
+ tickLabelHeight: 10,
10
+ maxLength: 10,
11
+ axisLabel: 10,
12
+ axisLine: 10,
13
+ });
14
+ const exp = 40;
15
+ expect(res).toStrictEqual(exp);
16
+ });
17
+ it('should return offset for bottom axis', () => {
18
+ const res = getAxisOffset({
19
+ orientation: 'bottom',
20
+ tick: 10,
21
+ tickOffset: 10,
22
+ tickLabelHeight: 10,
23
+ maxLength: 10,
24
+ axisLabel: 10,
25
+ axisLine: 10,
26
+ });
27
+ const exp = 40;
28
+ expect(res).toStrictEqual(exp);
29
+ });
30
+ it('should return offset for left axis', () => {
31
+ const res = getAxisOffset({
32
+ orientation: 'left',
33
+ tick: 10,
34
+ tickOffset: -10,
35
+ tickLabelHeight: 10,
36
+ maxLength: 10,
37
+ axisLabel: 10,
38
+ axisLine: 10,
39
+ });
40
+ const exp = 50;
41
+ expect(res).toStrictEqual(exp);
42
+ });
43
+ it('should return offset for right axis', () => {
44
+ const res = getAxisOffset({
45
+ orientation: 'right',
46
+ tick: 10,
47
+ tickOffset: 10,
48
+ tickLabelHeight: 10,
49
+ maxLength: 10,
50
+ axisLabel: 10,
51
+ axisLine: 10,
52
+ });
53
+ const exp = 50;
54
+ expect(res).toStrictEqual(exp);
55
+ });
56
+ });
57
+ describe('getTickLabelSize()', () => {
58
+ it('should return ticket label size - hideTickLabel', () => {
59
+ const res = getTickLabelSize({
60
+ isVertical: true,
61
+ hideTickLabel: true,
62
+ maxLength: 3,
63
+ tickOffset: 4,
64
+ tickLabelHeight: 5,
65
+ });
66
+ const exp = 7;
67
+ expect(res).toStrictEqual(exp);
68
+ });
69
+ it('should return ticket label size - vertical', () => {
70
+ const res = getTickLabelSize({
71
+ isVertical: true,
72
+ hideTickLabel: undefined,
73
+ maxLength: 3,
74
+ tickOffset: 4,
75
+ tickLabelHeight: 5,
76
+ });
77
+ const exp = 0;
78
+ expect(res).toStrictEqual(exp);
79
+ });
80
+ it('should return ticket label size - horizontal', () => {
81
+ const res = getTickLabelSize({
82
+ isVertical: false,
83
+ hideTickLabel: true,
84
+ maxLength: 3,
85
+ tickOffset: 4,
86
+ tickLabelHeight: 5,
87
+ });
88
+ const exp = 9;
89
+ expect(res).toStrictEqual(exp);
90
+ });
91
+ });
92
+ describe('getLabelOffset()', () => {
93
+ it('should get for top axis', () => {
94
+ const res = getLabelOffset({
95
+ orientation: 'top',
96
+ labelOffset: 1,
97
+ tickOffset: 2,
98
+ tickLabelSize: 3,
99
+ maxLength: 4,
100
+ });
101
+ const exp = -4;
102
+ expect(res).toStrictEqual(exp);
103
+ });
104
+ it('should get for right axis', () => {
105
+ const res = getLabelOffset({
106
+ orientation: 'right',
107
+ labelOffset: 1,
108
+ tickOffset: 2,
109
+ tickLabelSize: 3,
110
+ maxLength: 4,
111
+ });
112
+ const exp = 4;
113
+ expect(res).toStrictEqual(exp);
114
+ });
115
+ it('should get for bottom axis', () => {
116
+ const res = getLabelOffset({
117
+ orientation: 'bottom',
118
+ labelOffset: 1,
119
+ tickOffset: 2,
120
+ tickLabelSize: 3,
121
+ maxLength: 4,
122
+ });
123
+ const exp = 0;
124
+ expect(res).toStrictEqual(exp);
125
+ });
126
+ it('should get for left axis', () => {
127
+ const res = getLabelOffset({
128
+ orientation: 'left',
129
+ labelOffset: 1,
130
+ tickOffset: 2,
131
+ tickLabelSize: 3,
132
+ maxLength: 4,
133
+ });
134
+ const exp = 0;
135
+ expect(res).toStrictEqual(exp);
136
+ });
137
+ });
138
+ describe('computeAxisOffset()', () => {
139
+ it('should return a configuration for top axis', () => {
140
+ const axis = {
141
+ domain: [0, 1],
142
+ orientation: 'top',
143
+ label: 'test',
144
+ hideAxisLine: false,
145
+ hideTickLabel: false,
146
+ hideTicks: false,
147
+ tickFormat: undefined,
148
+ };
149
+ const res = computeAxisOffset(axis);
150
+ const exp = {
151
+ axisLabel: 30,
152
+ axisLine: 1,
153
+ labelOffset: 28,
154
+ offset: 63,
155
+ orientation: 'top',
156
+ tickLabelHeight: 28,
157
+ tickLabelMaxChar: 0,
158
+ tickLabelMaxLength: 0,
159
+ tickLabelOffset: -12,
160
+ tickLabelSize: 0,
161
+ tickLength: 4,
162
+ };
163
+ expect(res).toStrictEqual(exp);
164
+ });
165
+ it('should return a configuration for right axis', () => {
166
+ const axis = {
167
+ domain: [0, 1],
168
+ orientation: 'right',
169
+ label: 'test',
170
+ hideAxisLine: false,
171
+ hideTickLabel: false,
172
+ hideTicks: false,
173
+ tickFormat: undefined,
174
+ };
175
+ const res = computeAxisOffset(axis);
176
+ const exp = {
177
+ axisLabel: 30,
178
+ axisLine: 1,
179
+ labelOffset: 52,
180
+ offset: 71,
181
+ orientation: 'right',
182
+ tickLabelHeight: 20,
183
+ tickLabelMaxChar: 3,
184
+ tickLabelMaxLength: 32,
185
+ tickLabelOffset: 4,
186
+ tickLabelSize: 0,
187
+ tickLength: 4,
188
+ };
189
+ expect(res).toStrictEqual(exp);
190
+ });
191
+ it('should return a configuration for bottom axis', () => {
192
+ const axis = {
193
+ domain: [0, 1],
194
+ orientation: 'bottom',
195
+ label: 'test',
196
+ hideAxisLine: false,
197
+ hideTickLabel: false,
198
+ hideTicks: false,
199
+ tickFormat: undefined,
200
+ };
201
+ const res = computeAxisOffset(axis);
202
+ const exp = {
203
+ axisLabel: 30,
204
+ axisLine: 1,
205
+ labelOffset: 20,
206
+ offset: 55,
207
+ orientation: 'bottom',
208
+ tickLabelHeight: 20,
209
+ tickLabelMaxChar: 0,
210
+ tickLabelMaxLength: 0,
211
+ tickLabelOffset: 4,
212
+ tickLabelSize: 0,
213
+ tickLength: 4,
214
+ };
215
+ expect(res).toStrictEqual(exp);
216
+ });
217
+ it('should return a configuration for left axis', () => {
218
+ const axis = {
219
+ domain: [0, 1],
220
+ orientation: 'left',
221
+ label: 'test',
222
+ hideAxisLine: false,
223
+ hideTickLabel: false,
224
+ hideTicks: false,
225
+ tickFormat: undefined,
226
+ };
227
+ const res = computeAxisOffset(axis);
228
+ const exp = {
229
+ axisLabel: 30,
230
+ axisLine: 1,
231
+ labelOffset: 44,
232
+ offset: 63,
233
+ orientation: 'left',
234
+ tickLabelHeight: 20,
235
+ tickLabelMaxChar: 3,
236
+ tickLabelMaxLength: 24,
237
+ tickLabelOffset: -4,
238
+ tickLabelSize: 0,
239
+ tickLength: 4,
240
+ };
241
+ expect(res).toStrictEqual(exp);
242
+ });
243
+ it('should return a configuration hiding elements', () => {
244
+ const axis = {
245
+ domain: [0, 1],
246
+ orientation: 'left',
247
+ label: 'test',
248
+ hideAxisLine: true,
249
+ hideTickLabel: true,
250
+ hideTicks: true,
251
+ tickFormat: undefined,
252
+ };
253
+ const res = computeAxisOffset(axis);
254
+ const exp = {
255
+ axisLabel: 30,
256
+ axisLine: 0,
257
+ labelOffset: 16,
258
+ offset: 34,
259
+ orientation: 'left',
260
+ tickLabelHeight: 0,
261
+ tickLabelMaxChar: 3,
262
+ tickLabelMaxLength: 0,
263
+ tickLabelOffset: -4,
264
+ tickLabelSize: 4,
265
+ tickLength: 4,
266
+ };
267
+ expect(res).toStrictEqual(exp);
268
+ });
269
+ });
270
+ describe('computeAxisSystemOffset()', () => {
271
+ it('should return', () => {
272
+ const system = {
273
+ top: undefined,
274
+ right: undefined,
275
+ bottom: undefined,
276
+ left: undefined,
277
+ };
278
+ const res = computeAxisSystemOffset(system);
279
+ const exp = {
280
+ axis: {
281
+ bottom: undefined,
282
+ left: undefined,
283
+ right: undefined,
284
+ top: undefined,
285
+ },
286
+ offset: {
287
+ bottomAxisOffset: 0,
288
+ horizontalAxisOffset: 0,
289
+ leftAxisOffset: 0,
290
+ rightAxisOffset: 0,
291
+ topAxisOffset: 0,
292
+ verticalAxisOffset: 0,
293
+ },
294
+ };
295
+ expect(res).toStrictEqual(exp);
296
+ });
297
+ it('should return a 4 axis configuration', () => {
298
+ const system = {
299
+ top: {
300
+ domain: [0, 1],
301
+ orientation: 'top',
302
+ label: 'test',
303
+ hideAxisLine: false,
304
+ hideTickLabel: false,
305
+ hideTicks: false,
306
+ tickFormat: undefined,
307
+ },
308
+ right: {
309
+ domain: [0, 1],
310
+ orientation: 'right',
311
+ label: 'test',
312
+ hideAxisLine: false,
313
+ hideTickLabel: false,
314
+ hideTicks: false,
315
+ tickFormat: undefined,
316
+ },
317
+ bottom: {
318
+ domain: [0, 1],
319
+ orientation: 'bottom',
320
+ label: 'test',
321
+ hideAxisLine: false,
322
+ hideTickLabel: false,
323
+ hideTicks: false,
324
+ tickFormat: undefined,
325
+ },
326
+ left: {
327
+ domain: [0, 1],
328
+ orientation: 'left',
329
+ label: 'test',
330
+ hideAxisLine: false,
331
+ hideTickLabel: false,
332
+ hideTicks: false,
333
+ tickFormat: undefined,
334
+ },
335
+ };
336
+ const res = computeAxisSystemOffset(system);
337
+ const exp = {
338
+ axis: {
339
+ bottom: {
340
+ axisLabel: 30, axisLine: 1, labelOffset: 20, offset: 55, orientation: 'bottom', tickLabelHeight: 20, tickLabelMaxChar: 0, tickLabelMaxLength: 0, tickLabelOffset: 4, tickLabelSize: 0, tickLength: 4,
341
+ },
342
+ left: {
343
+ axisLabel: 30, axisLine: 1, labelOffset: 44, offset: 63, orientation: 'left', tickLabelHeight: 20, tickLabelMaxChar: 3, tickLabelMaxLength: 24, tickLabelOffset: -4, tickLabelSize: 0, tickLength: 4,
344
+ },
345
+ right: {
346
+ axisLabel: 30, axisLine: 1, labelOffset: 52, offset: 71, orientation: 'right', tickLabelHeight: 20, tickLabelMaxChar: 3, tickLabelMaxLength: 32, tickLabelOffset: 4, tickLabelSize: 0, tickLength: 4,
347
+ },
348
+ top: {
349
+ axisLabel: 30, axisLine: 1, labelOffset: 28, offset: 63, orientation: 'top', tickLabelHeight: 28, tickLabelMaxChar: 0, tickLabelMaxLength: 0, tickLabelOffset: -12, tickLabelSize: 0, tickLength: 4,
350
+ },
351
+ },
352
+ offset: {
353
+ bottomAxisOffset: 55,
354
+ horizontalAxisOffset: 118,
355
+ leftAxisOffset: 63,
356
+ rightAxisOffset: 71,
357
+ topAxisOffset: 63,
358
+ verticalAxisOffset: 134,
359
+ },
360
+ };
361
+ expect(res).toStrictEqual(exp);
362
+ });
363
+ });
364
+ describe('computeAxisStyleConfig()', () => {
365
+ it('should return', () => {
366
+ const system = {
367
+ top: {
368
+ domain: [0, 1],
369
+ orientation: 'top',
370
+ scaleType: 'linear',
371
+ label: 'test',
372
+ },
373
+ right: {
374
+ domain: [0, 1],
375
+ orientation: 'top',
376
+ scaleType: 'linear',
377
+ label: 'test',
378
+ },
379
+ bottom: {
380
+ domain: [0, 1],
381
+ orientation: 'top',
382
+ scaleType: 'linear',
383
+ label: 'test',
384
+ },
385
+ left: {
386
+ domain: [0, 1],
387
+ orientation: 'top',
388
+ scaleType: 'linear',
389
+ label: 'test',
390
+ },
391
+ };
392
+ const res = computeAxisStyleConfig(system);
393
+ const exp = {
394
+ bottom: { labelOffset: 28, labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: 'auto', dy: 4 } },
395
+ left: { labelOffset: 28, labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: 'middle', dx: -4, textAnchor: 'end' } },
396
+ offset: {
397
+ bottomAxisOffset: 63,
398
+ horizontalAxisOffset: 126,
399
+ leftAxisOffset: 63,
400
+ rightAxisOffset: 63,
401
+ topAxisOffset: 63,
402
+ verticalAxisOffset: 126,
403
+ },
404
+ right: { labelOffset: 28, labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: 'middle', dx: 4, textAnchor: 'start' } },
405
+ style: {
406
+ axisLineProps: { strokeDasharray: '', strokeWidth: 1 },
407
+ bottom: { labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: 'auto', dy: 4 } },
408
+ formatting: { maxCharactersLength: 20, omission: '...' },
409
+ labelProps: {
410
+ fontFamily: 'system-ui, sans-serif', fontSize: 12, fontWeight: 600, textAnchor: 'middle',
411
+ },
412
+ left: { labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: 'middle', dx: -4, textAnchor: 'end' } },
413
+ right: { labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: 'middle', dx: 4, textAnchor: 'start' } },
414
+ spacing: {
415
+ labelCharExtimatedWidth: 8, labelHeight: 14, labelOffset: 16, tickLabelHeight: 16, tickLength: 4,
416
+ },
417
+ tickLabelProps: { fontFamily: 'system-ui, sans-serif', fontSize: 14, fontWeight: 400 },
418
+ tickLineProps: { length: 4, strokeLinecap: 'round', strokeWidth: 1 },
419
+ top: { labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: 'auto', dy: -12 } },
420
+ },
421
+ top: { labelOffset: 28, labelProps: { dominantBaseline: 'auto' }, tickLabelProps: { dominantBaseline: 'auto', dy: -12 } },
422
+ };
423
+ expect(res).toStrictEqual(exp);
424
+ });
425
+ });
426
+ describe('inferScaleTypeFromDomain()', () => {
427
+ it('should return linear', () => {
428
+ const domain = [0, 1];
429
+ const scaleType = undefined;
430
+ const res = inferScaleTypeFromDomain(domain, scaleType);
431
+ const exp = 'linear';
432
+ expect(res).toStrictEqual(exp);
433
+ });
434
+ it('should return label', () => {
435
+ const domain = ['a', 'b'];
436
+ const scaleType = undefined;
437
+ const res = inferScaleTypeFromDomain(domain, scaleType);
438
+ const exp = 'label';
439
+ expect(res).toStrictEqual(exp);
440
+ });
441
+ it('should return defined scaleType', () => {
442
+ const domain = ['01-01-2020', '01-01-2023'];
443
+ const scaleType = 'label';
444
+ const res = inferScaleTypeFromDomain(domain, scaleType);
445
+ const exp = 'label';
446
+ expect(res).toStrictEqual(exp);
447
+ });
448
+ it('should return time', () => {
449
+ const domain = ['01-01-2020', '01-01-2023'];
450
+ const scaleType = undefined;
451
+ const res = inferScaleTypeFromDomain(domain, scaleType);
452
+ const exp = 'time';
453
+ expect(res).toStrictEqual(exp);
454
+ });
455
+ });
456
+ describe('scaleDomainToAxis()', () => {
457
+ it('should return undefined for empty domain', () => {
458
+ const axis = {
459
+ domain: [],
460
+ range: [0, 100],
461
+ scaleType: 'linear',
462
+ };
463
+ const scale = scaleDomainToAxis(axis);
464
+ const res = scale?.('0.5');
465
+ const exp = undefined;
466
+ expect(res).toStrictEqual(exp);
467
+ });
468
+ it('should return for linear', () => {
469
+ const axis = {
470
+ domain: [0, 1],
471
+ range: [0, 100],
472
+ scaleType: 'linear',
473
+ };
474
+ const scale = scaleDomainToAxis(axis);
475
+ const res = scale?.('0.5');
476
+ const exp = 50;
477
+ expect(res).toStrictEqual(exp);
478
+ });
479
+ it('should return for label', () => {
480
+ const axis = {
481
+ domain: ['a', 'b', 'c'],
482
+ range: [0, 100],
483
+ scaleType: 'label',
484
+ };
485
+ const scale = scaleDomainToAxis(axis);
486
+ const res = scale?.('b');
487
+ const exp = 50;
488
+ expect(res).toStrictEqual(exp);
489
+ });
490
+ it('should return for date', () => {
491
+ const axis = {
492
+ domain: ['01-01-2020', '01-01-2022'],
493
+ range: [0, 100],
494
+ scaleType: 'time',
495
+ };
496
+ const scale = scaleDomainToAxis(axis);
497
+ const res = scale?.(new Date('01-01-2021'));
498
+ const exp = 50;
499
+ expect(res).toStrictEqual(exp);
500
+ });
501
+ });
502
+ describe('handleTickFormat()', () => {
503
+ it('should return the same value w/o tickFormat', () => {
504
+ const axis = {
505
+ domain: [0, 1],
506
+ scaleType: 'linear',
507
+ orientation: 'top',
508
+ tickFormat: undefined,
509
+ };
510
+ const computed = computeAxisProperties({
511
+ axis,
512
+ maxRangeX: 800,
513
+ maxRangeY: 600,
514
+ positionTop: 0,
515
+ positionRight: 0,
516
+ positionBottom: 0,
517
+ positionLeft: 0,
518
+ });
519
+ const func = handleTickFormat(computed);
520
+ const res = func(1, 1);
521
+ const exp = 1;
522
+ expect(res).toStrictEqual(exp);
523
+ });
524
+ it('should return a formatted value', () => {
525
+ const axis = {
526
+ domain: [0, 1],
527
+ scaleType: 'linear',
528
+ orientation: 'top',
529
+ tickFormat: (v) => (`$ ${v}`),
530
+ };
531
+ const computed = computeAxisProperties({
532
+ axis,
533
+ maxRangeX: 800,
534
+ maxRangeY: 600,
535
+ positionTop: 0,
536
+ positionRight: 0,
537
+ positionBottom: 0,
538
+ positionLeft: 0,
539
+ });
540
+ const func = handleTickFormat(computed);
541
+ const res = func(1, 1);
542
+ const exp = '$ 1';
543
+ expect(res).toStrictEqual(exp);
544
+ });
545
+ it('should return an empty string w hideTickLabel', () => {
546
+ const axis = {
547
+ domain: [0, 1],
548
+ scaleType: 'linear',
549
+ orientation: 'top',
550
+ hideTickLabel: true,
551
+ tickFormat: (v) => (`$ ${v}`),
552
+ };
553
+ const computed = computeAxisProperties({
554
+ axis,
555
+ maxRangeX: 800,
556
+ maxRangeY: 600,
557
+ positionTop: 0,
558
+ positionRight: 0,
559
+ positionBottom: 0,
560
+ positionLeft: 0,
561
+ });
562
+ const func = handleTickFormat(computed);
563
+ const res = func(1, 1);
564
+ const exp = '';
565
+ expect(res).toStrictEqual(exp);
566
+ });
567
+ it('should return a truncated string', () => {
568
+ const axis = {
569
+ domain: ['1234567890123456789012345', '1234567890123456789012345'],
570
+ scaleType: 'label',
571
+ orientation: 'top',
572
+ hideTickLabel: false,
573
+ tickFormat: (v) => (`$ ${v}`),
574
+ };
575
+ const computed = computeAxisProperties({
576
+ axis,
577
+ maxRangeX: 800,
578
+ maxRangeY: 600,
579
+ positionTop: 0,
580
+ positionRight: 0,
581
+ positionBottom: 0,
582
+ positionLeft: 0,
583
+ });
584
+ const func = handleTickFormat(computed);
585
+ const res = func('1234567890123456789012345', 1);
586
+ const exp = '$ 123456789012345...';
587
+ expect(res).toStrictEqual(exp);
588
+ });
589
+ it('should return a truncated string w/o tickFormat', () => {
590
+ const axis = {
591
+ domain: ['1234567890123456789012345', '1234567890123456789012345'],
592
+ scaleType: 'label',
593
+ orientation: 'top',
594
+ hideTickLabel: false,
595
+ tickFormat: undefined,
596
+ };
597
+ const computed = computeAxisProperties({
598
+ axis,
599
+ maxRangeX: 800,
600
+ maxRangeY: 600,
601
+ positionTop: 0,
602
+ positionRight: 0,
603
+ positionBottom: 0,
604
+ positionLeft: 0,
605
+ });
606
+ const func = handleTickFormat(computed);
607
+ const res = func('1234567890123456789012345', 1);
608
+ const exp = '12345678901234567...';
609
+ expect(res).toStrictEqual(exp);
610
+ });
611
+ it('should return a formatted date value', () => {
612
+ const axis = {
613
+ domain: ['01-01-2020', '01-01-2023'],
614
+ scaleType: 'time',
615
+ orientation: 'top',
616
+ hideTickLabel: false,
617
+ tickFormat: (v) => (`today ${v}`),
618
+ };
619
+ const computed = computeAxisProperties({
620
+ axis,
621
+ maxRangeX: 800,
622
+ maxRangeY: 600,
623
+ positionTop: 0,
624
+ positionRight: 0,
625
+ positionBottom: 0,
626
+ positionLeft: 0,
627
+ });
628
+ const func = handleTickFormat(computed);
629
+ const res = func('01-01-2023', 1);
630
+ const exp = 'today 01-01-2023';
631
+ expect(res).toStrictEqual(exp);
632
+ });
633
+ });
634
+ describe('handleNumberOfTicks()', () => {
635
+ it('should return 10 fro large size', () => {
636
+ const axis = {
637
+ domain: [0, 1],
638
+ scaleType: 'linear',
639
+ orientation: 'top',
640
+ tickFormat: undefined,
641
+ };
642
+ const computed = computeAxisProperties({
643
+ axis,
644
+ maxRangeX: 800,
645
+ maxRangeY: 600,
646
+ positionTop: 0,
647
+ positionRight: 0,
648
+ positionBottom: 0,
649
+ positionLeft: 0,
650
+ });
651
+ const res = handleNumberOfTicks(800, 600, computed, viewportStyleConfig);
652
+ const exp = 10;
653
+ expect(res).toStrictEqual(exp);
654
+ });
655
+ it('should return 10 fro small size', () => {
656
+ const axis = {
657
+ domain: [0, 1],
658
+ scaleType: 'linear',
659
+ orientation: 'top',
660
+ tickFormat: undefined,
661
+ };
662
+ const computed = computeAxisProperties({
663
+ axis,
664
+ maxRangeX: 800,
665
+ maxRangeY: 600,
666
+ positionTop: 0,
667
+ positionRight: 0,
668
+ positionBottom: 0,
669
+ positionLeft: 0,
670
+ });
671
+ const res = handleNumberOfTicks(400, 400, computed, viewportStyleConfig);
672
+ const exp = 5;
673
+ expect(res).toStrictEqual(exp);
674
+ });
675
+ it('should return 10 fro tiny size', () => {
676
+ const axis = {
677
+ domain: [0, 1],
678
+ scaleType: 'linear',
679
+ orientation: 'top',
680
+ tickFormat: undefined,
681
+ };
682
+ const computed = computeAxisProperties({
683
+ axis,
684
+ maxRangeX: 800,
685
+ maxRangeY: 600,
686
+ positionTop: 0,
687
+ positionRight: 0,
688
+ positionBottom: 0,
689
+ positionLeft: 0,
690
+ });
691
+ const res = handleNumberOfTicks(200, 200, computed, viewportStyleConfig);
692
+ const exp = 3;
693
+ expect(res).toStrictEqual(exp);
694
+ });
695
+ });
696
+ describe('hasVerticalTickLabel()', () => {
697
+ it('should return false for large size and short labels', () => {
698
+ const width = 800;
699
+ const axis = {
700
+ domain: [0, 1],
701
+ scaleType: 'linear',
702
+ orientation: 'top',
703
+ };
704
+ const hasVertical = hasVerticalTickLabel(width, axis, viewportStyleConfig);
705
+ expect(hasVertical).not.toBeTruthy();
706
+ });
707
+ it('should return true for long labels', () => {
708
+ const width = 400;
709
+ const axis = {
710
+ domain: ['1234567890123456789', '1234567890123456789'],
711
+ scaleType: 'label',
712
+ orientation: 'top',
713
+ };
714
+ const hasVertical = hasVerticalTickLabel(width, axis, viewportStyleConfig);
715
+ expect(hasVertical).toBeTruthy();
716
+ });
717
+ it('should return true for long labels', () => {
718
+ const width = 200;
719
+ const axis = {
720
+ domain: ['1234567890123456789', '1234567890123456789'],
721
+ scaleType: 'label',
722
+ orientation: 'top',
723
+ };
724
+ const hasVertical = hasVerticalTickLabel(width, axis, viewportStyleConfig);
725
+ expect(hasVertical).toBeTruthy();
726
+ });
727
+ it('should return false for tiny size', () => {
728
+ const width = 200;
729
+ const axis = {
730
+ domain: [0, 100],
731
+ scaleType: 'linear',
732
+ orientation: 'top',
733
+ };
734
+ const hasVertical = hasVerticalTickLabel(width, axis, viewportStyleConfig);
735
+ expect(hasVertical).not.toBeTruthy();
736
+ });
737
+ it('should return true for small size', () => {
738
+ const width = 400;
739
+ const axis = {
740
+ domain: [0, 100],
741
+ scaleType: 'linear',
742
+ orientation: 'top',
743
+ };
744
+ const hasVertical = hasVerticalTickLabel(width, axis, viewportStyleConfig);
745
+ expect(hasVertical).toBeTruthy();
746
+ });
747
+ it('should return true for numTicks > 10', () => {
748
+ const width = 800;
749
+ const axis = {
750
+ domain: [0, 100],
751
+ scaleType: 'linear',
752
+ orientation: 'top',
753
+ numTicks: 20,
754
+ };
755
+ const hasVertical = hasVerticalTickLabel(width, axis, viewportStyleConfig);
756
+ expect(hasVertical).toBeTruthy();
757
+ });
758
+ it('should return false for vertical axis', () => {
759
+ const width = 800;
760
+ const axis = {
761
+ domain: [0, 100],
762
+ scaleType: 'linear',
763
+ orientation: 'left',
764
+ numTicks: 20,
765
+ };
766
+ const hasVertical = hasVerticalTickLabel(width, axis, viewportStyleConfig);
767
+ expect(hasVertical).not.toBeTruthy();
768
+ });
769
+ });
770
+ describe('handleVerticalTickLabelTransform()', () => {
771
+ it('should return style for top axis', () => {
772
+ const axis = {
773
+ domain: [0, 1],
774
+ scaleType: 'linear',
775
+ orientation: 'top',
776
+ tickFormat: undefined,
777
+ };
778
+ const computed = computeAxisProperties({
779
+ axis,
780
+ maxRangeX: 800,
781
+ maxRangeY: 600,
782
+ positionTop: 0,
783
+ positionRight: 0,
784
+ positionBottom: 0,
785
+ positionLeft: 0,
786
+ });
787
+ const res = handleVerticalTickLabelTransform(1, true, computed);
788
+ const exp = { transform: 'translate(9, -4) rotate(-90, 800, 0)' };
789
+ expect(res).toStrictEqual(exp);
790
+ });
791
+ it('should return style for top axis - horizontal label', () => {
792
+ const axis = {
793
+ domain: [0, 1],
794
+ scaleType: 'linear',
795
+ orientation: 'top',
796
+ tickFormat: undefined,
797
+ };
798
+ const computed = computeAxisProperties({
799
+ axis,
800
+ maxRangeX: 800,
801
+ maxRangeY: 600,
802
+ positionTop: 0,
803
+ positionRight: 0,
804
+ positionBottom: 0,
805
+ positionLeft: 0,
806
+ });
807
+ const res = handleVerticalTickLabelTransform(1, false, computed);
808
+ const exp = { transform: '', textAnchor: 'middle' };
809
+ expect(res).toStrictEqual(exp);
810
+ });
811
+ it('should return style for bottom axis', () => {
812
+ const axis = {
813
+ domain: [0, 1],
814
+ scaleType: 'linear',
815
+ orientation: 'bottom',
816
+ tickFormat: undefined,
817
+ };
818
+ const computed = computeAxisProperties({
819
+ axis,
820
+ maxRangeX: 800,
821
+ maxRangeY: 600,
822
+ positionTop: 0,
823
+ positionRight: 0,
824
+ positionBottom: 0,
825
+ positionLeft: 0,
826
+ });
827
+ const res = handleVerticalTickLabelTransform(1, true, computed);
828
+ const exp = { transform: 'translate(13, 6) rotate(90, 800, 0)' };
829
+ expect(res).toStrictEqual(exp);
830
+ });
831
+ it('should return style for bottom axis - horizontal label', () => {
832
+ const axis = {
833
+ domain: [0, 1],
834
+ scaleType: 'linear',
835
+ orientation: 'bottom',
836
+ tickFormat: undefined,
837
+ };
838
+ const computed = computeAxisProperties({
839
+ axis,
840
+ maxRangeX: 800,
841
+ maxRangeY: 600,
842
+ positionTop: 0,
843
+ positionRight: 0,
844
+ positionBottom: 0,
845
+ positionLeft: 0,
846
+ });
847
+ const res = handleVerticalTickLabelTransform(1, false, computed);
848
+ const exp = { transform: '', textAnchor: 'middle' };
849
+ expect(res).toStrictEqual(exp);
850
+ });
851
+ it('should return {} for left/right axis', () => {
852
+ const axis = {
853
+ domain: [0, 1],
854
+ scaleType: 'linear',
855
+ orientation: 'left',
856
+ tickFormat: undefined,
857
+ };
858
+ const computed = computeAxisProperties({
859
+ axis,
860
+ maxRangeX: 800,
861
+ maxRangeY: 600,
862
+ positionTop: 0,
863
+ positionRight: 0,
864
+ positionBottom: 0,
865
+ positionLeft: 0,
866
+ });
867
+ const res = handleVerticalTickLabelTransform(1, true, computed);
868
+ const exp = {};
869
+ expect(res).toStrictEqual(exp);
870
+ });
871
+ });
872
+ describe('handleVerticalTickLabelOffset()', () => {
873
+ it('should return 0 for no axis', () => {
874
+ const axis = undefined;
875
+ const res = handleVerticalTickLabelOffset(800, cartesianStyleConfig, axis);
876
+ const exp = 0;
877
+ expect(res).toStrictEqual(exp);
878
+ });
879
+ it('should return a value for vertical string labels', () => {
880
+ const axis = {
881
+ domain: ['1234567890123456789', '1234567890123456789'],
882
+ scaleType: 'label',
883
+ orientation: 'top',
884
+ };
885
+ const res = handleVerticalTickLabelOffset(400, cartesianStyleConfig, axis);
886
+ const exp = 136;
887
+ expect(res).toStrictEqual(exp);
888
+ });
889
+ it('should return a value for vertical date labels', () => {
890
+ const axis = {
891
+ domain: ['2011-10-10T14:48:00', '2011-10-10T14:48:00'],
892
+ scaleType: 'time',
893
+ orientation: 'top',
894
+ };
895
+ const res = handleVerticalTickLabelOffset(400, cartesianStyleConfig, axis);
896
+ const exp = 64;
897
+ expect(res).toStrictEqual(exp);
898
+ });
899
+ it('should return a value for vertical number labels', () => {
900
+ const axis = {
901
+ domain: [1234567890123456789, 1234567890123456789],
902
+ scaleType: 'linear',
903
+ orientation: 'top',
904
+ };
905
+ const res = handleVerticalTickLabelOffset(400, cartesianStyleConfig, axis);
906
+ const exp = 200;
907
+ expect(res).toStrictEqual(exp);
908
+ });
909
+ });
910
+ describe('computeAxisProperties()', () => {
911
+ it('should return properties for top axis', () => {
912
+ const axis = {
913
+ domain: [0, 1],
914
+ scaleType: 'linear',
915
+ orientation: 'top',
916
+ };
917
+ const res = computeAxisProperties({
918
+ axis,
919
+ maxRangeX: 800,
920
+ maxRangeY: 600,
921
+ positionTop: 1,
922
+ positionRight: 2,
923
+ positionBottom: 3,
924
+ positionLeft: 4,
925
+ });
926
+ expect(res.scale).toBeDefined();
927
+ });
928
+ it('should return properties for rigth axis', () => {
929
+ const axis = {
930
+ domain: [0, 1],
931
+ scaleType: 'linear',
932
+ orientation: 'right',
933
+ };
934
+ const res = computeAxisProperties({
935
+ axis,
936
+ maxRangeX: 800,
937
+ maxRangeY: 600,
938
+ positionTop: 1,
939
+ positionRight: 2,
940
+ positionBottom: 3,
941
+ positionLeft: 4,
942
+ });
943
+ expect(res.scale).toBeDefined();
944
+ });
945
+ it('should return properties for bottom axis', () => {
946
+ const axis = {
947
+ domain: [0, 1],
948
+ scaleType: 'linear',
949
+ orientation: 'bottom',
950
+ };
951
+ const res = computeAxisProperties({
952
+ axis,
953
+ maxRangeX: 800,
954
+ maxRangeY: 600,
955
+ positionTop: 1,
956
+ positionRight: 2,
957
+ positionBottom: 3,
958
+ positionLeft: 4,
959
+ });
960
+ expect(res.scale).toBeDefined();
961
+ });
962
+ it('should return properties for left axis', () => {
963
+ const axis = {
964
+ domain: [0, 1],
965
+ scaleType: 'linear',
966
+ orientation: 'left',
967
+ };
968
+ const res = computeAxisProperties({
969
+ axis,
970
+ maxRangeX: 800,
971
+ maxRangeY: 600,
972
+ positionTop: 1,
973
+ positionRight: 2,
974
+ positionBottom: 3,
975
+ positionLeft: 4,
976
+ });
977
+ expect(res.scale).toBeDefined();
978
+ });
979
+ it('should return undefined if no axis', () => {
980
+ const axis = undefined;
981
+ const res = computeAxisProperties({
982
+ axis,
983
+ maxRangeX: 800,
984
+ maxRangeY: 600,
985
+ positionTop: 1,
986
+ positionRight: 2,
987
+ positionBottom: 3,
988
+ positionLeft: 4,
989
+ });
990
+ expect(res).toBeUndefined();
991
+ });
992
+ });
993
+ describe('computeAxisSystemProperties()', () => {
994
+ it('should return', () => {
995
+ const axis = {
996
+ top: {
997
+ domain: [0, 1],
998
+ orientation: 'top',
999
+ scaleType: 'linear',
1000
+ },
1001
+ right: {
1002
+ domain: [0, 1],
1003
+ orientation: 'top',
1004
+ scaleType: 'linear',
1005
+ },
1006
+ bottom: {
1007
+ domain: [0, 1],
1008
+ orientation: 'top',
1009
+ scaleType: 'linear',
1010
+ },
1011
+ left: {
1012
+ domain: [0, 1],
1013
+ orientation: 'top',
1014
+ scaleType: 'linear',
1015
+ },
1016
+ };
1017
+ const res = computeAxisSystemProperties(axis, { maxWidth: 800, maxHeight: 600 }, {
1018
+ top: 1, right: 2, bottom: 3, left: 4,
1019
+ });
1020
+ expect(res.top.scale).toBeDefined();
1021
+ expect(res.right.scale).toBeDefined();
1022
+ expect(res.bottom.scale).toBeDefined();
1023
+ expect(res.left.scale).toBeDefined();
1024
+ });
1025
+ });
1026
+ describe('handleChartAxisLayout()', () => {
1027
+ it('should return a full configuration', () => {
1028
+ const index = {
1029
+ domain: [0, 1],
1030
+ scaleType: 'linear',
1031
+ };
1032
+ const series = {
1033
+ domain: [0, 1],
1034
+ scaleType: 'linear',
1035
+ };
1036
+ const overlay = {
1037
+ domain: [0, 1],
1038
+ scaleType: 'linear',
1039
+ };
1040
+ const res = handleChartAxisLayout(index, series, overlay);
1041
+ const exp = {
1042
+ horizontal: {
1043
+ bottom: { domain: [0, 1], orientation: 'bottom', scaleType: 'linear' }, left: { domain: [0, 1], orientation: 'left', scaleType: 'linear' }, right: { domain: [0, 1], orientation: 'right', scaleType: 'linear' }, top: undefined,
1044
+ },
1045
+ vertical: {
1046
+ bottom: { domain: [0, 1], orientation: 'bottom', scaleType: 'linear' }, left: { domain: [0, 1], orientation: 'left', scaleType: 'linear' }, right: undefined, top: { domain: [0, 1], orientation: 'top', scaleType: 'linear' },
1047
+ },
1048
+ };
1049
+ expect(res).toStrictEqual(exp);
1050
+ });
1051
+ it('should return a configuration w/o overlay', () => {
1052
+ const index = {
1053
+ domain: [0, 1],
1054
+ scaleType: 'linear',
1055
+ };
1056
+ const series = {
1057
+ domain: [0, 1],
1058
+ scaleType: 'linear',
1059
+ };
1060
+ const res = handleChartAxisLayout(index, series);
1061
+ const exp = {
1062
+ horizontal: {
1063
+ bottom: { domain: [0, 1], orientation: 'bottom', scaleType: 'linear' }, left: { domain: [0, 1], orientation: 'left', scaleType: 'linear' }, right: undefined, top: undefined,
1064
+ },
1065
+ vertical: {
1066
+ bottom: { domain: [0, 1], orientation: 'bottom', scaleType: 'linear' }, left: { domain: [0, 1], orientation: 'left', scaleType: 'linear' }, right: undefined, top: undefined,
1067
+ },
1068
+ };
1069
+ expect(res).toStrictEqual(exp);
1070
+ });
1071
+ });