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

Method _fitCols

src/plugins/plugin.legend.js:191–228  ·  view source on GitHub ↗
(titleHeight, labelFont, boxWidth, _itemHeight)

Source from the content-addressed store, hash-verified

189 }
190
191 _fitCols(titleHeight, labelFont, boxWidth, _itemHeight) {
192 const {ctx, maxHeight, options: {labels: {padding}}} = this;
193 const hitboxes = this.legendHitBoxes = [];
194 const columnSizes = this.columnSizes = [];
195 const heightLimit = maxHeight - titleHeight;
196
197 let totalWidth = padding;
198 let currentColWidth = 0;
199 let currentColHeight = 0;
200
201 let left = 0;
202 let col = 0;
203
204 this.legendItems.forEach((legendItem, i) => {
205 const {itemWidth, itemHeight} = calculateItemSize(boxWidth, labelFont, ctx, legendItem, _itemHeight);
206
207 // If too tall, go to new column
208 if (i > 0 && currentColHeight + itemHeight + 2 * padding > heightLimit) {
209 totalWidth += currentColWidth + padding;
210 columnSizes.push({width: currentColWidth, height: currentColHeight}); // previous column size
211 left += currentColWidth + padding;
212 col++;
213 currentColWidth = currentColHeight = 0;
214 }
215
216 // Store the hitbox width and height here. Final position will be updated in `draw`
217 hitboxes[i] = {left, top: currentColHeight, col, width: itemWidth, height: itemHeight};
218
219 // Get max width
220 currentColWidth = Math.max(currentColWidth, itemWidth);
221 currentColHeight += itemHeight + padding;
222 });
223
224 totalWidth += currentColWidth;
225 columnSizes.push({width: currentColWidth, height: currentColHeight}); // previous column size
226
227 return totalWidth;
228 }
229
230 adjustHitBoxes() {
231 if (!this.options.display) {

Callers 1

fitMethod · 0.95

Calls 1

calculateItemSizeFunction · 0.85

Tested by

no test coverage detected