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

Method update

src/controllers/controller.doughnut.js:208–238  ·  view source on GitHub ↗

* @param {string} mode

(mode)

Source from the content-addressed store, hash-verified

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