minBarLength at base going both ways (#7642)

This commit is contained in:
Jukka Kurkela
2020-07-17 20:29:43 +03:00
committed by Evert Timberg
parent 117c2bdb10
commit 2cbcd8892f
13 changed files with 211 additions and 1 deletions

View File

@@ -409,7 +409,7 @@ export default class BarController extends DatasetController {
// So we don't try to draw so huge rectangles.
// https://github.com/chartjs/Chart.js/issues/5247
// TODO: use borderWidth instead (need to move the parsing from rectangle)
const base = _limitValue(vScale.getPixelForValue(start),
let base = _limitValue(vScale.getPixelForValue(start),
vScale._startPixel - 10,
vScale._endPixel + 10);
@@ -418,6 +418,9 @@ export default class BarController extends DatasetController {
if (minBarLength !== undefined && Math.abs(size) < minBarLength) {
size = size < 0 ? -minBarLength : minBarLength;
if (value === 0) {
base -= size / 2;
}
head = base + size;
}

View File

@@ -0,0 +1,35 @@
module.exports = {
config: {
type: 'bar',
data: {
labels: [0, 1, 2],
datasets: [
{
data: [0, -0.01, -30],
backgroundColor: '#00ff00',
borderWidth: 0,
minBarLength: 20
}
]
},
options: {
legend: false,
title: false,
indexAxis: 'y',
scales: {
x: {
ticks: {
display: false
}
},
y: {display: false}
}
}
},
options: {
canvas: {
height: 512,
width: 512
}
}
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@@ -0,0 +1,35 @@
module.exports = {
config: {
type: 'bar',
data: {
labels: [0, 1, 2],
datasets: [
{
data: [0, 0.01, 30],
backgroundColor: '#00ff00',
borderWidth: 0,
minBarLength: 20
}
]
},
options: {
legend: false,
title: false,
indexAxis: 'y',
scales: {
x: {
ticks: {
display: false
}
},
y: {display: false}
}
}
},
options: {
canvas: {
height: 512,
width: 512
}
}
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

View File

@@ -0,0 +1,35 @@
module.exports = {
config: {
type: 'bar',
data: {
labels: [0, 1, 2, 3, 4],
datasets: [
{
data: [0, -0.01, 0.01, 30, -30],
backgroundColor: '#00ff00',
borderWidth: 0,
minBarLength: 20
}
]
},
options: {
legend: false,
title: false,
indexAxis: 'y',
scales: {
x: {
ticks: {
display: false
}
},
y: {display: false}
}
}
},
options: {
canvas: {
height: 512,
width: 512
}
}
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -0,0 +1,34 @@
module.exports = {
config: {
type: 'bar',
data: {
labels: [0, 1, 2],
datasets: [
{
data: [0, -0.01, -30],
backgroundColor: '#00ff00',
borderWidth: 0,
minBarLength: 20
}
]
},
options: {
legend: false,
title: false,
scales: {
x: {display: false},
y: {
ticks: {
display: false
}
}
}
}
},
options: {
canvas: {
height: 512,
width: 512
}
}
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

@@ -0,0 +1,34 @@
module.exports = {
config: {
type: 'bar',
data: {
labels: [0, 1, 2],
datasets: [
{
data: [0, 0.01, 30],
backgroundColor: '#00ff00',
borderWidth: 0,
minBarLength: 20
}
]
},
options: {
legend: false,
title: false,
scales: {
x: {display: false},
y: {
ticks: {
display: false
}
}
}
}
},
options: {
canvas: {
height: 512,
width: 512
}
}
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

@@ -0,0 +1,34 @@
module.exports = {
config: {
type: 'bar',
data: {
labels: [0, 1, 2, 3, 4],
datasets: [
{
data: [0, -0.01, 0.01, 30, -30],
backgroundColor: '#00ff00',
borderWidth: 0,
minBarLength: 20
}
]
},
options: {
legend: false,
title: false,
scales: {
x: {display: false},
y: {
ticks: {
display: false
}
}
}
}
},
options: {
canvas: {
height: 512,
width: 512
}
}
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB