@react-magma/charts 16.0.0-next.0 → 16.0.0-v6-next.2

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 (89) hide show
  1. package/dist/charts.js +1632 -221
  2. package/dist/charts.js.map +1 -1
  3. package/dist/charts.modern.module.js +1634 -224
  4. package/dist/charts.modern.module.js.map +1 -1
  5. package/dist/charts.umd.js +49747 -28263
  6. package/dist/charts.umd.js.map +1 -1
  7. package/dist/components/CarbonChart/CarbonChart.d.ts +1 -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 +232 -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/ChartTable/ChartTable.stories.d.ts +166 -0
  30. package/dist/components/LineChart/Chart.d.ts +27 -0
  31. package/dist/components/LineChart/ChartDataTable.d.ts +17 -0
  32. package/dist/components/LineChart/CustomAxisComponent.d.ts +3 -0
  33. package/dist/components/LineChart/CustomPointComponent.d.ts +17 -0
  34. package/dist/components/LineChart/DataTable.d.ts +5 -0
  35. package/dist/components/LineChart/GraphTooltip.d.ts +3 -0
  36. package/dist/components/LineChart/LegendButton.d.ts +6 -0
  37. package/dist/components/LineChart/LineChart.d.ts +67 -0
  38. package/dist/components/LineChart/LineChart.stories.d.ts +113 -0
  39. package/dist/components/LineChart/index.d.ts +1 -0
  40. package/dist/components/LineChart/magma-charts.d.ts +1 -0
  41. package/dist/index.d.ts +1 -0
  42. package/package.json +21 -24
  43. package/src/components/CarbonChart/CarbonChart.test.js +316 -188
  44. package/src/components/CarbonChart/CarbonChart.tsx +94 -84
  45. package/src/components/CarbonChart/CarbonChartArea.stories.tsx +5 -3
  46. package/src/components/CarbonChart/CarbonChartAreaStacked.stories.tsx +5 -3
  47. package/src/components/CarbonChart/CarbonChartBar.stories.tsx +5 -3
  48. package/src/components/CarbonChart/CarbonChartBarFloating.stories.tsx +5 -3
  49. package/src/components/CarbonChart/CarbonChartBarGrouped.stories.tsx +5 -3
  50. package/src/components/CarbonChart/CarbonChartBarStacked.stories.tsx +5 -3
  51. package/src/components/CarbonChart/CarbonChartBoxplot.stories.tsx +5 -3
  52. package/src/components/CarbonChart/CarbonChartBubble.stories.tsx +5 -3
  53. package/src/components/CarbonChart/CarbonChartBullet.stories.tsx +5 -3
  54. package/src/components/CarbonChart/CarbonChartCombo.stories.tsx +5 -3
  55. package/src/components/CarbonChart/CarbonChartDonut.stories.tsx +5 -3
  56. package/src/components/CarbonChart/CarbonChartGauge.stories.tsx +5 -3
  57. package/src/components/CarbonChart/CarbonChartHistogram.stories.tsx +5 -3
  58. package/src/components/CarbonChart/CarbonChartLine.stories.tsx +5 -3
  59. package/src/components/CarbonChart/CarbonChartLollipop.stories.tsx +5 -3
  60. package/src/components/CarbonChart/CarbonChartMeter.stories.tsx +5 -3
  61. package/src/components/CarbonChart/CarbonChartPie.stories.tsx +5 -3
  62. package/src/components/CarbonChart/CarbonChartRadar.stories.tsx +5 -3
  63. package/src/components/CarbonChart/CarbonChartScatter.stories.tsx +5 -3
  64. package/src/components/CarbonChart/CarbonChartSparkline.stories.tsx +5 -3
  65. package/src/components/CarbonChart/CarbonChartStep.stories.tsx +5 -3
  66. package/src/components/ChartTable/ChartDataTable.tsx +0 -3
  67. package/src/components/ChartTable/ChartFullscreenButton.tsx +7 -1
  68. package/src/components/ChartTable/ChartMoreOptionsButton.tsx +2 -1
  69. package/src/components/ChartTable/ChartTable.test.js +3 -9
  70. package/src/components/ChartTable/ChartTableButton.tsx +7 -2
  71. package/src/components/ChartTable/ChartTableModal.tsx +1 -1
  72. package/src/components/ChartTable/ChartToolbar.tsx +0 -1
  73. package/src/components/ChartTable/chartToolbarI18n.ts +1 -1
  74. package/src/components/LineChart/Chart.tsx +241 -0
  75. package/src/components/LineChart/ChartDataTable.test.js +165 -0
  76. package/src/components/LineChart/ChartDataTable.tsx +135 -0
  77. package/src/components/LineChart/CustomAxisComponent.tsx +30 -0
  78. package/src/components/LineChart/CustomPointComponent.tsx +93 -0
  79. package/src/components/LineChart/DataTable.tsx +57 -0
  80. package/src/components/LineChart/GraphTooltip.tsx +100 -0
  81. package/src/components/LineChart/LegendButton.tsx +77 -0
  82. package/src/components/LineChart/LineChart.stories.tsx +399 -0
  83. package/src/components/LineChart/LineChart.test.js +501 -0
  84. package/src/components/LineChart/LineChart.tsx +669 -0
  85. package/src/components/LineChart/index.ts +1 -0
  86. package/src/components/LineChart/magma-charts.ts +279 -0
  87. package/src/components/LineChart/test/exampleChartData.js +289 -0
  88. package/src/hooks/useCarbonModalFocusManagement.ts +0 -12
  89. package/src/index.ts +1 -0
