Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minimum bar length setting keeps bar base in view #10157

Merged
merged 1 commit into from Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.