]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix more style errors in controllers, elements, and scales
authorZach Panzarino <zachary@panzarino.com>
Wed, 14 Sep 2016 22:34:41 +0000 (22:34 +0000)
committerZach Panzarino <zachary@panzarino.com>
Wed, 14 Sep 2016 22:34:41 +0000 (22:34 +0000)
.eslintrc
src/controllers/controller.bar.js
src/controllers/controller.doughnut.js
src/controllers/controller.line.js
src/controllers/controller.polarArea.js
src/core/core.controller.js
src/core/core.element.js
src/elements/element.arc.js
src/elements/element.line.js
src/scales/scale.time.js

index 827b73c3777dc39e876e9c387b390542909f83da..340d657baf583f70ea77879d4818d5d2906cbb1f 100644 (file)
--- a/.eslintrc
+++ b/.eslintrc
@@ -96,7 +96,7 @@ rules:
   radix: 2
   vars-on-top: 0
   wrap-iife: 2
-  yoda: [2, never]
+  yoda: [1, never]
 
   # Strict
   strict: 0
index 73ed2df2a0d33dfeeb43849795588be4c26ba380..d9fa7bfeb05d705e6a7ea9f44129272e701b7ad4 100644 (file)
@@ -232,9 +232,8 @@ module.exports = function(Chart) {
 
                                if (value < 0) {
                                        return yScale.getPixelForValue(sumNeg + value);
-                               } else {
-                                       return yScale.getPixelForValue(sumPos + value);
                                }
+                               return yScale.getPixelForValue(sumPos + value);
                        }
 
                        return yScale.getPixelForValue(value);
@@ -409,8 +408,8 @@ module.exports = function(Chart) {
                                                startCorner = 0;
                                        }
 
-                                       function cornerAt(index) {
-                                               return corners[(startCorner + index) % 4];
+                                       function cornerAt(cornerIndex) {
+                                               return corners[(startCorner + cornerIndex) % 4];
                                        }
 
                                        // Draw rectangle from 'startCorner'
@@ -542,9 +541,8 @@ module.exports = function(Chart) {
 
                                if (value < 0) {
                                        return xScale.getPixelForValue(sumNeg + value);
-                               } else {
-                                       return xScale.getPixelForValue(sumPos + value);
                                }
+                               return xScale.getPixelForValue(sumPos + value);
                        }
 
                        return xScale.getPixelForValue(value);
index 40d4e2c842d2165a49269748e2bc51d1ebe5bf6c..0e9c5fe802cce90bd8774011b4adcd385a49c9b5 100644 (file)
@@ -64,9 +64,8 @@ module.exports = function(Chart) {
                                                                index: i
                                                        };
                                                });
-                                       } else {
-                                               return [];
                                        }
+                                       return [];
                                }
                        },
 
@@ -264,9 +263,8 @@ module.exports = function(Chart) {
                        var total = this.getMeta().total;
                        if (total > 0 && !isNaN(value)) {
                                return (Math.PI * 2.0) * (value / total);
-                       } else {
-                               return 0;
                        }
+                       return 0;
                },
 
                // gets the max border or hover width to properly scale pie charts
index a516a1e368e9b92d8b3dd19ef5591cd91af4a022..bfc061af22bfae78c128f2ba74d037be0704415e 100644 (file)
@@ -238,9 +238,8 @@ module.exports = function(Chart) {
                                var rightValue = Number(yScale.getRightValue(value));
                                if (rightValue < 0) {
                                        return yScale.getPixelForValue(sumNeg + rightValue);
-                               } else {
-                                       return yScale.getPixelForValue(sumPos + rightValue);
                                }
+                               return yScale.getPixelForValue(sumPos + rightValue);
                        }
 
                        return yScale.getPixelForValue(value);
index 6a11b4599ac451969818d2a1bbc9f3d2a0a3cd65..b27daf4170d7f61f9c7f67867a93a9448fc75246 100644 (file)
@@ -70,9 +70,8 @@ module.exports = function(Chart) {
                                                                index: i
                                                        };
                                                });
-                                       } else {
-                                               return [];
                                        }
+                                       return [];
                                }
                        },
 
@@ -209,9 +208,8 @@ module.exports = function(Chart) {
                        var count = this.getMeta().count;
                        if (count > 0 && !isNaN(value)) {
                                return (2 * Math.PI) / count;
-                       } else {
-                               return 0;
                        }
+                       return 0;
                }
        });
 };
index 0f74bcad6bfc621a0083ab8219f9cf02557bbe4a..30ba13418883d64ea2bc399b51181c6c3997baa3 100644 (file)
@@ -79,7 +79,7 @@ module.exports = function(Chart) {
                        return this;
                },
 
