Skip to content

Commit f23598c

Browse files
authored
Merge pull request #357 from bcgsc/bugfix/DEVSU-2089-image-size
[Hotfix][DEVSU-2089] SVG size in print
2 parents 0c0ef68 + 448f8ad commit f23598c

File tree

4 files changed

+53
-46
lines changed

4 files changed

+53
-46
lines changed

app/components/SvgImage/__tests__/SvgImage.test.tsx

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from './mockData';
1313
import SvgImage from '..';
1414

15-
jest.mock('react-virtualized-auto-sizer', () => ({ children }) => children({ height: 600, width: 600}));
15+
jest.mock('react-virtualized-auto-sizer', () => ({ children }) => children({ height: 600, width: 600 }));
1616

1717
describe('SvgImage', () => {
1818
test('It renders a normal SVG', async () => {
@@ -63,20 +63,4 @@ describe('SvgImage', () => {
6363

6464
expect(await screen.findByTestId('mock')).toBeInTheDocument();
6565
});
66-
67-
test('It fails to render an SVG that is not formatted correctly', async () => {
68-
let error;
69-
70-
try {
71-
render(
72-
<SvgImage
73-
image={mockSVGFormatError}
74-
/>,
75-
);
76-
} catch (err) {
77-
error = err;
78-
}
79-
80-
expect(error).not.toBeUndefined();
81-
});
8266
});

app/components/SvgImage/index.tsx

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, {
22
useEffect, useState, useRef, useMemo, useCallback,
33
} from 'react';
44
import { UncontrolledReactSVGPanZoom } from 'react-svg-pan-zoom';
5-
import InlineSVG from 'svg-inline-react';
5+
import InlineSVG from 'react-inlinesvg';
66
import AutoSizer from 'react-virtualized-auto-sizer';
77

88
import './index.scss';
@@ -74,7 +74,7 @@ const SvgImage = ({
7474
let overWidthRatio = svgWidth / MAX_PRINT_WIDTH;
7575
if (printOrientation === 'landscape') {
7676
overHeightRatio = svgHeight / MAX_PRINT_WIDTH;
77-
overWidthRatio = svgHeight / MAX_PRINT_WIDTH;
77+
overWidthRatio = svgWidth / MAX_PRINT_HEIGHT;
7878
}
7979
let nextRatio = 1;
8080

@@ -90,29 +90,17 @@ const SvgImage = ({
9090
const nextHeight = svgHeight / nextRatio;
9191
const nextWidth = svgWidth / nextRatio;
9292

93-
const svgStyle = {
94-
transformOrigin: 'top left',
95-
transform: printOrientation === 'landscape' ? `rotate(90deg) translate(0, -${nextHeight}px)` : '',
96-
};
97-
9893
return (
99-
<div style={svgStyle}>
100-
<UncontrolledReactSVGPanZoom
101-
ref={Viewer}
102-
width={svgWidth > nextWidth ? nextWidth : svgWidth}
103-
height={svgHeight > nextHeight ? nextHeight : svgHeight}
104-
background="#FFFFFF"
105-
detectAutoPan={false}
106-
defaultTool="auto"
107-
customMiniature={() => null}
108-
customToolbar={() => null}
109-
toolbarProps={{ position: 'left' }}
110-
>
111-
<svg width={svgWidth} height={svgHeight}>
112-
<InlineSVG src={processedImage} raw />
113-
</svg>
114-
</UncontrolledReactSVGPanZoom>
115-
</div>
94+
<InlineSVG
95+
src={processedImage}
96+
transform={`
97+
scale(${1 / nextRatio})
98+
translate(
99+
-${(svgWidth - nextWidth) / 2 + 48}
100+
-${(svgHeight - nextHeight) / 2}
101+
)
102+
`}
103+
/>
116104
);
117105
}
118106
return (
@@ -128,11 +116,11 @@ const SvgImage = ({
128116
detectAutoPan={false}
129117
defaultTool="auto"
130118
customMiniature={() => null}
131-
customToolbar={isPrint ? () => null : undefined}
119+
customToolbar={undefined}
132120
toolbarProps={{ position: 'left' }}
133121
>
134122
<svg width={svgWidth} height={svgHeight}>
135-
<InlineSVG src={processedImage} raw />
123+
<InlineSVG src={processedImage} />
136124
</svg>
137125
</UncontrolledReactSVGPanZoom>
138126
);

package-lock.json

Lines changed: 36 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "ipr-client",
4-
"version": "6.22.0",
4+
"version": "6.22.1",
55
"keywords": [],
66
"license": "GPL-3.0",
77
"sideEffects": false,
@@ -127,6 +127,7 @@
127127
"react-chartjs-2": "~3.3.0",
128128
"react-dom": "~17.0.2",
129129
"react-hook-form": "^7.40.0",
130+
"react-inlinesvg": "^4.0.5",
130131
"react-jss": "~10.6.0",
131132
"react-quill": "~2.0.0",
132133
"react-router-dom": "~5.1.2",

0 commit comments

Comments
 (0)