@react-magma/charts 13.3.1 → 13.3.2-v4-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-magma/charts",
3
- "version": "13.3.1",
3
+ "version": "13.3.2-v4-next.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -979,6 +979,77 @@ describe('CarbonChart', () => {
979
979
  });
980
980
  });
981
981
 
982
+ describe('fullscreen', () => {
983
+ const toolbarProps = {
984
+ dataSet,
985
+ options: chartOptions,
986
+ type: CarbonChartType.bar,
987
+ chartToolbar: {},
988
+ };
989
+
990
+ let setOptions;
991
+ let createChartSpy;
992
+
993
+ const setFullscreenElement = element => {
994
+ Object.defineProperty(document, 'fullscreenElement', {
995
+ configurable: true,
996
+ value: element,
997
+ });
998
+ act(() => {
999
+ document.dispatchEvent(new Event('fullscreenchange'));
1000
+ });
1001
+ };
1002
+
1003
+ beforeEach(() => {
1004
+ setOptions = jest.fn();
1005
+ createChartSpy = jest
1006
+ .spyOn(SimpleBarChart.prototype, 'createChart')
1007
+ .mockImplementation(holder => {
1008
+ holder.classList.add('cds--chart-holder');
1009
+ holder.style.height = chartOptions.height;
1010
+
1011
+ return { model: { setOptions, setData: jest.fn() } };
1012
+ });
1013
+ });
1014
+
1015
+ afterEach(() => {
1016
+ createChartSpy.mockRestore();
1017
+ delete document.fullscreenElement;
1018
+ });
1019
+
1020
+ it('does not update chart options when entering and exiting fullscreen', () => {
1021
+ const { container } = render(<CarbonChart {...toolbarProps} />);
1022
+ const holder = container.querySelector('.cds--chart-holder');
1023
+
1024
+ setFullscreenElement(container.firstChild);
1025
+
1026
+ expect(
1027
+ screen.getByRole('button', {
1028
+ name: `Exit ${chartOptions.title} full screen`,
1029
+ })
1030
+ ).toBeInTheDocument();
1031
+ expect(holder.style.height).toBe('100vh');
1032
+
1033
+ setFullscreenElement(null);
1034
+
1035
+ expect(
1036
+ screen.getByRole('button', {
1037
+ name: `View ${chartOptions.title} full screen`,
1038
+ })
1039
+ ).toBeInTheDocument();
1040
+ expect(holder.style.height).toBe(chartOptions.height);
1041
+ expect(setOptions).not.toHaveBeenCalled();
1042
+ });
1043
+
1044
+ it('does not update chart options on re-render with the same props', () => {
1045
+ const { rerender } = render(<CarbonChart {...toolbarProps} />);
1046
+
1047
+ rerender(<CarbonChart {...toolbarProps} chartToolbar={{}} />);
1048
+
1049
+ expect(setOptions).not.toHaveBeenCalled();
1050
+ });
1051
+ });
1052
+
982
1053
  describe('image export', () => {
983
1054
  const toolbarProps = {
984
1055
  dataSet,
@@ -1373,28 +1373,32 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1373
1373
  isInverse,
1374
1374
  ]);
1375
1375
 
1376
- const newOptions = {
1377
- ...options,
1378
- theme: isInverse ? ChartTheme.G100 : ChartTheme.WHITE,
1379
- color: {
1380
- scale: colorScale,
1381
- },
1382
- tooltip: {
1383
- ...(options?.tooltip || {}),
1384
- truncation: {
1385
- type: 'none',
1376
+ const hasChartToolbar = Boolean(chartToolbar);
1377
+ const newOptions = React.useMemo(
1378
+ () => ({
1379
+ ...options,
1380
+ theme: isInverse ? ChartTheme.G100 : ChartTheme.WHITE,
1381
+ color: {
1382
+ scale: colorScale,
1386
1383
  },
1387
- },
1388
- ...(chartToolbar
1389
- ? {
1390
- toolbar: { enabled: false },
1391
- title: chartTitle,
1392
- ...(options.fileDownload
1393
- ? {}
1394
- : { fileDownload: { fileName: chartTitle } }),
1395
- }
1396
- : {}),
1397
- };
1384
+ tooltip: {
1385
+ ...(options?.tooltip || {}),
1386
+ truncation: {
1387
+ type: 'none',
1388
+ },
1389
+ },
1390
+ ...(hasChartToolbar
1391
+ ? {
1392
+ toolbar: { enabled: false },
1393
+ title: chartTitle,
1394
+ ...(options.fileDownload
1395
+ ? {}
1396
+ : { fileDownload: { fileName: chartTitle } }),
1397
+ }
1398
+ : {}),
1399
+ }),
1400
+ [options, isInverse, colorScale, hasChartToolbar, chartTitle]
1401
+ );
1398
1402
 
1399
1403
  const ChartType = ALL_CHARTS[type];
1400
1404