@react-magma/charts 13.3.0-next.1 → 13.3.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.
- package/dist/charts.js +193 -236
- package/dist/charts.js.map +1 -1
- package/dist/charts.modern.module.js +193 -236
- package/dist/charts.modern.module.js.map +1 -1
- package/dist/charts.umd.js +666 -367
- package/dist/charts.umd.js.map +1 -1
- package/dist/components/CarbonChart/CarbonChart.d.ts +10 -0
- package/dist/components/ChartTable/ChartTable.stories.d.ts +6 -0
- package/package.json +3 -3
- package/src/components/CarbonChart/CarbonChart.test.js +151 -19
- package/src/components/CarbonChart/CarbonChart.tsx +293 -272
- package/src/components/ChartTable/ChartTable.stories.tsx +54 -0
|
@@ -103,5 +103,15 @@ export interface CarbonChartProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
103
103
|
* toolbar is automatically disabled.
|
|
104
104
|
*/
|
|
105
105
|
chartToolbar?: ChartToolbarConfig;
|
|
106
|
+
/**
|
|
107
|
+
* Custom content rendered below the toolbar row and above the chart itself,
|
|
108
|
+
* for example a filter. Requires `chartToolbar`; ignored without it.
|
|
109
|
+
*
|
|
110
|
+
* Providing this lays the toolbar out in normal flow instead of overlaying
|
|
111
|
+
* the single row Carbon reserves for its title, so the rendered height
|
|
112
|
+
* becomes toolbar + content + chart rather than the chart box alone. Set
|
|
113
|
+
* `options.height` so the chart still has a definite height of its own.
|
|
114
|
+
*/
|
|
115
|
+
additionalContent?: React.ReactNode;
|
|
106
116
|
}
|
|
107
117
|
export declare const CarbonChart: React.ForwardRefExoticComponent<CarbonChartProps & React.RefAttributes<HTMLDivElement>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-magma/charts",
|
|
3
|
-
"version": "13.3.
|
|
3
|
+
"version": "13.3.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"identity-obj-proxy": "^3.0.0",
|
|
48
48
|
"react": "^17.0.2",
|
|
49
49
|
"react-dom": "^17.0.2",
|
|
50
|
-
"react-magma-dom": "^4.
|
|
50
|
+
"react-magma-dom": "^4.17.0",
|
|
51
51
|
"react-magma-icons": "^3.2.5",
|
|
52
52
|
"rollup": "^4.52.4",
|
|
53
53
|
"rollup-plugin-postcss": "^4.0.2"
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@emotion/styled": "^11.13.0",
|
|
58
58
|
"react": "^17.0.2",
|
|
59
59
|
"react-dom": "^17.0.2",
|
|
60
|
-
"react-magma-dom": "^4.
|
|
60
|
+
"react-magma-dom": "^4.16.0",
|
|
61
61
|
"react-magma-icons": "^3.2.5"
|
|
62
62
|
},
|
|
63
63
|
"engines": {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
+
import { SimpleBarChart } from '@carbon/charts-react';
|
|
3
4
|
import { act, render, screen, fireEvent } from '@testing-library/react';
|
|
4
5
|
import userEvent from '@testing-library/user-event';
|
|
5
6
|
import { axe } from 'jest-axe';
|
|
@@ -190,6 +191,27 @@ describe('CarbonChart', () => {
|
|
|
190
191
|
);
|
|
191
192
|
});
|
|
192
193
|
|
|
194
|
+
it("pins Carbon's export `.filled` background to the inverse surface color", () => {
|
|
195
|
+
const testId = 'filled-bg-inverse';
|
|
196
|
+
const { getByTestId } = render(
|
|
197
|
+
<ThemeContext.Provider value={magma}>
|
|
198
|
+
<CarbonChart
|
|
199
|
+
testId={testId}
|
|
200
|
+
dataSet={dataSet}
|
|
201
|
+
options={chartOptions}
|
|
202
|
+
type={CarbonChartType.bar}
|
|
203
|
+
isInverse
|
|
204
|
+
/>
|
|
205
|
+
</ThemeContext.Provider>
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
expect(getByTestId(testId)).toHaveStyleRule(
|
|
209
|
+
'background-color',
|
|
210
|
+
magma.colors.primary600,
|
|
211
|
+
{ target: '.cds--chart-holder.filled' }
|
|
212
|
+
);
|
|
213
|
+
});
|
|
214
|
+
|
|
193
215
|
it('should apply theme.colors.neutral100 for inverse text color', () => {
|
|
194
216
|
const testId = 'text-inverse-test';
|
|
195
217
|
const { getByTestId } = render(
|
|
@@ -957,6 +979,108 @@ describe('CarbonChart', () => {
|
|
|
957
979
|
});
|
|
958
980
|
});
|
|
959
981
|
|
|
982
|
+
describe('image export', () => {
|
|
983
|
+
const toolbarProps = {
|
|
984
|
+
dataSet,
|
|
985
|
+
options: chartOptions,
|
|
986
|
+
type: CarbonChartType.bar,
|
|
987
|
+
chartToolbar: {},
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
let exportToPNG;
|
|
991
|
+
let exportToJPG;
|
|
992
|
+
let createChartSpy;
|
|
993
|
+
|
|
994
|
+
beforeEach(() => {
|
|
995
|
+
exportToPNG = jest.fn();
|
|
996
|
+
exportToJPG = jest.fn();
|
|
997
|
+
createChartSpy = jest
|
|
998
|
+
.spyOn(SimpleBarChart.prototype, 'createChart')
|
|
999
|
+
.mockImplementation(() => ({
|
|
1000
|
+
services: { domUtils: { exportToPNG, exportToJPG } },
|
|
1001
|
+
}));
|
|
1002
|
+
});
|
|
1003
|
+
|
|
1004
|
+
afterEach(() => {
|
|
1005
|
+
createChartSpy.mockRestore();
|
|
1006
|
+
});
|
|
1007
|
+
|
|
1008
|
+
it("runs Carbon's own PNG export from the More options menu", () => {
|
|
1009
|
+
render(<CarbonChart {...toolbarProps} />);
|
|
1010
|
+
|
|
1011
|
+
fireEvent.click(screen.getByRole('button', { name: 'More options' }));
|
|
1012
|
+
fireEvent.click(screen.getByText('Download as PNG'));
|
|
1013
|
+
|
|
1014
|
+
expect(exportToPNG).toHaveBeenCalledTimes(1);
|
|
1015
|
+
expect(exportToJPG).not.toHaveBeenCalled();
|
|
1016
|
+
});
|
|
1017
|
+
|
|
1018
|
+
it("runs Carbon's own JPG export from the More options menu", () => {
|
|
1019
|
+
render(<CarbonChart {...toolbarProps} />);
|
|
1020
|
+
|
|
1021
|
+
fireEvent.click(screen.getByRole('button', { name: 'More options' }));
|
|
1022
|
+
fireEvent.click(screen.getByText('Download as JPG'));
|
|
1023
|
+
|
|
1024
|
+
expect(exportToJPG).toHaveBeenCalledTimes(1);
|
|
1025
|
+
expect(exportToPNG).not.toHaveBeenCalled();
|
|
1026
|
+
});
|
|
1027
|
+
|
|
1028
|
+
it("keeps Carbon's own title alive and uses it as the export file name", () => {
|
|
1029
|
+
render(<CarbonChart {...toolbarProps} />);
|
|
1030
|
+
|
|
1031
|
+
const options = createChartSpy.mock.calls[0][2];
|
|
1032
|
+
expect(options.title).toBe(chartOptions.title);
|
|
1033
|
+
expect(options.fileDownload.fileName).toBe(chartOptions.title);
|
|
1034
|
+
});
|
|
1035
|
+
|
|
1036
|
+
it("reveals Carbon's hidden title for the capture and restores it afterwards", () => {
|
|
1037
|
+
jest.useFakeTimers();
|
|
1038
|
+
try {
|
|
1039
|
+
const { container } = render(<CarbonChart {...toolbarProps} />);
|
|
1040
|
+
const wrapper = container.querySelector('.carbon-chart-wrapper');
|
|
1041
|
+
|
|
1042
|
+
expect(wrapper).toHaveClass('has-magma-toolbar');
|
|
1043
|
+
|
|
1044
|
+
fireEvent.click(screen.getByRole('button', { name: 'More options' }));
|
|
1045
|
+
fireEvent.click(screen.getByText('Download as PNG'));
|
|
1046
|
+
|
|
1047
|
+
expect(wrapper).not.toHaveClass('has-magma-toolbar');
|
|
1048
|
+
|
|
1049
|
+
jest.runOnlyPendingTimers();
|
|
1050
|
+
expect(wrapper).toHaveClass('has-magma-toolbar');
|
|
1051
|
+
} finally {
|
|
1052
|
+
jest.useRealTimers();
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1055
|
+
|
|
1056
|
+
it('reveals the title for the flow layout (additionalContent) export too', () => {
|
|
1057
|
+
jest.useFakeTimers();
|
|
1058
|
+
try {
|
|
1059
|
+
const { container } = render(
|
|
1060
|
+
<CarbonChart
|
|
1061
|
+
{...toolbarProps}
|
|
1062
|
+
additionalContent={<div>Filter</div>}
|
|
1063
|
+
/>
|
|
1064
|
+
);
|
|
1065
|
+
const wrapper = container.querySelector('.carbon-chart-wrapper');
|
|
1066
|
+
|
|
1067
|
+
expect(createChartSpy.mock.calls[0][2].title).toBe(chartOptions.title);
|
|
1068
|
+
expect(wrapper).toHaveClass('has-magma-toolbar');
|
|
1069
|
+
|
|
1070
|
+
fireEvent.click(screen.getByRole('button', { name: 'More options' }));
|
|
1071
|
+
fireEvent.click(screen.getByText('Download as JPG'));
|
|
1072
|
+
|
|
1073
|
+
expect(exportToJPG).toHaveBeenCalledTimes(1);
|
|
1074
|
+
expect(wrapper).not.toHaveClass('has-magma-toolbar');
|
|
1075
|
+
|
|
1076
|
+
jest.runOnlyPendingTimers();
|
|
1077
|
+
expect(wrapper).toHaveClass('has-magma-toolbar');
|
|
1078
|
+
} finally {
|
|
1079
|
+
jest.useRealTimers();
|
|
1080
|
+
}
|
|
1081
|
+
});
|
|
1082
|
+
});
|
|
1083
|
+
|
|
960
1084
|
describe('dot keyboard accessibility', () => {
|
|
961
1085
|
let rafCallbacks;
|
|
962
1086
|
|
|
@@ -1020,15 +1144,6 @@ describe('CarbonChart', () => {
|
|
|
1020
1144
|
});
|
|
1021
1145
|
|
|
1022
1146
|
describe('focus on dot content', () => {
|
|
1023
|
-
it('should set opacity to 1 when a dot receives focus', () => {
|
|
1024
|
-
const wrapper = renderChart();
|
|
1025
|
-
const dot = addDot(wrapper);
|
|
1026
|
-
|
|
1027
|
-
fireEvent.focusIn(dot);
|
|
1028
|
-
|
|
1029
|
-
expect(dot.style.opacity).toBe('1');
|
|
1030
|
-
});
|
|
1031
|
-
|
|
1032
1147
|
it('should dispatch mouseover on dot focusin to reveal tooltip data', () => {
|
|
1033
1148
|
const wrapper = renderChart();
|
|
1034
1149
|
const dot = addDot(wrapper);
|
|
@@ -1068,28 +1183,45 @@ describe('CarbonChart', () => {
|
|
|
1068
1183
|
});
|
|
1069
1184
|
|
|
1070
1185
|
describe('data visibility', () => {
|
|
1071
|
-
it('should
|
|
1186
|
+
it('should dispatch mouseout on dot focusout to hide tooltip', () => {
|
|
1072
1187
|
const wrapper = renderChart();
|
|
1073
1188
|
const dot = addDot(wrapper);
|
|
1074
1189
|
|
|
1075
|
-
|
|
1076
|
-
|
|
1190
|
+
const mouseoutSpy = jest.fn();
|
|
1191
|
+
dot.addEventListener('mouseout', mouseoutSpy);
|
|
1077
1192
|
|
|
1193
|
+
fireEvent.focusIn(dot);
|
|
1078
1194
|
fireEvent.focusOut(dot);
|
|
1079
|
-
|
|
1195
|
+
|
|
1196
|
+
expect(mouseoutSpy).toHaveBeenCalledTimes(1);
|
|
1080
1197
|
});
|
|
1081
1198
|
|
|
1082
|
-
it('should dispatch mouseout
|
|
1199
|
+
it('should not dispatch mouseout when focus moves from one dot to another', () => {
|
|
1083
1200
|
const wrapper = renderChart();
|
|
1084
|
-
const
|
|
1201
|
+
const firstDot = addDot(wrapper);
|
|
1202
|
+
const secondDot = addDot(wrapper);
|
|
1085
1203
|
|
|
1086
1204
|
const mouseoutSpy = jest.fn();
|
|
1087
|
-
|
|
1205
|
+
firstDot.addEventListener('mouseout', mouseoutSpy);
|
|
1088
1206
|
|
|
1089
|
-
fireEvent.
|
|
1090
|
-
fireEvent.focusOut(dot);
|
|
1207
|
+
fireEvent.focusOut(firstDot, { relatedTarget: secondDot });
|
|
1091
1208
|
|
|
1092
|
-
expect(mouseoutSpy).
|
|
1209
|
+
expect(mouseoutSpy).not.toHaveBeenCalled();
|
|
1210
|
+
});
|
|
1211
|
+
});
|
|
1212
|
+
|
|
1213
|
+
describe('dynamic dot rendering', () => {
|
|
1214
|
+
it('should stamp tabindex="0" on dots added after initial raf pass', () => {
|
|
1215
|
+
const wrapper = renderChart();
|
|
1216
|
+
|
|
1217
|
+
// Run initial pass before adding a dot so the observer must handle it.
|
|
1218
|
+
act(() => rafCallbacks[rafCallbacks.length - 1](0));
|
|
1219
|
+
|
|
1220
|
+
const lateDot = addDot(wrapper);
|
|
1221
|
+
|
|
1222
|
+
act(() => mutationObserverCallback([]));
|
|
1223
|
+
|
|
1224
|
+
expect(lateDot).toHaveAttribute('tabindex', '0');
|
|
1093
1225
|
});
|
|
1094
1226
|
});
|
|
1095
1227
|
});
|