Skip to content

Commit 7eb41f6

Browse files
committed
Fix using above/below filling option with discontinuous lines
Added a test in the boundary folder
1 parent 4a9f446 commit 7eb41f6

File tree

5 files changed

+129
-2
lines changed

5 files changed

+129
-2
lines changed

src/plugins/plugin.filler.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,30 @@ function resolveTarget(sources, index, propagate) {
383383
}
384384

385385
function _clip(ctx, target, clipY) {
386+
const {segments, points} = target;
387+
let first = true;
388+
let lineLoop = false;
389+
386390
ctx.beginPath();
387-
target.path(ctx);
388-
ctx.lineTo(target.last().x, clipY);
391+
for (const segment of segments) {
392+
const {start, end} = segment;
393+
const firstPoint = points[start];
394+
const lastPoint = points[findSegmentEnd(start, end, points)];
395+
if (first) {
396+
ctx.moveTo(firstPoint.x, firstPoint.y);
397+
first = false;
398+
} else {
399+
ctx.lineTo(firstPoint.x, clipY);
400+
ctx.lineTo(firstPoint.x, firstPoint.y);
401+
}
402+
lineLoop = !!target.pathSegment(ctx, segment, {move: lineLoop});
403+
if (lineLoop) {
404+
ctx.closePath();
405+
} else {
406+
ctx.lineTo(lastPoint.x, clipY);
407+
}
408+
}
409+
389410
ctx.lineTo(target.first().x, clipY);
390411
ctx.closePath();
391412
ctx.clip();
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"config": {
3+
"type": "line",
4+
"data": {
5+
"labels": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"],
6+
"datasets": [{
7+
"borderColor": "rgb(42, 90, 145)",
8+
"data": [null, 12, 30, 36, 45, 53, 68, 79, null, 95, 18, 18, 180],
9+
"fill": {
10+
"target": "+1",
11+
"above": "rgba(4, 142, 43, 0.5)",
12+
"below": "rgba(241, 49, 34, 0.5)"
13+
}
14+
}, {
15+
"borderColor": "#00ADEE",
16+
"data": [null, 0, 0, 0, 0, 0, 20, 108, null, 72, 72, 72, 72],
17+
"fill": false
18+
}]
19+
},
20+
"options": {
21+
"responsive": false,
22+
"spanGaps": false,
23+
"scales": {
24+
"x": {
25+
"display": false
26+
},
27+
"y": {
28+
"display": false
29+
}
30+
},
31+
"elements": {
32+
"point": {
33+
"radius": 0
34+
},
35+
"line": {
36+
"cubicInterpolationMode": "monotone",
37+
"borderColor": "transparent"
38+
}
39+
},
40+
"plugins": {
41+
"legend": false,
42+
"title": false,
43+
"tooltip": false
44+
}
45+
}
46+
},
47+
"options": {
48+
"canvas": {
49+
"height": 256,
50+
"width": 512
51+
}
52+
}
53+
}
17.3 KB
Loading
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"config": {
3+
"type": "line",
4+
"data": {
5+
"labels": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"],
6+
"datasets": [{
7+
"borderColor": "rgb(42, 90, 145)",
8+
"data": [4, 12, 30, 36, 45, 53, 68, 79, null, 95, 18, null, 18, 180],
9+
"fill": {
10+
"target": "+1",
11+
"above": "rgba(4, 142, 43, 0.5)",
12+
"below": "rgba(241, 49, 34, 0.5)"
13+
}
14+
}, {
15+
"borderColor": "#00ADEE",
16+
"data": [0, 0, 0, 0, 0, 0, 20, 108, null, 72, 72, null, 72, 72],
17+
"fill": false
18+
}]
19+
},
20+
"options": {
21+
"responsive": false,
22+
"spanGaps": false,
23+
"scales": {
24+
"x": {
25+
"display": false
26+
},
27+
"y": {
28+
"display": false
29+
}
30+
},
31+
"elements": {
32+
"point": {
33+
"radius": 0
34+
},
35+
"line": {
36+
"cubicInterpolationMode": "monotone",
37+
"borderColor": "transparent"
38+
}
39+
},
40+
"plugins": {
41+
"legend": false,
42+
"title": false,
43+
"tooltip": false
44+
}
45+
}
46+
},
47+
"options": {
48+
"canvas": {
49+
"height": 256,
50+
"width": 512
51+
}
52+
}
53+
}
18.2 KB
Loading

0 commit comments

Comments
 (0)