minimum bar length setting keeps bar base in view (#10157)
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 11 KiB |
43
test/fixtures/controller.bar/minBarLength/horizontal-stacked.js
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
};
|
||||
BIN
test/fixtures/controller.bar/minBarLength/horizontal-stacked.png
vendored
Normal file
|
After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 11 KiB |
42
test/fixtures/controller.bar/minBarLength/vertical-stacked.js
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
};
|
||||
BIN
test/fixtures/controller.bar/minBarLength/vertical-stacked.png
vendored
Normal file
|
After Width: | Height: | Size: 8.5 KiB |