@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,142 @@
1
+ import { getMaxCharactersNum, getMinMaxDate, getMinMaxNumber, isArrayType, isArrayTypeObject, isArrayTypeString, removeNilsFromDomain, } from './math';
2
+ describe('getMaxCharactersNum()', () => {
3
+ it('should return the right amount for integers', () => {
4
+ const res = getMaxCharactersNum([100]);
5
+ expect(res).toBe(3);
6
+ });
7
+ it('should return the right amount for integers', () => {
8
+ const res = getMaxCharactersNum([0, 10000]);
9
+ expect(res).toBe(6);
10
+ });
11
+ it('should return the right amount for floats', () => {
12
+ const res = getMaxCharactersNum([0.1]);
13
+ expect(res).toBe(4);
14
+ });
15
+ it('should return the right amount for floats', () => {
16
+ const res = getMaxCharactersNum([0.1, 0.5]);
17
+ expect(res).toBe(4);
18
+ });
19
+ it('should return the right amount for floats with a div < 10', () => {
20
+ const res = getMaxCharactersNum([1, 9]);
21
+ expect(res).toBe(3);
22
+ });
23
+ it('should return 0 for zero length array', () => {
24
+ const res = getMaxCharactersNum([]);
25
+ expect(res).toBe(0);
26
+ });
27
+ it('should return a correct value with a custom tick formatting', () => {
28
+ const res = getMaxCharactersNum([0, 10], (v) => `£ ${v}`);
29
+ expect(res).toBe(4);
30
+ });
31
+ it('should return a correct string values', () => {
32
+ const res = getMaxCharactersNum(['xyz', 'abc']);
33
+ expect(res).toBe(3);
34
+ });
35
+ });
36
+ describe('getMinMaxNumber()', () => {
37
+ it('should find min and max values', () => {
38
+ const res = getMinMaxNumber([1, 10, 100]);
39
+ expect(res).toEqual([1, 100]);
40
+ });
41
+ it('should find min and max values', () => {
42
+ const res = getMinMaxNumber([100, 1, 10]);
43
+ expect(res).toEqual([1, 100]);
44
+ });
45
+ it('should be undefined for zero length array', () => {
46
+ const res = getMinMaxNumber([]);
47
+ expect(res).toBe(undefined);
48
+ });
49
+ });
50
+ describe('getMinMaxDate()', () => {
51
+ it('should get min/max value with numbers array', () => {
52
+ const d1 = new Date('2023-8-21').getTime();
53
+ const d2 = new Date('2022-8-21').getTime();
54
+ const res = getMinMaxDate([d1, d2]);
55
+ const minTime = new Date(res[0]).getTime();
56
+ const maxTime = new Date(res[1]).getTime();
57
+ expect(maxTime - minTime).toBeTruthy();
58
+ });
59
+ it('should get min/max value with Dates array', () => {
60
+ const d1 = new Date('2023-8-21');
61
+ const d2 = new Date('2022-8-21');
62
+ const res = getMinMaxDate([d1, d2]);
63
+ const minTime = new Date(res[0]).getTime();
64
+ const maxTime = new Date(res[1]).getTime();
65
+ expect(maxTime - minTime).toBeTruthy();
66
+ });
67
+ it('should get min/max value with Dates string', () => {
68
+ const d1 = '2023-8-21';
69
+ const d2 = '2022-8-21';
70
+ const res = getMinMaxDate([d1, d2]);
71
+ const minTime = new Date(res[0]).getTime();
72
+ const maxTime = new Date(res[1]).getTime();
73
+ expect(maxTime - minTime).toBeTruthy();
74
+ });
75
+ it('should get min/max value wrong Dates format', () => {
76
+ const res = getMinMaxDate([]);
77
+ expect(res).toBe(undefined);
78
+ });
79
+ });
80
+ describe('isArrayType()', () => {
81
+ it('should return true for string', () => {
82
+ const arr = ['a', 'b'];
83
+ const isType = isArrayType(arr, 'string');
84
+ expect(isType).toBeTruthy();
85
+ });
86
+ it('should return true for number', () => {
87
+ const arr = [1, 2];
88
+ const isType = isArrayType(arr, 'number');
89
+ expect(isType).toBeTruthy();
90
+ });
91
+ it('should return true for date', () => {
92
+ const arr = [new Date(0), new Date(0)];
93
+ const isType = isArrayType(arr, 'date');
94
+ expect(isType).toBeTruthy();
95
+ });
96
+ it('should return true for object', () => {
97
+ const arr = [{ a: 'test' }];
98
+ const isType = isArrayType(arr, 'object');
99
+ expect(isType).toBeTruthy();
100
+ });
101
+ it('should return true for array of array', () => {
102
+ const arr = [[1, 2, 3]];
103
+ const isType = isArrayType(arr, 'object');
104
+ expect(isType).toBeTruthy();
105
+ });
106
+ it('should return false for undefined array', () => {
107
+ const arr = [undefined];
108
+ const isType = isArrayType(arr, 'object');
109
+ expect(isType).not.toBeTruthy();
110
+ });
111
+ it('should return false for wrong values', () => {
112
+ const arr = [1, 2, 3];
113
+ const isType = isArrayType(arr, 'object');
114
+ expect(isType).not.toBeTruthy();
115
+ });
116
+ });
117
+ describe('isArrayTypeString()', () => {
118
+ it('should return true for string', () => {
119
+ const arr = ['a', 'b'];
120
+ const isType = isArrayTypeString(arr);
121
+ expect(isType).toBeTruthy();
122
+ });
123
+ });
124
+ describe('isArrayTypeObject()', () => {
125
+ it('should return true for object', () => {
126
+ const arr = [{}, {}];
127
+ const isType = isArrayTypeObject(arr);
128
+ expect(isType).toBeTruthy();
129
+ });
130
+ });
131
+ describe('removeNilsFromDomain()', () => {
132
+ it('should return non-nullables', () => {
133
+ const domain = [1, undefined, 2];
134
+ const res = removeNilsFromDomain(domain);
135
+ expect(res).toStrictEqual([1, 2]);
136
+ });
137
+ it('should return non-nullables', () => {
138
+ const domain = ['1', undefined, 2];
139
+ const res = removeNilsFromDomain(domain);
140
+ expect(res).toStrictEqual(['1', 2]);
141
+ });
142
+ });
@@ -0,0 +1,6 @@
1
+ import { LineChartOverlay, LineChartSeries } from '../types';
2
+ export declare const handleSeriesNames: (series: LineChartSeries) => string[];
3
+ export declare const handleSeriesColors: (series: LineChartSeries, palette: string[]) => (string | undefined)[];
4
+ export declare const handleOverlayName: (overlay: LineChartOverlay | undefined) => string;
5
+ export declare const handleOverlayColor: (overlay: LineChartOverlay | undefined, palette: string) => string;
6
+ //# sourceMappingURL=metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/utils/metadata.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG7D,eAAO,MAAM,iBAAiB,WAAY,eAAe,aAGvD,CAAC;AAEH,eAAO,MAAM,kBAAkB,WACrB,eAAe,WACd,MAAM,EAAE,2BAKjB,CAAC;AAEH,eAAO,MAAM,iBAAiB,YAAa,gBAAgB,GAAG,SAAS,WAStE,CAAC;AAEF,eAAO,MAAM,kBAAkB,YACpB,gBAAgB,GAAG,SAAS,WAC5B,MAAM,WACqB,CAAC"}
@@ -0,0 +1,36 @@
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 { getLabelFromPath } from './data';
18
+ export const handleSeriesNames = (series) => series.dataKey.map((s, i) => {
19
+ const renamed = series.rename ? series.rename(s, i) : getLabelFromPath(s);
20
+ return _.startCase(renamed);
21
+ });
22
+ export const handleSeriesColors = (series, palette) => series.dataKey.map((_, i) => (series.style?.[i]
23
+ ? series.style[i]?.stroke
24
+ : palette[i % palette.length]));
25
+ export const handleOverlayName = (overlay) => {
26
+ if (overlay) {
27
+ const { rename, label, dataKey } = overlay;
28
+ if (rename)
29
+ return rename;
30
+ if (label)
31
+ return _.startCase(label);
32
+ return _.startCase(dataKey);
33
+ }
34
+ return '';
35
+ };
36
+ export const handleOverlayColor = (overlay, palette) => overlay?.style?.stroke ?? palette;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=metadata.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.test.d.ts","sourceRoot":"","sources":["../../src/utils/metadata.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,102 @@
1
+ import { defaultLineChartPalette } from '../style-config';
2
+ import { handleOverlayColor, handleOverlayName, handleSeriesColors, handleSeriesNames, } from './metadata';
3
+ describe('handleSeriesNames()', () => {
4
+ it('should return formatted labels', () => {
5
+ const series = {
6
+ dataKey: ['test1', 'test2'],
7
+ };
8
+ const res = handleSeriesNames(series);
9
+ const exp = ['Test 1', 'Test 2'];
10
+ expect(res).toStrictEqual(exp);
11
+ });
12
+ it('should return renamed labels', () => {
13
+ const series = {
14
+ dataKey: ['test1', 'test2'],
15
+ rename: (k, i) => k.replace('test', `index ${i * 5}`),
16
+ };
17
+ const res = handleSeriesNames(series);
18
+ const exp = ['Index 01', 'Index 52'];
19
+ expect(res).toStrictEqual(exp);
20
+ });
21
+ });
22
+ describe('handleSeriesColors()', () => {
23
+ const colors = defaultLineChartPalette.light.series;
24
+ it('should return custom styled color', () => {
25
+ const series = {
26
+ dataKey: ['test1', 'test2'],
27
+ style: [{ stroke: 'blue' }, { stroke: 'green' }],
28
+ };
29
+ const res = handleSeriesColors(series, colors);
30
+ const exp = ['blue', 'green'];
31
+ expect(res).toStrictEqual(exp);
32
+ });
33
+ it('should return default palette color', () => {
34
+ const series = {
35
+ dataKey: ['test1', 'test2'],
36
+ };
37
+ const res = handleSeriesColors(series, colors);
38
+ const exp = ['hsl(149 83% 35%)', 'hsl(350 66% 49%)'];
39
+ expect(res).toStrictEqual(exp);
40
+ });
41
+ it('should return default palette color for a value greater than the palette color', () => {
42
+ const series = {
43
+ dataKey: Array(14).fill('test'),
44
+ };
45
+ const res = handleSeriesColors(series, colors)[13];
46
+ const exp = 'hsl(350 66% 49%)';
47
+ expect(res).toStrictEqual(exp);
48
+ });
49
+ });
50
+ describe('handleOverlayName()', () => {
51
+ it('should return default formatted datakey', () => {
52
+ const overlay = {
53
+ dataKey: 'test',
54
+ };
55
+ const res = handleOverlayName(overlay);
56
+ const exp = 'Test';
57
+ expect(res).toStrictEqual(exp);
58
+ });
59
+ it('should return preferred formatted labels', () => {
60
+ const overlay = {
61
+ dataKey: 'test',
62
+ label: 'best',
63
+ };
64
+ const res = handleOverlayName(overlay);
65
+ const exp = 'Best';
66
+ expect(res).toStrictEqual(exp);
67
+ });
68
+ it('should return renamed labels', () => {
69
+ const overlay = {
70
+ dataKey: 'test',
71
+ rename: 'fest',
72
+ };
73
+ const res = handleOverlayName(overlay);
74
+ const exp = 'fest';
75
+ expect(res).toStrictEqual(exp);
76
+ });
77
+ it('should return empty string w/o overlay', () => {
78
+ const res = handleOverlayName(undefined);
79
+ const exp = '';
80
+ expect(res).toStrictEqual(exp);
81
+ });
82
+ });
83
+ describe('handleOverlayColor()', () => {
84
+ const colors = defaultLineChartPalette.light.overlay;
85
+ it('should return the default color', () => {
86
+ const overlay = {
87
+ dataKey: 'test',
88
+ };
89
+ const res = handleOverlayColor(overlay, colors);
90
+ const exp = 'hsl(14 63% 53%)';
91
+ expect(res).toStrictEqual(exp);
92
+ });
93
+ it('should return a custom styled color', () => {
94
+ const overlay = {
95
+ dataKey: 'test',
96
+ style: { stroke: 'salmon' },
97
+ };
98
+ const res = handleOverlayColor(overlay, colors);
99
+ const exp = 'salmon';
100
+ expect(res).toStrictEqual(exp);
101
+ });
102
+ });
@@ -0,0 +1,3 @@
1
+ import { CartesianAxis, ViewportStyleConfig } from '../types';
2
+ export declare const manageViewport: (width: number, height: number, axis: CartesianAxis, config: ViewportStyleConfig) => import("../types").ViewportSizeConfig;
3
+ //# sourceMappingURL=viewport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewport.d.ts","sourceRoot":"","sources":["../../src/utils/viewport.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE9D,eAAO,MAAM,cAAc,UAAW,MAAM,UAAU,MAAM,QAAQ,aAAa,UAAU,mBAAmB,0CAe7G,CAAC"}
@@ -0,0 +1,29 @@
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
+ export const manageViewport = (width, height, axis, config) => {
18
+ const { orientation, numTicks, scaleType, domain, } = axis;
19
+ const isVertical = orientation === 'left' || orientation === 'right';
20
+ const size = isVertical ? height : width;
21
+ const key = isVertical ? 'maxHeight' : 'maxWidth';
22
+ const defaultLabelTicksNum = scaleType === 'label' ? domain.length : undefined;
23
+ const defaultConfigLarge = defaultLabelTicksNum ?? config.large.numTicks;
24
+ if (_.inRange(size, 0, config.small[key]))
25
+ return config.small;
26
+ if (_.inRange(size, config.small[key], config.medium[key]))
27
+ return config.medium;
28
+ return numTicks ? { ...config.large, numTicks } : { ...config.large, numTicks: defaultConfigLarge };
29
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=viewport.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewport.test.d.ts","sourceRoot":"","sources":["../../src/utils/viewport.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,63 @@
1
+ import { viewportStyleConfig } from '../style-config';
2
+ import { computeAxisProperties } from './axis';
3
+ import { manageViewport } from './viewport';
4
+ describe('manageViewport()', () => {
5
+ it('should return correct number of ticks - horizontal/linear', () => {
6
+ const axis = {
7
+ domain: [0, 1],
8
+ scaleType: 'linear',
9
+ orientation: 'top',
10
+ };
11
+ const cartesian = computeAxisProperties({
12
+ axis,
13
+ maxRangeX: 800,
14
+ maxRangeY: 600,
15
+ positionTop: 1,
16
+ positionRight: 2,
17
+ positionBottom: 3,
18
+ positionLeft: 4,
19
+ });
20
+ const res = manageViewport(800, 600, cartesian, viewportStyleConfig);
21
+ const exp = { numTicks: 10 };
22
+ expect(res).toStrictEqual(exp);
23
+ });
24
+ it('should return correct number of ticks - vertical/label', () => {
25
+ const axis = {
26
+ domain: ['a', 'b'],
27
+ scaleType: 'label',
28
+ orientation: 'left',
29
+ };
30
+ const cartesian = computeAxisProperties({
31
+ axis,
32
+ maxRangeX: 800,
33
+ maxRangeY: 600,
34
+ positionTop: 1,
35
+ positionRight: 2,
36
+ positionBottom: 3,
37
+ positionLeft: 4,
38
+ });
39
+ const res = manageViewport(800, 600, cartesian, viewportStyleConfig);
40
+ const exp = { numTicks: 2 };
41
+ expect(res).toStrictEqual(exp);
42
+ });
43
+ it('should return custom number of ticks', () => {
44
+ const axis = {
45
+ domain: ['a', 'b'],
46
+ scaleType: 'label',
47
+ orientation: 'left',
48
+ numTicks: 10,
49
+ };
50
+ const cartesian = computeAxisProperties({
51
+ axis,
52
+ maxRangeX: 200,
53
+ maxRangeY: 200,
54
+ positionTop: 1,
55
+ positionRight: 2,
56
+ positionBottom: 3,
57
+ positionLeft: 4,
58
+ });
59
+ const res = manageViewport(800, 600, cartesian, viewportStyleConfig);
60
+ const exp = { numTicks: 10 };
61
+ expect(res).toStrictEqual(exp);
62
+ });
63
+ });
package/package.json ADDED
@@ -0,0 +1,106 @@
1
+ {
2
+ "name": "@wonderflow/charts",
3
+ "version": "12.8.0",
4
+ "description": "Wonderflow's Wanda Design System Charting Library",
5
+ "author": "Wonderflow Design Team",
6
+ "contributors": [
7
+ "Patrick Tabarelli <patrick.tabarelli@gmail.com> (https://github.com/patricktabar)"
8
+ ],
9
+ "license": "Apache-2.0",
10
+ "types": "dist/index.d.ts",
11
+ "main": "dist/index.js",
12
+ "files": [
13
+ "dist",
14
+ "core",
15
+ "core.css"
16
+ ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "engines": {
21
+ "node": ">=14.x",
22
+ "npm": ">=8.x"
23
+ },
24
+ "scripts": {
25
+ "start": "run-s watch:csstypes",
26
+ "prebuild": "run-s clean build:csstypes",
27
+ "build": "run-s build:ts build:css",
28
+ "postbuild": "rimraf dist/**/_mixins.css",
29
+ "build:ts": "tsc && tsc-alias",
30
+ "build:css": "cpy '**/*.css' '../dist' --parents --cwd=src && postcss dist/*.css \"dist/**/!(utils)/!(_mixins).css\" --replace",
31
+ "lint": "run-s lint:styles",
32
+ "lint:styles": "stylelint ./src/**/*.css",
33
+ "clean": "rimraf dist",
34
+ "watch:csstypes": "tcm -w -p '**/*.module.css' src",
35
+ "build:csstypes": "tcm -p '**/*.module.css' src"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/wonderflow-bv/wanda.git"
40
+ },
41
+ "browserslist": [
42
+ "last 2 Chrome versions",
43
+ "last 2 Firefox versions",
44
+ "last 2 Safari versions",
45
+ "last 2 Edge versions"
46
+ ],
47
+ "keywords": [
48
+ "charts",
49
+ "wonderflow",
50
+ "library",
51
+ "react"
52
+ ],
53
+ "bugs": {
54
+ "url": "https://github.com/wonderflow-bv/wanda/issues"
55
+ },
56
+ "homepage": "https://github.com/wonderflow-bv/wanda",
57
+ "peerDependencies": {
58
+ "react": ">=17.0",
59
+ "react-dom": ">=17.0"
60
+ },
61
+ "devDependencies": {
62
+ "@babel/core": "7.19.3",
63
+ "@babel/preset-typescript": "7.18.6",
64
+ "@types/d3": "7.4.1",
65
+ "@types/react": "17.0.43",
66
+ "@types/react-dom": "17.0.14",
67
+ "@types/react-table": "7.7.12",
68
+ "@types/react-test-renderer": "18.0.0",
69
+ "@types/uuid": "9.0.2",
70
+ "@wonderflow/config": "12.8.0",
71
+ "babel-loader": "8.2.5",
72
+ "cpy-cli": "3.1.1",
73
+ "postcss": "8.4.17",
74
+ "postcss-cli": "10.0.0",
75
+ "react": "17.0.2",
76
+ "react-dom": "17.0.2",
77
+ "tsconfig": "10.0.0",
78
+ "typed-css-modules": "0.7.2",
79
+ "typescript": "4.8.4",
80
+ "typescript-plugin-css-modules": "3.4.0"
81
+ },
82
+ "dependencies": {
83
+ "@visx/annotation": "3.3.0",
84
+ "@visx/axis": "3.3.0",
85
+ "@visx/clip-path": "3.3.0",
86
+ "@visx/curve": "3.3.0",
87
+ "@visx/event": "3.3.0",
88
+ "@visx/gradient": "3.3.0",
89
+ "@visx/grid": "3.3.0",
90
+ "@visx/group": "3.3.0",
91
+ "@visx/mock-data": "3.3.0",
92
+ "@visx/responsive": "3.3.0",
93
+ "@visx/scale": "3.3.0",
94
+ "@visx/shape": "3.3.0",
95
+ "@visx/text": "3.3.0",
96
+ "@visx/tooltip": "3.3.0",
97
+ "@visx/vendor": "3.3.0",
98
+ "ahooks": "3.7.5",
99
+ "clsx": "1.2.1",
100
+ "d3": "7.8.5",
101
+ "framer-motion": "6.5.1",
102
+ "lodash": "4.17.21",
103
+ "type-fest": "3.0.0",
104
+ "uuid": "9.0.0"
105
+ }
106
+ }