(canvas: HTMLCanvasElement, width: number, height: number)
| 131 | } |
| 132 | |
| 133 | function getContainerSize(canvas: HTMLCanvasElement, width: number, height: number): Partial<Scale> { |
| 134 | let maxWidth: number, maxHeight: number; |
| 135 | |
| 136 | if (width === undefined || height === undefined) { |
| 137 | const container = canvas && _getParentNode(canvas); |
| 138 | if (!container) { |
| 139 | width = canvas.clientWidth; |
| 140 | height = canvas.clientHeight; |
| 141 | } else { |
| 142 | const rect = container.getBoundingClientRect(); // this is the border box of the container |
| 143 | const containerStyle = getComputedStyle(container); |
| 144 | const containerBorder = getPositionedStyle(containerStyle, 'border', 'width'); |
| 145 | const containerPadding = getPositionedStyle(containerStyle, 'padding'); |
| 146 | width = rect.width - containerPadding.width - containerBorder.width; |
| 147 | height = rect.height - containerPadding.height - containerBorder.height; |
| 148 | maxWidth = parseMaxStyle(containerStyle.maxWidth, container, 'clientWidth'); |
| 149 | maxHeight = parseMaxStyle(containerStyle.maxHeight, container, 'clientHeight'); |
| 150 | } |
| 151 | } |
| 152 | return { |
| 153 | width, |
| 154 | height, |
| 155 | maxWidth: maxWidth || INFINITY, |
| 156 | maxHeight: maxHeight || INFINITY |
| 157 | }; |
| 158 | } |
| 159 | |
| 160 | const round1 = (v: number) => Math.round(v * 10) / 10; |
| 161 |
no test coverage detected