MCPcopy Create free account
hub / github.com/chartjs/Chart.js / update

Method update

src/controllers/controller.doughnut.js:211–241  ·  view source on GitHub ↗

* @param {string} mode

(mode)

Source from the content-addressed store, hash-verified

209 * @param {string} mode
210 */
211 update(mode) {
212 const chart = this.chart;
213 const {chartArea} = chart;
214 const meta = this._cachedMeta;
215 const arcs = meta.data;
216 const spacing = this.getMaxBorderWidth() + this.getMaxOffset(arcs) + this.options.spacing;
217 const maxSize = Math.max((Math.min(chartArea.width, chartArea.height) - spacing) / 2, 0);
218 const cutout = Math.min(toPercentage(this.options.cutout, maxSize), 1);
219 const chartWeight = this._getRingWeight(this.index);
220
221 // Compute the maximal rotation & circumference limits.
222 // If we only consider our dataset, this can cause problems when two datasets
223 // are both less than a circle with different rotations (starting angles)
224 const {circumference, rotation} = this._getRotationExtents();
225 const {ratioX, ratioY, offsetX, offsetY} = getRatioAndOffset(rotation, circumference, cutout);
226 const maxWidth = (chartArea.width - spacing) / ratioX;
227 const maxHeight = (chartArea.height - spacing) / ratioY;
228 const maxRadius = Math.max(Math.min(maxWidth, maxHeight) / 2, 0);
229 const outerRadius = toDimension(this.options.radius, maxRadius);
230 const innerRadius = Math.max(outerRadius * cutout, 0);
231 const radiusLength = (outerRadius - innerRadius) / this._getVisibleDatasetWeightTotal();
232 this.offsetX = offsetX * outerRadius;
233 this.offsetY = offsetY * outerRadius;
234
235 meta.total = this.calculateTotal();
236
237 this.outerRadius = outerRadius - radiusLength * this._getRingWeightOffset(this.index);
238 this.innerRadius = Math.max(this.outerRadius - radiusLength * chartWeight, 0);
239
240 this.updateElements(arcs, 0, arcs.length, mode);
241 }
242
243 /**
244 * @private

Callers

nothing calls this directly

Calls 11

getMaxBorderWidthMethod · 0.95
getMaxOffsetMethod · 0.95
_getRingWeightMethod · 0.95
_getRotationExtentsMethod · 0.95
calculateTotalMethod · 0.95
_getRingWeightOffsetMethod · 0.95
updateElementsMethod · 0.95
toPercentageFunction · 0.85
getRatioAndOffsetFunction · 0.85
toDimensionFunction · 0.85

Tested by

no test coverage detected