@@ -0,0 +1,165 @@
1
+ import * as React from 'react';
2
+
3
+ import { render } from '@testing-library/react';
4
+
5
+ import { ChartDataTable } from './ChartDataTable';
6
+ import { basicData, explicitData } from './test/exampleChartData';
7
+
8
+ describe('Chart Data Table', () => {
9
+ describe('Basic Data', () => {
10
+ it('should render chart data with x values values', () => {
11
+ const label = '2019 Annual Sales Figures';
12
+ const { getByText, getAllByText } = render(
13
+ <ChartDataTable
14
+ data={basicData}
15
+ xData={{
16
+ label,
17
+ }}
18
+ yData={{
19
+ tickFormat: t => `$${t}k`,
20
+ }}
21
+ />
22
+ );
23
+
24
+ expect(getByText(label)).toBeInTheDocument();
25
+ expect(getByText(basicData[0].data[0].x)).toBeInTheDocument();
26
+ expect(getByText(basicData[0].name)).toBeInTheDocument();
27
+ expect(
28
+ getAllByText(`$${basicData[0].data[0].y}k`)[0]
29
+ ).toBeInTheDocument();
30
+ });
31
+
32
+ it('should render chart data with x tick values and an x tick format function', () => {
33
+ const label = '2019 Annual Sales Figures';
34
+ const { getByText } = render(
35
+ <ChartDataTable
36
+ data={basicData}
37
+ xData={{
38
+ label,
39
+ tickFormat: t => `Month of ${t}`,
40
+ tickValues: ['Jan', 'Feb', 'March', 'April', 'May'],
41
+ }}
42
+ yData={{
43
+ tickFormat: t => `$${t}k`,
44
+ }}
45
+ />
46
+ );
47
+
48
+ expect(getByText('Month of Jan')).toBeInTheDocument();
49
+ });
50
+
51
+ it('should render chart data with an x tick format array', () => {
52
+ const label = '2019 Annual Sales Figures';
53
+ const { getByText, getAllByText } = render(
54
+ <ChartDataTable
55
+ data={basicData}
56
+ xData={{
57
+ label,
58
+ tickFormat: ['Jan', 'Feb', 'March', 'April', 'May'],
59
+ }}
60
+ yData={{
61
+ tickFormat: t => `$${t}k`,
62
+ }}
63
+ />
64
+ );
65
+
66
+ expect(getByText(label)).toBeInTheDocument();
67
+ expect(getByText('Jan')).toBeInTheDocument();
68
+ expect(getByText(basicData[0].name)).toBeInTheDocument();
69
+ expect(
70
+ getAllByText(`$${basicData[0].data[0].y}k`)[0]
71
+ ).toBeInTheDocument();
72
+ });
73
+ });
74
+
75
+ describe('Explicit Data', () => {
76
+ it('should render chart data with x tick values', () => {
77
+ const label = '2019 Annual Sales Figures';
78
+ const { getByText, getAllByText } = render(
79
+ <ChartDataTable
80
+ data={explicitData}
81
+ xData={{
82
+ keyValue: 'month',
83
+ label,
84
+ tickValues: ['Jan', 'Feb', 'March', 'April', 'May'],
85
+ }}
86
+ yData={{
87
+ keyValue: 'sales',
88
+ tickFormat: t => `$${t}k`,
89
+ }}
90
+ />
91
+ );
92
+
93
+ expect(getByText(label)).toBeInTheDocument();
94
+ expect(getByText('Jan')).toBeInTheDocument();
95
+ expect(getByText(explicitData[0].name)).toBeInTheDocument();
96
+ expect(
97
+ getAllByText(`$${explicitData[0].data[0].sales}k`)[0]
98
+ ).toBeInTheDocument();
99
+ });
100
+
101
+ it('should render column header for x values using the x key value when no label is provided', () => {
102
+ const { getByText } = render(
103
+ <ChartDataTable
104
+ data={explicitData}
105
+ xData={{
106
+ keyValue: 'month',
107
+ tickValues: ['Jan', 'Feb', 'March', 'April', 'May'],
108
+ }}
109
+ yData={{
110
+ keyValue: 'sales',
111
+ tickFormat: t => `$${t}k`,
112
+ }}
113
+ />
114
+ );
115
+
116
+ expect(getByText('month')).toBeInTheDocument();
117
+ });
118
+
119
+ it('should render chart data with x tick values and an x tick format function', () => {
120
+ const label = '2019 Annual Sales Figures';
121
+ const { getByText } = render(
122
+ <ChartDataTable
123
+ data={explicitData}
124
+ xData={{
125
+ label,
126
+ keyValue: 'month',
127
+ tickFormat: t => `Month of ${t}`,
128
+ tickValues: ['Jan', 'Feb', 'March', 'April', 'May'],
129
+ }}
130
+ yData={{
131
+ keyValue: 'sales',
132
+ tickFormat: t => `$${t}k`,
133
+ }}
134
+ />
135
+ );
136
+
137
+ expect(getByText('Month of Jan')).toBeInTheDocument();
138
+ });
139
+
140
+ it('should render chart data with an x tick format array', () => {
141
+ const label = '2019 Annual Sales Figures';
142
+ const { getByText, getAllByText } = render(
143
+ <ChartDataTable
144
+ data={explicitData}
145
+ xData={{
146
+ label,
147
+ keyValue: 'month',
148
+ tickFormat: ['Jan', 'Feb', 'March', 'April', 'May'],
149
+ }}
150
+ yData={{
151
+ keyValue: 'sales',
152
+ tickFormat: t => `$${t}k`,
153
+ }}
154
+ />
155
+ );
156
+
157
+ expect(getByText(label)).toBeInTheDocument();
158
+ expect(getByText('Jan')).toBeInTheDocument();
159
+ expect(getByText(explicitData[0].name)).toBeInTheDocument();
160
+ expect(
161
+ getAllByText(`$${explicitData[0].data[0].sales}k`)[0]
162
+ ).toBeInTheDocument();
163
+ });
164
+ });
165
+ });
@@ -0,0 +1,135 @@
1
+ import * as React from 'react';
2
+
3
+ import { Card, Datagrid, Spinner } from 'react-magma-dom';
4
+ import { VictoryAxisProps } from 'victory';
5
+
6
+ export function toCamelCase(str: string) {
7
+ return str
8
+ .toLowerCase()
9
+ .replace(/[^a-z 0-9]/gi, '')
10
+ .replace(/(?:^\w|[A-Z]|\b\w)/g, (ltr, index) =>
11
+ index === 0 ? ltr.toLowerCase() : ltr.toUpperCase()
12
+ )
13
+ .replace(/\s+/g, '');
14
+ }
15
+
16
+ export interface DataTableProps {
17
+ data?: any[];
18
+ xData: {
19
+ keyValue?: string | number | symbol;
20
+ label?: VictoryAxisProps['label'];
21
+ tickFormat?: Partial<VictoryAxisProps['tickFormat']>;
22
+ tickValues?: VictoryAxisProps['tickValues'];
23
+ };
24
+ yData: {
25
+ keyValue?: string | number | symbol;
26
+ tickFormat?: Partial<VictoryAxisProps['tickFormat']>;
27
+ };
28
+ }
29
+
30
+ export const ChartDataTable = (props: DataTableProps) => {
31
+ const {
32
+ data = [],
33
+ xData: {
34
+ keyValue: xKeyValue,
35
+ label: xAxisLabel,
36
+ tickFormat: xTickFormat,
37
+ tickValues: xTickValues,
38
+ },
39
+ yData: { keyValue: yKeyValue, tickFormat: yTickFormat },
40
+ } = props;
41
+ const [dataForTable, setDataForTable] = React.useState({
42
+ columns: [],
43
+ rows: [],
44
+ });
45
+
46
+ React.useEffect(() => {
47
+ setDataForTable(convertData());
48
+ }, [data]);
49
+
50
+ function convertData() {
51
+ const xField = toCamelCase((xKeyValue || xAxisLabel || 'x') as string);
52
+ const xTickValuesArray = data.reduce((valuesArray, { data: dataset }) => {
53
+ dataset.forEach((datum: any) => {
54
+ const value = datum.x || (xKeyValue && datum[xKeyValue]);
55
+ !valuesArray.includes(value) && valuesArray.push(value);
56
+ });
57
+
58
+ return valuesArray;
59
+ }, []);
60
+
61
+ const baseTableData = {
62
+ columns:
63
+ xTickValuesArray.length > 0
64
+ ? [
65
+ {
66
+ field: xField,
67
+ header: xAxisLabel || xKeyValue || 'X',
68
+ isRowHeader: true,
69
+ },
70
+ ]
71
+ : [],
72
+ rows: xTickValuesArray.reduce(
73
+ (agg: any[], tick: number, index: number) => {
74
+ const tickValue =
75
+ xTickValues &&
76
+ typeof tick === 'number' &&
77
+ xTickValues.length === xTickValuesArray.length
78
+ ? xTickFormat && typeof xTickFormat === 'function'
79
+ ? xTickFormat(xTickValues[tick - 1])
80
+ : xTickValues[tick - 1]
81
+ : xTickFormat && Array.isArray(xTickFormat)
82
+ ? xTickFormat[tick - 1]
83
+ : xTickFormat && typeof xTickFormat === 'function'
84
+ ? xTickFormat(tick)
85
+ : tick;
86
+ agg.push({
87
+ [xField]: tickValue,
88
+ id: index,
89
+ });
90
+
91
+ return agg;
92
+ },
93
+ []
94
+ ),
95
+ };
96
+
97
+ return data.reduce((tableData, datum) => {
98
+ const { name: header, data: dataset } = datum;
99
+ const field = toCamelCase(header);
100
+
101
+ tableData.columns.push({
102
+ field,
103
+ header,
104
+ });
105
+
106
+ dataset.forEach((d: any, i: number) => {
107
+ const yValue = d.y !== undefined ? d.y : yKeyValue && d[yKeyValue];
108
+ tableData.rows[i] = {
109
+ ...tableData.rows[i],
110
+ id: baseTableData.rows.length > 0 ? i + 1 : i,
111
+ [field]:
112
+ yTickFormat && typeof yTickFormat === 'function'
113
+ ? yTickFormat(yValue)
114
+ : yValue,
115
+ };
116
+ });
117
+
118
+ return tableData;
119
+ }, baseTableData);
120
+ }
121
+
122
+ return (
123
+ <Card>
124
+ {dataForTable.rows.length > 0 ? (
125
+ <Datagrid
126
+ hasPagination={false}
127
+ columns={dataForTable.columns}
128
+ rows={dataForTable.rows}
129
+ />
130
+ ) : (
131
+ <Spinner />
132
+ )}
133
+ </Card>
134
+ );
135
+ };
@@ -0,0 +1,30 @@
1
+ import * as React from 'react';
2
+
3
+ import { LineSegment, LineSegmentProps } from 'victory';
4
+
5
+ export const CustomAxisComponent: React.FunctionComponent<LineSegmentProps> = ({
6
+ events,
7
+ ...props
8
+ }: any) => {
9
+ return (
10
+ <g>
11
+ <LineSegment
12
+ {...props}
13
+ events={events}
14
+ style={{
15
+ strokeWidth: '50px',
16
+ stroke: 'transparent',
17
+ }}
18
+ />
19
+ <LineSegment
20
+ {...props}
21
+ events={events}
22
+ style={{
23
+ strokeWidth: '1px',
24
+ stroke: 'black',
25
+ strokeOpacity: '0.2',
26
+ }}
27
+ />
28
+ </g>
29
+ );
30
+ };
@@ -0,0 +1,93 @@
1
+ import * as React from 'react';
2
+
3
+ import { useForceUpdate } from 'react-magma-dom';
4
+ import { Point, PointProps } from 'victory';
5
+
6
+ export interface CustomScatterDataComponentInterface extends PointProps {
7
+ lineIndex: number;
8
+ pointRefArray: React.MutableRefObject<React.MutableRefObject<Element>[]>;
9
+ registerPoint: (
10
+ refArray: React.MutableRefObject<React.MutableRefObject<Element>[]>,
11
+ ref: React.MutableRefObject<Element>
12
+ ) => void;
13
+ unregisterPoint: (
14
+ refArray: React.MutableRefObject<React.MutableRefObject<Element>[]>,
15
+ ref: React.MutableRefObject<Element>
16
+ ) => void;
17
+ }
18
+
19
+ export interface CustomPointComponentInterface {
20
+ lineIndex: number;
21
+ pointIndex: PointProps['index'];
22
+ pointRefArray: React.MutableRefObject<React.MutableRefObject<Element>[]>;
23
+ registerPoint: (
24
+ refArray: React.MutableRefObject<React.MutableRefObject<Element>[]>,
25
+ ref: React.MutableRefObject<Element>
26
+ ) => void;
27
+ unregisterPoint: (
28
+ refArray: React.MutableRefObject<React.MutableRefObject<Element>[]>,
29
+ ref: React.MutableRefObject<Element>
30
+ ) => void;
31
+ }
32
+
33
+ export const CustomScatterDataComponent = (
34
+ props: CustomScatterDataComponentInterface
35
+ ) => {
36
+ const {
37
+ datum,
38
+ index: pointIndex,
39
+ lineIndex,
40
+ pointRefArray,
41
+ registerPoint,
42
+ unregisterPoint,
43
+ ...other
44
+ } = props;
45
+ return (
46
+ <Point
47
+ {...other}
48
+ ariaLabel={datum.label}
49
+ pathComponent={
50
+ <CustomPointComponent
51
+ lineIndex={lineIndex}
52
+ pointIndex={pointIndex}
53
+ pointRefArray={pointRefArray}
54
+ registerPoint={registerPoint}
55
+ unregisterPoint={unregisterPoint}
56
+ />
57
+ }
58
+ role="button"
59
+ tabIndex={0}
60
+ />
61
+ );
62
+ };
63
+
64
+ export const CustomPointComponent = (props: CustomPointComponentInterface) => {
65
+ const {
66
+ lineIndex,
67
+ pointRefArray,
68
+ pointIndex,
69
+ registerPoint,
70
+ unregisterPoint,
71
+ ...other
72
+ } = props;
73
+ const forceUpdate = useForceUpdate();
74
+ const ref = React.useRef<SVGPathElement | null>(null);
75
+
76
+ React.useEffect(() => {
77
+ registerPoint(pointRefArray, ref as React.MutableRefObject<Element>);
78
+
79
+ forceUpdate();
80
+
81
+ return () =>
82
+ unregisterPoint(pointRefArray, ref as React.MutableRefObject<Element>);
83
+ }, []);
84
+
85
+ return (
86
+ <path
87
+ ref={ref}
88
+ data-line-index={lineIndex}
89
+ data-point-index={pointIndex}
90
+ {...other}
91
+ />
92
+ );
93
+ };
@@ -0,0 +1,57 @@
1
+ import * as React from 'react';
2
+
3
+ import {
4
+ Card,
5
+ Table,
6
+ TableHead,
7
+ TableBody,
8
+ TableRow,
9
+ TableHeaderCell,
10
+ TableCell,
11
+ TableHeaderCellScope,
12
+ } from 'react-magma-dom';
13
+
14
+ export interface DataTableProps {
15
+ data?: any;
16
+ }
17
+
18
+ export const DataTable = (props: DataTableProps) => {
19
+ const { data } = props;
20
+
21
+ return (
22
+ <Card>
23
+ <Table>
24
+ <TableHead>
25
+ <TableRow>
26
+ <TableHeaderCell style={{ width: '160px' }} />
27
+ <TableHeaderCell>Jan</TableHeaderCell>
28
+ <TableHeaderCell>Feb</TableHeaderCell>
29
+ <TableHeaderCell>Mar</TableHeaderCell>
30
+ <TableHeaderCell>April</TableHeaderCell>
31
+ <TableHeaderCell>May</TableHeaderCell>
32
+ </TableRow>
33
+ </TableHead>
34
+ <TableBody>
35
+ {data.map((dataset: any, i: number) => (
36
+ <TableRow key={dataset.label ?? `row-${i}`}>
37
+ <TableHeaderCell
38
+ scope={TableHeaderCellScope.row}
39
+ style={{
40
+ borderRight: '1px solid #dfdfdf',
41
+ borderBottom: 0,
42
+ }}
43
+ >
44
+ Team {i + 1}
45
+ </TableHeaderCell>
46
+ <TableCell>${dataset[0].y * 10}k</TableCell>
47
+ <TableCell>${dataset[1].y * 10}k</TableCell>
48
+ <TableCell>${dataset[2].y * 10}k</TableCell>
49
+ <TableCell>${dataset[3].y * 10}k</TableCell>
50
+ <TableCell>${dataset[4].y * 10}k</TableCell>
51
+ </TableRow>
52
+ ))}
53
+ </TableBody>
54
+ </Table>
55
+ </Card>
56
+ );
57
+ };
@@ -0,0 +1,100 @@
1
+ import * as React from 'react';
2
+
3
+ import styled from '@emotion/styled';
4
+ import {
5
+ StyledTooltip,
6
+ ThemeContext,
7
+ TooltipArrow,
8
+ TooltipPosition,
9
+ ThemeInterface,
10
+ } from 'react-magma-dom';
11
+
12
+ const StyledGraphTooltip = styled(StyledTooltip)`
13
+ background: ${(props: any) => props.theme.colors.neutral100};
14
+ border: 1px solid ${(props: any) => props.theme.colors.neutral300};
15
+ box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
16
+ box-sizing: border-box;
17
+ color: ${(props: any) => props.theme.colors.neutral};
18
+ font-size: ${(props: any) => props.theme.typeScale.size02.fontSize};
19
+ font-weight: normal;
20
+ line-height: ${(props: any) => props.theme.typeScale.size02.lineHeight};
21
+ margin: 0;
22
+ padding: 8px;
23
+ width: fit-content;
24
+ div {
25
+ margin-bottom: 8px;
26
+ display: flex;
27
+ align-items: flex-start;
28
+ &:last-of-type {
29
+ margin-bottom: 0;
30
+ }
31
+ }
32
+ `;
33
+
34
+ const TooltipColorSwatch = styled.span`
35
+ background: ${(props: any) => props.color};
36
+ border: ${(props: any) => (props.color ? 'none' : '3px solid black')};
37
+ border-radius: 4px;
38
+ height: 20px;
39
+ width: 20px;
40
+ margin-right: 8px;
41
+ `;
42
+
43
+ export const GraphTooltip = (props: any) => {
44
+ const { datum, index, showTooltip, x, y } = props;
45
+
46
+ const theme: ThemeInterface = React.useContext(ThemeContext);
47
+ const linePointIndex = `${index}-${datum.index}`;
48
+
49
+ return showTooltip === linePointIndex ? (
50
+ <g style={{ pointerEvents: 'none' }}>
51
+ <foreignObject x={x} y={y} width="275" height="100%">
52
+ <StyledGraphTooltip
53
+ position={TooltipPosition.top}
54
+ role="tooltip"
55
+ theme={theme}
56
+ >
57
+ <div>
58
+ <TooltipColorSwatch color={theme.iterableColors[index]} />
59
+ <span>{datum.label}</span>
60
+ </div>
61
+ <TooltipArrow theme={theme} />
62
+ </StyledGraphTooltip>
63
+ </foreignObject>
64
+ </g>
65
+ ) : null;
66
+ };
67
+
68
+ export const AxisTooltip = (props: any) => {
69
+ const { x, y, activePoints, hiddenData, dataLength } = props;
70
+
71
+ const pointsIndexes = Array.from(
72
+ Array(dataLength - 0),
73
+ (_, i) => i + 0
74
+ ).filter(i => !hiddenData.includes(i));
75
+
76
+ const theme: ThemeInterface = React.useContext(ThemeContext);
77
+
78
+ return (
79
+ <g style={{ pointerEvents: 'none' }}>
80
+ <foreignObject x={x} y={y} width="275" height="100%">
81
+ <StyledGraphTooltip
82
+ data-testid="axis-tooltip"
83
+ position={TooltipPosition.top}
84
+ role="tooltip"
85
+ theme={theme}
86
+ >
87
+ {activePoints.map((point: any, i: number) => (
88
+ <div key={i}>
89
+ <TooltipColorSwatch
90
+ color={theme.iterableColors[pointsIndexes[i]]}
91
+ />
92
+ <span>{point.label}</span>
93
+ </div>
94
+ ))}
95
+ <TooltipArrow theme={theme} />
96
+ </StyledGraphTooltip>
97
+ </foreignObject>
98
+ </g>
99
+ );
100
+ };
@@ -0,0 +1,77 @@
1
+ import * as React from 'react';
2
+
3
+ import { ThemeContext, Checkbox } from 'react-magma-dom';
4
+
5
+ export interface DataTableProps {
6
+ name?: string;
7
+ color?: string;
8
+ }
9
+
10
+ export const LegendButton = React.forwardRef<HTMLButtonElement, any>(
11
+ (props, ref) => {
12
+ const {
13
+ children,
14
+ color,
15
+ dataIndex,
16
+ isHidden,
17
+ onClick,
18
+ name,
19
+ focusCurrentLine,
20
+ resetLineFocus,
21
+ ...other
22
+ } = props;
23
+
24
+ function handleClick() {
25
+ onClick && typeof onClick === 'function' && onClick(dataIndex);
26
+
27
+ if (!isHidden) {
28
+ resetLineFocus &&
29
+ typeof resetLineFocus === 'function' &&
30
+ resetLineFocus();
31
+ }
32
+ }
33
+
34
+ function handleOnMouseEnterOrFocus() {
35
+ if (!isHidden) {
36
+ focusCurrentLine &&
37
+ typeof focusCurrentLine === 'function' &&
38
+ focusCurrentLine(dataIndex);
39
+ }
40
+ }
41
+
42
+ const theme = React.useContext(ThemeContext);
43
+
44
+ return (
45
+ <div
46
+ style={{ display: 'inline-flex' }}
47
+ onMouseEnter={handleOnMouseEnterOrFocus}
48
+ onMouseLeave={resetLineFocus}
49
+ >
50
+ <Checkbox
51
+ checked={!isHidden}
52
+ color={color}
53
+ containerStyle={{
54
+ alignItems: 'center',
55
+ border: '0',
56
+ boxShadow: '0 0 0',
57
+ color: theme.colors.neutral,
58
+ display: 'inline-flex',
59
+ margin: '0 36px 20px 0',
60
+ padding: '0',
61
+ }}
62
+ inputStyle={{
63
+ border: color ? `none` : `2px solid ${theme.colors.neutral800}`,
64
+ borderRadius: '4px',
65
+ }}
66
+ labelText={name}
67
+ onBlur={resetLineFocus}
68
+ onClick={handleClick}
69
+ onFocus={handleOnMouseEnterOrFocus}
70
+ ref={ref}
71
+ theme={theme}
72
+ {...other}
73
+ />
74
+ </div>
75
+ );
76
+ }
77
+ );