Skip to content

Commit

Permalink
minimum bar length setting keeps bar base in view (#10157)
Browse files Browse the repository at this point in the history
  • Loading branch information
etimberg committed Feb 13, 2022
1 parent c80b145 commit edd764f
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/controllers/controller.bar.js
Expand Up @@ -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;
}

Expand Down
Binary file modified test/fixtures/controller.bar/minBarLength/horizontal-neg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bar/minBarLength/horizontal-pos.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions test/fixtures/controller.bar/minBarLength/horizontal-stacked.js
@@ -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
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bar/minBarLength/vertical-neg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bar/minBarLength/vertical-pos.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions test/fixtures/controller.bar/minBarLength/vertical-stacked.js
@@ -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
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit edd764f

Please sign in to comment.