]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
changed option name for radar chart from offsetAngle to startAngle. Added test to... 2984/head
authorunknown <slinhart@knights.ucf.edu>
Mon, 18 Jul 2016 05:11:30 +0000 (23:11 -0600)
committerunknown <slinhart@knights.ucf.edu>
Mon, 18 Jul 2016 05:11:30 +0000 (23:11 -0600)
docs/05-Radar-Chart.md
src/scales/scale.radialLinear.js
test/scale.radialLinear.tests.js

index dbf3f3c57a2c72c52c4b576b0473375437e9a752..e974d2a19c57205ee1a4b914a73774f23efd455a 100644 (file)
@@ -98,7 +98,7 @@ scale | Object | [See Scales](#scales) and [Defaults for Radial Linear Scale](#s
 *scale*.type | String |"radialLinear" | As defined in ["Radial Linear"](#scales-radial-linear-scale).
 *elements*.line | Object | | Options for all line elements used on the chart, as defined in the global elements, duplicated here to show Radar chart specific defaults.
 *elements.line*.lineTension | Number | 0 | Tension exhibited by lines when calculating splineCurve. Setting to 0 creates straight lines.
-offsetAngle | Number | 0 | The number of degrees to rotate the chart clockwise.
+startAngle | Number | 0 | The number of degrees to rotate the chart clockwise.
 
 You can override these for your `Chart` instance by passing a second argument into the `Radar` method as an object with the keys you want to override.
 
index 900ade4eac6af1ed16a13f0dbdcaf6dc19df5759..d0cb7f2c6d08d2d6c594585c08340cc5a97aa179 100644 (file)
@@ -232,14 +232,14 @@ module.exports = function(Chart) {
 
                getIndexAngle: function(index) {
                        var angleMultiplier = (Math.PI * 2) / this.getValueCount();
-                       var offsetAngle = this.chart.options && this.chart.options.offsetAngle ?
-                               this.chart.options.offsetAngle :
+                       var startAngle = this.chart.options && this.chart.options.startAngle ?
+                               this.chart.options.startAngle :
                                0;
 
-                       var offsetAngleRadians = offsetAngle * Math.PI * 2 / 360;
+                       var startAngleRadians = startAngle * Math.PI * 2 / 360;
 
                        // Start from the top instead of right, so remove a quarter of the circle
-                       return index * angleMultiplier - (Math.PI / 2) + offsetAngleRadians;
+                       return index * angleMultiplier - (Math.PI / 2) + startAngleRadians;
                },
                getDistanceFromCenterForValue: function(value) {
                        var me = this;
index d7b61695eb2067c05c1ceaa15c7d227fd33d5d90..bb84181e1a243dbc61b184422b1a99c95598a4fb 100644 (file)
@@ -420,4 +420,43 @@ describe('Test the radial linear scale', function() {
                expect(chartInstance.scale.getDistanceFromCenterForValue(chartInstance.scale.min)).toBe(225);
                expect(chartInstance.scale.getDistanceFromCenterForValue(chartInstance.scale.max)).toBe(0);
        });
+
+       it('should correctly get angles for all points', function() {
+               chartInstance = window.acquireChart({
+                       type: 'radar',
+                       data: {
+                               datasets: [{
+                                       data: [10, 5, 0, 25, 78]
+                               }],
+                               labels: ['label1', 'label2', 'label3', 'label4', 'label5']
+                       },
+                       options: {
+                               scale: {
+                                       pointLabels: {
+                                               callback: function(value, index) {
+                                                       return index.toString();
+                                               }
+                                       }
+                               },
+                               startAngle: 15
+                       }
+               });
+
+               var radToNearestDegree = function(rad) {
+                       return Math.round((360 * rad) / (2 * Math.PI));
+               }
+
+               var slice = 72; // (360 / 5)
+
+               for(var i = 0; i < 5; i++) {
+                       expect(radToNearestDegree(chartInstance.scale.getIndexAngle(i))).toBe(15 + (slice * i) - 90);
+               }
+
+               chartInstance.options.startAngle = 0;
+               chartInstance.update();
+
+               for(var i = 0; i < 5; i++) {
+                       expect(radToNearestDegree(chartInstance.scale.getIndexAngle(i))).toBe((slice * i) - 90);
+               }
+       });
 });