mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-04 07:24:02 +01:00
minBarLength at base going both ways (#7642)
This commit is contained in:
committed by
Evert Timberg
parent
117c2bdb10
commit
2cbcd8892f
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
35
test/fixtures/controller.bar/minBarLength/horizontal-neg.js
vendored
Normal file
35
test/fixtures/controller.bar/minBarLength/horizontal-neg.js
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
};
|
||||
BIN
test/fixtures/controller.bar/minBarLength/horizontal-neg.png
vendored
Normal file
BIN
test/fixtures/controller.bar/minBarLength/horizontal-neg.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
35
test/fixtures/controller.bar/minBarLength/horizontal-pos.js
vendored
Normal file
35
test/fixtures/controller.bar/minBarLength/horizontal-pos.js
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
};
|
||||
BIN
test/fixtures/controller.bar/minBarLength/horizontal-pos.png
vendored
Normal file
BIN
test/fixtures/controller.bar/minBarLength/horizontal-pos.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.7 KiB |
35
test/fixtures/controller.bar/minBarLength/horizontal.js
vendored
Normal file
35
test/fixtures/controller.bar/minBarLength/horizontal.js
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
};
|
||||
BIN
test/fixtures/controller.bar/minBarLength/horizontal.png
vendored
Normal file
BIN
test/fixtures/controller.bar/minBarLength/horizontal.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
34
test/fixtures/controller.bar/minBarLength/vertical-neg.js
vendored
Normal file
34
test/fixtures/controller.bar/minBarLength/vertical-neg.js
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
};
|
||||
BIN
test/fixtures/controller.bar/minBarLength/vertical-neg.png
vendored
Normal file
BIN
test/fixtures/controller.bar/minBarLength/vertical-neg.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.8 KiB |
34
test/fixtures/controller.bar/minBarLength/vertical-pos.js
vendored
Normal file
34
test/fixtures/controller.bar/minBarLength/vertical-pos.js
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
};
|
||||
BIN
test/fixtures/controller.bar/minBarLength/vertical-pos.png
vendored
Normal file
BIN
test/fixtures/controller.bar/minBarLength/vertical-pos.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.8 KiB |
34
test/fixtures/controller.bar/minBarLength/vertical.js
vendored
Normal file
34
test/fixtures/controller.bar/minBarLength/vertical.js
vendored
Normal 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
|
||||
}
|
||||
}
|
||||
};
|
||||
BIN
test/fixtures/controller.bar/minBarLength/vertical.png
vendored
Normal file
BIN
test/fixtures/controller.bar/minBarLength/vertical.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.8 KiB |
Reference in New Issue
Block a user