From: Zach Panzarino Date: Wed, 14 Sep 2016 22:34:41 +0000 (+0000) Subject: Fix more style errors in controllers, elements, and scales X-Git-Tag: v2.3.0-rc.1~1^2~6^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dd8fa78b453dd71f88934f0b561e2d613be6a1ab;p=thirdparty%2FChart.js.git Fix more style errors in controllers, elements, and scales --- diff --git a/.eslintrc b/.eslintrc index 827b73c37..340d657ba 100644 --- 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 diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 73ed2df2a..d9fa7bfeb 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -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); diff --git a/src/controllers/controller.doughnut.js b/src/controllers/controller.doughnut.js index 40d4e2c84..0e9c5fe80 100644 --- a/src/controllers/controller.doughnut.js +++ b/src/controllers/controller.doughnut.js @@ -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 diff --git a/src/controllers/controller.line.js b/src/controllers/controller.line.js index a516a1e36..bfc061af2 100644 --- a/src/controllers/controller.line.js +++ b/src/controllers/controller.line.js @@ -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); diff --git a/src/controllers/controller.polarArea.js b/src/controllers/controller.polarArea.js index 6a11b4599..b27daf417 100644 --- a/src/controllers/controller.polarArea.js +++ b/src/controllers/controller.polarArea.js @@ -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; } }); }; diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 0f74bcad6..30ba13418 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -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= vm.innerRadius && distance <= vm.outerRadius); return (betweenAngles && withinRadius); - } else { - return false; } + return false; }, tooltipPosition: function() { var vm = this._view; diff --git a/src/elements/element.line.js b/src/elements/element.line.js index 6ce178fbd..9981d3d2f 100644 --- a/src/elements/element.line.js +++ b/src/elements/element.line.js @@ -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 diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index 7895dd490..5a5638cef 100755 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -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) {