From: Simon Brunel Date: Sat, 3 Sep 2016 08:53:32 +0000 (+0200) Subject: Enforce consistent tab indentation X-Git-Tag: v2.3.0-rc.1~1^2~14^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3d40774c7d835b738227d13dbca365ea50ba7a85;p=thirdparty%2FChart.js.git Enforce consistent tab indentation indent: [error, tab] (http://eslint.org/docs/rules/indent) --- diff --git a/.eslintrc b/.eslintrc index cb5b0d49e..b02b49bfe 100644 --- a/.eslintrc +++ b/.eslintrc @@ -139,7 +139,7 @@ rules: func-style: 0 id-length: 0 id-match: 0 - indent: 0 + indent: [2, tab] jsx-quotes: 0 key-spacing: 0 linebreak-style: 0 diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 46d44fe16..1621274d3 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -142,8 +142,8 @@ module.exports = function(Chart) { var fullBarWidth = categoryWidth / datasetCount; if (xScale.ticks.length !== me.chart.data.labels.length) { - var perc = xScale.ticks.length / me.chart.data.labels.length; - fullBarWidth = fullBarWidth * perc; + var perc = xScale.ticks.length / me.chart.data.labels.length; + fullBarWidth = fullBarWidth * perc; } var barWidth = fullBarWidth * xScale.options.barPercentage; @@ -326,7 +326,7 @@ module.exports = function(Chart) { }, label: function(tooltipItem, data) { var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || ''; - return datasetLabel + ': ' + tooltipItem.xLabel; + return datasetLabel + ': ' + tooltipItem.xLabel; } } } diff --git a/src/controllers/controller.doughnut.js b/src/controllers/controller.doughnut.js index 637caea37..096f3085a 100644 --- a/src/controllers/controller.doughnut.js +++ b/src/controllers/controller.doughnut.js @@ -166,8 +166,8 @@ module.exports = function(Chart) { minSize = Math.min(availableWidth / size.width, availableHeight / size.height); offset = {x: (max.x + min.x) * -0.5, y: (max.y + min.y) * -0.5}; } - chart.borderWidth = me.getMaxBorderWidth(meta.data); + chart.borderWidth = me.getMaxBorderWidth(meta.data); chart.outerRadius = Math.max((minSize - chart.borderWidth) / 2, 0); chart.innerRadius = Math.max(cutoutPercentage ? (chart.outerRadius / 100) * (cutoutPercentage) : 1, 0); chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount(); @@ -268,23 +268,23 @@ module.exports = function(Chart) { return 0; } }, - + //gets the max border or hover width to properly scale pie charts - getMaxBorderWidth: function (elements) { - var max = 0, + getMaxBorderWidth: function (elements) { + var max = 0, index = this.index, length = elements.length, borderWidth, hoverWidth; - for (var i = 0; i < length; i++) { - borderWidth = elements[i]._model ? elements[i]._model.borderWidth : 0; - hoverWidth = elements[i]._chart ? elements[i]._chart.config.data.datasets[index].hoverBorderWidth : 0; - - max = borderWidth > max ? borderWidth : max; - max = hoverWidth > max ? hoverWidth : max; - } - return max; - } + for (var i = 0; i < length; i++) { + borderWidth = elements[i]._model ? elements[i]._model.borderWidth : 0; + hoverWidth = elements[i]._chart ? elements[i]._chart.config.data.datasets[index].hoverBorderWidth : 0; + + max = borderWidth > max ? borderWidth : max; + max = hoverWidth > max ? hoverWidth : max; + } + return max; + } }); }; diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 6eb74a7c4..2ee3712ba 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -461,7 +461,7 @@ module.exports = function(Chart) { }, me); return elementsArray; - }, + }, getElementsAtEventForMode: function(e, mode) { var me = this; @@ -472,8 +472,8 @@ module.exports = function(Chart) { return me.getElementsAtEvent(e); case 'dataset': return me.getDatasetAtEvent(e); - case 'x-axis': - return me.getElementsAtXAxis(e); + case 'x-axis': + return me.getElementsAtXAxis(e); default: return e; } @@ -499,14 +499,14 @@ module.exports = function(Chart) { var meta = dataset._meta[me.id]; if (!meta) { meta = dataset._meta[me.id] = { - type: null, - data: [], - dataset: null, - controller: null, - hidden: null, // See isDatasetVisible() comment - xAxisID: null, - yAxisID: null - }; + type: null, + data: [], + dataset: null, + controller: null, + hidden: null, // See isDatasetVisible() comment + xAxisID: null, + yAxisID: null + }; } return meta; @@ -591,7 +591,7 @@ module.exports = function(Chart) { break; case 'label': case 'dataset': - case 'x-axis': + case 'x-axis': // elements = elements; break; default: diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index 4318a9c95..bc140800d 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -158,8 +158,7 @@ module.exports = function(Chart) { model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth); } - }); - + }); Chart.DatasetController.extend = helpers.inherits; }; \ No newline at end of file diff --git a/src/core/core.element.js b/src/core/core.element.js index 5bab6d49c..e385074ae 100644 --- a/src/core/core.element.js +++ b/src/core/core.element.js @@ -2,103 +2,103 @@ module.exports = function(Chart) { - var helpers = Chart.helpers; - - Chart.elements = {}; - - Chart.Element = function(configuration) { - helpers.extend(this, configuration); - this.initialize.apply(this, arguments); - }; - - helpers.extend(Chart.Element.prototype, { - - initialize: function() { - this.hidden = false; - }, - - pivot: function() { - var me = this; - if (!me._view) { - me._view = helpers.clone(me._model); - } - me._start = helpers.clone(me._view); - return me; - }, - - transition: function(ease) { - var me = this; - - if (!me._view) { - me._view = helpers.clone(me._model); - } - - // No animation -> No Transition - if (ease === 1) { - me._view = me._model; - me._start = null; - return me; - } - - if (!me._start) { - me.pivot(); - } - - helpers.each(me._model, function(value, key) { - - if (key[0] === '_') { - // Only non-underscored properties - } - - // Init if doesn't exist - 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]) { - // It's the same! Woohoo! - } - - // Color transitions if possible - 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') { - 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 { - me._view[key] = value; - } - }, me); - - return me; - }, - - tooltipPosition: function() { - return { - x: this._model.x, - y: this._model.y - }; - }, - - hasValue: function() { - return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y); - } - }); - - Chart.Element.extend = helpers.inherits; + var helpers = Chart.helpers; + + Chart.elements = {}; + + Chart.Element = function(configuration) { + helpers.extend(this, configuration); + this.initialize.apply(this, arguments); + }; + + helpers.extend(Chart.Element.prototype, { + + initialize: function() { + this.hidden = false; + }, + + pivot: function() { + var me = this; + if (!me._view) { + me._view = helpers.clone(me._model); + } + me._start = helpers.clone(me._view); + return me; + }, + + transition: function(ease) { + var me = this; + + if (!me._view) { + me._view = helpers.clone(me._model); + } + + // No animation -> No Transition + if (ease === 1) { + me._view = me._model; + me._start = null; + return me; + } + + if (!me._start) { + me.pivot(); + } + + helpers.each(me._model, function(value, key) { + + if (key[0] === '_') { + // Only non-underscored properties + } + + // Init if doesn't exist + 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]) { + // It's the same! Woohoo! + } + + // Color transitions if possible + 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') { + 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 { + me._view[key] = value; + } + }, me); + + return me; + }, + + tooltipPosition: function() { + return { + x: this._model.x, + y: this._model.y + }; + }, + + hasValue: function() { + return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y); + } + }); + + Chart.Element.extend = helpers.inherits; }; diff --git a/src/core/core.legend.js b/src/core/core.legend.js index ffe42c904..fe5b47f80 100644 --- a/src/core/core.legend.js +++ b/src/core/core.legend.js @@ -346,7 +346,7 @@ module.exports = function(Chart) { // Draw box as legend symbol if (!isLineWidthZero) { - ctx.strokeRect(x, y, boxWidth, fontSize); + ctx.strokeRect(x, y, boxWidth, fontSize); } ctx.fillRect(x, y, boxWidth, fontSize); } diff --git a/src/core/core.scale.js b/src/core/core.scale.js index ca2546b26..8faa49ef5 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -170,12 +170,12 @@ module.exports = function(Chart) { var me = this; // Convert ticks to strings me.ticks = me.ticks.map(function(numericalTick, index, ticks) { - if (me.options.ticks.userCallback) { - return me.options.ticks.userCallback(numericalTick, index, ticks); - } - return me.options.ticks.callback(numericalTick, index, ticks); - }, - me); + if (me.options.ticks.userCallback) { + return me.options.ticks.userCallback(numericalTick, index, ticks); + } + return me.options.ticks.callback(numericalTick, index, ticks); + }, + me); }, afterTickToLabelConversion: function() { helpers.callCallback(this.options.afterTickToLabelConversion, [this]); diff --git a/src/elements/element.arc.js b/src/elements/element.arc.js index e91b9c2c8..64d960483 100644 --- a/src/elements/element.arc.js +++ b/src/elements/element.arc.js @@ -2,92 +2,92 @@ module.exports = function(Chart) { - var helpers = Chart.helpers, - globalOpts = Chart.defaults.global; - - globalOpts.elements.arc = { - backgroundColor: globalOpts.defaultColor, - borderColor: "#fff", - borderWidth: 2 - }; - - Chart.elements.Arc = Chart.Element.extend({ - inLabelRange: function(mouseX) { - var vm = this._view; - - if (vm) { - return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2)); - } else { - return false; - } - }, - inRange: function(chartX, chartY) { - var vm = this._view; - - if (vm) { - var pointRelativePosition = helpers.getAngleFromPoint(vm, { - x: chartX, - y: chartY - }), - angle = pointRelativePosition.angle, - distance = pointRelativePosition.distance; - - //Sanitise angle range - var startAngle = vm.startAngle; - var endAngle = vm.endAngle; - while (endAngle < startAngle) { - endAngle += 2.0 * Math.PI; - } - while (angle > endAngle) { - angle -= 2.0 * Math.PI; - } - while (angle < startAngle) { - angle += 2.0 * Math.PI; - } - - //Check if within the range of the open/close angle - var betweenAngles = (angle >= startAngle && angle <= endAngle), - withinRadius = (distance >= vm.innerRadius && distance <= vm.outerRadius); - - return (betweenAngles && withinRadius); - } else { - return false; - } - }, - tooltipPosition: function() { - var vm = this._view; - - var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2), - rangeFromCentre = (vm.outerRadius - vm.innerRadius) / 2 + vm.innerRadius; - return { - x: vm.x + (Math.cos(centreAngle) * rangeFromCentre), - y: vm.y + (Math.sin(centreAngle) * rangeFromCentre) - }; - }, - draw: function() { - - var ctx = this._chart.ctx, - vm = this._view, - sA = vm.startAngle, - eA = vm.endAngle; - - ctx.beginPath(); - - ctx.arc(vm.x, vm.y, vm.outerRadius, sA, eA); - ctx.arc(vm.x, vm.y, vm.innerRadius, eA, sA, true); - - ctx.closePath(); - ctx.strokeStyle = vm.borderColor; - ctx.lineWidth = vm.borderWidth; - - ctx.fillStyle = vm.backgroundColor; - - ctx.fill(); - ctx.lineJoin = 'bevel'; - - if (vm.borderWidth) { - ctx.stroke(); - } - } - }); + var helpers = Chart.helpers, + globalOpts = Chart.defaults.global; + + globalOpts.elements.arc = { + backgroundColor: globalOpts.defaultColor, + borderColor: "#fff", + borderWidth: 2 + }; + + Chart.elements.Arc = Chart.Element.extend({ + inLabelRange: function(mouseX) { + var vm = this._view; + + if (vm) { + return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2)); + } else { + return false; + } + }, + inRange: function(chartX, chartY) { + var vm = this._view; + + if (vm) { + var pointRelativePosition = helpers.getAngleFromPoint(vm, { + x: chartX, + y: chartY + }), + angle = pointRelativePosition.angle, + distance = pointRelativePosition.distance; + + //Sanitise angle range + var startAngle = vm.startAngle; + var endAngle = vm.endAngle; + while (endAngle < startAngle) { + endAngle += 2.0 * Math.PI; + } + while (angle > endAngle) { + angle -= 2.0 * Math.PI; + } + while (angle < startAngle) { + angle += 2.0 * Math.PI; + } + + //Check if within the range of the open/close angle + var betweenAngles = (angle >= startAngle && angle <= endAngle), + withinRadius = (distance >= vm.innerRadius && distance <= vm.outerRadius); + + return (betweenAngles && withinRadius); + } else { + return false; + } + }, + tooltipPosition: function() { + var vm = this._view; + + var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2), + rangeFromCentre = (vm.outerRadius - vm.innerRadius) / 2 + vm.innerRadius; + return { + x: vm.x + (Math.cos(centreAngle) * rangeFromCentre), + y: vm.y + (Math.sin(centreAngle) * rangeFromCentre) + }; + }, + draw: function() { + + var ctx = this._chart.ctx, + vm = this._view, + sA = vm.startAngle, + eA = vm.endAngle; + + ctx.beginPath(); + + ctx.arc(vm.x, vm.y, vm.outerRadius, sA, eA); + ctx.arc(vm.x, vm.y, vm.innerRadius, eA, sA, true); + + ctx.closePath(); + ctx.strokeStyle = vm.borderColor; + ctx.lineWidth = vm.borderWidth; + + ctx.fillStyle = vm.backgroundColor; + + ctx.fill(); + ctx.lineJoin = 'bevel'; + + if (vm.borderWidth) { + ctx.stroke(); + } + } + }); }; diff --git a/src/scales/scale.category.js b/src/scales/scale.category.js index 7e7d552fc..7767ef58d 100644 --- a/src/scales/scale.category.js +++ b/src/scales/scale.category.js @@ -70,9 +70,9 @@ module.exports = function(Chart) { var valueWidth = innerWidth / offsetAmt; var widthOffset = (valueWidth * (index - me.minIndex)) + me.paddingLeft; - if (me.options.gridLines.offsetGridLines && includeOffset || me.maxIndex === me.minIndex && includeOffset) { + if (me.options.gridLines.offsetGridLines && includeOffset || me.maxIndex === me.minIndex && includeOffset) { widthOffset += (valueWidth / 2); - } + } return me.left + Math.round(widthOffset); } else { diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 86cc516af..fe3e44c4f 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -243,7 +243,7 @@ module.exports = function(Chart) { range = helpers.log10(me.end) - helpers.log10(start); innerDimension = me.height - (paddingTop + paddingBottom); pixel = (me.bottom - paddingBottom) - (innerDimension / range * (helpers.log10(newVal) - helpers.log10(start))); - } + } } return pixel; }, diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index c7b64cbd3..50d3c3bec 100755 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -78,8 +78,8 @@ module.exports = function(Chart) { getLabelMoment: function(datasetIndex, index) { if (datasetIndex === null || index === null) { return null; - } - + } + if (typeof this.labelMoments[datasetIndex] !== 'undefined') { return this.labelMoments[datasetIndex][index]; }