minimum bar length setting keeps bar base in view (#10157)

This commit is contained in:
Evert Timberg
2022-02-13 15:27:46 -05:00
committed by GitHub
parent c80b1450f5
commit edd764fcb5
9 changed files with 90 additions and 0 deletions

View File

@@ -543,6 +543,11 @@ export default class BarController extends DatasetController {
if (value === actualBase) {
base -= size / 2;
}
const startPixel = vScale.getPixelForDecimal(0);
const endPixel = vScale.getPixelForDecimal(1);
const min = Math.min(startPixel, endPixel);
const max = Math.max(startPixel, endPixel);
base = Math.max(Math.min(base, max), min);
head = base + size;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -0,0 +1,43 @@
module.exports = {
config: {
type: 'bar',
data: {
labels: [0, 1, 2, 3, 4],
datasets: [{
data: [0, 0.01, 30],
backgroundColor: '#00ff00',
borderColor: '#000',
borderWidth: 4,
minBarLength: 20,
xAxisID: 'x2',
}]
},
options: {
indexAxis: 'y',
scales: {
x: {
stack: 'demo',
ticks: {
display: false
}
},
x2: {
type: 'linear',
position: 'bottom',
stack: 'demo',
stackWeight: 1,
ticks: {
display: false
}
},
y: {display: false},
}
}
},
options: {
canvas: {
height: 512,
width: 512
}
}
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -0,0 +1,42 @@
module.exports = {
config: {
type: 'bar',
data: {
labels: [0, 1, 2, 3, 4],
datasets: [{
data: [0, 0.01, 30],
backgroundColor: '#00ff00',
borderColor: '#000',
borderWidth: 4,
minBarLength: 20,
yAxisID: 'y2',
}]
},
options: {
scales: {
x: {display: false},
y: {
stack: 'demo',
ticks: {
display: false
}
},
y2: {
type: 'linear',
position: 'left',
stack: 'demo',
stackWeight: 1,
ticks: {
display: false
}
}
}
}
},
options: {
canvas: {
height: 512,
width: 512
}
}
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB