@react-magma/charts 13.0.0 → 13.0.1

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 (83) hide show
  1. package/dist/charts.js +2450 -1
  2. package/dist/charts.js.map +1 -1
  3. package/dist/charts.modern.module.js +2428 -1
  4. package/dist/charts.modern.module.js.map +1 -1
  5. package/dist/charts.umd.js +49165 -1
  6. package/dist/charts.umd.js.map +1 -1
  7. package/dist/components/CarbonChart/CarbonChart.d.ts +2 -1
  8. package/dist/components/CarbonChart/CarbonChartArea.stories.d.ts +310 -0
  9. package/dist/components/CarbonChart/CarbonChartAreaStacked.stories.d.ts +136 -0
  10. package/dist/components/CarbonChart/CarbonChartBar.stories.d.ts +214 -0
  11. package/dist/components/CarbonChart/CarbonChartBarFloating.stories.d.ts +82 -0
  12. package/dist/components/CarbonChart/CarbonChartBarGrouped.stories.d.ts +234 -0
  13. package/dist/components/CarbonChart/CarbonChartBarStacked.stories.d.ts +266 -0
  14. package/dist/components/CarbonChart/CarbonChartBoxplot.stories.d.ts +53 -0
  15. package/dist/components/CarbonChart/CarbonChartBubble.stories.d.ts +196 -0
  16. package/dist/components/CarbonChart/CarbonChartBullet.stories.d.ts +35 -0
  17. package/dist/components/CarbonChart/CarbonChartCombo.stories.d.ts +580 -0
  18. package/dist/components/CarbonChart/CarbonChartDonut.stories.d.ts +120 -0
  19. package/dist/components/CarbonChart/CarbonChartGauge.stories.d.ts +43 -0
  20. package/dist/components/CarbonChart/CarbonChartHistogram.stories.d.ts +89 -0
  21. package/dist/components/CarbonChart/CarbonChartLine.stories.d.ts +577 -0
  22. package/dist/components/CarbonChart/CarbonChartLollipop.stories.d.ts +55 -0
  23. package/dist/components/CarbonChart/CarbonChartMeter.stories.d.ts +127 -0
  24. package/dist/components/CarbonChart/CarbonChartPie.stories.d.ts +101 -0
  25. package/dist/components/CarbonChart/CarbonChartRadar.stories.d.ts +98 -0
  26. package/dist/components/CarbonChart/CarbonChartScatter.stories.d.ts +173 -0
  27. package/dist/components/CarbonChart/CarbonChartSparkline.stories.d.ts +51 -0
  28. package/dist/components/CarbonChart/CarbonChartStep.stories.d.ts +38 -0
  29. package/dist/components/LineChart/Chart.d.ts +27 -0
  30. package/dist/components/LineChart/ChartDataTable.d.ts +17 -0
  31. package/dist/components/LineChart/CustomAxisComponent.d.ts +3 -0
  32. package/dist/components/LineChart/CustomPointComponent.d.ts +17 -0
  33. package/dist/components/LineChart/DataTable.d.ts +5 -0
  34. package/dist/components/LineChart/GraphTooltip.d.ts +3 -0
  35. package/dist/components/LineChart/LegendButton.d.ts +6 -0
  36. package/dist/components/LineChart/LineChart.d.ts +67 -0
  37. package/dist/components/LineChart/LineChart.stories.d.ts +113 -0
  38. package/dist/components/LineChart/index.d.ts +1 -0
  39. package/dist/components/LineChart/magma-charts.d.ts +1 -0
  40. package/dist/index.d.ts +1 -0
  41. package/package.json +28 -26
  42. package/src/components/CarbonChart/CarbonChart.test.js +506 -0
  43. package/src/components/CarbonChart/CarbonChart.tsx +53 -57
  44. package/src/components/CarbonChart/CarbonChartArea.stories.tsx +1 -1
  45. package/src/components/CarbonChart/CarbonChartAreaStacked.stories.tsx +1 -1
  46. package/src/components/CarbonChart/CarbonChartBar.stories.tsx +1 -1
  47. package/src/components/CarbonChart/CarbonChartBarFloating.stories.tsx +1 -1
  48. package/src/components/CarbonChart/CarbonChartBarGrouped.stories.tsx +1 -1
  49. package/src/components/CarbonChart/CarbonChartBarStacked.stories.tsx +1 -1
  50. package/src/components/CarbonChart/CarbonChartBoxplot.stories.tsx +1 -1
  51. package/src/components/CarbonChart/CarbonChartBubble.stories.tsx +1 -1
  52. package/src/components/CarbonChart/CarbonChartBullet.stories.tsx +1 -1
  53. package/src/components/CarbonChart/CarbonChartCombo.stories.tsx +1 -1
  54. package/src/components/CarbonChart/CarbonChartDonut.stories.tsx +1 -1
  55. package/src/components/CarbonChart/CarbonChartGauge.stories.tsx +1 -1
  56. package/src/components/CarbonChart/CarbonChartHistogram.stories.tsx +1 -1
  57. package/src/components/CarbonChart/CarbonChartLine.stories.tsx +1 -1
  58. package/src/components/CarbonChart/CarbonChartLollipop.stories.tsx +1 -1
  59. package/src/components/CarbonChart/CarbonChartMeter.stories.tsx +1 -1
  60. package/src/components/CarbonChart/CarbonChartPie.stories.tsx +1 -1
  61. package/src/components/CarbonChart/CarbonChartRadar.stories.tsx +1 -1
  62. package/src/components/CarbonChart/CarbonChartScatter.stories.tsx +1 -1
  63. package/src/components/CarbonChart/CarbonChartSparkline.stories.tsx +1 -1
  64. package/src/components/CarbonChart/CarbonChartStep.stories.tsx +1 -1
  65. package/src/components/CarbonChart/carbon-charts.css +24931 -0
  66. package/src/components/LineChart/Chart.tsx +241 -0
  67. package/src/components/LineChart/ChartDataTable.test.js +165 -0
  68. package/src/components/LineChart/ChartDataTable.tsx +135 -0
  69. package/src/components/LineChart/CustomAxisComponent.tsx +30 -0
  70. package/src/components/LineChart/CustomPointComponent.tsx +93 -0
  71. package/src/components/LineChart/DataTable.tsx +57 -0
  72. package/src/components/LineChart/GraphTooltip.tsx +100 -0
  73. package/src/components/LineChart/LegendButton.tsx +77 -0
  74. package/src/components/LineChart/LineChart.stories.tsx +399 -0
  75. package/src/components/LineChart/LineChart.test.js +501 -0
  76. package/src/components/LineChart/LineChart.tsx +669 -0
  77. package/src/components/LineChart/index.ts +1 -0
  78. package/src/components/LineChart/magma-charts.ts +279 -0
  79. package/src/components/LineChart/test/exampleChartData.js +289 -0
  80. package/src/index.ts +1 -0
  81. package/dist/components/CarbonChart/CarbonChart.test.d.ts +0 -1
  82. package/dist/components/CarbonChart/embeddedStyles.d.ts +0 -1
  83. package/src/components/CarbonChart/embeddedStyles.ts +0 -24880
