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

Function update

src/core/core.layouts.js:345–454  ·  src/core/core.layouts.js::update

* Fits boxes of the given chart into the given size by having each box measure itself * then running a fitting algorithm * @param {Chart} chart - the chart * @param {number} width - the width to fit into * @param {number} height - the height to fit into * @param {number} minPadding - mini

(chart, width, height, minPadding)

Source from the content-addressed store, hash-verified

343 * @param {number} minPadding - minimum padding required for each side of chart area
344 */
345 update(chart, width, height, minPadding) {
346 if (!chart) {
347 return;
348 }
349
350 const padding = toPadding(chart.options.layout.padding);
351 const availableWidth = Math.max(width - padding.width, 0);
352 const availableHeight = Math.max(height - padding.height, 0);
353 const boxes = buildLayoutBoxes(chart.boxes);
354 const verticalBoxes = boxes.vertical;
355 const horizontalBoxes = boxes.horizontal;
356
357 class="cm">// Before any changes are made, notify boxes that an update is about to being
358 class="cm">// This is used to clear any cached data (e.g. scale limits)
359 each(chart.boxes, box => {
360 if (typeof box.beforeLayout === class="st">'function') {
361 box.beforeLayout();
362 }
363 });
364
365 class="cm">// Essentially we now have any number of boxes on each of the 4 sides.
366 class="cm">// Our canvas looks like the following.
367 class="cm">// The areas L1 and L2 are the left axes. R1 is the right axis, T1 is the top axis and
368 class="cm">// B1 is the bottom axis
369 class="cm">// There are also 4 quadrant-like locations (left to right instead of clockwise) reserved for chart overlays
370 class="cm">// These locations are single-box locations only, when trying to register a chartArea location that is already taken,
371 class="cm">// an error will be thrown.
372 class="cm">//
373 class="cm">// |----------------------------------------------------|
374 class="cm">// | T1 (Full Width) |
375 class="cm">// |----------------------------------------------------|
376 class="cm">// | | | T2 | |
377 class="cm">// | |----|-------------------------------------|----|
378 class="cm">// | | | C1 | | C2 | |
379 class="cm">// | | |----| |----| |
380 class="cm">// | | | | |
381 class="cm">// | L1 | L2 | ChartArea (C0) | R1 |
382 class="cm">// | | | | |
383 class="cm">// | | |----| |----| |
384 class="cm">// | | | C3 | | C4 | |
385 class="cm">// | |----|-------------------------------------|----|
386 class="cm">// | | | B1 | |
387 class="cm">// |----------------------------------------------------|
388 class="cm">// | B2 (Full Width) |
389 class="cm">// |----------------------------------------------------|
390 class="cm">//
391
392 const visibleVerticalBoxCount = verticalBoxes.reduce((total, wrap) =>
393 wrap.box.options && wrap.box.options.display === false ? total : total + 1, 0) || 1;
394
395 const params = Object.freeze({
396 outerWidth: width,
397 outerHeight: height,
398 padding,
399 availableWidth,
400 availableHeight,
401 vBoxMaxWidth: availableWidth / 2 / visibleVerticalBoxCount,
402 hBoxMaxHeight: availableHeight / 2

Callers

nothing calls this directly

Calls 10

toPaddingFunction · 0.85
buildLayoutBoxesFunction · 0.85
eachFunction · 0.85
updateMaxPaddingFunction · 0.85
setLayoutDimsFunction · 0.85
fitBoxesFunction · 0.85
handleMaxPaddingFunction · 0.85
placeBoxesFunction · 0.85
beforeLayoutMethod · 0.65
updateMethod · 0.65

Tested by

no test coverage detected