mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-06 00:14:03 +01:00
Fix more style errors in controllers, elements, and scales
This commit is contained in:
@@ -96,7 +96,7 @@ rules:
|
||||
radix: 2
|
||||
vars-on-top: 0
|
||||
wrap-iife: 2
|
||||
yoda: [2, never]
|
||||
yoda: [1, never]
|
||||
|
||||
# Strict
|
||||
strict: 0
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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 || {};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user