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

Function getRatioAndOffset

src/controllers/controller.doughnut.js:10–35  ·  view source on GitHub ↗

* @typedef { import('../core/core.controller.js').default } Chart

(rotation, circumference, cutout)

Source from the content-addressed store, hash-verified

8 */
9
10function getRatioAndOffset(rotation, circumference, cutout) {
11 let ratioX = 1;
12 let ratioY = 1;
13 let offsetX = 0;
14 let offsetY = 0;
15 // If the chart's circumference isn't a full circle, calculate size as a ratio of the width/height of the arc
16 if (circumference < TAU) {
17 const startAngle = rotation;
18 const endAngle = startAngle + circumference;
19 const startX = Math.cos(startAngle);
20 const startY = Math.sin(startAngle);
21 const endX = Math.cos(endAngle);
22 const endY = Math.sin(endAngle);
23 const calcMax = (angle, a, b) => _angleBetween(angle, startAngle, endAngle, true) ? 1 : Math.max(a, a * cutout, b, b * cutout);
24 const calcMin = (angle, a, b) => _angleBetween(angle, startAngle, endAngle, true) ? -1 : Math.min(a, a * cutout, b, b * cutout);
25 const maxX = calcMax(0, startX, endX);
26 const maxY = calcMax(HALF_PI, startY, endY);
27 const minX = calcMin(PI, startX, endX);
28 const minY = calcMin(PI + HALF_PI, startY, endY);
29 ratioX = (maxX - minX) / 2;
30 ratioY = (maxY - minY) / 2;
31 offsetX = -(maxX + minX) / 2;
32 offsetY = -(maxY + minY) / 2;
33 }
34 return {ratioX, ratioY, offsetX, offsetY};
35}
36
37export default class DoughnutController extends DatasetController {
38

Callers 1

updateMethod · 0.85

Calls 2

calcMaxFunction · 0.85
calcMinFunction · 0.85

Tested by

no test coverage detected