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

Function updateDims

src/core/core.layouts.js:116–147  ·  view source on GitHub ↗
(chartArea, params, layout, stacks)

Source from the content-addressed store, hash-verified

114}
115
116function updateDims(chartArea, params, layout, stacks) {
117 const {pos, box} = layout;
118 const maxPadding = chartArea.maxPadding;
119
120 // dynamically placed boxes size is not considered
121 if (!isObject(pos)) {
122 if (layout.size) {
123 // this layout was already counted for, lets first reduce old size
124 chartArea[pos] -= layout.size;
125 }
126 const stack = stacks[layout.stack] || {size: 0, count: 1};
127 stack.size = Math.max(stack.size, layout.horizontal ? box.height : box.width);
128 layout.size = stack.size / stack.count;
129 chartArea[pos] += layout.size;
130 }
131
132 if (box.getPadding) {
133 updateMaxPadding(maxPadding, box.getPadding());
134 }
135
136 const newWidth = Math.max(0, params.outerWidth - getCombinedMax(maxPadding, chartArea, 'left', 'right'));
137 const newHeight = Math.max(0, params.outerHeight - getCombinedMax(maxPadding, chartArea, 'top', 'bottom'));
138 const widthChanged = newWidth !== chartArea.w;
139 const heightChanged = newHeight !== chartArea.h;
140 chartArea.w = newWidth;
141 chartArea.h = newHeight;
142
143 // return booleans on the changes per direction
144 return layout.horizontal
145 ? {same: widthChanged, other: heightChanged}
146 : {same: heightChanged, other: widthChanged};
147}
148
149function handleMaxPadding(chartArea) {
150 const maxPadding = chartArea.maxPadding;

Callers 1

fitBoxesFunction · 0.85

Calls 4

isObjectFunction · 0.85
updateMaxPaddingFunction · 0.85
getCombinedMaxFunction · 0.85
getPaddingMethod · 0.65

Tested by

no test coverage detected