mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-05 07:54:04 +01:00
Support boundary filling modes in radialLinear scale (#6281)
This commit is contained in:
committed by
Simon Brunel
parent
7d8526f691
commit
cfcdcccc32
@@ -37,6 +37,12 @@ var mappers = {
|
||||
var x = boundary ? boundary.x : null;
|
||||
var y = boundary ? boundary.y : null;
|
||||
|
||||
if (helpers.isArray(boundary)) {
|
||||
return function(point, i) {
|
||||
return boundary[i];
|
||||
};
|
||||
}
|
||||
|
||||
return function(point) {
|
||||
return {
|
||||
x: x === null ? point.x : x,
|
||||
@@ -96,7 +102,7 @@ function decodeFill(el, index, count) {
|
||||
}
|
||||
}
|
||||
|
||||
function computeBoundary(source) {
|
||||
function computeLinearBoundary(source) {
|
||||
var model = source.el._model || {};
|
||||
var scale = source.el._scale || {};
|
||||
var fill = source.fill;
|
||||
@@ -117,8 +123,6 @@ function computeBoundary(source) {
|
||||
target = model.scaleTop === undefined ? scale.top : model.scaleTop;
|
||||
} else if (model.scaleZero !== undefined) {
|
||||
target = model.scaleZero;
|
||||
} else if (scale.getBasePosition) {
|
||||
target = scale.getBasePosition();
|
||||
} else if (scale.getBasePixel) {
|
||||
target = scale.getBasePixel();
|
||||
}
|
||||
@@ -140,6 +144,44 @@ function computeBoundary(source) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function computeCircularBoundary(source) {
|
||||
var scale = source.el._scale;
|
||||
var options = scale.options;
|
||||
var length = scale.chart.data.labels.length;
|
||||
var fill = source.fill;
|
||||
var target = [];
|
||||
var start, end, center, i, point;
|
||||
|
||||
if (!length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
start = options.ticks.reverse ? scale.max : scale.min;
|
||||
end = options.ticks.reverse ? scale.min : scale.max;
|
||||
center = scale.getPointPositionForValue(0, start);
|
||||
for (i = 0; i < length; ++i) {
|
||||
point = fill === 'start' || fill === 'end'
|
||||
? scale.getPointPositionForValue(i, fill === 'start' ? start : end)
|
||||
: scale.getBasePosition(i);
|
||||
if (options.gridLines.circular) {
|
||||
point.cx = center.x;
|
||||
point.cy = center.y;
|
||||
point.angle = scale.getIndexAngle(i) - Math.PI / 2;
|
||||
}
|
||||
target.push(point);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
function computeBoundary(source) {
|
||||
var scale = source.el._scale || {};
|
||||
|
||||
if (scale.getPointPositionForValue) {
|
||||
return computeCircularBoundary(source);
|
||||
}
|
||||
return computeLinearBoundary(source);
|
||||
}
|
||||
|
||||
function resolveTarget(sources, index, propagate) {
|
||||
var source = sources[index];
|
||||
var fill = source.fill;
|
||||
@@ -191,7 +233,7 @@ function isDrawable(point) {
|
||||
}
|
||||
|
||||
function drawArea(ctx, curve0, curve1, len0, len1) {
|
||||
var i;
|
||||
var i, cx, cy, r;
|
||||
|
||||
if (!len0 || !len1) {
|
||||
return;
|
||||
@@ -203,6 +245,16 @@ function drawArea(ctx, curve0, curve1, len0, len1) {
|
||||
helpers.canvas.lineTo(ctx, curve0[i - 1], curve0[i]);
|
||||
}
|
||||
|
||||
if (curve1[0].angle !== undefined) {
|
||||
cx = curve1[0].cx;
|
||||
cy = curve1[0].cy;
|
||||
r = Math.sqrt(Math.pow(curve1[0].x - cx, 2) + Math.pow(curve1[0].y - cy, 2));
|
||||
for (i = len1 - 1; i > 0; --i) {
|
||||
ctx.arc(cx, cy, r, curve1[i].angle, curve1[i - 1].angle, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// joining the two area curves
|
||||
ctx.lineTo(curve1[len1 - 1].x, curve1[len1 - 1].y);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user