@wonderflow/charts 13.0.0 → 14.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/components/bar-chart/bar-chart.d.ts +3 -3
  2. package/dist/components/bar-chart/bar-chart.d.ts.map +1 -1
  3. package/dist/components/bar-chart/bar-chart.js +4 -4
  4. package/dist/components/cartesian-base/cartesian-base.d.ts +5 -0
  5. package/dist/components/cartesian-base/cartesian-base.d.ts.map +1 -1
  6. package/dist/components/cartesian-base/cartesian-base.js +3 -2
  7. package/dist/components/line-chart/line-chart.d.ts +5 -5
  8. package/dist/components/line-chart/line-chart.d.ts.map +1 -1
  9. package/dist/components/line-chart/line-chart.js +2 -2
  10. package/dist/components/shapes/bars/bars-label.d.ts +22 -0
  11. package/dist/components/shapes/bars/bars-label.d.ts.map +1 -0
  12. package/dist/components/shapes/bars/bars-label.js +35 -0
  13. package/dist/components/shapes/bars/bars-layout.d.ts +3 -0
  14. package/dist/components/shapes/bars/bars-layout.d.ts.map +1 -0
  15. package/dist/components/shapes/bars/bars-layout.js +36 -0
  16. package/dist/components/shapes/bars/bars-overlay-labels.d.ts +6 -0
  17. package/dist/components/shapes/bars/bars-overlay-labels.d.ts.map +1 -0
  18. package/dist/components/shapes/bars/bars-overlay-labels.js +62 -0
  19. package/dist/components/shapes/bars/bars-overlay.js +4 -4
  20. package/dist/components/shapes/bars/bars-series-labels.d.ts +6 -0
  21. package/dist/components/shapes/bars/bars-series-labels.d.ts.map +1 -0
  22. package/dist/components/shapes/bars/bars-series-labels.js +62 -0
  23. package/dist/components/shapes/bars/bars-series.d.ts.map +1 -1
  24. package/dist/components/shapes/bars/bars-series.js +4 -4
  25. package/dist/components/shapes/bars/bars-stack-overlay-labels.d.ts +6 -0
  26. package/dist/components/shapes/bars/bars-stack-overlay-labels.d.ts.map +1 -0
  27. package/dist/components/shapes/bars/bars-stack-overlay-labels.js +50 -0
  28. package/dist/components/shapes/bars/bars-stack-overlay.d.ts +6 -0
  29. package/dist/components/shapes/bars/bars-stack-overlay.d.ts.map +1 -0
  30. package/dist/components/shapes/bars/bars-stack-overlay.js +50 -0
  31. package/dist/components/shapes/bars/bars-stack-series-labels.d.ts +6 -0
  32. package/dist/components/shapes/bars/bars-stack-series-labels.d.ts.map +1 -0
  33. package/dist/components/shapes/bars/bars-stack-series-labels.js +50 -0
  34. package/dist/components/shapes/bars/bars-stack-series.d.ts +6 -0
  35. package/dist/components/shapes/bars/bars-stack-series.d.ts.map +1 -0
  36. package/dist/components/shapes/bars/bars-stack-series.js +48 -0
  37. package/dist/components/shapes/bars/bars-tooltip.d.ts.map +1 -1
  38. package/dist/components/shapes/bars/bars-tooltip.js +22 -11
  39. package/dist/components/shapes/bars/bars.d.ts.map +1 -1
  40. package/dist/components/shapes/bars/bars.js +9 -7
  41. package/dist/components/shapes/bars/bars.test.js +93 -0
  42. package/dist/components/shapes/bars/index.d.ts +8 -0
  43. package/dist/components/shapes/bars/index.d.ts.map +1 -1
  44. package/dist/components/shapes/bars/index.js +8 -0
  45. package/dist/components/shapes/lines/lines-marker-labels.d.ts.map +1 -1
  46. package/dist/components/shapes/lines/lines-marker-labels.js +7 -3
  47. package/dist/components/shapes/lines/lines-tooltip.js +3 -3
  48. package/dist/components/shapes/lines/lines.d.ts.map +1 -1
  49. package/dist/components/shapes/lines/lines.js +1 -1
  50. package/dist/hooks/hooks.test.js +8 -3
  51. package/dist/hooks/useBarChart.d.ts +3 -2
  52. package/dist/hooks/useBarChart.d.ts.map +1 -1
  53. package/dist/hooks/useBarChart.js +20 -14
  54. package/dist/hooks/useBars.d.ts +19 -5
  55. package/dist/hooks/useBars.d.ts.map +1 -1
  56. package/dist/hooks/useBars.js +53 -14
  57. package/dist/hooks/useCartesian.d.ts +2 -1
  58. package/dist/hooks/useCartesian.d.ts.map +1 -1
  59. package/dist/hooks/useCartesian.js +4 -3
  60. package/dist/hooks/useLineChart.d.ts +1 -1
  61. package/dist/hooks/useLineChart.d.ts.map +1 -1
  62. package/dist/hooks/useLineChart.js +8 -6
  63. package/dist/hooks/useLines.d.ts +4 -1
  64. package/dist/hooks/useLines.d.ts.map +1 -1
  65. package/dist/hooks/useLines.js +2 -2
  66. package/dist/hooks/useTrendline.d.ts +14 -10
  67. package/dist/hooks/useTrendline.d.ts.map +1 -1
  68. package/dist/style-config/bars.d.ts.map +1 -1
  69. package/dist/style-config/bars.js +11 -1
  70. package/dist/types/bar-chart.d.ts +6 -7
  71. package/dist/types/bar-chart.d.ts.map +1 -1
  72. package/dist/types/bars.d.ts +39 -0
  73. package/dist/types/bars.d.ts.map +1 -1
  74. package/dist/types/cartesian.d.ts +4 -0
  75. package/dist/types/cartesian.d.ts.map +1 -1
  76. package/dist/types/line-chart.d.ts +5 -7
  77. package/dist/types/line-chart.d.ts.map +1 -1
  78. package/dist/types/main.d.ts +1 -1
  79. package/dist/types/main.d.ts.map +1 -1
  80. package/dist/utils/bars.d.ts +53 -5
  81. package/dist/utils/bars.d.ts.map +1 -1
  82. package/dist/utils/bars.js +252 -7
  83. package/dist/utils/bars.test.js +296 -3
  84. package/dist/utils/data.d.ts +9 -4
  85. package/dist/utils/data.d.ts.map +1 -1
  86. package/dist/utils/data.js +41 -6
  87. package/dist/utils/data.test.js +23 -7
  88. package/dist/utils/lines.d.ts +3 -3
  89. package/dist/utils/lines.d.ts.map +1 -1
  90. package/dist/utils/lines.js +3 -1
  91. package/dist/utils/lines.test.js +1 -1
  92. package/dist/utils/metadata.d.ts +2 -4
  93. package/dist/utils/metadata.d.ts.map +1 -1
  94. package/dist/utils/metadata.js +5 -0
  95. package/dist/utils/metadata.test.js +2 -2
  96. package/package.json +12 -12
