]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
minBarLength at base going both ways (#7642)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Fri, 17 Jul 2020 17:29:43 +0000 (20:29 +0300)
committerGitHub <noreply@github.com>
Fri, 17 Jul 2020 17:29:43 +0000 (13:29 -0400)
13 files changed:
src/controllers/controller.bar.js
test/fixtures/controller.bar/minBarLength/horizontal-neg.js [new file with mode: 0644]
test/fixtures/controller.bar/minBarLength/horizontal-neg.png [new file with mode: 0644]
test/fixtures/controller.bar/minBarLength/horizontal-pos.js [new file with mode: 0644]
test/fixtures/controller.bar/minBarLength/horizontal-pos.png [new file with mode: 0644]
test/fixtures/controller.bar/minBarLength/horizontal.js [new file with mode: 0644]
test/fixtures/controller.bar/minBarLength/horizontal.png [new file with mode: 0644]
test/fixtures/controller.bar/minBarLength/vertical-neg.js [new file with mode: 0644]
test/fixtures/controller.bar/minBarLength/vertical-neg.png [new file with mode: 0644]
test/fixtures/controller.bar/minBarLength/vertical-pos.js [new file with mode: 0644]
test/fixtures/controller.bar/minBarLength/vertical-pos.png [new file with mode: 0644]
test/fixtures/controller.bar/minBarLength/vertical.js [new file with mode: 0644]
test/fixtures/controller.bar/minBarLength/vertical.png [new file with mode: 0644]

index c2ce35d8c50a9a5384e3621e3b37b7e2d838a6a6..32769d59ba5792d91ad062a38e6908671e1f57ec 100644 (file)
@@ -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 (file)
index 0000000..8cfba0f
--- /dev/null
@@ -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 (file)
index 0000000..3ffb684
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 (file)
index 0000000..c5f9649
--- /dev/null
@@ -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 (file)
index 0000000..7999ebb
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 (file)
index 0000000..789b484
--- /dev/null
@@ -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 (file)
index 0000000..83d5b82
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 (file)
index 0000000..f5976b5
--- /dev/null
@@ -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 (file)
index 0000000..ec9636f
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 (file)
index 0000000..7d69b29
--- /dev/null
@@ -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 (file)
index 0000000..b5d4f8a
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 (file)
index 0000000..29da8a6
--- /dev/null
@@ -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 (file)
index 0000000..a78cb13
Binary files /dev/null and b/test/fixtures/controller.bar/minBarLength/vertical.png differ