-               resize: function resize(silent) {
+               resize: function(silent) {
                        var me = this;
                        var chart = me.chart;
                        var canvas = chart.canvas;
@@ -145,9 +145,12 @@ module.exports = function(Chart) {
                        if (options.scales) {
                                items = items.concat(
                                        (options.scales.xAxes || []).map(function(xAxisOptions) {
-                                               return {options: xAxisOptions, dtype: 'category'}; }),
+                                               return {options: xAxisOptions, dtype: 'category'};
+                                       }),
                                        (options.scales.yAxes || []).map(function(yAxisOptions) {
-                                               return {options: yAxisOptions, dtype: 'linear'}; }));
+                                               return {options: yAxisOptions, dtype: 'linear'};
+                                       })
+                               );
                        }
 
                        if (options.scale) {
@@ -226,7 +229,7 @@ module.exports = function(Chart) {
                        }, me);
                },
 
-               update: function update(animationDuration, lazy) {
+               update: function(animationDuration, lazy) {
                        var me = this;
                        Chart.plugins.notify('beforeUpdate', [me]);
 
@@ -300,7 +303,7 @@ module.exports = function(Chart) {
                        }
                },
 
-               render: function render(duration, lazy) {
+               render: function(duration, lazy) {
                        var me = this;
                        Chart.plugins.notify('beforeRender', [me]);
 
@@ -515,7 +518,7 @@ module.exports = function(Chart) {
                getVisibleDatasetCount: function() {
                        var count = 0;
                        for (var i = 0, ilen = this.data.datasets.length; i<ilen; ++i) {
-                                if (this.isDatasetVisible(i)) {
+                               if (this.isDatasetVisible(i)) {
                                        count++;
                                }
                        }
@@ -607,7 +610,7 @@ module.exports = function(Chart) {
                        }
                },
 
-               eventHandler: function eventHandler(e) {
+               eventHandler: function(e) {
                        var me = this;
                        var tooltip = me.tooltip;
                        var options = me.options || {};
index 14c6dbad2f2cc4a4ca0d24a8a1f4794fe080151e..d8dc57208a40f3c602d0bac9f8ae0432df81168e 100644 (file)
@@ -48,38 +48,30 @@ module.exports = function(Chart) {
 
                                if (key[0] === '_') {
                                        // Only non-underscored properties
-                               }
-
                                // Init if doesn't exist
-                               else if (!me._view.hasOwnProperty(key)) {
+                               else if (!me._view.hasOwnProperty(key)) {
                                        if (typeof value === 'number' && !isNaN(me._view[key])) {
                                                me._view[key] = value * ease;
                                        } else {
                                                me._view[key] = value;
                                        }
-                               }
-
                                // No unnecessary computations
-                               else if (value === me._view[key]) {
+                               else if (value === me._view[key]) {
                                        // It's the same! Woohoo!
-                               }
-
                                // Color transitions if possible
-                               else if (typeof value === 'string') {
+                               else if (typeof value === 'string') {
                                        try {
                                                var color = helpers.color(me._model[key]).mix(helpers.color(me._start[key]), ease);
                                                me._view[key] = color.rgbString();
                                        } catch (err) {
                                                me._view[key] = value;
                                        }
-                               }
                                // Number transitions
-                               else if (typeof value === 'number') {
+                               else if (typeof value === 'number') {
                                        var startVal = me._start[key] !== undefined && isNaN(me._start[key]) === false ? me._start[key] : 0;
                                        me._view[key] = ((me._model[key] - startVal) * ease) + startVal;
-                               }
                                // Everything else
-                               else {
+                               else {
                                        me._view[key] = value;
                                }
                        }, me);
index 6056e847762380a19eb19dea7672f7ba6725b17c..b114e6f04b7ed3c002ab0ff0bc44307354924b8a 100644 (file)
@@ -17,9 +17,8 @@ module.exports = function(Chart) {
 
                        if (vm) {
                                return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2));
-                       } else {
-                               return false;
                        }
+                       return false;
                },
                inRange: function(chartX, chartY) {
                        var vm = this._view;
@@ -50,9 +49,8 @@ module.exports = function(Chart) {
                                        withinRadius = (distance >= vm.innerRadius && distance <= vm.outerRadius);
 
                                return (betweenAngles && withinRadius);
-                       } else {
-                               return false;
                        }
+                       return false;
                },
                tooltipPosition: function() {
                        var vm = this._view;
index 6ce178fbd6e5b2e64dff6346b76ced8548772ddc..9981d3d2f63ffc9bdd0d72c8666d858ae8200b02 100644 (file)
@@ -31,20 +31,20 @@ module.exports = function(Chart) {
 
                        // Helper function to draw a line to a point
                        function lineToPoint(previousPoint, point) {
-                               var vm = point._view;
+                               var pointvm = point._view;
                                if (point._view.steppedLine === true) {
-                                       ctx.lineTo(point._view.x, previousPoint._view.y);
-                                       ctx.lineTo(point._view.x, point._view.y);
+                                       ctx.lineTo(pointvm.x, previousPoint._view.y);
+                                       ctx.lineTo(pointvm.x, pointvm.y);
                                } else if (point._view.tension === 0) {
-                                       ctx.lineTo(vm.x, vm.y);
+                                       ctx.lineTo(pointvm.x, pointvm.y);
                                } else {
                                        ctx.bezierCurveTo(
                                                previousPoint._view.controlPointNextX,
                                                previousPoint._view.controlPointNextY,
-                                               vm.controlPointPreviousX,
-                                               vm.controlPointPreviousY,
-                                               vm.x,
-                                               vm.y
+                                               pointvm.controlPointPreviousX,
+                                               pointvm.controlPointPreviousY,
+                                               pointvm.x,
+                                               pointvm.y
                                        );
                                }
                        }
@@ -99,13 +99,11 @@ module.exports = function(Chart) {
                                                                if (spanGaps && lastDrawnIndex !== -1) {
                                                                        // We are spanning the gap, so simple draw a line to this point
                                                                        lineToPoint(previous, current);
+                                                               } else if (loop) {
+                                                                       ctx.lineTo(currentVM.x, currentVM.y);
                                                                } else {
-                                                                       if (loop) {
-                                                                               ctx.lineTo(currentVM.x, currentVM.y);
-                                                                       } else {
-                                                                               ctx.lineTo(currentVM.x, scaleZero);
-                                                                               ctx.lineTo(currentVM.x, currentVM.y);
-                                                                       }
+                                                                       ctx.lineTo(currentVM.x, scaleZero);
+                                                                       ctx.lineTo(currentVM.x, currentVM.y);
                                                                }
                                                        } else {
                                                                // Line to next point
index 7895dd490c589024011b02e284c45a9e5a48b8dc..5a5638cef70bcf1636a95961d9045befa44f0b97 100755 (executable)
@@ -52,15 +52,15 @@ module.exports = function(Chart) {
 
                        // defaults to unit's corresponding unitFormat below or override using pattern string from http://momentjs.com/docs/#/displaying/format/
                        displayFormats: {
-                               'millisecond': 'h:mm:ss.SSS a', // 11:20:01.123 AM,
-                               'second': 'h:mm:ss a', // 11:20:01 AM
-                               'minute': 'h:mm:ss a', // 11:20:01 AM
-                               'hour': 'MMM D, hA', // Sept 4, 5PM
-                               'day': 'll', // Sep 4 2015
-                               'week': 'll', // Week 46, or maybe "[W]WW - YYYY" ?
-                               'month': 'MMM YYYY', // Sept 2015
-                               'quarter': '[Q]Q - YYYY', // Q3
-                               'year': 'YYYY' // 2015
+                               millisecond: 'h:mm:ss.SSS a', // 11:20:01.123 AM,
+                               second: 'h:mm:ss a', // 11:20:01 AM
+                               minute: 'h:mm:ss a', // 11:20:01 AM
+                               hour: 'MMM D, hA', // Sept 4, 5PM
+                               day: 'll', // Sep 4 2015
+                               week: 'll', // Week 46, or maybe "[W]WW - YYYY" ?
+                               month: 'MMM YYYY', // Sept 2015
+                               quarter: '[Q]Q - YYYY', // Q3
+                               year: 'YYYY' // 2015
                        }
                },
                ticks: {
@@ -107,9 +107,8 @@ module.exports = function(Chart) {
                        var me = this;
                        if (me.options.time.unit === 'week' && me.options.time.isoWeekday !== false) {
                                return tick.clone().startOf('isoWeek').isoWeekday(me.options.time.isoWeekday);
-                       } else {
-                               return tick.clone().startOf(me.tickUnit);
                        }
+                       return tick.clone().startOf(me.tickUnit);
                },
                determineDataLimits: function() {
                        var me = this;
@@ -381,9 +380,8 @@ module.exports = function(Chart) {
 
                        if (callback) {
                                return callback(formattedTick, index, ticks);
-                       } else {
-                               return formattedTick;
                        }
+                       return formattedTick;
                },
                convertTicksToLabels: function() {
                        var me = this;
@@ -415,12 +413,11 @@ module.exports = function(Chart) {
                                        var valueOffset = (innerWidth * decimal) + me.paddingLeft;
 
                                        return me.left + Math.round(valueOffset);
-                               } else {
-                                       var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
-                                       var heightOffset = (innerHeight * decimal) + me.paddingTop;
-
-                                       return me.top + Math.round(heightOffset);
                                }
+                               var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
+                               var heightOffset = (innerHeight * decimal) + me.paddingTop;
+
+                               return me.top + Math.round(heightOffset);
                        }
                },
                getPixelForTick: function(index) {