]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Removed the line scale override file since functionality no longer directly exists... 1488/head
authorEvert Timberg <evert.timberg@gmail.com>
Mon, 28 Sep 2015 01:34:16 +0000 (21:34 -0400)
committerEvert Timberg <evert.timberg@gmail.com>
Mon, 28 Sep 2015 01:34:16 +0000 (21:34 -0400)
samples/line-scale-override.html [deleted file]
src/core/core.scale.js
test/scale.linear.tests.js

diff --git a/samples/line-scale-override.html b/samples/line-scale-override.html
deleted file mode 100644 (file)
index a92b14a..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-<!doctype html>
-<html>
-
-<head>
-    <title>Line Chart with Scale Override</title>
-    <script src="../Chart.js"></script>
-    <script src="../node_modules/jquery/dist/jquery.min.js"></script>
-</head>
-
-<body>
-    <div style="width:50%;">
-        <canvas id="canvas" style="width:100%;height:100%"></canvas>
-    </div>
-    <br>
-    <br>
-    <button id="randomizeData">Randomize Data</button>
-    <button id="addDataset">Add Dataset</button>
-    <button id="removeDataset">Remove Dataset</button>
-    <button id="addData">Add Data</button>
-    <button id="removeData">Remove Data</button>
-    <script>
-    var randomScalingFactor = function() {
-        return Math.round(Math.random() * 100 * (Math.random() > 0.5 ? -1 : 1));
-    };
-    var randomColorFactor = function() {
-        return Math.round(Math.random() * 255);
-    };
-    var randomColor = function(opacity) {
-        return 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',' + (opacity || '.3') + ')';
-    };
-
-    var config = {
-        type: 'line',
-        data: {
-            labels: ["January", "February", "March", "April", "May", "June", "July"],
-            datasets: [{
-                label: "My First dataset",
-                data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()],
-                fill: false,
-            }, {
-                label: "My Second dataset",
-                data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()],
-            }]
-        },
-        options: {
-            responsive: true,
-            scales: {
-                xAxes: [{
-                    display: true
-                }],
-                yAxes: [{
-                    display: true,
-                    override: {
-                        start: -100,
-                        stepWidth: 10,
-                        steps: 20
-                    }
-                }]
-            }
-        }
-    };
-
-    $.each(config.data.datasets, function(i, dataset) {
-        dataset.borderColor = randomColor(0.4);
-        dataset.backgroundColor = randomColor(0.5);
-        dataset.pointBorderColor = randomColor(0.7);
-        dataset.pointBackgroundColor = randomColor(0.5);
-        dataset.pointBorderWidth = 1;
-    });
-
-    console.log(config.data);
-
-    window.onload = function() {
-        var ctx = document.getElementById("canvas").getContext("2d");
-        window.myLine = new Chart(ctx, config);
-    };
-
-    $('#randomizeData').click(function() {
-        $.each(config.data.datasets, function(i, dataset) {
-            dataset.data = dataset.data.map(function() {
-                return randomScalingFactor();
-            });
-
-        });
-
-        window.myLine.update();
-    });
-
-    $('#addDataset').click(function() {
-        var newDataset = {
-            label: 'Dataset ' + config.data.datasets.length,
-            borderColor: randomColor(0.4),
-            backgroundColor: randomColor(0.5),
-            pointBorderColor: randomColor(0.7),
-            pointBackgroundColor: randomColor(0.5),
-            pointBorderWidth: 1,
-            data: [],
-        };
-
-        for (var index = 0; index < config.data.labels.length; ++index) {
-            newDataset.data.push(randomScalingFactor());
-        }
-
-        config.data.datasets.push(newDataset);
-        window.myLine.update();
-    });
-
-    $('#addData').click(function() {
-        if (config.data.datasets.length > 0) {
-            config.data.labels.push('dataset #' + config.data.labels.length);
-
-            for (var index = 0; index < config.data.datasets.length; ++index) {
-                config.data.datasets[index].data.push(randomScalingFactor());
-            }
-
-            window.myLine.update();
-        }
-    });
-
-    $('#removeDataset').click(function() {
-        config.data.datasets.splice(0, 1);
-        window.myLine.update();
-    });
-
-    $('#removeData').click(function() {
-        config.data.labels.splice(-1, 1); // remove the label first
-
-        config.data.datasets.forEach(function(dataset, datasetIndex) {
-            dataset.data.pop();
-        });
-
-        window.myLine.update();
-    });
-    </script>
-</body>
-
-</html>
index 6835effacafadc8153a0f582571e99f8268837b7..40c73b4f5514c26b9d6550d88530f31ba7c7a103 100644 (file)
                                        var firstLabelWidth = this.ctx.measureText(this.ticks[0]).width;
                                        var lastLabelWidth = this.ctx.measureText(this.ticks[this.ticks.length - 1]).width;
 
-                                       // Ensure that our ticks are always inside the canvas
+                                       // Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned which means that the right padding is dominated
+                                       // by the font height 
                                        var cosRotation = Math.cos(helpers.toRadians(this.labelRotation));
-                                       this.paddingLeft = (cosRotation * firstLabelWidth) / 2 + 3; // add 3 px to move away from canvas edges
-                                       this.paddingRight = (cosRotation * lastLabelWidth) / 2 + 3;
+                                       var sinRotation = Math.sin(helpers.toRadians(this.labelRotation));
+                                       this.paddingLeft = this.labelRotation !== 0 ? (cosRotation * firstLabelWidth) + 3 : firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges
+                                       this.paddingRight = this.labelRotation !== 0 ? (sinRotation * (this.options.ticks.fontSize / 2)) + 3 : lastLabelWidth / 2 + 3; // when rotated
                                } else {
                                        // A vertical axis is more constrained by the width. Labels are the dominant factor here, so get that length first
                                        var maxLabelWidth = this.maxWidth - this.minSize.width;
 
                                                if (this.options.ticks.show) {
                                                        this.ctx.save();
-                                                       this.ctx.translate(xLabelValue, (isRotated) ? this.top + 12 : this.top + 8);
+                                                       this.ctx.translate(xLabelValue, (isRotated) ? this.top + 12 : this.options.position === "top" ? this.bottom - 10 : this.top + 10);
                                                        this.ctx.rotate(helpers.toRadians(this.labelRotation) * -1);
                                                        this.ctx.font = this.font;
                                                        this.ctx.textAlign = (isRotated) ? "right" : "center";
-                                                       this.ctx.textBaseline = (isRotated) ? "middle" : "top";
+                                                       this.ctx.textBaseline = (isRotated) ? "middle" : this.options.position === "top" ? "bottom" : "top";
                                                        this.ctx.fillText(label, 0, 0);
                                                        this.ctx.restore();
                                                }
index 52a49ef4ee96be3252fc87c3bb9fa22e134c4e5a..c927c97c3726b8483c0642075ae15424f1e8b90e 100644 (file)
@@ -620,7 +620,7 @@ describe('Linear Scale', function() {
                        "args": []
                }, {
                        "name": "translate",
-                       "args": [8, 8]
+                       "args": [8, 10]
                }, {
                        "name": "rotate",
                        "args": [-0]
@@ -659,7 +659,7 @@ describe('Linear Scale', function() {
                        "args": []
                }, {
                        "name": "translate",
-                       "args": [51, 8]
+                       "args": [51, 10]
                }, {
                        "name": "rotate",
                        "args": [-0]
@@ -698,7 +698,7 @@ describe('Linear Scale', function() {
                        "args": []
                }, {
                        "name": "translate",
-                       "args": [93, 8]
+                       "args": [93, 10]
                }, {
                        "name": "rotate",
                        "args": [-0]