Skip to content

Commit 4886922

Browse files
kurklesimonbrunel
authored andcommitted
Fill before drawing lines (chartjs#6208)
1 parent e68a16b commit 4886922

File tree

3 files changed

+81
-16
lines changed

3 files changed

+81
-16
lines changed

src/plugins/plugin.filler.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -296,23 +296,29 @@ module.exports = {
296296
}
297297
},
298298

299-
beforeDatasetDraw: function(chart, args) {
300-
var meta = args.meta.$filler;
301-
if (!meta) {
302-
return;
303-
}
304-
299+
beforeDatasetsDraw: function(chart) {
300+
var count = (chart.data.datasets || []).length - 1;
305301
var ctx = chart.ctx;
306-
var el = meta.el;
307-
var view = el._view;
308-
var points = el._children || [];
309-
var mapper = meta.mapper;
310-
var color = view.backgroundColor || defaults.global.defaultColor;
311-
312-
if (mapper && color && points.length) {
313-
helpers.canvas.clipArea(ctx, chart.chartArea);
314-
doFill(ctx, points, mapper, view, color, el._loop);
315-
helpers.canvas.unclipArea(ctx);
302+
var meta, i, el, view, points, mapper, color;
303+
304+
for (i = count; i >= 0; --i) {
305+
meta = chart.getDatasetMeta(i).$filler;
306+
307+
if (!meta || !meta.visible) {
308+
continue;
309+
}
310+
311+
el = meta.el;
312+
view = el._view;
313+
points = el._children || [];
314+
mapper = meta.mapper;
315+
color = view.backgroundColor || defaults.global.defaultColor;
316+
317+
if (mapper && color && points.length) {
318+
helpers.canvas.clipArea(ctx, chart.chartArea);
319+
doFill(ctx, points, mapper, view, color, el._loop);
320+
helpers.canvas.unclipArea(ctx);
321+
}
316322
}
317323
}
318324
};
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"config": {
3+
"type": "line",
4+
"data": {
5+
"labels": ["0", "1", "2", "3", "4", "5", "6", "7", "8"],
6+
"datasets": [{
7+
"backgroundColor": "rgba(255, 0, 0, 0.25)",
8+
"data": [null, null, 0, -1, 0, 1, 0, -1, 0],
9+
"fill": 1
10+
}, {
11+
"backgroundColor": "rgba(0, 255, 0, 0.25)",
12+
"data": [1, 0, null, 1, 0, null, -1, 0, 1],
13+
"fill": "+1"
14+
}, {
15+
"backgroundColor": "rgba(0, 0, 255, 0.25)",
16+
"data": [0, 2, 0, -2, 0, 2, 0],
17+
"fill": 3
18+
}, {
19+
"backgroundColor": "rgba(255, 0, 255, 0.25)",
20+
"data": [2, 0, -2, 0, 2, 0, -2, 0, 2],
21+
"fill": "-2"
22+
}, {
23+
"backgroundColor": "rgba(255, 255, 0, 0.25)",
24+
"data": [3, 1, -1, -3, -1, 1, 3, 1, -1],
25+
"fill": "-1"
26+
}]
27+
},
28+
"options": {
29+
"responsive": false,
30+
"spanGaps": false,
31+
"legend": false,
32+
"title": false,
33+
"scales": {
34+
"xAxes": [{
35+
"display": false
36+
}],
37+
"yAxes": [{
38+
"display": false
39+
}]
40+
},
41+
"elements": {
42+
"point": {
43+
"radius": 0
44+
},
45+
"line": {
46+
"borderColor": "black",
47+
"borderWidth": 5,
48+
"tension": 0
49+
}
50+
}
51+
}
52+
},
53+
"options": {
54+
"canvas": {
55+
"height": 256,
56+
"width": 512
57+
}
58+
}
59+
}
Loading

0 commit comments

Comments
 (0)