mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Enforce consistent tab indentation
indent: [error, tab] (http://eslint.org/docs/rules/indent)
This commit is contained in:
parent
69ab0d3e23
commit
3d40774c7d
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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;
|
||||
};
|
||||
@ -2,103 +2,103 @@
|
||||
|
||||
module.exports = function(Chart) {
|
||||
|
||||
var helpers = Chart.helpers;
|
||||
var helpers = Chart.helpers;
|
||||
|
||||
Chart.elements = {};
|
||||
Chart.elements = {};
|
||||
|
||||
Chart.Element = function(configuration) {
|
||||
helpers.extend(this, configuration);
|
||||
this.initialize.apply(this, arguments);
|
||||
};
|
||||
Chart.Element = function(configuration) {
|
||||
helpers.extend(this, configuration);
|
||||
this.initialize.apply(this, arguments);
|
||||
};
|
||||
|
||||
helpers.extend(Chart.Element.prototype, {
|
||||
helpers.extend(Chart.Element.prototype, {
|
||||
|
||||
initialize: function() {
|
||||
this.hidden = false;
|
||||
},
|
||||
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;
|
||||
},
|
||||
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);
|
||||
}
|
||||
transition: function(ease) {
|
||||
var me = this;
|
||||
|
||||
// No animation -> No Transition
|
||||
if (ease === 1) {
|
||||
me._view = me._model;
|
||||
me._start = null;
|
||||
return me;
|
||||
}
|
||||
if (!me._view) {
|
||||
me._view = helpers.clone(me._model);
|
||||
}
|
||||
|
||||
if (!me._start) {
|
||||
me.pivot();
|
||||
}
|
||||
// No animation -> No Transition
|
||||
if (ease === 1) {
|
||||
me._view = me._model;
|
||||
me._start = null;
|
||||
return me;
|
||||
}
|
||||
|
||||
helpers.each(me._model, function(value, key) {
|
||||
if (!me._start) {
|
||||
me.pivot();
|
||||
}
|
||||
|
||||
if (key[0] === '_') {
|
||||
// Only non-underscored properties
|
||||
}
|
||||
helpers.each(me._model, function(value, key) {
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
if (key[0] === '_') {
|
||||
// Only non-underscored properties
|
||||
}
|
||||
|
||||
// No unnecessary computations
|
||||
else if (value === me._view[key]) {
|
||||
// It's the same! Woohoo!
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
// No unnecessary computations
|
||||
else if (value === me._view[key]) {
|
||||
// It's the same! Woohoo!
|
||||
}
|
||||
|
||||
return me;
|
||||
},
|
||||
// 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);
|
||||
|
||||
tooltipPosition: function() {
|
||||
return {
|
||||
x: this._model.x,
|
||||
y: this._model.y
|
||||
};
|
||||
},
|
||||
return me;
|
||||
},
|
||||
|
||||
hasValue: function() {
|
||||
return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
|
||||
}
|
||||
});
|
||||
tooltipPosition: function() {
|
||||
return {
|
||||
x: this._model.x,
|
||||
y: this._model.y
|
||||
};
|
||||
},
|
||||
|
||||
Chart.Element.extend = helpers.inherits;
|
||||
hasValue: function() {
|
||||
return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
|
||||
}
|
||||
});
|
||||
|
||||
Chart.Element.extend = helpers.inherits;
|
||||
|
||||
};
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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]);
|
||||
|
||||
@ -2,92 +2,92 @@
|
||||
|
||||
module.exports = function(Chart) {
|
||||
|
||||
var helpers = Chart.helpers,
|
||||
globalOpts = Chart.defaults.global;
|
||||
var helpers = Chart.helpers,
|
||||
globalOpts = Chart.defaults.global;
|
||||
|
||||
globalOpts.elements.arc = {
|
||||
backgroundColor: globalOpts.defaultColor,
|
||||
borderColor: "#fff",
|
||||
borderWidth: 2
|
||||
};
|
||||
globalOpts.elements.arc = {
|
||||
backgroundColor: globalOpts.defaultColor,
|
||||
borderColor: "#fff",
|
||||
borderWidth: 2
|
||||
};
|
||||
|
||||
Chart.elements.Arc = Chart.Element.extend({
|
||||
inLabelRange: function(mouseX) {
|
||||
var vm = this._view;
|
||||
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) {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
//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);
|
||||
//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;
|
||||
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 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;
|
||||
var ctx = this._chart.ctx,
|
||||
vm = this._view,
|
||||
sA = vm.startAngle,
|
||||
eA = vm.endAngle;
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.beginPath();
|
||||
|
||||
ctx.arc(vm.x, vm.y, vm.outerRadius, sA, eA);
|
||||
ctx.arc(vm.x, vm.y, vm.innerRadius, eA, sA, true);
|
||||
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.closePath();
|
||||
ctx.strokeStyle = vm.borderColor;
|
||||
ctx.lineWidth = vm.borderWidth;
|
||||
|
||||
ctx.fillStyle = vm.backgroundColor;
|
||||
ctx.fillStyle = vm.backgroundColor;
|
||||
|
||||
ctx.fill();
|
||||
ctx.lineJoin = 'bevel';
|
||||
ctx.fill();
|
||||
ctx.lineJoin = 'bevel';
|
||||
|
||||
if (vm.borderWidth) {
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
});
|
||||
if (vm.borderWidth) {
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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;
|
||||
},
|
||||
|
||||
@ -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];
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user