@react-magma/charts 12.0.1 → 13.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 (82) hide show
  1. package/dist/charts.js +1 -2450
  2. package/dist/charts.js.map +1 -1
  3. package/dist/charts.modern.module.js +1 -2428
  4. package/dist/charts.modern.module.js.map +1 -1
  5. package/dist/charts.umd.js +1 -48555
  6. package/dist/charts.umd.js.map +1 -1
  7. package/dist/components/CarbonChart/CarbonChart.d.ts +1 -2
  8. package/dist/components/CarbonChart/CarbonChart.test.d.ts +1 -0
  9. package/dist/components/CarbonChart/embeddedStyles.d.ts +1 -0
  10. package/dist/index.d.ts +0 -1
  11. package/package.json +25 -27
  12. package/src/components/CarbonChart/CarbonChart.tsx +18 -13
  13. package/src/components/CarbonChart/CarbonChartArea.stories.tsx +1 -1
  14. package/src/components/CarbonChart/CarbonChartAreaStacked.stories.tsx +1 -1
  15. package/src/components/CarbonChart/CarbonChartBar.stories.tsx +1 -1
  16. package/src/components/CarbonChart/CarbonChartBarFloating.stories.tsx +1 -1
  17. package/src/components/CarbonChart/CarbonChartBarGrouped.stories.tsx +1 -1
  18. package/src/components/CarbonChart/CarbonChartBarStacked.stories.tsx +1 -1
  19. package/src/components/CarbonChart/CarbonChartBoxplot.stories.tsx +1 -1
  20. package/src/components/CarbonChart/CarbonChartBubble.stories.tsx +1 -1
  21. package/src/components/CarbonChart/CarbonChartBullet.stories.tsx +1 -1
  22. package/src/components/CarbonChart/CarbonChartCombo.stories.tsx +1 -1
  23. package/src/components/CarbonChart/CarbonChartDonut.stories.tsx +1 -1
  24. package/src/components/CarbonChart/CarbonChartGauge.stories.tsx +1 -1
  25. package/src/components/CarbonChart/CarbonChartHistogram.stories.tsx +1 -1
  26. package/src/components/CarbonChart/CarbonChartLine.stories.tsx +1 -1
  27. package/src/components/CarbonChart/CarbonChartLollipop.stories.tsx +1 -1
  28. package/src/components/CarbonChart/CarbonChartMeter.stories.tsx +1 -1
  29. package/src/components/CarbonChart/CarbonChartPie.stories.tsx +1 -1
  30. package/src/components/CarbonChart/CarbonChartRadar.stories.tsx +1 -1
  31. package/src/components/CarbonChart/CarbonChartScatter.stories.tsx +1 -1
  32. package/src/components/CarbonChart/CarbonChartSparkline.stories.tsx +1 -1
  33. package/src/components/CarbonChart/CarbonChartStep.stories.tsx +1 -1
  34. package/src/components/CarbonChart/embeddedStyles.ts +24880 -0
  35. package/src/index.ts +0 -1
  36. package/dist/components/CarbonChart/CarbonChartArea.stories.d.ts +0 -310
  37. package/dist/components/CarbonChart/CarbonChartAreaStacked.stories.d.ts +0 -136
  38. package/dist/components/CarbonChart/CarbonChartBar.stories.d.ts +0 -214
  39. package/dist/components/CarbonChart/CarbonChartBarFloating.stories.d.ts +0 -82
  40. package/dist/components/CarbonChart/CarbonChartBarGrouped.stories.d.ts +0 -234
  41. package/dist/components/CarbonChart/CarbonChartBarStacked.stories.d.ts +0 -266
  42. package/dist/components/CarbonChart/CarbonChartBoxplot.stories.d.ts +0 -53
  43. package/dist/components/CarbonChart/CarbonChartBubble.stories.d.ts +0 -196
  44. package/dist/components/CarbonChart/CarbonChartBullet.stories.d.ts +0 -35
  45. package/dist/components/CarbonChart/CarbonChartCombo.stories.d.ts +0 -580
  46. package/dist/components/CarbonChart/CarbonChartDonut.stories.d.ts +0 -120
  47. package/dist/components/CarbonChart/CarbonChartGauge.stories.d.ts +0 -43
  48. package/dist/components/CarbonChart/CarbonChartHistogram.stories.d.ts +0 -89
  49. package/dist/components/CarbonChart/CarbonChartLine.stories.d.ts +0 -577
  50. package/dist/components/CarbonChart/CarbonChartLollipop.stories.d.ts +0 -55
  51. package/dist/components/CarbonChart/CarbonChartMeter.stories.d.ts +0 -127
  52. package/dist/components/CarbonChart/CarbonChartPie.stories.d.ts +0 -101
  53. package/dist/components/CarbonChart/CarbonChartRadar.stories.d.ts +0 -98
  54. package/dist/components/CarbonChart/CarbonChartScatter.stories.d.ts +0 -173
  55. package/dist/components/CarbonChart/CarbonChartSparkline.stories.d.ts +0 -51
  56. package/dist/components/CarbonChart/CarbonChartStep.stories.d.ts +0 -38
  57. package/dist/components/LineChart/Chart.d.ts +0 -27
  58. package/dist/components/LineChart/ChartDataTable.d.ts +0 -17
  59. package/dist/components/LineChart/CustomAxisComponent.d.ts +0 -3
  60. package/dist/components/LineChart/CustomPointComponent.d.ts +0 -17
  61. package/dist/components/LineChart/DataTable.d.ts +0 -5
  62. package/dist/components/LineChart/GraphTooltip.d.ts +0 -3
  63. package/dist/components/LineChart/LegendButton.d.ts +0 -6
  64. package/dist/components/LineChart/LineChart.d.ts +0 -67
  65. package/dist/components/LineChart/LineChart.stories.d.ts +0 -113
  66. package/dist/components/LineChart/index.d.ts +0 -1
  67. package/dist/components/LineChart/magma-charts.d.ts +0 -1
  68. package/src/components/CarbonChart/carbon-charts.css +0 -7303
  69. package/src/components/LineChart/Chart.tsx +0 -241
  70. package/src/components/LineChart/ChartDataTable.test.js +0 -165
  71. package/src/components/LineChart/ChartDataTable.tsx +0 -135
  72. package/src/components/LineChart/CustomAxisComponent.tsx +0 -30
  73. package/src/components/LineChart/CustomPointComponent.tsx +0 -93
  74. package/src/components/LineChart/DataTable.tsx +0 -57
  75. package/src/components/LineChart/GraphTooltip.tsx +0 -100
  76. package/src/components/LineChart/LegendButton.tsx +0 -77
  77. package/src/components/LineChart/LineChart.stories.tsx +0 -399
  78. package/src/components/LineChart/LineChart.test.js +0 -501
  79. package/src/components/LineChart/LineChart.tsx +0 -669
  80. package/src/components/LineChart/index.ts +0 -1
  81. package/src/components/LineChart/magma-charts.ts +0 -279
  82. package/src/components/LineChart/test/exampleChartData.js +0 -289
@@ -1,501 +0,0 @@
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
- });