@react-magma/charts 14.2.1 → 15.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/dist/charts.js +1511 -111
- package/dist/charts.js.map +1 -1
- package/dist/charts.modern.module.js +1513 -114
- package/dist/charts.modern.module.js.map +1 -1
- package/dist/charts.umd.js +48975 -28130
- package/dist/charts.umd.js.map +1 -1
- package/dist/components/CarbonChart/CarbonChart.d.ts +1 -1
- package/dist/components/CarbonChart/CarbonChartArea.stories.d.ts +310 -0
- package/dist/components/CarbonChart/CarbonChartAreaStacked.stories.d.ts +136 -0
- package/dist/components/CarbonChart/CarbonChartBar.stories.d.ts +232 -0
- package/dist/components/CarbonChart/CarbonChartBarFloating.stories.d.ts +82 -0
- package/dist/components/CarbonChart/CarbonChartBarGrouped.stories.d.ts +234 -0
- package/dist/components/CarbonChart/CarbonChartBarStacked.stories.d.ts +266 -0
- package/dist/components/CarbonChart/CarbonChartBoxplot.stories.d.ts +53 -0
- package/dist/components/CarbonChart/CarbonChartBubble.stories.d.ts +196 -0
- package/dist/components/CarbonChart/CarbonChartBullet.stories.d.ts +35 -0
- package/dist/components/CarbonChart/CarbonChartCombo.stories.d.ts +580 -0
- package/dist/components/CarbonChart/CarbonChartDonut.stories.d.ts +120 -0
- package/dist/components/CarbonChart/CarbonChartGauge.stories.d.ts +43 -0
- package/dist/components/CarbonChart/CarbonChartHistogram.stories.d.ts +89 -0
- package/dist/components/CarbonChart/CarbonChartLine.stories.d.ts +577 -0
- package/dist/components/CarbonChart/CarbonChartLollipop.stories.d.ts +55 -0
- package/dist/components/CarbonChart/CarbonChartMeter.stories.d.ts +127 -0
- package/dist/components/CarbonChart/CarbonChartPie.stories.d.ts +101 -0
- package/dist/components/CarbonChart/CarbonChartRadar.stories.d.ts +98 -0
- package/dist/components/CarbonChart/CarbonChartScatter.stories.d.ts +173 -0
- package/dist/components/CarbonChart/CarbonChartSparkline.stories.d.ts +51 -0
- package/dist/components/CarbonChart/CarbonChartStep.stories.d.ts +38 -0
- package/dist/components/ChartTable/ChartTable.stories.d.ts +166 -0
- package/dist/components/LineChart/Chart.d.ts +27 -0
- package/dist/components/LineChart/ChartDataTable.d.ts +17 -0
- package/dist/components/LineChart/CustomAxisComponent.d.ts +3 -0
- package/dist/components/LineChart/CustomPointComponent.d.ts +17 -0
- package/dist/components/LineChart/DataTable.d.ts +5 -0
- package/dist/components/LineChart/GraphTooltip.d.ts +3 -0
- package/dist/components/LineChart/LegendButton.d.ts +6 -0
- package/dist/components/LineChart/LineChart.d.ts +67 -0
- package/dist/components/LineChart/LineChart.stories.d.ts +113 -0
- package/dist/components/LineChart/index.d.ts +1 -0
- package/dist/components/LineChart/magma-charts.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/package.json +19 -22
- package/src/components/CarbonChart/CarbonChart.test.js +185 -172
- package/src/components/CarbonChart/CarbonChart.tsx +19 -18
- package/src/components/CarbonChart/CarbonChartArea.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartAreaStacked.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartBar.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartBarFloating.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartBarGrouped.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartBarStacked.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartBoxplot.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartBubble.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartBullet.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartCombo.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartDonut.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartGauge.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartHistogram.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartLine.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartLollipop.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartMeter.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartPie.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartRadar.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartScatter.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartSparkline.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartStep.stories.tsx +5 -3
- package/src/components/ChartTable/ChartDataTable.tsx +0 -3
- package/src/components/ChartTable/ChartMoreOptionsButton.tsx +0 -1
- package/src/components/ChartTable/ChartTable.test.js +0 -8
- package/src/components/ChartTable/ChartTableButton.tsx +0 -1
- package/src/components/ChartTable/ChartToolbar.tsx +0 -1
- package/src/components/ChartTable/chartToolbarI18n.ts +1 -1
- package/src/components/LineChart/Chart.tsx +241 -0
- package/src/components/LineChart/ChartDataTable.test.js +165 -0
- package/src/components/LineChart/ChartDataTable.tsx +135 -0
- package/src/components/LineChart/CustomAxisComponent.tsx +30 -0
- package/src/components/LineChart/CustomPointComponent.tsx +93 -0
- package/src/components/LineChart/DataTable.tsx +57 -0
- package/src/components/LineChart/GraphTooltip.tsx +100 -0
- package/src/components/LineChart/LegendButton.tsx +77 -0
- package/src/components/LineChart/LineChart.stories.tsx +399 -0
- package/src/components/LineChart/LineChart.test.js +501 -0
- package/src/components/LineChart/LineChart.tsx +669 -0
- package/src/components/LineChart/index.ts +1 -0
- package/src/components/LineChart/magma-charts.ts +279 -0
- package/src/components/LineChart/test/exampleChartData.js +289 -0
- package/src/hooks/useCarbonModalFocusManagement.ts +0 -12
- package/src/index.ts +1 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { StoryFn, Meta } from '@storybook/react-
|
|
3
|
+
import { StoryFn, Meta } from '@storybook/react/types-6-0';
|
|
4
4
|
import { Card } from 'react-magma-dom';
|
|
5
5
|
|
|
6
6
|
import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
|
|
@@ -15,8 +15,10 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
type: {
|
|
18
|
-
control: {
|
|
19
|
-
|
|
18
|
+
control: {
|
|
19
|
+
type: 'select',
|
|
20
|
+
options: CarbonChartType,
|
|
21
|
+
},
|
|
20
22
|
},
|
|
21
23
|
},
|
|
22
24
|
} as Meta;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { StoryFn, Meta } from '@storybook/react-
|
|
3
|
+
import { StoryFn, Meta } from '@storybook/react/types-6-0';
|
|
4
4
|
import { Card } from 'react-magma-dom';
|
|
5
5
|
|
|
6
6
|
import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
|
|
@@ -15,8 +15,10 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
type: {
|
|
18
|
-
control: {
|
|
19
|
-
|
|
18
|
+
control: {
|
|
19
|
+
type: 'select',
|
|
20
|
+
options: CarbonChartType,
|
|
21
|
+
},
|
|
20
22
|
},
|
|
21
23
|
},
|
|
22
24
|
} as Meta;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { StoryFn, Meta } from '@storybook/react-
|
|
3
|
+
import { StoryFn, Meta } from '@storybook/react/types-6-0';
|
|
4
4
|
import { Card } from 'react-magma-dom';
|
|
5
5
|
|
|
6
6
|
import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
|
|
@@ -15,8 +15,10 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
type: {
|
|
18
|
-
control: {
|
|
19
|
-
|
|
18
|
+
control: {
|
|
19
|
+
type: 'select',
|
|
20
|
+
options: CarbonChartType,
|
|
21
|
+
},
|
|
20
22
|
},
|
|
21
23
|
},
|
|
22
24
|
} as Meta;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { StoryFn, Meta } from '@storybook/react-
|
|
3
|
+
import { StoryFn, Meta } from '@storybook/react/types-6-0';
|
|
4
4
|
import { Card } from 'react-magma-dom';
|
|
5
5
|
|
|
6
6
|
import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
|
|
@@ -15,8 +15,10 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
type: {
|
|
18
|
-
control: {
|
|
19
|
-
|
|
18
|
+
control: {
|
|
19
|
+
type: 'select',
|
|
20
|
+
options: CarbonChartType,
|
|
21
|
+
},
|
|
20
22
|
},
|
|
21
23
|
},
|
|
22
24
|
} as Meta;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { StoryFn, Meta } from '@storybook/react-
|
|
3
|
+
import { StoryFn, Meta } from '@storybook/react/types-6-0';
|
|
4
4
|
import { Card } from 'react-magma-dom';
|
|
5
5
|
|
|
6
6
|
import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
|
|
@@ -15,8 +15,10 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
type: {
|
|
18
|
-
control: {
|
|
19
|
-
|
|
18
|
+
control: {
|
|
19
|
+
type: 'select',
|
|
20
|
+
options: CarbonChartType,
|
|
21
|
+
},
|
|
20
22
|
},
|
|
21
23
|
},
|
|
22
24
|
} as Meta;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { StoryFn, Meta } from '@storybook/react-
|
|
3
|
+
import { StoryFn, Meta } from '@storybook/react/types-6-0';
|
|
4
4
|
import { Card } from 'react-magma-dom';
|
|
5
5
|
|
|
6
6
|
import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
|
|
@@ -15,8 +15,10 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
type: {
|
|
18
|
-
control: {
|
|
19
|
-
|
|
18
|
+
control: {
|
|
19
|
+
type: 'select',
|
|
20
|
+
options: CarbonChartType,
|
|
21
|
+
},
|
|
20
22
|
},
|
|
21
23
|
},
|
|
22
24
|
} as Meta;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { StoryFn, Meta } from '@storybook/react-
|
|
3
|
+
import { StoryFn, Meta } from '@storybook/react/types-6-0';
|
|
4
4
|
import { Card } from 'react-magma-dom';
|
|
5
5
|
|
|
6
6
|
import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
|
|
@@ -15,8 +15,10 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
type: {
|
|
18
|
-
control: {
|
|
19
|
-
|
|
18
|
+
control: {
|
|
19
|
+
type: 'select',
|
|
20
|
+
options: CarbonChartType,
|
|
21
|
+
},
|
|
20
22
|
},
|
|
21
23
|
},
|
|
22
24
|
} as Meta;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { StoryFn, Meta } from '@storybook/react-
|
|
3
|
+
import { StoryFn, Meta } from '@storybook/react/types-6-0';
|
|
4
4
|
import { Card } from 'react-magma-dom';
|
|
5
5
|
|
|
6
6
|
import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
|
|
@@ -15,8 +15,10 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
type: {
|
|
18
|
-
control: {
|
|
19
|
-
|
|
18
|
+
control: {
|
|
19
|
+
type: 'select',
|
|
20
|
+
options: CarbonChartType,
|
|
21
|
+
},
|
|
20
22
|
},
|
|
21
23
|
},
|
|
22
24
|
} as Meta;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { StoryFn, Meta } from '@storybook/react-
|
|
3
|
+
import { StoryFn, Meta } from '@storybook/react/types-6-0';
|
|
4
4
|
import { Card } from 'react-magma-dom';
|
|
5
5
|
|
|
6
6
|
import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
|
|
@@ -15,8 +15,10 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
type: {
|
|
18
|
-
control: {
|
|
19
|
-
|
|
18
|
+
control: {
|
|
19
|
+
type: 'select',
|
|
20
|
+
options: CarbonChartType,
|
|
21
|
+
},
|
|
20
22
|
},
|
|
21
23
|
},
|
|
22
24
|
} as Meta;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { StoryFn, Meta } from '@storybook/react-
|
|
3
|
+
import { StoryFn, Meta } from '@storybook/react/types-6-0';
|
|
4
4
|
import { Card } from 'react-magma-dom';
|
|
5
5
|
|
|
6
6
|
import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
|
|
@@ -15,8 +15,10 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
type: {
|
|
18
|
-
control: {
|
|
19
|
-
|
|
18
|
+
control: {
|
|
19
|
+
type: 'select',
|
|
20
|
+
options: CarbonChartType,
|
|
21
|
+
},
|
|
20
22
|
},
|
|
21
23
|
},
|
|
22
24
|
} as Meta;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { StoryFn, Meta } from '@storybook/react-
|
|
3
|
+
import { StoryFn, Meta } from '@storybook/react/types-6-0';
|
|
4
4
|
import { Card } from 'react-magma-dom';
|
|
5
5
|
|
|
6
6
|
import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
|
|
@@ -15,8 +15,10 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
type: {
|
|
18
|
-
control: {
|
|
19
|
-
|
|
18
|
+
control: {
|
|
19
|
+
type: 'select',
|
|
20
|
+
options: CarbonChartType,
|
|
21
|
+
},
|
|
20
22
|
},
|
|
21
23
|
},
|
|
22
24
|
} as Meta;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { StoryFn, Meta } from '@storybook/react-
|
|
3
|
+
import { StoryFn, Meta } from '@storybook/react/types-6-0';
|
|
4
4
|
import { Card } from 'react-magma-dom';
|
|
5
5
|
|
|
6
6
|
import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
|
|
@@ -15,8 +15,10 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
type: {
|
|
18
|
-
control: {
|
|
19
|
-
|
|
18
|
+
control: {
|
|
19
|
+
type: 'select',
|
|
20
|
+
options: CarbonChartType,
|
|
21
|
+
},
|
|
20
22
|
},
|
|
21
23
|
},
|
|
22
24
|
} as Meta;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { StoryFn, Meta } from '@storybook/react-
|
|
3
|
+
import { StoryFn, Meta } from '@storybook/react/types-6-0';
|
|
4
4
|
import { Card } from 'react-magma-dom';
|
|
5
5
|
|
|
6
6
|
import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
|
|
@@ -15,8 +15,10 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
type: {
|
|
18
|
-
control: {
|
|
19
|
-
|
|
18
|
+
control: {
|
|
19
|
+
type: 'select',
|
|
20
|
+
options: CarbonChartType,
|
|
21
|
+
},
|
|
20
22
|
},
|
|
21
23
|
},
|
|
22
24
|
} as Meta;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { StoryFn, Meta } from '@storybook/react-
|
|
3
|
+
import { StoryFn, Meta } from '@storybook/react/types-6-0';
|
|
4
4
|
import { Card } from 'react-magma-dom';
|
|
5
5
|
|
|
6
6
|
import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
|
|
@@ -15,8 +15,10 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
type: {
|
|
18
|
-
control: {
|
|
19
|
-
|
|
18
|
+
control: {
|
|
19
|
+
type: 'select',
|
|
20
|
+
options: CarbonChartType,
|
|
21
|
+
},
|
|
20
22
|
},
|
|
21
23
|
},
|
|
22
24
|
} as Meta;
|
|
@@ -32,7 +32,6 @@ function deriveColumns(
|
|
|
32
32
|
dataSet: Array<Record<string, React.ReactNode>>
|
|
33
33
|
): ChartDataTableColumn[] {
|
|
34
34
|
if (!dataSet.length) return [];
|
|
35
|
-
|
|
36
35
|
return Object.keys(dataSet[0]).map(key => ({
|
|
37
36
|
header: key.charAt(0).toUpperCase() + key.slice(1),
|
|
38
37
|
key,
|
|
@@ -45,7 +44,6 @@ export function ChartDataTable({
|
|
|
45
44
|
isInverse,
|
|
46
45
|
}: ChartDataTableProps) {
|
|
47
46
|
const resolvedColumns = columns || deriveColumns(dataSet);
|
|
48
|
-
|
|
49
47
|
return (
|
|
50
48
|
<Table isInverse={isInverse}>
|
|
51
49
|
<TableHead>
|
|
@@ -60,7 +58,6 @@ export function ChartDataTable({
|
|
|
60
58
|
const rowKey = resolvedColumns
|
|
61
59
|
.map(col => String(row[col.key] ?? ''))
|
|
62
60
|
.join('-');
|
|
63
|
-
|
|
64
61
|
return (
|
|
65
62
|
<TableRow key={`${rowKey}-${index}`}>
|
|
66
63
|
{resolvedColumns.map(col => (
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import '@testing-library/jest-dom';
|
|
4
3
|
import {
|
|
5
4
|
act,
|
|
6
5
|
render,
|
|
@@ -63,7 +62,6 @@ describe('ChartDataTable', () => {
|
|
|
63
62
|
{ header: 'Category', key: 'group' },
|
|
64
63
|
{ header: 'Count', key: 'value' },
|
|
65
64
|
];
|
|
66
|
-
|
|
67
65
|
render(<ChartDataTable columns={columns} dataSet={dataSet} />);
|
|
68
66
|
|
|
69
67
|
expect(
|
|
@@ -168,7 +166,6 @@ describe('ChartTableModal', () => {
|
|
|
168
166
|
it('calls onClose when close button is activated', async () => {
|
|
169
167
|
jest.useFakeTimers();
|
|
170
168
|
const onClose = jest.fn();
|
|
171
|
-
|
|
172
169
|
render(
|
|
173
170
|
<ChartTableModal
|
|
174
171
|
dataSet={dataSet}
|
|
@@ -220,7 +217,6 @@ describe('ChartTableButton', () => {
|
|
|
220
217
|
);
|
|
221
218
|
|
|
222
219
|
const button = screen.getByRole('button', { name: 'Overall Performance' });
|
|
223
|
-
|
|
224
220
|
expect(button).toHaveAttribute('aria-haspopup', 'dialog');
|
|
225
221
|
});
|
|
226
222
|
|
|
@@ -256,7 +252,6 @@ describe('ChartTableButton', () => {
|
|
|
256
252
|
|
|
257
253
|
it('calls onClick when activated', () => {
|
|
258
254
|
const onClick = jest.fn();
|
|
259
|
-
|
|
260
255
|
render(
|
|
261
256
|
<ChartTableButton
|
|
262
257
|
ariaLabel="Overall Performance"
|
|
@@ -284,7 +279,6 @@ describe('ChartTableButton', () => {
|
|
|
284
279
|
);
|
|
285
280
|
|
|
286
281
|
const button = screen.getByRole('button', { name: 'Overall Performance' });
|
|
287
|
-
|
|
288
282
|
fireEvent.mouseEnter(button);
|
|
289
283
|
|
|
290
284
|
await waitFor(() => {
|
|
@@ -310,13 +304,11 @@ describe('ChartFullscreenButton', () => {
|
|
|
310
304
|
const button = screen.getByRole('button', {
|
|
311
305
|
name: 'View chart in full screen',
|
|
312
306
|
});
|
|
313
|
-
|
|
314
307
|
expect(button).not.toHaveAttribute('aria-haspopup');
|
|
315
308
|
});
|
|
316
309
|
|
|
317
310
|
it('calls onClick when activated', () => {
|
|
318
311
|
const onClick = jest.fn();
|
|
319
|
-
|
|
320
312
|
render(
|
|
321
313
|
<ChartFullscreenButton
|
|
322
314
|
ariaLabel="View chart in full screen"
|
|
@@ -32,7 +32,7 @@ const defaults: ChartToolbarI18n = {
|
|
|
32
32
|
* Reads chart toolbar i18n strings from the I18nContext if available,
|
|
33
33
|
* falling back to English defaults.
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
// eslint-disable-next-line complexity
|
|
36
36
|
export function useChartToolbarI18n(): ChartToolbarI18n {
|
|
37
37
|
const i18n = React.useContext(I18nContext);
|
|
38
38
|
const toolbar = (i18n.charts as { toolbar?: Partial<ChartToolbarI18n> })
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import { css } from '@emotion/react';
|
|
4
|
+
import {
|
|
5
|
+
Announce,
|
|
6
|
+
ButtonVariant,
|
|
7
|
+
Card,
|
|
8
|
+
I18nContext,
|
|
9
|
+
IconButton,
|
|
10
|
+
Paragraph,
|
|
11
|
+
Tab,
|
|
12
|
+
TabPanel,
|
|
13
|
+
TabPanelsContainer,
|
|
14
|
+
Tabs,
|
|
15
|
+
TabsContainer,
|
|
16
|
+
ThemeContext,
|
|
17
|
+
Tooltip,
|
|
18
|
+
TypographyVisualStyle,
|
|
19
|
+
useDescendants,
|
|
20
|
+
styled,
|
|
21
|
+
} from 'react-magma-dom';
|
|
22
|
+
import { KeyboardIcon } from 'react-magma-icons';
|
|
23
|
+
|
|
24
|
+
import { ChartDataTable } from './ChartDataTable';
|
|
25
|
+
import { LineChart, LineChartProps } from './LineChart';
|
|
26
|
+
|
|
27
|
+
interface BaseChartProps {
|
|
28
|
+
/**
|
|
29
|
+
* Description of what the line chart data represents placed above the chart
|
|
30
|
+
*/
|
|
31
|
+
description?: string;
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
testId?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Title of the line chart
|
|
38
|
+
*/
|
|
39
|
+
title: string;
|
|
40
|
+
/**
|
|
41
|
+
* Type of chart - for now just 'line' is accepted
|
|
42
|
+
*/
|
|
43
|
+
type: string;
|
|
44
|
+
}
|
|
45
|
+
export interface ChartProps<T extends any>
|
|
46
|
+
extends BaseChartProps,
|
|
47
|
+
Omit<React.HTMLAttributes<HTMLDivElement>, 'title'>,
|
|
48
|
+
LineChartProps<T> {}
|
|
49
|
+
|
|
50
|
+
const StyledTitle = styled.span`
|
|
51
|
+
color: ${props => props.theme.colors.neutral};
|
|
52
|
+
font-size: ${props => props.theme.typeScale.size04.fontSize};
|
|
53
|
+
font-weight: 600;
|
|
54
|
+
font-family: ${props => props.theme.bodyFont};
|
|
55
|
+
line-height: ${props => props.theme.typeScale.size04.lineHeight};
|
|
56
|
+
margin: 0 0 12px 0;
|
|
57
|
+
`;
|
|
58
|
+
|
|
59
|
+
const StyledParagraph = styled(Paragraph)`
|
|
60
|
+
font-size: ${props => props.theme.typeScale.size02.fontSize};
|
|
61
|
+
margin: 0 0 18px 0;
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
const StyledTabsContainer = styled(TabsContainer)`
|
|
65
|
+
width: 800px;
|
|
66
|
+
ul {
|
|
67
|
+
box-shadow: inset 0 -1px 0 ${props => props.theme.colors.neutral300};
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
const StyledTabPanel = styled(TabPanel)`
|
|
72
|
+
padding: 22px 0;
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
const KeyboardInstructionsCard = styled(Card)<{
|
|
76
|
+
isOpen?: boolean;
|
|
77
|
+
maxHeight?: string;
|
|
78
|
+
width?: string;
|
|
79
|
+
}>`
|
|
80
|
+
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
|
|
81
|
+
display: ${props => (props.isOpen ? 'block' : 'none')};
|
|
82
|
+
right: ${props => props.theme.spaceScale.spacing02};
|
|
83
|
+
max-height: ${props =>
|
|
84
|
+
props.maxHeight ? props.maxHeight : props.theme.dropdown.content.maxHeight};
|
|
85
|
+
opacity: ${props => (props.isOpen ? '1' : '0')};
|
|
86
|
+
outline: 0;
|
|
87
|
+
overflow-y: auto;
|
|
88
|
+
padding: ${props => props.theme.spaceScale.spacing05}
|
|
89
|
+
${props => props.theme.spaceScale.spacing05};
|
|
90
|
+
position: absolute;
|
|
91
|
+
transition: opacity 0.3s;
|
|
92
|
+
white-space: nowrap;
|
|
93
|
+
z-index: 2;
|
|
94
|
+
|
|
95
|
+
${props =>
|
|
96
|
+
props.width &&
|
|
97
|
+
css`
|
|
98
|
+
white-space: normal;
|
|
99
|
+
width: ${props.width};
|
|
100
|
+
`}
|
|
101
|
+
`;
|
|
102
|
+
|
|
103
|
+
function BaseChart<T>(props: ChartProps<T>, ref: React.Ref<HTMLDivElement>) {
|
|
104
|
+
const { description, title, testId, type, ...other } = props;
|
|
105
|
+
const keyboardInstructionsRef = React.useRef<HTMLButtonElement>(null);
|
|
106
|
+
const lastFocusedScatterPoint = React.useRef<SVGPathElement>(null);
|
|
107
|
+
const theme = React.useContext(ThemeContext);
|
|
108
|
+
const i18n = React.useContext(I18nContext);
|
|
109
|
+
|
|
110
|
+
const [pointRefArray, registerPoint, unregisterPoint] = useDescendants();
|
|
111
|
+
|
|
112
|
+
const [isKeyboardInstructionsOpen, setIsKeyboardInstructionsOpen] =
|
|
113
|
+
React.useState<boolean>(false);
|
|
114
|
+
|
|
115
|
+
function handleKeyboardInstructionsButtonBlur() {
|
|
116
|
+
setIsKeyboardInstructionsOpen(false);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function handleKeyboardInstructionsButtonClick() {
|
|
120
|
+
setIsKeyboardInstructionsOpen(prevOpen => !prevOpen);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function handleKeyboardInstructionsButtonKeydown(event: {
|
|
124
|
+
preventDefault?: any;
|
|
125
|
+
key?: any;
|
|
126
|
+
shiftKey?: any;
|
|
127
|
+
}) {
|
|
128
|
+
const { key, shiftKey } = event;
|
|
129
|
+
|
|
130
|
+
switch (key) {
|
|
131
|
+
case 'Escape': {
|
|
132
|
+
setIsKeyboardInstructionsOpen(false);
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case 'Tab': {
|
|
136
|
+
if (
|
|
137
|
+
!shiftKey &&
|
|
138
|
+
lastFocusedScatterPoint &&
|
|
139
|
+
lastFocusedScatterPoint.current &&
|
|
140
|
+
pointRefArray.current.find(
|
|
141
|
+
point => point.current === lastFocusedScatterPoint.current
|
|
142
|
+
)
|
|
143
|
+
) {
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
lastFocusedScatterPoint.current.focus();
|
|
146
|
+
}
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<div ref={ref}>
|
|
154
|
+
<StyledTitle theme={theme}>{title}</StyledTitle>
|
|
155
|
+
{description && (
|
|
156
|
+
<StyledParagraph
|
|
157
|
+
theme={theme}
|
|
158
|
+
visualStyle={TypographyVisualStyle.bodySmall}
|
|
159
|
+
>
|
|
160
|
+
{description}
|
|
161
|
+
</StyledParagraph>
|
|
162
|
+
)}
|
|
163
|
+
<StyledTabsContainer theme={theme}>
|
|
164
|
+
<Tabs>
|
|
165
|
+
<Tab>{i18n.charts.line.chartTabLabel}</Tab>
|
|
166
|
+
<Tab>{i18n.charts.line.dataTabLabel}</Tab>
|
|
167
|
+
<div
|
|
168
|
+
onBlur={handleKeyboardInstructionsButtonBlur}
|
|
169
|
+
style={{
|
|
170
|
+
display: 'inline-block',
|
|
171
|
+
marginLeft: 'auto',
|
|
172
|
+
}}
|
|
173
|
+
>
|
|
174
|
+
<Tooltip
|
|
175
|
+
content={i18n.charts.line.keyboardInstructionsTooltip}
|
|
176
|
+
ref={keyboardInstructionsRef}
|
|
177
|
+
>
|
|
178
|
+
<IconButton
|
|
179
|
+
aria-controls="keyboardInstructions"
|
|
180
|
+
aria-label={i18n.charts.line.keyboardInstructionsTooltip}
|
|
181
|
+
aria-expanded={Boolean(isKeyboardInstructionsOpen)}
|
|
182
|
+
icon={<KeyboardIcon />}
|
|
183
|
+
onClick={handleKeyboardInstructionsButtonClick}
|
|
184
|
+
onKeyDown={handleKeyboardInstructionsButtonKeydown}
|
|
185
|
+
variant={ButtonVariant.link}
|
|
186
|
+
/>
|
|
187
|
+
</Tooltip>
|
|
188
|
+
<Announce>
|
|
189
|
+
<KeyboardInstructionsCard
|
|
190
|
+
id="keyboardInstructions"
|
|
191
|
+
isOpen={isKeyboardInstructionsOpen}
|
|
192
|
+
theme={theme}
|
|
193
|
+
width="350px"
|
|
194
|
+
>
|
|
195
|
+
<Paragraph
|
|
196
|
+
visualStyle={TypographyVisualStyle.headingXSmall}
|
|
197
|
+
style={{ margin: '0 0 16px' }}
|
|
198
|
+
>
|
|
199
|
+
{i18n.charts.line.keyboardInstructionsHeader}
|
|
200
|
+
</Paragraph>
|
|
201
|
+
{i18n.charts.line.keyboardInstructions}
|
|
202
|
+
</KeyboardInstructionsCard>
|
|
203
|
+
</Announce>
|
|
204
|
+
</div>
|
|
205
|
+
</Tabs>
|
|
206
|
+
<TabPanelsContainer>
|
|
207
|
+
<StyledTabPanel theme={theme}>
|
|
208
|
+
{type === 'line' && (
|
|
209
|
+
<LineChart<T>
|
|
210
|
+
{...other}
|
|
211
|
+
lastFocusedScatterPoint={lastFocusedScatterPoint}
|
|
212
|
+
pointRefArray={pointRefArray}
|
|
213
|
+
registerPoint={registerPoint}
|
|
214
|
+
tabRef={keyboardInstructionsRef}
|
|
215
|
+
unregisterPoint={unregisterPoint}
|
|
216
|
+
/>
|
|
217
|
+
)}
|
|
218
|
+
</StyledTabPanel>
|
|
219
|
+
<StyledTabPanel theme={theme}>
|
|
220
|
+
<ChartDataTable
|
|
221
|
+
data={other.data}
|
|
222
|
+
xData={{
|
|
223
|
+
keyValue: other.x,
|
|
224
|
+
label: other.componentProps?.xAxis?.label,
|
|
225
|
+
tickFormat: other.componentProps?.xAxis?.tickFormat,
|
|
226
|
+
}}
|
|
227
|
+
yData={{
|
|
228
|
+
keyValue: other.y,
|
|
229
|
+
tickFormat: other.componentProps?.yAxis?.tickFormat,
|
|
230
|
+
}}
|
|
231
|
+
/>
|
|
232
|
+
</StyledTabPanel>
|
|
233
|
+
</TabPanelsContainer>
|
|
234
|
+
</StyledTabsContainer>
|
|
235
|
+
</div>
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export const Chart = React.forwardRef(BaseChart) as <T>(
|
|
240
|
+
props: ChartProps<T> & { ref?: React.MutableRefObject<HTMLDivElement> }
|
|
241
|
+
) => ReturnType<typeof BaseChart>;
|