@react-magma/charts 0.0.0-9de073 → 0.0.0-next.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.
- package/README.md +1 -40
- package/dist/charts.js +1 -1
- package/dist/charts.js.map +1 -1
- package/dist/charts.modern.js +63 -25
- package/dist/charts.modern.js.map +1 -1
- package/dist/charts.modern.module.js +1 -1
- package/dist/charts.modern.module.js.map +1 -1
- package/dist/charts.umd.js +1 -1
- package/dist/charts.umd.js.map +1 -1
- package/dist/components/LineChart/Chart.d.ts +11 -2
- package/dist/components/LineChart/ChartDataTable.d.ts +2 -1
- package/dist/components/LineChart/CustomAxisComponent.d.ts +3 -0
- package/dist/components/LineChart/CustomPointComponent.d.ts +17 -1
- package/dist/components/LineChart/DataTable.d.ts +1 -0
- package/dist/components/LineChart/GraphTooltip.d.ts +2 -1
- package/dist/components/LineChart/LegendButton.d.ts +1 -1
- package/dist/components/LineChart/LineChart.d.ts +29 -1
- package/dist/components/LineChart/LineChart.stories.d.ts +6 -7
- package/dist/components/LineChart/magma-charts.d.ts +1 -457
- package/dist/index.d.ts +0 -1
- package/package.json +8 -6
- package/src/components/LineChart/Chart.tsx +180 -20
- package/src/components/LineChart/ChartDataTable.test.js +1 -1
- package/src/components/LineChart/ChartDataTable.tsx +38 -32
- package/src/components/LineChart/CustomAxisComponent.tsx +29 -0
- package/src/components/LineChart/CustomPointComponent.tsx +81 -8
- package/src/components/LineChart/DataTable.tsx +3 -1
- package/src/components/LineChart/GraphTooltip.tsx +58 -26
- package/src/components/LineChart/LegendButton.tsx +32 -32
- package/src/components/LineChart/LineChart.stories.tsx +9 -9
- package/src/components/LineChart/LineChart.test.js +105 -11
- package/src/components/LineChart/LineChart.tsx +277 -113
- package/src/components/LineChart/magma-charts.ts +279 -0
- package/src/index.ts +0 -1
- package/dist/components/DataViz/DataVizTabs.d.ts +0 -8
- package/dist/components/DataViz/index.d.ts +0 -1
- package/src/components/DataViz/DataVizTabs.tsx +0 -48
- package/src/components/DataViz/index.ts +0 -1
- package/src/components/LineChart/magma-charts.js +0 -309
|
@@ -1,32 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { ThemeContext, Checkbox } from 'react-magma-dom';
|
|
3
3
|
|
|
4
4
|
export interface DataTableProps {
|
|
5
|
-
|
|
5
|
+
name?: string;
|
|
6
6
|
color?: string;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
const StyledButton = styled.button`
|
|
10
|
-
align-items: center;
|
|
11
|
-
background: none;
|
|
12
|
-
border: 0;
|
|
13
|
-
box-shadow: 0 0 0;
|
|
14
|
-
cursor: pointer;
|
|
15
|
-
display: inline-flex;
|
|
16
|
-
margin-right: 24px;
|
|
17
|
-
padding: 0;
|
|
18
|
-
`;
|
|
19
|
-
|
|
20
|
-
const ColorSwatch = styled.span`
|
|
21
|
-
border: ${props => (props.color ? 'none' : '3px solid black')};
|
|
22
|
-
border-radius: 4px;
|
|
23
|
-
display: inline-block;
|
|
24
|
-
height: 28px;
|
|
25
|
-
margin-right: 8px;
|
|
26
|
-
width: 28px;
|
|
27
|
-
background: ${props => props.color};
|
|
28
|
-
`;
|
|
29
|
-
|
|
30
9
|
export const LegendButton = React.forwardRef<HTMLButtonElement, any>(
|
|
31
10
|
(props, ref) => {
|
|
32
11
|
const {
|
|
@@ -35,6 +14,7 @@ export const LegendButton = React.forwardRef<HTMLButtonElement, any>(
|
|
|
35
14
|
dataIndex,
|
|
36
15
|
isHidden,
|
|
37
16
|
onClick,
|
|
17
|
+
name,
|
|
38
18
|
focusCurrentLine,
|
|
39
19
|
resetLineFocus,
|
|
40
20
|
...other
|
|
@@ -58,19 +38,39 @@ export const LegendButton = React.forwardRef<HTMLButtonElement, any>(
|
|
|
58
38
|
}
|
|
59
39
|
}
|
|
60
40
|
|
|
41
|
+
const theme = React.useContext(ThemeContext);
|
|
42
|
+
|
|
61
43
|
return (
|
|
62
|
-
<
|
|
63
|
-
|
|
64
|
-
onClick={handleClick}
|
|
65
|
-
onFocus={handleOnMouseEnterOrFocus}
|
|
44
|
+
<div
|
|
45
|
+
style={{ display: 'inline-flex' }}
|
|
66
46
|
onMouseEnter={handleOnMouseEnterOrFocus}
|
|
67
47
|
onMouseLeave={resetLineFocus}
|
|
68
|
-
ref={ref}
|
|
69
|
-
{...other}
|
|
70
48
|
>
|
|
71
|
-
<
|
|
72
|
-
|
|
73
|
-
|
|
49
|
+
<Checkbox
|
|
50
|
+
checked={!isHidden}
|
|
51
|
+
color={color}
|
|
52
|
+
containerStyle={{
|
|
53
|
+
alignItems: 'center',
|
|
54
|
+
border: '0',
|
|
55
|
+
boxShadow: '0 0 0',
|
|
56
|
+
color: theme.colors.neutral,
|
|
57
|
+
display: 'inline-flex',
|
|
58
|
+
margin: '0 36px 20px 0',
|
|
59
|
+
padding: '0',
|
|
60
|
+
}}
|
|
61
|
+
inputStyle={{
|
|
62
|
+
border: color ? `none` : `2px solid ${theme.colors.neutral02}`,
|
|
63
|
+
borderRadius: '4px',
|
|
64
|
+
}}
|
|
65
|
+
labelText={name}
|
|
66
|
+
onBlur={resetLineFocus}
|
|
67
|
+
onClick={handleClick}
|
|
68
|
+
onFocus={handleOnMouseEnterOrFocus}
|
|
69
|
+
ref={ref}
|
|
70
|
+
theme={theme}
|
|
71
|
+
{...other}
|
|
72
|
+
/>
|
|
73
|
+
</div>
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
76
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
import { Chart, ChartProps } from './index';
|
|
3
3
|
import { Story, Meta } from '@storybook/react/types-6-0';
|
|
4
4
|
import {
|
|
@@ -21,7 +21,7 @@ const data = [
|
|
|
21
21
|
{
|
|
22
22
|
name: 'Team 2',
|
|
23
23
|
data: [
|
|
24
|
-
{ x: 1, y: 27, label: 'Team 2, January, $
|
|
24
|
+
{ x: 1, y: 27, label: 'Team 2, January, $27k' },
|
|
25
25
|
{ x: 2, y: 33, label: 'Team 2, February, $33k' },
|
|
26
26
|
{ x: 3, y: 39, label: 'Team 2, March, $39k' },
|
|
27
27
|
{ x: 4, y: 28, label: 'Team 2, April, $28k' },
|
|
@@ -31,11 +31,11 @@ const data = [
|
|
|
31
31
|
{
|
|
32
32
|
name: 'Team 3',
|
|
33
33
|
data: [
|
|
34
|
-
{ x: 1, y: 32, label: 'Team 3, January, $
|
|
35
|
-
{ x: 2, y: 41, label: 'Team 3, February, $
|
|
36
|
-
{ x: 3, y: 45, label: 'Team 3, March, $
|
|
37
|
-
{ x: 4, y: 56, label: 'Team 3, April, $
|
|
38
|
-
{ x: 5, y: 48, label: 'Team 3, May, $
|
|
34
|
+
{ x: 1, y: 32, label: 'Team 3, January, $32k' },
|
|
35
|
+
{ x: 2, y: 41, label: 'Team 3, February, $41k' },
|
|
36
|
+
{ x: 3, y: 45, label: 'Team 3, March, $45k' },
|
|
37
|
+
{ x: 4, y: 56, label: 'Team 3, April, $56k' },
|
|
38
|
+
{ x: 5, y: 48, label: 'Team 3, May, $48k' },
|
|
39
39
|
],
|
|
40
40
|
},
|
|
41
41
|
{
|
|
@@ -92,7 +92,7 @@ const explicitData = [
|
|
|
92
92
|
{
|
|
93
93
|
name: 'Team 1',
|
|
94
94
|
data: [
|
|
95
|
-
{ month: 1, sales: 39, label: 'Team 1, January, $
|
|
95
|
+
{ month: 1, sales: 39, label: 'Team 1, January, $39k' },
|
|
96
96
|
{ month: 2, sales: 28, label: 'Team 1, February, $28k' },
|
|
97
97
|
{ month: 3, sales: 35, label: 'Team 1, March, $35k' },
|
|
98
98
|
{ month: 4, sales: 44, label: 'Team 1, April, $44k' },
|
|
@@ -109,7 +109,7 @@ const explicitData = [
|
|
|
109
109
|
{
|
|
110
110
|
name: 'Team 2',
|
|
111
111
|
data: [
|
|
112
|
-
{ month: 1, sales: 27, label: 'Team 2, January, $
|
|
112
|
+
{ month: 1, sales: 27, label: 'Team 2, January, $27k' },
|
|
113
113
|
{ month: 2, sales: 33, label: 'Team 2, February, $33k' },
|
|
114
114
|
{ month: 3, sales: 39, label: 'Team 2, March, $39k' },
|
|
115
115
|
{ month: 4, sales: 28, label: 'Team 2, April, $28k' },
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
import { render, fireEvent, waitFor } from '@testing-library/react';
|
|
3
3
|
import userEvent from '@testing-library/user-event';
|
|
4
4
|
import { basicData, explicitData } from './test/exampleChartData';
|
|
5
5
|
import { Chart } from '.';
|
|
6
|
+
import { defaultI18n } from 'react-magma-dom';
|
|
6
7
|
|
|
7
8
|
const componentProps = {
|
|
8
9
|
xAxis: {
|
|
@@ -97,11 +98,11 @@ describe('Line Chart', () => {
|
|
|
97
98
|
userEvent.hover(getByText('Team 2'));
|
|
98
99
|
|
|
99
100
|
expect(
|
|
100
|
-
container.querySelectorAll('svg')[
|
|
101
|
-
).toHaveStyle('opacity: .1');
|
|
102
|
-
expect(
|
|
103
|
-
container.querySelectorAll('svg')[2].childNodes[3].querySelector('path')
|
|
101
|
+
container.querySelectorAll('svg')[3].childNodes[2].querySelector('path')
|
|
104
102
|
).toHaveStyle('opacity: 1');
|
|
103
|
+
expect(
|
|
104
|
+
container.querySelectorAll('svg')[3].childNodes[3].querySelector('path')
|
|
105
|
+
).toHaveStyle('opacity: .1');
|
|
105
106
|
});
|
|
106
107
|
|
|
107
108
|
it('should unrender line if legend button is clicked', () => {
|
|
@@ -114,11 +115,11 @@ describe('Line Chart', () => {
|
|
|
114
115
|
/>
|
|
115
116
|
);
|
|
116
117
|
|
|
117
|
-
expect(container.querySelectorAll('svg')[
|
|
118
|
+
expect(container.querySelectorAll('svg')[3].childNodes.length).toEqual(10);
|
|
118
119
|
|
|
119
120
|
userEvent.click(getByText('Team 2'));
|
|
120
121
|
|
|
121
|
-
expect(container.querySelectorAll('svg')[
|
|
122
|
+
expect(container.querySelectorAll('svg')[3].childNodes.length).toEqual(8);
|
|
122
123
|
});
|
|
123
124
|
|
|
124
125
|
describe('keyboard behavior', () => {
|
|
@@ -134,12 +135,13 @@ describe('Line Chart', () => {
|
|
|
134
135
|
|
|
135
136
|
userEvent.click(getByText(/chart/i, { selector: 'button' }));
|
|
136
137
|
userEvent.tab();
|
|
138
|
+
userEvent.tab();
|
|
137
139
|
|
|
138
140
|
expect(getByLabelText(basicData[0].data[0].label)).toHaveFocus();
|
|
139
141
|
|
|
140
142
|
userEvent.tab();
|
|
141
143
|
|
|
142
|
-
expect(
|
|
144
|
+
expect(getByLabelText(/team 1/i, { selector: 'input' })).toHaveFocus();
|
|
143
145
|
});
|
|
144
146
|
|
|
145
147
|
it('should only shift tab in to the graph and out, not between lines or scatter points', () => {
|
|
@@ -160,7 +162,95 @@ describe('Line Chart', () => {
|
|
|
160
162
|
|
|
161
163
|
userEvent.tab({ shift: true });
|
|
162
164
|
|
|
163
|
-
expect(
|
|
165
|
+
expect(
|
|
166
|
+
getByLabelText(defaultI18n.charts.line.keyboardInstructionsTooltip)
|
|
167
|
+
).toHaveFocus();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('should focus last focused scatter point when tabbing or shift tabbing back in to the chart', () => {
|
|
171
|
+
const data = [
|
|
172
|
+
{
|
|
173
|
+
name: 'Team 1',
|
|
174
|
+
data: [
|
|
175
|
+
{ x: 1, y: 3.9, label: 'Team 1, January, $39k' },
|
|
176
|
+
{ x: 2, y: 2.8, label: 'Team 1, February, $28k' },
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
name: 'Team 2',
|
|
181
|
+
data: [
|
|
182
|
+
{ x: 1, y: 2.7, label: 'Team 2, January, $39k' },
|
|
183
|
+
{ x: 2, y: 3.3, label: 'Team 2, February, $33k' },
|
|
184
|
+
],
|
|
185
|
+
},
|
|
186
|
+
];
|
|
187
|
+
const { getByText, getByLabelText } = render(
|
|
188
|
+
<Chart
|
|
189
|
+
componentProps={componentProps}
|
|
190
|
+
type="line"
|
|
191
|
+
data={data}
|
|
192
|
+
title="Basic"
|
|
193
|
+
/>
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
userEvent.click(getByText(/chart/i, { selector: 'button' }));
|
|
197
|
+
userEvent.tab();
|
|
198
|
+
userEvent.tab();
|
|
199
|
+
|
|
200
|
+
expect(getByLabelText(basicData[0].data[0].label)).toHaveFocus();
|
|
201
|
+
|
|
202
|
+
userEvent.keyboard('{arrowright}');
|
|
203
|
+
|
|
204
|
+
expect(getByLabelText(data[0].data[1].label)).toHaveFocus();
|
|
205
|
+
|
|
206
|
+
userEvent.tab();
|
|
207
|
+
userEvent.tab({ shift: true });
|
|
208
|
+
|
|
209
|
+
expect(getByLabelText(data[0].data[1].label)).toHaveFocus();
|
|
210
|
+
|
|
211
|
+
userEvent.tab({ shift: true });
|
|
212
|
+
userEvent.tab();
|
|
213
|
+
|
|
214
|
+
expect(getByLabelText(data[0].data[1].label)).toHaveFocus();
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
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', () => {
|
|
218
|
+
const data = [
|
|
219
|
+
{
|
|
220
|
+
name: 'Team 1',
|
|
221
|
+
data: [
|
|
222
|
+
{ x: 1, y: 3.9, label: 'Team 1, January, $39k' },
|
|
223
|
+
{ x: 2, y: 2.8, label: 'Team 1, February, $28k' },
|
|
224
|
+
],
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
name: 'Team 2',
|
|
228
|
+
data: [
|
|
229
|
+
{ x: 1, y: 2.7, label: 'Team 2, January, $39k' },
|
|
230
|
+
{ x: 2, y: 3.3, label: 'Team 2, February, $33k' },
|
|
231
|
+
],
|
|
232
|
+
},
|
|
233
|
+
];
|
|
234
|
+
const { getByText, getByLabelText } = render(
|
|
235
|
+
<Chart
|
|
236
|
+
componentProps={componentProps}
|
|
237
|
+
type="line"
|
|
238
|
+
data={data}
|
|
239
|
+
title="Basic"
|
|
240
|
+
/>
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
userEvent.click(getByText(/chart/i, { selector: 'button' }));
|
|
244
|
+
userEvent.tab();
|
|
245
|
+
userEvent.tab();
|
|
246
|
+
|
|
247
|
+
expect(getByLabelText(basicData[0].data[0].label)).toHaveFocus();
|
|
248
|
+
|
|
249
|
+
userEvent.tab();
|
|
250
|
+
userEvent.keyboard('{enter}');
|
|
251
|
+
userEvent.tab({ shift: true });
|
|
252
|
+
|
|
253
|
+
expect(getByLabelText(data[1].data[1].label)).toHaveFocus();
|
|
164
254
|
});
|
|
165
255
|
|
|
166
256
|
it('should use right arrow keys to go through scatter points', () => {
|
|
@@ -191,6 +281,7 @@ describe('Line Chart', () => {
|
|
|
191
281
|
|
|
192
282
|
userEvent.click(getByText(/chart/i, { selector: 'button' }));
|
|
193
283
|
userEvent.tab();
|
|
284
|
+
userEvent.tab();
|
|
194
285
|
|
|
195
286
|
expect(getByLabelText(data[0].data[0].label)).toHaveFocus();
|
|
196
287
|
|
|
@@ -272,6 +363,7 @@ describe('Line Chart', () => {
|
|
|
272
363
|
|
|
273
364
|
userEvent.click(getByText(/chart/i, { selector: 'button' }));
|
|
274
365
|
userEvent.tab();
|
|
366
|
+
userEvent.tab();
|
|
275
367
|
|
|
276
368
|
expect(getByLabelText(data[0].data[0].label)).toHaveFocus();
|
|
277
369
|
|
|
@@ -329,6 +421,7 @@ describe('Line Chart', () => {
|
|
|
329
421
|
|
|
330
422
|
userEvent.click(getByText(/chart/i, { selector: 'button' }));
|
|
331
423
|
userEvent.tab();
|
|
424
|
+
userEvent.tab();
|
|
332
425
|
|
|
333
426
|
expect(getByLabelText(basicData[0].data[0].label)).toHaveFocus();
|
|
334
427
|
|
|
@@ -355,7 +448,7 @@ describe('Line Chart', () => {
|
|
|
355
448
|
|
|
356
449
|
userEvent.keyboard('{arrowup}');
|
|
357
450
|
|
|
358
|
-
expect(getByLabelText(basicData[2].data[
|
|
451
|
+
expect(getByLabelText(basicData[2].data[4].label)).toHaveFocus();
|
|
359
452
|
});
|
|
360
453
|
|
|
361
454
|
it('should wrap to the last line when clicking the up arrow key while focused on the first line', () => {
|
|
@@ -370,6 +463,7 @@ describe('Line Chart', () => {
|
|
|
370
463
|
|
|
371
464
|
userEvent.click(getByText(/chart/i, { selector: 'button' }));
|
|
372
465
|
userEvent.tab();
|
|
466
|
+
userEvent.tab();
|
|
373
467
|
|
|
374
468
|
expect(getByLabelText(basicData[0].data[0].label)).toHaveFocus();
|
|
375
469
|
|
|
@@ -396,7 +490,7 @@ describe('Line Chart', () => {
|
|
|
396
490
|
|
|
397
491
|
userEvent.keyboard('{arrowdown}');
|
|
398
492
|
|
|
399
|
-
expect(getByLabelText(basicData[0].data[
|
|
493
|
+
expect(getByLabelText(basicData[0].data[4].label)).toHaveFocus();
|
|
400
494
|
});
|
|
401
495
|
});
|
|
402
496
|
});
|