From: Jukka Kurkela Date: Fri, 17 Jul 2020 17:29:43 +0000 (+0300) Subject: minBarLength at base going both ways (#7642) X-Git-Tag: v3.0.0-beta.2~32 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7f4b74d9564500b1f926438d82e50b9cf088caed;p=thirdparty%2FChart.js.git minBarLength at base going both ways (#7642) --- diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index c2ce35d8c..32769d59b 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -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; } diff --git a/test/fixtures/controller.bar/minBarLength/horizontal-neg.js b/test/fixtures/controller.bar/minBarLength/horizontal-neg.js new file mode 100644 index 000000000..8cfba0f0d --- /dev/null +++ b/test/fixtures/controller.bar/minBarLength/horizontal-neg.js @@ -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 + } + } +}; diff --git a/test/fixtures/controller.bar/minBarLength/horizontal-neg.png b/test/fixtures/controller.bar/minBarLength/horizontal-neg.png new file mode 100644 index 000000000..3ffb6841a Binary files /dev/null and b/test/fixtures/controller.bar/minBarLength/horizontal-neg.png differ diff --git a/test/fixtures/controller.bar/minBarLength/horizontal-pos.js b/test/fixtures/controller.bar/minBarLength/horizontal-pos.js new file mode 100644 index 000000000..c5f964955 --- /dev/null +++ b/test/fixtures/controller.bar/minBarLength/horizontal-pos.js @@ -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 + } + } +}; diff --git a/test/fixtures/controller.bar/minBarLength/horizontal-pos.png b/test/fixtures/controller.bar/minBarLength/horizontal-pos.png new file mode 100644 index 000000000..7999ebbba Binary files /dev/null and b/test/fixtures/controller.bar/minBarLength/horizontal-pos.png differ diff --git a/test/fixtures/controller.bar/minBarLength/horizontal.js b/test/fixtures/controller.bar/minBarLength/horizontal.js new file mode 100644 index 000000000..789b484c4 --- /dev/null +++ b/test/fixtures/controller.bar/minBarLength/horizontal.js @@ -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 + } + } +}; diff --git a/test/fixtures/controller.bar/minBarLength/horizontal.png b/test/fixtures/controller.bar/minBarLength/horizontal.png new file mode 100644 index 000000000..83d5b82dc Binary files /dev/null and b/test/fixtures/controller.bar/minBarLength/horizontal.png differ diff --git a/test/fixtures/controller.bar/minBarLength/vertical-neg.js b/test/fixtures/controller.bar/minBarLength/vertical-neg.js new file mode 100644 index 000000000..f5976b5ac --- /dev/null +++ b/test/fixtures/controller.bar/minBarLength/vertical-neg.js @@ -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 + } + } +}; diff --git a/test/fixtures/controller.bar/minBarLength/vertical-neg.png b/test/fixtures/controller.bar/minBarLength/vertical-neg.png new file mode 100644 index 000000000..ec9636feb Binary files /dev/null and b/test/fixtures/controller.bar/minBarLength/vertical-neg.png differ diff --git a/test/fixtures/controller.bar/minBarLength/vertical-pos.js b/test/fixtures/controller.bar/minBarLength/vertical-pos.js new file mode 100644 index 000000000..7d69b2920 --- /dev/null +++ b/test/fixtures/controller.bar/minBarLength/vertical-pos.js @@ -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 + } + } +}; diff --git a/test/fixtures/controller.bar/minBarLength/vertical-pos.png b/test/fixtures/controller.bar/minBarLength/vertical-pos.png new file mode 100644 index 000000000..b5d4f8a2e Binary files /dev/null and b/test/fixtures/controller.bar/minBarLength/vertical-pos.png differ diff --git a/test/fixtures/controller.bar/minBarLength/vertical.js b/test/fixtures/controller.bar/minBarLength/vertical.js new file mode 100644 index 000000000..29da8a6e1 --- /dev/null +++ b/test/fixtures/controller.bar/minBarLength/vertical.js @@ -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 + } + } +}; diff --git a/test/fixtures/controller.bar/minBarLength/vertical.png b/test/fixtures/controller.bar/minBarLength/vertical.png new file mode 100644 index 000000000..a78cb133d Binary files /dev/null and b/test/fixtures/controller.bar/minBarLength/vertical.png differ