Skip to content

Commit 9bd22fa

Browse files
committed
Fix dataset ordering issues
Chart.js draws datasets in the reverse order (the first dataset in the array is drawn last, thus on top of the others), which means that labels for the first dataset should be drawn on top of the other labels but also not discarded when `display: 'auto'`.
1 parent d85e750 commit 9bd22fa

6 files changed

Lines changed: 35 additions & 35 deletions

File tree

docs/guide/positioning.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ display: function(context) {
6262
The `display: 'auto'` option can be used to prevent overlapping labels, based on the following rules when two labels overlap:
6363

6464
- if both labels are `display: true`, they will be drawn overlapping
65-
- if both labels are `display: 'auto'`, the one with the highest data index will be hidden. If labels are at the same data index, the one with the lowest dataset index will be hidden
65+
- if both labels are `display: 'auto'`, the one with the highest data index will be hidden. If labels are at the same data index, the one with the highest dataset index will be hidden
6666
- if one label is `display: true` and the other one is `display: 'auto'`, the one with `'auto'` will be hidden (whatever the data/dataset indices)
6767

6868
::: tip NOTE

src/layout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export default {
112112
var sb = b.$layout;
113113

114114
return sa._idx === sb._idx
115-
? sa._set - sb._set
115+
? sb._set - sa._set
116116
: sb._idx - sa._idx;
117117
});
118118

test/fixtures/options.clip/clip-indexable.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ export default {
1717
datasets: [{
1818
data: data,
1919
datalabels: {
20-
backgroundColor: '#ff0077',
21-
borderColor: 'white',
22-
padding: 32,
20+
backgroundColor: '#0f7',
21+
borderColor: 'black',
22+
padding: 16,
2323
clip: [
24+
true,
2425
false,
2526
true,
2627
false,
@@ -29,17 +30,15 @@ export default {
2930
true,
3031
false,
3132
true,
32-
false
3333
]
3434
}
3535
}, {
3636
data: data,
3737
datalabels: {
38-
backgroundColor: '#00ff77',
39-
borderColor: 'black',
40-
padding: 16,
38+
backgroundColor: '#f07',
39+
borderColor: 'white',
40+
padding: 32,
4141
clip: [
42-
true,
4342
false,
4443
true,
4544
false,
@@ -48,6 +47,7 @@ export default {
4847
true,
4948
false,
5049
true,
50+
false
5151
]
5252
}
5353
}]

test/fixtures/options.clip/clip-scriptable.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ export default {
1717
datasets: [{
1818
data: data,
1919
datalabels: {
20-
backgroundColor: '#ff0077',
21-
borderColor: 'white',
22-
padding: 32
20+
backgroundColor: '#0f7',
21+
borderColor: 'black',
22+
padding: 16
2323
}
2424
}, {
2525
data: data,
2626
datalabels: {
27-
backgroundColor: '#00ff77',
28-
borderColor: 'black',
29-
padding: 16
27+
backgroundColor: '#f07',
28+
borderColor: 'white',
29+
padding: 32
3030
}
3131
}]
3232
},
@@ -38,7 +38,7 @@ export default {
3838
datalabels: {
3939
borderWidth: 4,
4040
clip: function(ctx) {
41-
return (ctx.dataIndex + ctx.datasetIndex) % 2 === 0;
41+
return (ctx.dataIndex + ctx.datasetIndex) % 2 === 1;
4242
},
4343
font: {
4444
size: 0

test/fixtures/options.clip/clip-values.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ export default {
1717
datasets: [{
1818
data: data,
1919
datalabels: {
20-
backgroundColor: '#ff0077',
21-
borderColor: 'white',
22-
clip: true,
23-
padding: 32
20+
backgroundColor: '#0f7',
21+
borderColor: 'black',
22+
clip: false,
23+
padding: 16
2424
}
2525
}, {
2626
data: data,
2727
datalabels: {
28-
backgroundColor: '#00ff77',
29-
borderColor: 'black',
30-
clip: false,
31-
padding: 16
28+
backgroundColor: '#f07',
29+
borderColor: 'white',
30+
clip: true,
31+
padding: 32
3232
}
3333
}]
3434
},

test/fixtures/options.display/display-values-bool.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ export default {
44
data: {
55
labels: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
66
datasets: [{
7-
data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
7+
data: [4, 3, 2, 1, 0, 0, -1, -2, -3, -4],
88
datalabels: {
9-
backgroundColor: '#f0f',
10-
// display: (fallback: true)
9+
backgroundColor: '#ff0',
10+
display: false
1111
}
1212
}, {
13-
data: [-4, -2, 0, 2, 4, 2, 0, -2, -4, -2, 0],
13+
data: [4, 2, 0, -2, -4, -2, 0, 2, 4, 2, 0],
1414
datalabels: {
15-
backgroundColor: '#f00',
15+
backgroundColor: '#0f0',
1616
display: true
1717
}
1818
}, {
19-
data: [4, 2, 0, -2, -4, -2, 0, 2, 4, 2, 0],
19+
data: [-4, -2, 0, 2, 4, 2, 0, -2, -4, -2, 0],
2020
datalabels: {
21-
backgroundColor: '#0f0',
21+
backgroundColor: '#f00',
2222
display: true
2323
}
2424
}, {
25-
data: [4, 3, 2, 1, 0, 0, -1, -2, -3, -4],
25+
data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2626
datalabels: {
27-
backgroundColor: '#ff0',
28-
display: false
27+
backgroundColor: '#f0f',
28+
// display: (fallback: true)
2929
}
3030
}]
3131
},

0 commit comments

Comments
 (0)