@@ -1,4 +1,4 @@
1
- import { getBarSize, getHeightForVerticalChartWithFixedBarSize } from './bars';
1
+ import { getBarChartLabels, getBarChartLabelsMaxLength, getBarChartLabelsMaxSize, getBarIndexPositionSeries, getBarLabelContent, getBarSize, getHeightForVerticalChartWithFixedBarSize, getLinearDomainStackSeries, getStackBarIndexPositionOverlay, getStackBarIndexPositionSeries, getStackBarLabelContent, getStackBarLabelMorphology, getStackBarThickness, } from './bars';
2
2
  describe('getBarSize()', () => {
3
3
  const bar = {
4
4
  color: 'red',
@@ -34,7 +34,7 @@ describe('getBarSize()', () => {
34
34
  expect(res).toStrictEqual(exp);
35
35
  });
36
36
  });
37
- describe('getBarPosition()', () => {
37
+ describe('getBarSize()', () => {
38
38
  const bar = {
39
39
  color: 'red',
40
40
  height: 60,
@@ -70,7 +70,7 @@ describe('getBarPosition()', () => {
70
70
  });
71
71
  it('should return position, negative false', () => {
72
72
  const res = getBarSize({ ...bar, value: -50 }, axis, true);
73
- const exp = -60;
73
+ const exp = 0;
74
74
  expect(res).toStrictEqual(exp);
75
75
  });
76
76
  });
@@ -93,3 +93,296 @@ describe('getHeightForVerticalChartWithFixedBarSize()', () => {
93
93
  const res = getHeightForVerticalChartWithFixedBarSize(config, data, metadata);
94
94
  expect(res).toStrictEqual(227);
95
95
  });
96
+ describe('getBarIndexPositionSeries()', () => {
97
+ const bar = {
98
+ color: 'red',
99
+ height: 10,
100
+ index: 1,
101
+ key: 'test',
102
+ value: 123,
103
+ width: 20,
104
+ x: 3,
105
+ y: 5,
106
+ };
107
+ it('should return for custom thickness - horizontal', () => {
108
+ const res = getBarIndexPositionSeries(bar, 24, true);
109
+ const exp = 1;
110
+ expect(res).toStrictEqual(exp);
111
+ });
112
+ it('should return for custom thickness - vertical', () => {
113
+ const res = getBarIndexPositionSeries(bar, 24, false);
114
+ const exp = -2;
115
+ expect(res).toStrictEqual(exp);
116
+ });
117
+ it('should return for no custom thickness', () => {
118
+ const res = getBarIndexPositionSeries(bar, 20, false);
119
+ const exp = 0;
120
+ expect(res).toStrictEqual(exp);
121
+ });
122
+ });
123
+ describe('getStackBarIndexPositionSeries()', () => {
124
+ const bar = {
125
+ color: 'red',
126
+ height: 10,
127
+ index: 1,
128
+ key: 'test',
129
+ value: 123,
130
+ width: 20,
131
+ x: 3,
132
+ y: 5,
133
+ };
134
+ it('should return w custom thickness, overlay, horizontal', () => {
135
+ const res = getStackBarIndexPositionSeries(bar, 24, true, true);
136
+ const exp = -12;
137
+ expect(res).toStrictEqual(exp);
138
+ });
139
+ it('should return w custom thickness, no overlay, horizontal', () => {
140
+ const res = getStackBarIndexPositionSeries(bar, 24, false, true);
141
+ const exp = 1;
142
+ expect(res).toStrictEqual(exp);
143
+ });
144
+ it('should return w custom thickness, no overlay, vertical', () => {
145
+ const res = getStackBarIndexPositionSeries(bar, 20, false, false);
146
+ const exp = 0;
147
+ expect(res).toStrictEqual(exp);
148
+ });
149
+ it('should return w/o custom thickness, overlay, horizontal', () => {
150
+ const res = getStackBarIndexPositionSeries(bar, 20, true, true);
151
+ const exp = -8;
152
+ expect(res).toStrictEqual(exp);
153
+ });
154
+ it('should return w/o custom thickness, overlay, vertical', () => {
155
+ const res = getStackBarIndexPositionSeries(bar, 10, true, false);
156
+ const exp = -1;
157
+ expect(res).toStrictEqual(exp);
158
+ });
159
+ it('should return w custom thickness, overlay, vertical', () => {
160
+ const res = getStackBarIndexPositionSeries(bar, 12, true, false);
161
+ const exp = -3;
162
+ expect(res).toStrictEqual(exp);
163
+ });
164
+ it('should return w/o custom thickness, no overlay, vertical', () => {
165
+ const res = getStackBarIndexPositionSeries(bar, 10, false, false);
166
+ const exp = 5;
167
+ expect(res).toStrictEqual(exp);
168
+ });
169
+ });
170
+ describe('getStackBarIndexPositionOverlay()', () => {
171
+ const bar = {
172
+ color: 'red',
173
+ height: 10,
174
+ index: 1,
175
+ key: 'test',
176
+ value: 123,
177
+ width: 20,
178
+ x: 3,
179
+ y: 5,
180
+ };
181
+ it('should return - no custom width, horizontal', () => {
182
+ const res = getStackBarIndexPositionOverlay(bar, 20, true);
183
+ const exp = 14;
184
+ expect(res).toStrictEqual(exp);
185
+ });
186
+ it('should return - custom width, horizontal', () => {
187
+ const res = getStackBarIndexPositionOverlay(bar, 24, true);
188
+ const exp = 14;
189
+ expect(res).toStrictEqual(exp);
190
+ });
191
+ it('should return - custom width, vertical', () => {
192
+ const res = getStackBarIndexPositionOverlay(bar, 14, false);
193
+ const exp = 11;
194
+ expect(res).toStrictEqual(exp);
195
+ });
196
+ it('should return - no custom width, vertical', () => {
197
+ const res = getStackBarIndexPositionOverlay(bar, 10, false);
198
+ const exp = 11;
199
+ expect(res).toStrictEqual(exp);
200
+ });
201
+ });
202
+ describe('getStackBarThickness()', () => {
203
+ it('should return w fixbarsize and no overlay', () => {
204
+ const res = getStackBarThickness(24, 100, true, false);
205
+ const exp = 24;
206
+ expect(res).toStrictEqual(exp);
207
+ });
208
+ it('should return w/o fixbarsize and no overlay', () => {
209
+ const res = getStackBarThickness(24, 20, false, false);
210
+ const exp = 24;
211
+ expect(res).toStrictEqual(exp);
212
+ });
213
+ it('should return w fixbarsize and overlay', () => {
214
+ const res = getStackBarThickness(24, 100, true, true);
215
+ const exp = 11.5;
216
+ expect(res).toStrictEqual(exp);
217
+ });
218
+ it('should return w/o fixbarsize and overlay', () => {
219
+ const res = getStackBarThickness(24, 20, false, true);
220
+ const exp = 11.5;
221
+ expect(res).toStrictEqual(exp);
222
+ });
223
+ });
224
+ describe('getLinearDomainStackSeries()', () => {
225
+ it('should return for multiple nested keys', () => {
226
+ const data = [
227
+ { test: { idy: 10, idx: 20 } },
228
+ { test: { idy: 30, idx: 18 } }
229
+ ];
230
+ const datakey = ['test.idy', 'test.idx'];
231
+ const res = getLinearDomainStackSeries(data, datakey, [0, 10]);
232
+ const exp = [0, 48];
233
+ expect(res).toStrictEqual(exp);
234
+ });
235
+ it('should return for multiple nested keys w negative values', () => {
236
+ const data = [
237
+ { test: { idy: -10, idx: 20 } },
238
+ { test: { idy: 30, idx: -18 } }
239
+ ];
240
+ const datakey = ['test.idy', 'test.idx'];
241
+ const res = getLinearDomainStackSeries(data, datakey, [0, 10]);
242
+ const exp = [0, 12];
243
+ expect(res).toStrictEqual(exp);
244
+ });
245
+ });
246
+ describe('getBarChartLabels()', () => {
247
+ const data = [
248
+ { test: { idy: 10, idx: 20 } },
249
+ { test: { idy: 30, idx: 18 } }
250
+ ];
251
+ it('should return for multiple series', () => {
252
+ const series = {
253
+ dataKey: ['test.idy', 'test.idx'],
254
+ };
255
+ const res = getBarChartLabels(data, series);
256
+ const { series: s } = res;
257
+ const exp = [
258
+ { extraData: '', length: 3, value: 10 },
259
+ { extraData: '', length: 3, value: 20 },
260
+ ];
261
+ expect(s[0]).toStrictEqual(exp);
262
+ });
263
+ it('should return for multiple series', () => {
264
+ const series = {
265
+ dataKey: ['test.idx'],
266
+ };
267
+ const overlay = {
268
+ dataKey: ['test.idy'],
269
+ };
270
+ const res = getBarChartLabels(data, series, overlay);
271
+ const { series: s, overlay: o } = res;
272
+ const expSeries = [{ extraData: '', length: 3, value: 20 }];
273
+ const expOverlay = [{ extraData: '', length: 3, value: 10 }];
274
+ expect(s[0]).toStrictEqual(expSeries);
275
+ expect(o[0]).toStrictEqual(expOverlay);
276
+ });
277
+ });
278
+ describe('getBarChartLabelsMaxLength()', () => {
279
+ const data = [
280
+ { test: { idy: 10, idx: 20 } },
281
+ { test: { idy: 30, idx: 18 } }
282
+ ];
283
+ it('should return for series', () => {
284
+ const series = {
285
+ dataKey: ['test.idy', 'test.idx'],
286
+ };
287
+ const labels = getBarChartLabels(data, series);
288
+ const res = getBarChartLabelsMaxLength(labels);
289
+ const exp = 3;
290
+ expect(res).toStrictEqual(exp);
291
+ });
292
+ it('should return for series and overlay', () => {
293
+ const series = {
294
+ dataKey: ['test.idx'],
295
+ };
296
+ const overlay = {
297
+ dataKey: ['test.idy'],
298
+ };
299
+ const labels = getBarChartLabels(data, series, overlay);
300
+ const res = getBarChartLabelsMaxLength(labels);
301
+ const exp = 3;
302
+ expect(res).toStrictEqual(exp);
303
+ });
304
+ });
305
+ describe('getBarChartLabelsMaxSize()', () => {
306
+ it('should return', () => {
307
+ const res = getBarChartLabelsMaxSize(10);
308
+ const exp = 96;
309
+ expect(res).toStrictEqual(exp);
310
+ });
311
+ });
312
+ describe('getBarLabelContent()', () => {
313
+ const bar = {
314
+ color: 'red',
315
+ height: 10,
316
+ index: 1,
317
+ key: 'test',
318
+ value: 123,
319
+ width: 20,
320
+ x: 3,
321
+ y: 5,
322
+ };
323
+ it('should return for plain object', () => {
324
+ const datum = { test: 101, extra: 321 };
325
+ const res = getBarLabelContent(datum, bar, 'test', d => d.extra);
326
+ const exp = { extra: 321, separator: ' - ', value: 123 };
327
+ expect(res).toStrictEqual(exp);
328
+ });
329
+ it('should return for nested object', () => {
330
+ const datum = { nested: { test: 101, extra: 321 } };
331
+ const res = getBarLabelContent(datum, bar, 'nested.test', d => d.extra);
332
+ const exp = { extra: 321, separator: ' - ', value: 123 };
333
+ expect(res).toStrictEqual(exp);
334
+ });
335
+ });
336
+ describe('getStackBarLabelContent()', () => {
337
+ it('should return for plain object', () => {
338
+ const datum = { test: 101, extra: 321 };
339
+ const res = getStackBarLabelContent(datum, ['test'], d => d.extra, 0);
340
+ const exp = { extra: 321, separator: ' - ', value: 101 };
341
+ expect(res).toStrictEqual(exp);
342
+ });
343
+ it('should return for nested object', () => {
344
+ const datum = { nested: { test: 101, extra: 321 } };
345
+ const res = getStackBarLabelContent(datum, ['nested.test'], d => d.extra, 0);
346
+ const exp = { extra: 321, separator: ' - ', value: 101 };
347
+ expect(res).toStrictEqual(exp);
348
+ });
349
+ });
350
+ describe('getStackBarLabelMorphology()', () => {
351
+ const bar = {
352
+ color: 'red',
353
+ height: 60,
354
+ index: 1,
355
+ key: 'name',
356
+ value: 15,
357
+ width: 24,
358
+ x: 20,
359
+ y: 35,
360
+ };
361
+ const content = { value: '10', separator: ' - ', extra: '23' };
362
+ const position = { x: 0, y: 0 };
363
+ const dimension = { xMax: 800, yMax: 600 };
364
+ it('should return morphology', () => {
365
+ const res = getStackBarLabelMorphology(bar, undefined, content, 24, position, dimension, true);
366
+ const exp = {
367
+ rect: { width: 19, x: 2.5, y: 56 },
368
+ text: { x: 12, y: 69 },
369
+ };
370
+ expect(res).toStrictEqual(exp);
371
+ });
372
+ it('should return morphology w extra data', () => {
373
+ const res = getStackBarLabelMorphology(bar, () => 'true', content, 24, position, dimension, true);
374
+ const exp = {
375
+ rect: { width: 67, x: -21.5, y: 56 },
376
+ text: { x: 12, y: 69 },
377
+ };
378
+ expect(res).toStrictEqual(exp);
379
+ });
380
+ it('should return morphology w extra data - vertical', () => {
381
+ const res = getStackBarLabelMorphology(bar, () => 'true', content, 24, position, dimension, false);
382
+ const exp = {
383
+ rect: { width: 67, x: 0, y: 3 },
384
+ text: { x: 33.5, y: 16 },
385
+ };
386
+ expect(res).toStrictEqual(exp);
387
+ });
388
+ });
@@ -1,14 +1,18 @@
1
1
  import { Except } from 'type-fest';
2
- import { AverageType, AxisProps, Bar, Data, LineChartIndex, LineChartSeries, SortingType, TrendlineType } from '../types';
3
- import { BarChartIndex, BarChartSeries } from '../types/bar-chart';
2
+ import { AverageType, AxisProps, Bar, BarChartIndex, BarChartSeries, ChartIndex, ChartSeries, Data, LineChartIndex, LineChartSeries, SortingType, TrendlineType } from '../types';
4
3
  export declare const getValueFromObjectByPath: (object: Record<string, unknown>, path: string) => unknown;
5
4
  export declare const getPrimitiveFromObjectByPath: (object: Record<string, unknown>, path: string) => string | number | undefined;
6
5
  export declare const getLabelFromPath: (path: string) => string;
7
6
  export declare const getPrimitivesFromObjectArrayByPath: (arr: Array<Record<string, unknown>>, path: string) => (string | number | undefined)[];
8
7
  export declare const removeKeysFromObject: (obj: Record<string, unknown>, keys: string[]) => Record<string, unknown>;
9
8
  export declare const mirrorDomain: (domain: Array<NonNullable<string | number>>) => NonNullable<string | number>[] | (number | undefined)[];
10
- export declare const handleAxisDomainAndScaleType: <T extends BarChartIndex | BarChartSeries | LineChartIndex | LineChartSeries>(data: Data, axis: T) => Except<AxisProps, 'orientation'>;
11
- export declare const handleChartDomainAndScaleType: <T extends BarChartIndex | LineChartIndex, U extends BarChartSeries | LineChartSeries>(data: Data, index: T, series: U, overlay?: U | undefined) => {
9
+ export declare const handleAxisDomainAndScaleType: <T extends ChartSeries | ChartIndex>(data: Data, axis: T, isStacked?: boolean) => Except<AxisProps, 'orientation'>;
10
+ export declare const handleLineChartDomainAndScaleType: <T extends LineChartIndex, U extends LineChartSeries>(data: Data, index: T, series: U, overlay?: U | undefined) => {
11
+ index: Except<AxisProps, "orientation">;
12
+ series: Except<AxisProps, "orientation">;
13
+ overlay: Except<AxisProps, "orientation"> | undefined;
14
+ };
15
+ export declare const handleBarChartDomainAndScaleType: <T extends BarChartIndex, U extends BarChartSeries>(data: Data, index: T, series: U, overlay?: U | undefined, isStacked?: boolean) => {
12
16
  index: Except<AxisProps, "orientation">;
13
17
  series: Except<AxisProps, "orientation">;
14
18
  overlay: Except<AxisProps, "orientation"> | undefined;
@@ -17,4 +21,5 @@ export declare const extractBarValueFromNestedKey: (barGroup: any, index: number
17
21
  export declare const sortBarsBy: (bars: Bar[], sorting: SortingType, isHorizontal: boolean) => Bar[];
18
22
  export declare const computeAverage: (data: Data, dataKeys: string[]) => AverageType | undefined;
19
23
  export declare const computeTrendline: (data: Data, dataKeys: string[]) => TrendlineType[];
24
+ export declare const getDataKeyParentObject: (datum: Record<string, any>, dataKey: string) => any;
20
25
  //# sourceMappingURL=data.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/utils/data.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EACL,WAAW,EACX,SAAS,EACT,GAAG,EACH,IAAI,EAAE,cAAc,EACpB,eAAe,EAAE,WAAW,EAAE,aAAa,EAC5C,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAQnE,eAAO,MAAM,wBAAwB,WAAY,OAAO,MAAM,EAAE,OAAO,CAAC,QAAQ,MAAM,YAA0B,CAAC;AAEjH,eAAO,MAAM,4BAA4B,WAAY,O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YAA0B,CAAC;AAEjH,eAAO,MAAM,4BAA4B,WAAY,OAAO,MAAM,EAAE,OAAO,CAAC,QAAQ,MAAM,gCAGzF,CAAC;AAEF,eAAO,MAAM,gBAAgB,SAAU,MAAM,WAc5C,CAAC;AAEF,eAAO,MAAM,kCAAkC,QACxC,MAAM,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC,QAC7B,MAAM,oCAC0C,CAAC;AAEzD,eAAO,MAAM,oBAAoB,QAAS,OAAO,MAAM,EAAE,OAAO,CAAC,QAAQ,MAAM,EAAE,4BAQhF,CAAC;AAEF,eAAO,MAAM,YAAY,WAAY,MAAM,YAAY,MAAM,GAAG,MAAM,CAAC,CAAC,4DAcvE,CAAC;AAEF,eAAO,MAAM,4BAA4B,wEAIzB,OAAO,KAClB,OAAO,SAAS,EAAE,aAAa,CA6EnC,CAAC;AAEF,eAAO,MAAM,iCAAiC;;;;CAmB7C,CAAC;AAEF,eAAO,MAAM,gCAAgC,4HAO7B,OAAO;;;;CAqBtB,CAAC;AAEF,eAAO,MAAM,4BAA4B,aAC7B,GAAG,SACN,MAAM,6BAEE,GAAG,KAAK,MAAM,GAAG,SAAS,WAChC,MAAM,gBACD,OAAO,QAsBrB,CAAC;AAEH,eAAO,MAAM,UAAU,SACf,GAAG,EAAE,WACF,WAAW,gBACN,OAAO,UAgCtB,CAAC;AAEF,eAAO,MAAM,cAAc,yBAEf,MAAM,EAAE,KACjB,WAAW,GAAG,SAWhB,CAAC;AAEF,eAAO,MAAM,gBAAgB,yBAEjB,MAAM,EAAE,KACjB,aAAa,EAoCd,CAAC;AAEH,eAAO,MAAM,sBAAsB,UAC1B,OAAO,MAAM,EAAE,GAAG,CAAC,WACjB,MAAM,QAKhB,CAAC"}
@@ -15,7 +15,9 @@
15
15
  */
16
16
  import _ from 'lodash';
17
17
  import { SimpleLinearRegression } from 'ml-regression-simple-linear';
18
- import { inferScaleTypeFromDomain } from './axis';
18
+ import { barsStyleConfig } from '../style-config/bars';
19
+ import { clampLinearDomain, inferScaleTypeFromDomain } from './axis';
20
+ import { getLinearDomainStackSeries } from './bars';
19
21
  import { formatDate, maxPrecision } from './format';
20
22
  import { getMinMaxDate, getMinMaxNumber, removeNilsFromDomain, } from './math';
21
23
  export const getValueFromObjectByPath = (object, path) => _.at(object, path)[0];
@@ -55,7 +57,7 @@ export const mirrorDomain = (domain) => {
55
57
  }
56
58
  return domain;
57
59
  };
58
- export const handleAxisDomainAndScaleType = (data, axis) => {
60
+ export const handleAxisDomainAndScaleType = (data, axis, isStacked) => {
59
61
  const hasData = Boolean(data.length);
60
62
  let res = {
61
63
  ...axis,
@@ -68,7 +70,9 @@ export const handleAxisDomainAndScaleType = (data, axis) => {
68
70
  const keys = typeof dataKey === 'string' ? [dataKey] : dataKey;
69
71
  const primitivesFromArray = keys.map((k) => getPrimitivesFromObjectArrayByPath(data, k));
70
72
  const domainData = _.flattenDeep(primitivesFromArray);
71
- let ownDomain = removeNilsFromDomain(domainData);
73
+ let ownDomain = isStacked
74
+ ? removeNilsFromDomain(getLinearDomainStackSeries(data, keys, domainData))
75
+ : removeNilsFromDomain(domainData);
72
76
  const st = inferScaleTypeFromDomain(domainData, scaleType);
73
77
  const hasCustomDomain = !!(domain?.length);
74
78
  if (hasCustomDomain) {
@@ -102,8 +106,14 @@ export const handleAxisDomainAndScaleType = (data, axis) => {
102
106
  else if (st === 'linear') {
103
107
  const minMaxNum = getMinMaxNumber(ownDomain);
104
108
  if (minMaxNum) {
105
- const [min, max] = minMaxNum;
106
- ownDomain = [min, _.ceil(max * 1.05)];
109
+ const clamped = clampLinearDomain(minMaxNum);
110
+ const [min, max] = clamped;
111
+ const extra = 1.05;
112
+ if (min === 0 && max > 0)
113
+ ownDomain = [min, _.ceil(max * extra)];
114
+ if (min < 0 && max === 0)
115
+ ownDomain = [_.floor(min * extra), max];
116
+ ownDomain = [_.floor(min * extra), _.ceil(max * extra)];
107
117
  }
108
118
  }
109
119
  res = {
@@ -114,7 +124,7 @@ export const handleAxisDomainAndScaleType = (data, axis) => {
114
124
  }
115
125
  return removeKeysFromObject(res, ['dataKey', 'style', 'rename']);
116
126
  };
117
- export const handleChartDomainAndScaleType = (data, index, series, overlay) => {
127
+ export const handleLineChartDomainAndScaleType = (data, index, series, overlay) => {
118
128
  const i = handleAxisDomainAndScaleType(data, index);
119
129
  const s = handleAxisDomainAndScaleType(data, series);
120
130
  const o = overlay
@@ -126,6 +136,25 @@ export const handleChartDomainAndScaleType = (data, index, series, overlay) => {
126
136
  overlay: o,
127
137
  };
128
138
  };
139
+ export const handleBarChartDomainAndScaleType = (data, index, series, overlay, isStacked) => {
140
+ const indexOverride = {
141
+ ...index,
142
+ scaleType: 'label',
143
+ paddingInner: barsStyleConfig.paddingInner,
144
+ paddingOuter: barsStyleConfig.paddingOuter,
145
+ round: true,
146
+ };
147
+ const i = handleAxisDomainAndScaleType(data, indexOverride);
148
+ const s = handleAxisDomainAndScaleType(data, series, isStacked);
149
+ const o = overlay
150
+ ? handleAxisDomainAndScaleType(data, overlay, isStacked)
151
+ : undefined;
152
+ return {
153
+ index: i,
154
+ series: s,
155
+ overlay: o,
156
+ };
157
+ };
129
158
  export const extractBarValueFromNestedKey = (barGroup, index, data, scale, maxSize, isHorizontal) => barGroup.bars.map((bar) => {
130
159
  if (!bar.value) {
131
160
  const newValue = getPrimitiveFromObjectByPath(data[index], bar.key);
@@ -211,3 +240,9 @@ export const computeTrendline = (data, dataKeys) => dataKeys.map((k) => {
211
240
  to,
212
241
  };
213
242
  });
243
+ export const getDataKeyParentObject = (datum, dataKey) => {
244
+ const labelFromPath = getLabelFromPath(dataKey);
245
+ if (labelFromPath === dataKey)
246
+ return datum;
247
+ return _.at(datum, labelFromPath)[0];
248
+ };
@@ -1,4 +1,4 @@
1
- import { computeAverage, computeTrendline, extractBarValueFromNestedKey, getLabelFromPath, getPrimitiveFromObjectByPath, getPrimitivesFromObjectArrayByPath, getValueFromObjectByPath, handleAxisDomainAndScaleType, handleChartDomainAndScaleType, mirrorDomain, sortBarsBy, } from './data';
1
+ import { computeAverage, computeTrendline, extractBarValueFromNestedKey, getDataKeyParentObject, getLabelFromPath, getPrimitiveFromObjectByPath, getPrimitivesFromObjectArrayByPath, getValueFromObjectByPath, handleAxisDomainAndScaleType, handleLineChartDomainAndScaleType, mirrorDomain, sortBarsBy, } from './data';
2
2
  const data = [
3
3
  {
4
4
  user: 'joe',
@@ -211,7 +211,7 @@ describe('handleAxisDomainAndScaleType()', () => {
211
211
  const res = handleAxisDomainAndScaleType(data, axis);
212
212
  const exp = {
213
213
  scaleType: 'linear',
214
- domain: [3, 105],
214
+ domain: [0, 105],
215
215
  };
216
216
  expect(res).toStrictEqual(exp);
217
217
  });
@@ -313,18 +313,18 @@ describe('handleChartDomainAndScaleType()', () => {
313
313
  const index = { dataKey: 'date' };
314
314
  const series = { dataKey: ['value', 'percentage'] };
315
315
  const overlay = { dataKey: ['overlay'] };
316
- const res = handleChartDomainAndScaleType(data, index, series, overlay);
316
+ const res = handleLineChartDomainAndScaleType(data, index, series, overlay);
317
317
  const exp = {
318
318
  index: {
319
319
  domain: ['01-01-2000', '01-01-2010', '01-01-2020'],
320
320
  scaleType: 'time',
321
321
  },
322
322
  series: {
323
- domain: [20, 105],
323
+ domain: [0, 105],
324
324
  scaleType: 'linear',
325
325
  },
326
326
  overlay: {
327
- domain: [12, 30],
327
+ domain: [0, 30],
328
328
  scaleType: 'linear',
329
329
  },
330
330
  };
@@ -354,14 +354,14 @@ describe('handleChartDomainAndScaleType()', () => {
354
354
  const index = { dataKey: 'date' };
355
355
  const series = { dataKey: ['value', 'percentage'] };
356
356
  const overlay = undefined;
357
- const res = handleChartDomainAndScaleType(data, index, series, overlay);
357
+ const res = handleLineChartDomainAndScaleType(data, index, series, overlay);
358
358
  const exp = {
359
359
  index: {
360
360
  domain: ['01-01-2000', '01-01-2010', '01-01-2020'],
361
361
  scaleType: 'time',
362
362
  },
363
363
  series: {
364
- domain: [20, 105],
364
+ domain: [0, 105],
365
365
  scaleType: 'linear',
366
366
  },
367
367
  overlay: undefined,
@@ -570,3 +570,19 @@ describe('mirrorDomain()', () => {
570
570
  expect(res).toStrictEqual(exp);
571
571
  });
572
572
  });
573
+ describe('getDataKeyParentObject()', () => {
574
+ it('should return datum', () => {
575
+ const datum = { key: 1, extra: 2 };
576
+ const datakey = 'key';
577
+ const res = getDataKeyParentObject(datum, datakey);
578
+ const exp = datum;
579
+ expect(res).toStrictEqual(exp);
580
+ });
581
+ it('should return parent object', () => {
582
+ const datum = { nested: { key: 1, extra: 2 } };
583
+ const datakey = 'nested.key';
584
+ const res = getDataKeyParentObject(datum, datakey);
585
+ const exp = { key: 1, extra: 2 };
586
+ expect(res).toStrictEqual(exp);
587
+ });
588
+ });
@@ -22,8 +22,8 @@ export declare const getMarkerLabelProps: (pos: {
22
22
  maxWidth: number;
23
23
  maxHeight: number;
24
24
  }, isHorizontal: boolean, theme: Theme) => {
25
- anchor: "end" | "middle" | "start" | "inherit" | undefined;
26
- verticalAnchor: "end" | "middle" | "start" | undefined;
25
+ anchor: "middle" | "inherit" | "end" | "start" | undefined;
26
+ verticalAnchor: "middle" | "end" | "start" | undefined;
27
27
  fontColor: string;
28
28
  fontSize: number;
29
29
  fontWeight: number;
@@ -37,7 +37,7 @@ export declare const getMarkerLabelProps: (pos: {
37
37
  titleProps: {
38
38
  x: number;
39
39
  y: number;
40
- textAnchor: "end" | "middle" | "start" | "inherit" | undefined;
40
+ textAnchor: "middle" | "inherit" | "end" | "start" | undefined;
41
41
  };
42
42
  backgroundProps: {
43
43
  rx: number;
@@ -1 +1 @@
1
- {"version":3,"file":"lines.d.ts","sourceRoot":"","sources":["../../src/utils/lines.ts"],"names":[],"mappings":"AAuBA,OAAO,EACL,aAAa,EAAE,IAAI,EAAE,mBAAmB,EAAE,KAAK,EAChD,MAAM,UAAU,CAAC;AAGlB,eAAO,MAAM,QAAQ,SAAU,aAAa,WAAW,MAAM,UAAU,OAAO,MAAM,EAAE,OAAO,CAAC,uBAU7F,CAAC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D,CAAC;AAEvF,eAAO,MAAM,cAAc;WAShB,OAAO,MAAM,EAAE,OAAO,CAAC;eACnB,aAAa;kBACV,MAAM;eACT,aAAa;kBACV,MAAM;kBACN,OAAO;;;;CASxB,CAAC;AAEF,eAAO,MAAM,gBAAgB,aAAc,mBAAmB,GAAG,SAAS,gBAAgB,OAAO,oCAOhG,CAAC;AAEF,eAAO,MAAM,oBAAoB,UAAW,MAAM,eAAe,MAAM,gCAatE,CAAC;AAEF,eAAO,MAAM,mBAAmB,QACzB;IAAE,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,aAC1C;IAAE,QAAQ,EAAE,MAAM,CAAE;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,gBACrC,OAAO,SACd,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;CA2Eb,CAAC;AAEF,eAAO,MAAM,eAAe,QACrB,MAAM,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC,iBACpB,OAAO,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,gCAgB9C,CAAC;AAEP,eAAO,MAAM,cAAc,8BAEV,OAAO,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,gCA6BnD,CAAC"}
@@ -70,7 +70,9 @@ export const getLinesRenderer = (renderAs, isHorizontal) => {
70
70
  return curveLinear;
71
71
  return whichStep;
72
72
  };
73
- export const isMarkerLabelVisible = (index, totalLabels, maxLabels = 12) => {
73
+ export const isMarkerLabelVisible = (index, totalLabels, maxLabels = 24) => {
74
+ if (totalLabels <= maxLabels)
75
+ return true;
74
76
  const divider = maxLabels > 1 ? maxLabels : 1;
75
77
  const step = Math.ceil(totalLabels / divider);
76
78
  const half = Math.round(totalLabels / 2);
@@ -307,7 +307,7 @@ describe('isMarkerLabelVisible()', () => {
307
307
  });
308
308
  it('should return true w/o maxLabel', () => {
309
309
  const isVisible = isMarkerLabelVisible(19, 20);
310
- expect(isVisible).not.toBeTruthy();
310
+ expect(isVisible).toBeTruthy();
311
311
  });
312
312
  });
313
313
  describe('getMarkerLabelProps()', () => {
@@ -1,8 +1,6 @@
1
- import { LineChartSeries } from '../types';
1
+ import { ChartSeries, LineChartSeries } from '../types';
2
2
  import { BarChartSeries } from '../types/bar-chart';
3
- declare type ChartSeries = LineChartSeries | BarChartSeries;
4
- export declare const handleSeriesNames: (series: ChartSeries) => string[];
3
+ export declare const handleSeriesNames: <T extends ChartSeries>(series: T) => string[];
5
4
  export declare const handleLineChartSeriesColors: (series: LineChartSeries, palette: string[]) => string[];
6
5
  export declare const handleBarChartSeriesColors: (series: BarChartSeries, palette: string[]) => string[];
7
- export {};
8
6
  //# sourceMappingURL=metadata.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/utils/metadata.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD,aAAK,WAAW,GAAG,eAAe,GAAG,cAAc,CAAC;AAEpD,eAAO,MAAM,iBAAiB,WACpB,WAAW,aAInB,CAAC;AAEH,eAAO,MAAM,2BAA2B,WAC9B,eAAe,WACd,MAAM,EAAE,aAGjB,CAAC;AAEH,eAAO,MAAM,0BAA0B,WAC7B,cAAc,WACb,MAAM,EAAE,aAGjB,CAAC"}
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/utils/metadata.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD,eAAO,MAAM,iBAAiB,wCAE3B,MAAM,EAUL,CAAC;AAEL,eAAO,MAAM,2BAA2B,WAC9B,eAAe,WACd,MAAM,EAAE,KAChB,MAAM,EAEP,CAAC;AAEH,eAAO,MAAM,0BAA0B,WAC7B,cAAc,WACb,MAAM,EAAE,aAGjB,CAAC"}
@@ -16,6 +16,11 @@
16
16
  import _ from 'lodash';
17
17
  import { getLabelFromPath } from './data';
18
18
  export const handleSeriesNames = (series) => series.dataKey.map((s, i) => {
19
+ const hasAxisLabel = Boolean(series.label);
20
+ const hasSingleKey = series.dataKey.length === 1;
21
+ const hasRenaming = Boolean(series.rename);
22
+ if (hasSingleKey && hasAxisLabel && !hasRenaming)
23
+ return _.startCase(series.label);
19
24
  const renamed = series.rename ? series.rename(s, i) : getLabelFromPath(s);
20
25
  return _.startCase(renamed);
21
26
  });
@@ -12,10 +12,10 @@ describe('handleSeriesNames()', () => {
12
12
  it('should return renamed labels', () => {
13
13
  const series = {
14
14
  dataKey: ['test1', 'test2'],
15
- rename: (k, i) => k.replace('test', `index ${i * 5}`),
15
+ rename: k => k.replace('test', 'item'),
16
16
  };
17
17
  const res = handleSeriesNames(series);
18
- const exp = ['Index 01', 'Index 52'];
18
+ const exp = ['Item 1', 'Item 2'];
19
19
  expect(res).toStrictEqual(exp);
20
20
  });
21
21
  });