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

Function parseBorderRadius

src/elements/element.arc.ts:66–89  ·  view source on GitHub ↗

* Parse border radius from the provided options

(arc: ArcElement, innerRadius: number, outerRadius: number, angleDelta: number)

Source from the content-addressed store, hash-verified

64 * Parse border radius from the provided options
65 */
66function parseBorderRadius(arc: ArcElement, innerRadius: number, outerRadius: number, angleDelta: number) {
67 const o = toRadiusCorners(arc.options.borderRadius);
68 const halfThickness = (outerRadius - innerRadius) / 2;
69 const innerLimit = Math.min(halfThickness, angleDelta * innerRadius / 2);
70
71 // Outer limits are complicated. We want to compute the available angular distance at
72 // a radius of outerRadius - borderRadius because for small angular distances, this term limits.
73 // We compute at r = outerRadius - borderRadius because this circle defines the center of the border corners.
74 //
75 // If the borderRadius is large, that value can become negative.
76 // This causes the outer borders to lose their radius entirely, which is rather unexpected. To solve that, if borderRadius > outerRadius
77 // we know that the thickness term will dominate and compute the limits at that point
78 const computeOuterLimit = (val) => {
79 const outerArcLimit = (outerRadius - Math.min(halfThickness, val)) * angleDelta / 2;
80 return _limitValue(val, 0, Math.min(halfThickness, outerArcLimit));
81 };
82
83 return {
84 outerStart: computeOuterLimit(o.outerStart),
85 outerEnd: computeOuterLimit(o.outerEnd),
86 innerStart: _limitValue(o.innerStart, 0, innerLimit),
87 innerEnd: _limitValue(o.innerEnd, 0, innerLimit),
88 };
89}
90
91/**
92 * Convert (r, 𝜃) to (x, y)

Callers 1

pathArcFunction · 0.70

Calls 3

toRadiusCornersFunction · 0.85
computeOuterLimitFunction · 0.85
_limitValueFunction · 0.85

Tested by

no test coverage detected