未验证 提交 8e68481e 编写于 作者: E Evert Timberg 提交者: GitHub

Remove const me = this pattern (#9646)

上级 183a1a9f
......@@ -310,10 +310,9 @@ export default class BarController extends DatasetController {
* @protected
*/
getLabelAndValue(index) {
const me = this;
const meta = me._cachedMeta;
const meta = this._cachedMeta;
const {iScale, vScale} = meta;
const parsed = me.getParsed(index);
const parsed = this.getParsed(index);
const custom = parsed._custom;
const value = isFloatBar(custom)
? '[' + custom.start + ', ' + custom.end + ']'
......@@ -326,39 +325,35 @@ export default class BarController extends DatasetController {
}
initialize() {
const me = this;
me.enableOptionSharing = true;
this.enableOptionSharing = true;
super.initialize();
const meta = me._cachedMeta;
meta.stack = me.getDataset().stack;
const meta = this._cachedMeta;
meta.stack = this.getDataset().stack;
}
update(mode) {
const me = this;
const meta = me._cachedMeta;
me.updateElements(meta.data, 0, meta.data.length, mode);
const meta = this._cachedMeta;
this.updateElements(meta.data, 0, meta.data.length, mode);
}
updateElements(bars, start, count, mode) {
const me = this;
const reset = mode === 'reset';
const {index, _cachedMeta: {vScale}} = me;
const {index, _cachedMeta: {vScale}} = this;
const base = vScale.getBasePixel();
const horizontal = vScale.isHorizontal();
const ruler = me._getRuler();
const firstOpts = me.resolveDataElementOptions(start, mode);
const sharedOptions = me.getSharedOptions(firstOpts);
const includeOptions = me.includeOptions(mode, sharedOptions);
const ruler = this._getRuler();
const firstOpts = this.resolveDataElementOptions(start, mode);
const sharedOptions = this.getSharedOptions(firstOpts);
const includeOptions = this.includeOptions(mode, sharedOptions);
me.updateSharedOptions(sharedOptions, mode, firstOpts);
this.updateSharedOptions(sharedOptions, mode, firstOpts);
for (let i = start; i < start + count; i++) {
const parsed = me.getParsed(i);
const vpixels = reset || isNullOrUndef(parsed[vScale.axis]) ? {base, head: base} : me._calculateBarValuePixels(i);
const ipixels = me._calculateBarIndexPixels(i, ruler);
const parsed = this.getParsed(i);
const vpixels = reset || isNullOrUndef(parsed[vScale.axis]) ? {base, head: base} : this._calculateBarValuePixels(i);
const ipixels = this._calculateBarIndexPixels(i, ruler);
const stack = (parsed._stacks || {})[vScale.axis];
const properties = {
......@@ -372,10 +367,10 @@ export default class BarController extends DatasetController {
};
if (includeOptions) {
properties.options = sharedOptions || me.resolveDataElementOptions(i, bars[i].active ? 'active' : mode);
properties.options = sharedOptions || this.resolveDataElementOptions(i, bars[i].active ? 'active' : mode);
}
setBorderSkipped(properties, properties.options || bars[i].options, stack, index);
me.updateElement(bars[i], i, properties, mode);
this.updateElement(bars[i], i, properties, mode);
}
}
......@@ -387,10 +382,9 @@ export default class BarController extends DatasetController {
* @private
*/
_getStacks(last, dataIndex) {
const me = this;
const meta = me._cachedMeta;
const meta = this._cachedMeta;
const iScale = meta.iScale;
const metasets = iScale.getMatchingVisibleMetas(me._type);
const metasets = iScale.getMatchingVisibleMetas(this._type);
const stacked = iScale.options.stacked;
const ilen = metasets.length;
const stacks = [];
......@@ -468,15 +462,14 @@ export default class BarController extends DatasetController {
* @private
*/
_getRuler() {
const me = this;
const opts = me.options;
const meta = me._cachedMeta;
const opts = this.options;
const meta = this._cachedMeta;
const iScale = meta.iScale;
const pixels = [];
let i, ilen;
for (i = 0, ilen = meta.data.length; i < ilen; ++i) {
pixels.push(iScale.getPixelForValue(me.getParsed(i)[iScale.axis], i));
pixels.push(iScale.getPixelForValue(this.getParsed(i)[iScale.axis], i));
}
const barThickness = opts.barThickness;
......@@ -487,7 +480,7 @@ export default class BarController extends DatasetController {
pixels,
start: iScale._startPixel,
end: iScale._endPixel,
stackCount: me._getStackCount(),
stackCount: this._getStackCount(),
scale: iScale,
grouped: opts.grouped,
// bar thickness ratio used for non-grouped bars
......@@ -500,15 +493,14 @@ export default class BarController extends DatasetController {
* @private
*/
_calculateBarValuePixels(index) {
const me = this;
const {_cachedMeta: {vScale, _stacked}, options: {base: baseValue, minBarLength}} = me;
const {_cachedMeta: {vScale, _stacked}, options: {base: baseValue, minBarLength}} = this;
const actualBase = baseValue || 0;
const parsed = me.getParsed(index);
const parsed = this.getParsed(index);
const custom = parsed._custom;
const floating = isFloatBar(custom);
let value = parsed[vScale.axis];
let start = 0;
let length = _stacked ? me.applyStack(vScale, parsed, _stacked) : value;
let length = _stacked ? this.applyStack(vScale, parsed, _stacked) : value;
let head, size;
if (length !== value) {
......@@ -529,7 +521,7 @@ export default class BarController extends DatasetController {
const startValue = !isNullOrUndef(baseValue) && !floating ? baseValue : start;
let base = vScale.getPixelForValue(startValue);
if (me.chart.getDataVisibility(index)) {
if (this.chart.getDataVisibility(index)) {
head = vScale.getPixelForValue(start + length);
} else {
// When not visible, no height
......@@ -564,24 +556,23 @@ export default class BarController extends DatasetController {
* @private
*/
_calculateBarIndexPixels(index, ruler) {
const me = this;
const scale = ruler.scale;
const options = me.options;
const options = this.options;
const skipNull = options.skipNull;
const maxBarThickness = valueOrDefault(options.maxBarThickness, Infinity);
let center, size;
if (ruler.grouped) {
const stackCount = skipNull ? me._getStackCount(index) : ruler.stackCount;
const stackCount = skipNull ? this._getStackCount(index) : ruler.stackCount;
const range = options.barThickness === 'flex'
? computeFlexCategoryTraits(index, ruler, options, stackCount)
: computeFitCategoryTraits(index, ruler, options, stackCount);
const stackIndex = me._getStackIndex(me.index, me._cachedMeta.stack, skipNull ? index : undefined);
const stackIndex = this._getStackIndex(this.index, this._cachedMeta.stack, skipNull ? index : undefined);
center = range.start + (range.chunk * stackIndex) + (range.chunk / 2);
size = Math.min(maxBarThickness, range.chunk * range.ratio);
} else {
// For non-grouped bar charts, exact pixel values are used
center = scale.getPixelForValue(me.getParsed(index)[scale.axis], index);
center = scale.getPixelForValue(this.getParsed(index)[scale.axis], index);
size = Math.min(maxBarThickness, ruler.min * ruler.ratio);
}
......@@ -594,16 +585,15 @@ export default class BarController extends DatasetController {
}
draw() {
const me = this;
const meta = me._cachedMeta;
const meta = this._cachedMeta;
const vScale = meta.vScale;
const rects = meta.data;
const ilen = rects.length;
let i = 0;
for (; i < ilen; ++i) {
if (me.getParsed(i)[vScale.axis] !== null) {
rects[i].draw(me._ctx);
if (this.getParsed(i)[vScale.axis] !== null) {
rects[i].draw(this._ctx);
}
}
}
......
......@@ -44,10 +44,9 @@ export default class BubbleController extends DatasetController {
* @protected
*/
getLabelAndValue(index) {
const me = this;
const meta = me._cachedMeta;
const meta = this._cachedMeta;
const {xScale, yScale} = meta;
const parsed = me.getParsed(index);
const parsed = this.getParsed(index);
const x = xScale.getLabelForValue(parsed.x);
const y = yScale.getLabelForValue(parsed.y);
const r = parsed._custom;
......@@ -59,26 +58,24 @@ export default class BubbleController extends DatasetController {
}
update(mode) {
const me = this;
const points = me._cachedMeta.data;
const points = this._cachedMeta.data;
// Update Points
me.updateElements(points, 0, points.length, mode);
this.updateElements(points, 0, points.length, mode);
}
updateElements(points, start, count, mode) {
const me = this;
const reset = mode === 'reset';
const {iScale, vScale} = me._cachedMeta;
const firstOpts = me.resolveDataElementOptions(start, mode);
const sharedOptions = me.getSharedOptions(firstOpts);
const includeOptions = me.includeOptions(mode, sharedOptions);
const {iScale, vScale} = this._cachedMeta;
const firstOpts = this.resolveDataElementOptions(start, mode);
const sharedOptions = this.getSharedOptions(firstOpts);
const includeOptions = this.includeOptions(mode, sharedOptions);
const iAxis = iScale.axis;
const vAxis = vScale.axis;
for (let i = start; i < start + count; i++) {
const point = points[i];
const parsed = !reset && me.getParsed(i);
const parsed = !reset && this.getParsed(i);
const properties = {};
const iPixel = properties[iAxis] = reset ? iScale.getPixelForDecimal(0.5) : iScale.getPixelForValue(parsed[iAxis]);
const vPixel = properties[vAxis] = reset ? vScale.getBasePixel() : vScale.getPixelForValue(parsed[vAxis]);
......@@ -86,17 +83,17 @@ export default class BubbleController extends DatasetController {
properties.skip = isNaN(iPixel) || isNaN(vPixel);
if (includeOptions) {
properties.options = me.resolveDataElementOptions(i, point.active ? 'active' : mode);
properties.options = this.resolveDataElementOptions(i, point.active ? 'active' : mode);
if (reset) {
properties.options.radius = 0;
}
}
me.updateElement(point, i, properties, mode);
this.updateElement(point, i, properties, mode);
}
me.updateSharedOptions(sharedOptions, mode, firstOpts);
this.updateSharedOptions(sharedOptions, mode, firstOpts);
}
/**
......
......@@ -94,11 +94,9 @@ export default class DoughnutController extends DatasetController {
let min = TAU;
let max = -TAU;
const me = this;
for (let i = 0; i < me.chart.data.datasets.length; ++i) {
if (me.chart.isDatasetVisible(i)) {
const controller = me.chart.getDatasetMeta(i).controller;
for (let i = 0; i < this.chart.data.datasets.length; ++i) {
if (this.chart.isDatasetVisible(i)) {
const controller = this.chart.getDatasetMeta(i).controller;
const rotation = controller._getRotation();
const circumference = controller._getCircumference();
......@@ -117,80 +115,77 @@ export default class DoughnutController extends DatasetController {
* @param {string} mode
*/
update(mode) {
const me = this;
const chart = me.chart;
const chart = this.chart;
const {chartArea} = chart;
const meta = me._cachedMeta;
const meta = this._cachedMeta;
const arcs = meta.data;
const spacing = me.getMaxBorderWidth() + me.getMaxOffset(arcs) + me.options.spacing;
const spacing = this.getMaxBorderWidth() + this.getMaxOffset(arcs) + this.options.spacing;
const maxSize = Math.max((Math.min(chartArea.width, chartArea.height) - spacing) / 2, 0);
const cutout = Math.min(toPercentage(me.options.cutout, maxSize), 1);
const chartWeight = me._getRingWeight(me.index);
const cutout = Math.min(toPercentage(this.options.cutout, maxSize), 1);
const chartWeight = this._getRingWeight(this.index);
// Compute the maximal rotation & circumference limits.
// If we only consider our dataset, this can cause problems when two datasets
// are both less than a circle with different rotations (starting angles)
const {circumference, rotation} = me._getRotationExtents();
const {circumference, rotation} = this._getRotationExtents();
const {ratioX, ratioY, offsetX, offsetY} = getRatioAndOffset(rotation, circumference, cutout);
const maxWidth = (chartArea.width - spacing) / ratioX;
const maxHeight = (chartArea.height - spacing) / ratioY;
const maxRadius = Math.max(Math.min(maxWidth, maxHeight) / 2, 0);
const outerRadius = toDimension(me.options.radius, maxRadius);
const outerRadius = toDimension(this.options.radius, maxRadius);
const innerRadius = Math.max(outerRadius * cutout, 0);
const radiusLength = (outerRadius - innerRadius) / me._getVisibleDatasetWeightTotal();
me.offsetX = offsetX * outerRadius;
me.offsetY = offsetY * outerRadius;
const radiusLength = (outerRadius - innerRadius) / this._getVisibleDatasetWeightTotal();
this.offsetX = offsetX * outerRadius;
this.offsetY = offsetY * outerRadius;
meta.total = me.calculateTotal();
meta.total = this.calculateTotal();
me.outerRadius = outerRadius - radiusLength * me._getRingWeightOffset(me.index);
me.innerRadius = Math.max(me.outerRadius - radiusLength * chartWeight, 0);
this.outerRadius = outerRadius - radiusLength * this._getRingWeightOffset(this.index);
this.innerRadius = Math.max(this.outerRadius - radiusLength * chartWeight, 0);
me.updateElements(arcs, 0, arcs.length, mode);
this.updateElements(arcs, 0, arcs.length, mode);
}
/**
* @private
*/
_circumference(i, reset) {
const me = this;
const opts = me.options;
const meta = me._cachedMeta;
const circumference = me._getCircumference();
const opts = this.options;
const meta = this._cachedMeta;
const circumference = this._getCircumference();
if ((reset && opts.animation.animateRotate) || !this.chart.getDataVisibility(i) || meta._parsed[i] === null || meta.data[i].hidden) {
return 0;
}
return me.calculateCircumference(meta._parsed[i] * circumference / TAU);
return this.calculateCircumference(meta._parsed[i] * circumference / TAU);
}
updateElements(arcs, start, count, mode) {
const me = this;
const reset = mode === 'reset';
const chart = me.chart;
const chart = this.chart;
const chartArea = chart.chartArea;
const opts = chart.options;
const animationOpts = opts.animation;
const centerX = (chartArea.left + chartArea.right) / 2;
const centerY = (chartArea.top + chartArea.bottom) / 2;
const animateScale = reset && animationOpts.animateScale;
const innerRadius = animateScale ? 0 : me.innerRadius;
const outerRadius = animateScale ? 0 : me.outerRadius;
const firstOpts = me.resolveDataElementOptions(start, mode);
const sharedOptions = me.getSharedOptions(firstOpts);
const includeOptions = me.includeOptions(mode, sharedOptions);
let startAngle = me._getRotation();
const innerRadius = animateScale ? 0 : this.innerRadius;
const outerRadius = animateScale ? 0 : this.outerRadius;
const firstOpts = this.resolveDataElementOptions(start, mode);
const sharedOptions = this.getSharedOptions(firstOpts);
const includeOptions = this.includeOptions(mode, sharedOptions);
let startAngle = this._getRotation();
let i;
for (i = 0; i < start; ++i) {
startAngle += me._circumference(i, reset);
startAngle += this._circumference(i, reset);
}
for (i = start; i < start + count; ++i) {
const circumference = me._circumference(i, reset);
const circumference = this._circumference(i, reset);
const arc = arcs[i];
const properties = {
x: centerX + me.offsetX,
y: centerY + me.offsetY,
x: centerX + this.offsetX,
y: centerY + this.offsetY,
startAngle,
endAngle: startAngle + circumference,
circumference,
......@@ -198,13 +193,13 @@ export default class DoughnutController extends DatasetController {
innerRadius
};
if (includeOptions) {
properties.options = sharedOptions || me.resolveDataElementOptions(i, arc.active ? 'active' : mode);
properties.options = sharedOptions || this.resolveDataElementOptions(i, arc.active ? 'active' : mode);
}
startAngle += circumference;
me.updateElement(arc, i, properties, mode);
this.updateElement(arc, i, properties, mode);
}
me.updateSharedOptions(sharedOptions, mode, firstOpts);
this.updateSharedOptions(sharedOptions, mode, firstOpts);
}
calculateTotal() {
......@@ -232,9 +227,8 @@ export default class DoughnutController extends DatasetController {
}
getLabelAndValue(index) {
const me = this;
const meta = me._cachedMeta;
const chart = me.chart;
const meta = this._cachedMeta;
const chart = this.chart;
const labels = chart.data.labels || [];
const value = formatNumber(meta._parsed[index], chart.options.locale);
......@@ -245,9 +239,8 @@ export default class DoughnutController extends DatasetController {
}
getMaxBorderWidth(arcs) {
const me = this;
let max = 0;
const chart = me.chart;
const chart = this.chart;
let i, ilen, meta, controller, options;
if (!arcs) {
......@@ -257,7 +250,7 @@ export default class DoughnutController extends DatasetController {
meta = chart.getDatasetMeta(i);
arcs = meta.data;
controller = meta.controller;
if (controller !== me) {
if (controller !== this) {
controller.configure();
}
break;
......
......@@ -11,15 +11,14 @@ export default class LineController extends DatasetController {
}
update(mode) {
const me = this;
const meta = me._cachedMeta;
const meta = this._cachedMeta;
const {dataset: line, data: points = [], _dataset} = meta;
// @ts-ignore
const animationsDisabled = me.chart._animationsDisabled;
const animationsDisabled = this.chart._animationsDisabled;
let {start, count} = getStartAndCountOfVisiblePoints(meta, points, animationsDisabled);
me._drawStart = start;
me._drawCount = count;
this._drawStart = start;
this._drawCount = count;
if (scaleRangesChanged(meta)) {
start = 0;
......@@ -27,78 +26,76 @@ export default class LineController extends DatasetController {
}
// Update Line
line._datasetIndex = me.index;
line._datasetIndex = this.index;
line._decimated = !!_dataset._decimated;
line.points = points;
const options = me.resolveDatasetElementOptions(mode);
if (!me.options.showLine) {
const options = this.resolveDatasetElementOptions(mode);
if (!this.options.showLine) {
options.borderWidth = 0;
}
options.segment = me.options.segment;
me.updateElement(line, undefined, {
options.segment = this.options.segment;
this.updateElement(line, undefined, {
animated: !animationsDisabled,
options
}, mode);
// Update Points
me.updateElements(points, start, count, mode);
this.updateElements(points, start, count, mode);
}
updateElements(points, start, count, mode) {
const me = this;
const reset = mode === 'reset';
const {iScale, vScale, _stacked} = me._cachedMeta;
const firstOpts = me.resolveDataElementOptions(start, mode);
const sharedOptions = me.getSharedOptions(firstOpts);
const includeOptions = me.includeOptions(mode, sharedOptions);
const {iScale, vScale, _stacked} = this._cachedMeta;
const firstOpts = this.resolveDataElementOptions(start, mode);
const sharedOptions = this.getSharedOptions(firstOpts);
const includeOptions = this.includeOptions(mode, sharedOptions);
const iAxis = iScale.axis;
const vAxis = vScale.axis;
const spanGaps = me.options.spanGaps;
const spanGaps = this.options.spanGaps;
const maxGapLength = isNumber(spanGaps) ? spanGaps : Number.POSITIVE_INFINITY;
const directUpdate = me.chart._animationsDisabled || reset || mode === 'none';
let prevParsed = start > 0 && me.getParsed(start - 1);
const directUpdate = this.chart._animationsDisabled || reset || mode === 'none';
let prevParsed = start > 0 && this.getParsed(start - 1);
for (let i = start; i < start + count; ++i) {
const point = points[i];
const parsed = me.getParsed(i);
const parsed = this.getParsed(i);
const properties = directUpdate ? point : {};
const nullData = isNullOrUndef(parsed[vAxis]);
const iPixel = properties[iAxis] = iScale.getPixelForValue(parsed[iAxis], i);
const vPixel = properties[vAxis] = reset || nullData ? vScale.getBasePixel() : vScale.getPixelForValue(_stacked ? me.applyStack(vScale, parsed, _stacked) : parsed[vAxis], i);
const vPixel = properties[vAxis] = reset || nullData ? vScale.getBasePixel() : vScale.getPixelForValue(_stacked ? this.applyStack(vScale, parsed, _stacked) : parsed[vAxis], i);
properties.skip = isNaN(iPixel) || isNaN(vPixel) || nullData;
properties.stop = i > 0 && (parsed[iAxis] - prevParsed[iAxis]) > maxGapLength;
properties.parsed = parsed;
if (includeOptions) {
properties.options = sharedOptions || me.resolveDataElementOptions(i, point.active ? 'active' : mode);
properties.options = sharedOptions || this.resolveDataElementOptions(i, point.active ? 'active' : mode);
}
if (!directUpdate) {
me.updateElement(point, i, properties, mode);
this.updateElement(point, i, properties, mode);
}
prevParsed = parsed;
}
me.updateSharedOptions(sharedOptions, mode, firstOpts);
this.updateSharedOptions(sharedOptions, mode, firstOpts);
}
/**
* @protected
*/
getMaxOverflow() {
const me = this;
const meta = me._cachedMeta;
const meta = this._cachedMeta;
const dataset = meta.dataset;
const border = dataset.options && dataset.options.borderWidth || 0;
const data = meta.data || [];
if (!data.length) {
return border;
}
const firstPoint = data[0].size(me.resolveDataElementOptions(0));
const lastPoint = data[data.length - 1].size(me.resolveDataElementOptions(data.length - 1));
const firstPoint = data[0].size(this.resolveDataElementOptions(0));
const lastPoint = data[data.length - 1].size(this.resolveDataElementOptions(data.length - 1));
return Math.max(border, firstPoint, lastPoint) / 2;
}
......
......@@ -12,9 +12,8 @@ export default class PolarAreaController extends DatasetController {
}
getLabelAndValue(index) {
const me = this;
const meta = me._cachedMeta;
const chart = me.chart;
const meta = this._cachedMeta;
const chart = this.chart;
const labels = chart.data.labels || [];
const value = formatNumber(meta._parsed[index].r, chart.options.locale);
......@@ -35,8 +34,7 @@ export default class PolarAreaController extends DatasetController {
* @private
*/
_updateRadius() {
const me = this;
const chart = me.chart;
const chart = this.chart;
const chartArea = chart.chartArea;
const opts = chart.options;
const minSize = Math.min(chartArea.right - chartArea.left, chartArea.bottom - chartArea.top);
......@@ -45,33 +43,32 @@ export default class PolarAreaController extends DatasetController {
const innerRadius = Math.max(opts.cutoutPercentage ? (outerRadius / 100) * (opts.cutoutPercentage) : 1, 0);
const radiusLength = (outerRadius - innerRadius) / chart.getVisibleDatasetCount();
me.outerRadius = outerRadius - (radiusLength * me.index);
me.innerRadius = me.outerRadius - radiusLength;
this.outerRadius = outerRadius - (radiusLength * this.index);
this.innerRadius = this.outerRadius - radiusLength;
}
updateElements(arcs, start, count, mode) {
const me = this;
const reset = mode === 'reset';
const