]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Reverse scale on radar/polar area 1436/head
authorJan Kalina <jkalina@redhat.com>
Wed, 2 Sep 2015 21:14:12 +0000 (23:14 +0200)
committerJan Kalina <jkalina@redhat.com>
Wed, 2 Sep 2015 21:21:39 +0000 (23:21 +0200)
samples/polar-area.html
samples/radar.html
samples/scatter-multi-axis.html
src/scales/scale.radialLinear.js

index e7c992d8ea52ffe38a5fea3a99147f0729b0b552..89915530bc9793550d41f9315f59b181d8348cd3 100644 (file)
             ]
         },
         options: {
-            responsive: true
+            responsive: true,
+            scale: {
+                beginAtZero: true,
+                reverse: false
+            }
         }
     };
 
index b84b8458369c9ac573491fc809c968fc7a85c1e8..80b544e0d12787576c41cc22c5e8ca922c6f4a8e 100644 (file)
                 pointHighlightStroke: "rgba(151,187,205,1)",
                 data: [null, randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
             }]
+        },
+        options: {
+            scale: {
+                beginAtZero: true,
+                reverse: false
+            }
         }
     };
 
index a25c5f1b12a40eced05943f96a8585ccdc69122b..e8af68cd4754fc03da8c79c2f8f4c657bd1373e2 100644 (file)
                                type: "linear", // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
                                display: true,
                                position: "right",
+                               reverse: true,
                                id: "y-axis-2",
                        
                                // grid line settings
index 0e9c763b30def1ec99e17966350f7edb9bedea40..5c24bd5c668753e9aa48b290393a87abcdb795d2 100644 (file)
@@ -27,6 +27,7 @@
                },
 
                // scale numbers
+               reverse: false,
                beginAtZero: true,
 
                // label settings
@@ -94,6 +95,8 @@
 
                        helpers.each(this.data.datasets, function(dataset) {
                                helpers.each(dataset.data, function(value, index) {
+                                       if (value === null) return;
+
                                        if (this.min === null) {
                                                this.min = value;
                                        } else if (value < this.min) {
                        return index * angleMultiplier - (Math.PI / 2);
                },
                getDistanceFromCenterForValue: function(value) {
+                       if (value === null) return 0; // null always in center
                        // Take into account half font size + the yPadding of the top value
                        var scalingFactor = this.drawingArea / (this.max - this.min);
-                       return (value - this.min) * scalingFactor;
+                       if (this.options.reverse) {
+                               return (this.max - value) * scalingFactor;
+                       } else {
+                               return (value - this.min) * scalingFactor;
+                       }
                },
                getPointPosition: function(index, distanceFromCenter) {
                        var thisAngle = this.getIndexAngle(index);
                        if (this.options.display) {
                                var ctx = this.ctx;
                                helpers.each(this.yLabels, function(label, index) {
-                                       // Don't draw a centre value
-                                       if (index > 0) {
+                                       // Don't draw a centre value (if it is minimum)
+                                       if (index > 0 || this.options.reverse) {
                                                var yCenterOffset = this.getDistanceFromCenterForValue(this.ticks[index]);
                                                var yHeight = this.yCenter - yCenterOffset;
 
 
                                        for (var i = this.getValueCount() - 1; i >= 0; i--) {
                                                if (this.options.angleLines.show) {
-                                                       var outerPosition = this.getPointPosition(i, this.getDistanceFromCenterForValue(this.max));
+                                                       var outerPosition = this.getPointPosition(i, this.getDistanceFromCenterForValue(this.options.reverse ? this.min : this.max));
                                                        ctx.beginPath();
                                                        ctx.moveTo(this.xCenter, this.yCenter);
                                                        ctx.lineTo(outerPosition.x, outerPosition.y);
                                                        ctx.closePath();
                                                }
                                                // Extra 3px out for some label spacing
-                                               var pointLabelPosition = this.getPointPosition(i, this.getDistanceFromCenterForValue(this.max) + 5);
+                                               var pointLabelPosition = this.getPointPosition(i, this.getDistanceFromCenterForValue(this.options.reverse ? this.min : this.max) + 5);
                                                ctx.font = helpers.fontString(this.options.pointLabels.fontSize, this.options.pointLabels.fontStyle, this.options.pointLabels.fontFamily);
                                                ctx.fillStyle = this.options.pointLabels.fontColor;