]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Proper tick position for right positioned axis (#5401)
authorEvert Timberg <evert.timberg+github@gmail.com>
Wed, 11 Apr 2018 22:16:32 +0000 (18:16 -0400)
committerGitHub <noreply@github.com>
Wed, 11 Apr 2018 22:16:32 +0000 (18:16 -0400)
* Proper tick position for right positioned axis
* Test for tick mark drawing

src/core/core.scale.js
test/fixtures/core.scale/tick-drawing.json [new file with mode: 0644]
test/fixtures/core.scale/tick-drawing.png [new file with mode: 0644]

index 5ab6b8c090f177b205955fbcce9b926bc6916b77..78ede6985f619c45acea468c9612adf66ecd1f55 100644 (file)
@@ -705,8 +705,8 @@ module.exports = Element.extend({
                var itemsToDraw = [];
 
                var axisWidth = me.options.gridLines.lineWidth;
-               var xTickStart = options.position === 'right' ? me.right : me.right - axisWidth - tl;
-               var xTickEnd = options.position === 'right' ? me.right + tl : me.right;
+               var xTickStart = options.position === 'right' ? me.left : me.right - axisWidth - tl;
+               var xTickEnd = options.position === 'right' ? me.left + tl : me.right;
                var yTickStart = options.position === 'bottom' ? me.top + axisWidth : me.bottom - tl - axisWidth;
                var yTickEnd = options.position === 'bottom' ? me.top + axisWidth + tl : me.bottom + axisWidth;
 
diff --git a/test/fixtures/core.scale/tick-drawing.json b/test/fixtures/core.scale/tick-drawing.json
new file mode 100644 (file)
index 0000000..7c9d6da
--- /dev/null
@@ -0,0 +1,79 @@
+{
+    "config": {
+        "type": "horizontalBar",
+        "data": {
+            "labels": ["January", "February", "March", "April", "May", "June", "July"],
+                       "datasets": []
+        },
+        "options": {
+            "legend": false,
+            "title": false,
+            "scales": {
+                "xAxes": [{
+                    "type": "category",
+                    "position": "top",
+                    "id": "x-axis-1",
+                    "ticks": {
+                        "display": false
+                    },
+                    "gridLines":{
+                        "drawOnChartArea": false,
+                        "drawBorder": false,
+                        "color": "rgba(0, 0, 0, 1)",
+                        "zeroLineColor": "rgba(0, 0, 0, 1)"
+                    }
+                }, {
+                    "type": "category",
+                    "position": "bottom",
+                    "id": "x-axis-2",
+                    "ticks": {
+                        "display": false
+                    },
+                    "gridLines":{
+                        "drawOnChartArea": false,
+                        "drawBorder": false,
+                        "color": "rgba(0, 0, 0, 1)",
+                        "zeroLineColor": "rgba(0, 0, 0, 1)"
+                    }
+                }],
+                "yAxes": [{
+                    "position": "left",
+                    "id": "y-axis-1",
+                    "type": "linear",
+                    "ticks": {
+                        "display": false,
+                        "min": -100,
+                        "max": 100
+                    },
+                    "gridLines":{
+                        "drawOnChartArea": false,
+                        "drawBorder": false,
+                        "color": "rgba(0, 0, 0, 1)",
+                        "zeroLineColor": "rgba(0, 0, 0, 1)"
+                    }
+                }, {
+                    "type": "linear",
+                    "id": "y-axis-2",
+                    "position": "right",
+                    "ticks": {
+                        "display": false,
+                        "min": 0,
+                        "max": 50
+                    },
+                    "gridLines":{
+                        "drawOnChartArea": false,
+                        "drawBorder": false,
+                        "color": "rgba(0, 0, 0, 1)",
+                        "zeroLineColor": "rgba(0, 0, 0, 1)"
+                    }
+                }]
+            }
+        }
+    },
+    "options": {
+        "canvas": {
+            "height": 256,
+            "width": 512
+        }
+    }
+}
diff --git a/test/fixtures/core.scale/tick-drawing.png b/test/fixtures/core.scale/tick-drawing.png
new file mode 100644 (file)
index 0000000..fb80cd0
Binary files /dev/null and b/test/fixtures/core.scale/tick-drawing.png differ