MCPcopy
hub / github.com/chartjs/Chart.js / getContainerSize

Function getContainerSize

src/helpers/helpers.dom.ts:133–158  ·  view source on GitHub ↗
(canvas: HTMLCanvasElement, width: number, height: number)

Source from the content-addressed store, hash-verified

131}
132
133function 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
160const round1 = (v: number) => Math.round(v * 10) / 10;
161

Callers 1

getMaximumSizeFunction · 0.85

Calls 4

_getParentNodeFunction · 0.85
getComputedStyleFunction · 0.85
getPositionedStyleFunction · 0.85
parseMaxStyleFunction · 0.85

Tested by

no test coverage detected