@@ -0,0 +1,501 @@
1
+ import * as React from 'react';
2
+
3
+ import { render, fireEvent } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+ import { defaultI18n } from 'react-magma-dom';
6
+
7
+ import { basicData, explicitData } from './test/exampleChartData';
8
+
9
+ import { Chart } from '.';
10
+
11
+ const componentProps = {
12
+ xAxis: {
13
+ label: '2019 Annual Sales Figures',
14
+ tickFormat: ['Jan', 'Feb', 'March', 'April', 'May'],
15
+ },
16
+ yAxis: {
17
+ domain: [0, 8],
18
+ label: 'Conversion Rate',
19
+ tickFormat: t => `$${t}0k`,
20
+ tickValues: [1, 2, 3, 4, 5, 6, 7, 8],
21
+ },
22
+ };
23
+
24
+ describe('Line Chart', () => {
25
+ it('should render with basic x/y data', () => {
26
+ const { getByText, getByLabelText } = render(
27
+ <Chart
28
+ componentProps={componentProps}
29
+ type="line"
30
+ data={basicData}
31
+ title="Basic"
32
+ />
33
+ );
34
+
35
+ expect(getByText(componentProps.xAxis.label)).toBeInTheDocument();
36
+ expect(getByText(componentProps.yAxis.label)).toBeInTheDocument();
37
+ expect(getByText('Jan')).toBeInTheDocument();
38
+ expect(getByLabelText(basicData[0].data[0].label)).toBeInTheDocument();
39
+ });
40
+
41
+ it('should render with explicit data', () => {
42
+ const { getByText, getByLabelText } = render(
43
+ <Chart
44
+ componentProps={componentProps}
45
+ type="line"
46
+ data={explicitData}
47
+ title="Basic"
48
+ x="month"
49
+ y="sales"
50
+ />
51
+ );
52
+
53
+ expect(getByText(componentProps.xAxis.label)).toBeInTheDocument();
54
+ expect(getByText(componentProps.yAxis.label)).toBeInTheDocument();
55
+ expect(getByText('Jan')).toBeInTheDocument();
56
+ expect(getByLabelText(explicitData[0].data[0].label)).toBeInTheDocument();
57
+ });
58
+
59
+ it('should render point data in a tooltip on focus', () => {
60
+ const { getByText, getByLabelText } = render(
61
+ <Chart
62
+ componentProps={componentProps}
63
+ type="line"
64
+ data={basicData}
65
+ title="Basic"
66
+ />
67
+ );
68
+
69
+ const firstScatterPoint = getByLabelText(basicData[0].data[0].label);
70
+ fireEvent.focus(firstScatterPoint);
71
+
72
+ expect(getByText(basicData[0].data[0].label)).toBeInTheDocument();
73
+ });
74
+
75
+ it('should render point data in a tooltip on hover', () => {
76
+ const { getByText, getByLabelText } = render(
77
+ <Chart
78
+ componentProps={componentProps}
79
+ type="line"
80
+ data={basicData}
81
+ title="Basic"
82
+ />
83
+ );
84
+
85
+ const firstScatterPoint = getByLabelText(basicData[0].data[0].label);
86
+ fireEvent.mouseOver(firstScatterPoint);
87
+
88
+ expect(getByText(basicData[0].data[0].label)).toBeInTheDocument();
89
+ });
90
+
91
+ it('should highlight only hovered line', () => {
92
+ const { container, getByText } = render(
93
+ <Chart
94
+ componentProps={componentProps}
95
+ type="line"
96
+ data={basicData}
97
+ title="Basic"
98
+ />
99
+ );
100
+
101
+ userEvent.hover(getByText('Team 2'));
102
+
103
+ expect(
104
+ container.querySelectorAll('svg')[3].childNodes[2].querySelector('path')
105
+ ).toHaveStyle('opacity: 1');
106
+ expect(
107
+ container.querySelectorAll('svg')[3].childNodes[3].querySelector('path')
108
+ ).toHaveStyle('opacity: .1');
109
+ });
110
+
111
+ it('should unrender line if legend button is clicked', () => {
112
+ const { container, getByText } = render(
113
+ <Chart
114
+ componentProps={componentProps}
115
+ type="line"
116
+ data={basicData}
117
+ title="Basic"
118
+ />
119
+ );
120
+
121
+ expect(container.querySelectorAll('svg')[3].childNodes.length).toEqual(10);
122
+
123
+ userEvent.click(getByText('Team 2'));
124
+
125
+ expect(container.querySelectorAll('svg')[3].childNodes.length).toEqual(8);
126
+ });
127
+
128
+ describe('keyboard behavior', () => {
129
+ it('should only tab in to the graph and out, not between lines or scatter points', () => {
130
+ const { getByText, getByLabelText } = render(
131
+ <Chart
132
+ componentProps={componentProps}
133
+ type="line"
134
+ data={basicData}
135
+ title="Basic"
136
+ />
137
+ );
138
+
139
+ userEvent.click(getByText(/chart/i, { selector: 'button' }));
140
+ userEvent.tab();
141
+ userEvent.tab();
142
+
143
+ expect(getByLabelText(basicData[0].data[0].label)).toHaveFocus();
144
+
145
+ userEvent.tab();
146
+
147
+ expect(getByLabelText(/team 1/i, { selector: 'input' })).toHaveFocus();
148
+ });
149
+
150
+ it('should only shift tab in to the graph and out, not between lines or scatter points', () => {
151
+ const { getByText, getByLabelText } = render(
152
+ <Chart
153
+ componentProps={componentProps}
154
+ type="line"
155
+ data={basicData}
156
+ title="Basic"
157
+ />
158
+ );
159
+
160
+ userEvent.click(getByText(/team 1/i));
161
+
162
+ userEvent.tab({ shift: true });
163
+
164
+ expect(getByLabelText(basicData[3].data[4].label)).toHaveFocus();
165
+
166
+ userEvent.tab({ shift: true });
167
+
168
+ expect(
169
+ getByLabelText(defaultI18n.charts.line.keyboardInstructionsTooltip)
170
+ ).toHaveFocus();
171
+ });
172
+
173
+ it('should focus last focused scatter point when tabbing or shift tabbing back in to the chart', () => {
174
+ const data = [
175
+ {
176
+ name: 'Team 1',
177
+ data: [
178
+ { x: 1, y: 3.9, label: 'Team 1, January, $39k' },
179
+ { x: 2, y: 2.8, label: 'Team 1, February, $28k' },
180
+ ],
181
+ },
182
+ {
183
+ name: 'Team 2',
184
+ data: [
185
+ { x: 1, y: 2.7, label: 'Team 2, January, $39k' },
186
+ { x: 2, y: 3.3, label: 'Team 2, February, $33k' },
187
+ ],
188
+ },
189
+ ];
190
+ const { getByText, getByLabelText } = render(
191
+ <Chart
192
+ componentProps={componentProps}
193
+ type="line"
194
+ data={data}
195
+ title="Basic"
196
+ />
197
+ );
198
+
199
+ userEvent.click(getByText(/chart/i, { selector: 'button' }));
200
+ userEvent.tab();
201
+ userEvent.tab();
202
+
203
+ expect(getByLabelText(basicData[0].data[0].label)).toHaveFocus();
204
+
205
+ userEvent.keyboard('{arrowright}');
206
+
207
+ expect(getByLabelText(data[0].data[1].label)).toHaveFocus();
208
+
209
+ userEvent.tab();
210
+ userEvent.tab({ shift: true });
211
+
212
+ expect(getByLabelText(data[0].data[1].label)).toHaveFocus();
213
+
214
+ userEvent.tab({ shift: true });
215
+ userEvent.tab();
216
+
217
+ expect(getByLabelText(data[0].data[1].label)).toHaveFocus();
218
+ });
219
+
220
+ it('should focus last scatter point in the graph when shift tabbing back in to the chart and the last focused scatter point is no longer on the graph', () => {
221
+ const data = [
222
+ {
223
+ name: 'Team 1',
224
+ data: [
225
+ { x: 1, y: 3.9, label: 'Team 1, January, $39k' },
226
+ { x: 2, y: 2.8, label: 'Team 1, February, $28k' },
227
+ ],
228
+ },
229
+ {
230
+ name: 'Team 2',
231
+ data: [
232
+ { x: 1, y: 2.7, label: 'Team 2, January, $39k' },
233
+ { x: 2, y: 3.3, label: 'Team 2, February, $33k' },
234
+ ],
235
+ },
236
+ ];
237
+ const { getByText, getByLabelText } = render(
238
+ <Chart
239
+ componentProps={componentProps}
240
+ type="line"
241
+ data={data}
242
+ title="Basic"
243
+ />
244
+ );
245
+
246
+ userEvent.click(getByText(/chart/i, { selector: 'button' }));
247
+ userEvent.tab();
248
+ userEvent.tab();
249
+
250
+ expect(getByLabelText(basicData[0].data[0].label)).toHaveFocus();
251
+
252
+ userEvent.tab();
253
+ userEvent.keyboard('{space}');
254
+ userEvent.tab({ shift: true });
255
+
256
+ expect(getByLabelText(data[1].data[1].label)).toHaveFocus();
257
+ });
258
+
259
+ it('should use right arrow keys to go through scatter points', () => {
260
+ const data = [
261
+ {
262
+ name: 'Team 1',
263
+ data: [
264
+ { x: 1, y: 3.9, label: 'Team 1, January, $39k' },
265
+ { x: 2, y: 2.8, label: 'Team 1, February, $28k' },
266
+ ],
267
+ },
268
+ {
269
+ name: 'Team 2',
270
+ data: [
271
+ { x: 1, y: 2.7, label: 'Team 2, January, $39k' },
272
+ { x: 2, y: 3.3, label: 'Team 2, February, $33k' },
273
+ ],
274
+ },
275
+ ];
276
+ const { getByText, getByLabelText } = render(
277
+ <Chart
278
+ componentProps={componentProps}
279
+ type="line"
280
+ data={data}
281
+ title="Basic"
282
+ />
283
+ );
284
+
285
+ userEvent.click(getByText(/chart/i, { selector: 'button' }));
286
+ userEvent.tab();
287
+ userEvent.tab();
288
+
289
+ expect(getByLabelText(data[0].data[0].label)).toHaveFocus();
290
+
291
+ userEvent.keyboard('{arrowright}');
292
+
293
+ expect(getByLabelText(data[0].data[1].label)).toHaveFocus();
294
+
295
+ userEvent.keyboard('{arrowright}');
296
+
297
+ expect(getByLabelText(data[1].data[0].label)).toHaveFocus();
298
+ });
299
+
300
+ it('should use left arrow keys to go through scatter points', () => {
301
+ const data = [
302
+ {
303
+ name: 'Team 1',
304
+ data: [
305
+ { x: 1, y: 3.9, label: 'Team 1, January, $39k' },
306
+ { x: 2, y: 2.8, label: 'Team 1, February, $28k' },
307
+ ],
308
+ },
309
+ {
310
+ name: 'Team 2',
311
+ data: [
312
+ { x: 1, y: 2.7, label: 'Team 2, January, $39k' },
313
+ { x: 2, y: 3.3, label: 'Team 2, February, $33k' },
314
+ ],
315
+ },
316
+ ];
317
+ const { getByText, getByLabelText } = render(
318
+ <Chart
319
+ componentProps={componentProps}
320
+ type="line"
321
+ data={data}
322
+ title="Basic"
323
+ />
324
+ );
325
+
326
+ userEvent.click(getByText(/team 1/i));
327
+ userEvent.click(getByText(/team 1/i));
328
+ userEvent.tab({ shift: true });
329
+
330
+ expect(getByLabelText(data[1].data[1].label)).toHaveFocus();
331
+
332
+ userEvent.keyboard('{arrowleft}');
333
+
334
+ expect(getByLabelText(data[1].data[0].label)).toHaveFocus();
335
+
336
+ userEvent.keyboard('{arrowleft}');
337
+
338
+ expect(getByLabelText(data[0].data[1].label)).toHaveFocus();
339
+ });
340
+
341
+ it('should wrap to the last scatter point when the left arrow key is clicked while focusing the first scatter point', () => {
342
+ const data = [
343
+ {
344
+ name: 'Team 1',
345
+ data: [
346
+ { x: 1, y: 3.9, label: 'Team 1, January, $39k' },
347
+ { x: 2, y: 2.8, label: 'Team 1, February, $28k' },
348
+ ],
349
+ },
350
+ {
351
+ name: 'Team 2',
352
+ data: [
353
+ { x: 1, y: 2.7, label: 'Team 2, January, $39k' },
354
+ { x: 2, y: 3.3, label: 'Team 2, February, $33k' },
355
+ ],
356
+ },
357
+ ];
358
+ const { getByText, getByLabelText } = render(
359
+ <Chart
360
+ componentProps={componentProps}
361
+ type="line"
362
+ data={data}
363
+ title="Basic"
364
+ />
365
+ );
366
+
367
+ userEvent.click(getByText(/chart/i, { selector: 'button' }));
368
+ userEvent.tab();
369
+ userEvent.tab();
370
+
371
+ expect(getByLabelText(data[0].data[0].label)).toHaveFocus();
372
+
373
+ userEvent.keyboard('{arrowleft}');
374
+
375
+ expect(getByLabelText(data[1].data[1].label)).toHaveFocus();
376
+ });
377
+
378
+ it('should wrap to the first scatter point when the right arrow key is clicked while focusing the last scatter point', () => {
379
+ const data = [
380
+ {
381
+ name: 'Team 1',
382
+ data: [
383
+ { x: 1, y: 3.9, label: 'Team 1, January, $39k' },
384
+ { x: 2, y: 2.8, label: 'Team 1, February, $28k' },
385
+ ],
386
+ },
387
+ {
388
+ name: 'Team 2',
389
+ data: [
390
+ { x: 1, y: 2.7, label: 'Team 2, January, $39k' },
391
+ { x: 2, y: 3.3, label: 'Team 2, February, $33k' },
392
+ ],
393
+ },
394
+ ];
395
+ const { getByText, getByLabelText } = render(
396
+ <Chart
397
+ componentProps={componentProps}
398
+ type="line"
399
+ data={data}
400
+ title="Basic"
401
+ />
402
+ );
403
+
404
+ userEvent.click(getByText(/chart/i, { selector: 'button' }));
405
+ userEvent.tab();
406
+ userEvent.tab();
407
+ userEvent.keyboard('{arrowdown}');
408
+ userEvent.keyboard('{arrowright}');
409
+
410
+ expect(getByLabelText(data[1].data[1].label)).toHaveFocus();
411
+
412
+ userEvent.keyboard('{arrowright}');
413
+
414
+ expect(getByLabelText(data[0].data[0].label)).toHaveFocus();
415
+ });
416
+
417
+ it('should go to the next line when clicking the down arrow key', () => {
418
+ const { getByText, getByLabelText } = render(
419
+ <Chart
420
+ componentProps={componentProps}
421
+ type="line"
422
+ data={basicData}
423
+ title="Basic"
424
+ />
425
+ );
426
+
427
+ userEvent.click(getByText(/chart/i, { selector: 'button' }));
428
+ userEvent.tab();
429
+ userEvent.tab();
430
+
431
+ expect(getByLabelText(basicData[0].data[0].label)).toHaveFocus();
432
+
433
+ userEvent.keyboard('{arrowdown}');
434
+
435
+ expect(getByLabelText(basicData[1].data[0].label)).toHaveFocus();
436
+ });
437
+
438
+ it('should go to the previous line when clicking the up arrow key', () => {
439
+ const { getByText, getByLabelText } = render(
440
+ <Chart
441
+ componentProps={componentProps}
442
+ type="line"
443
+ data={basicData}
444
+ title="Basic"
445
+ />
446
+ );
447
+
448
+ userEvent.click(getByText(/team 1/i));
449
+ userEvent.click(getByText(/team 1/i));
450
+ userEvent.tab({ shift: true });
451
+
452
+ expect(getByLabelText(basicData[3].data[4].label)).toHaveFocus();
453
+
454
+ userEvent.keyboard('{arrowup}');
455
+
456
+ expect(getByLabelText(basicData[2].data[4].label)).toHaveFocus();
457
+ });
458
+
459
+ it('should wrap to the last line when clicking the up arrow key while focused on the first line', () => {
460
+ const { getByText, getByLabelText } = render(
461
+ <Chart
462
+ componentProps={componentProps}
463
+ type="line"
464
+ data={basicData}
465
+ title="Basic"
466
+ />
467
+ );
468
+
469
+ userEvent.click(getByText(/chart/i, { selector: 'button' }));
470
+ userEvent.tab();
471
+ userEvent.tab();
472
+
473
+ expect(getByLabelText(basicData[0].data[0].label)).toHaveFocus();
474
+
475
+ userEvent.keyboard('{arrowup}');
476
+
477
+ expect(getByLabelText(basicData[3].data[0].label)).toHaveFocus();
478
+ });
479
+
480
+ it('should wrap to the first line when clicking the down arrow key while focused on the last line', () => {
481
+ const { getByText, getByLabelText } = render(
482
+ <Chart
483
+ componentProps={componentProps}
484
+ type="line"
485
+ data={basicData}
486
+ title="Basic"
487
+ />
488
+ );
489
+
490
+ userEvent.click(getByText(/team 1/i));
491
+ userEvent.click(getByText(/team 1/i));
492
+ userEvent.tab({ shift: true });
493
+
494
+ expect(getByLabelText(basicData[3].data[4].label)).toHaveFocus();
495
+
496
+ userEvent.keyboard('{arrowdown}');
497
+
498
+ expect(getByLabelText(basicData[0].data[4].label)).toHaveFocus();
499
+ });
500
+ });
501
+ });