Skip to content

Commit

Permalink
Remove unnecessary method argument (#6878)
Browse files Browse the repository at this point in the history
Remove unnecessary method argument
  • Loading branch information
benmccann authored and etimberg committed Dec 31, 2019
1 parent 3427479 commit 8bc250f
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 54 deletions.
2 changes: 1 addition & 1 deletion docs/getting-started/v3-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ Animation system was completely rewritten in Chart.js v3. Each property can now

* `Chart.Animation.animationObject` was renamed to `Chart.Animation`
* `Chart.Animation.chartInstance` was renamed to `Chart.Animation.chart`
* `DatasetController.updateElement` was renamed to `DatasetController.updateElements`
* `helpers._decimalPlaces` was renamed to `helpers.math._decimalPlaces`
* `helpers.almostEquals` was renamed to `helpers.math.almostEquals`
* `helpers.almostWhole` was renamed to `helpers.math.almostWhole`
Expand Down Expand Up @@ -168,6 +167,7 @@ Animation system was completely rewritten in Chart.js v3. Each property can now

##### Dataset Controllers

* `updateElement` was replaced with `updateElements` now taking the elements to update, the `start` index, and `mode`
* `setHoverStyle` and `removeHoverStyle` now additionally take the `datasetIndex` and `index`

#### Interactions
Expand Down
15 changes: 8 additions & 7 deletions src/controllers/controller.bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ module.exports = DatasetController.extend({
const me = this;
const rects = me._cachedMeta.data;

me.updateElements(rects, 0, rects.length, mode);
me.updateElements(rects, 0, mode);
},

updateElements: function(rectangles, start, count, mode) {
updateElements: function(rectangles, start, mode) {
const me = this;
const reset = mode === 'reset';
const vscale = me._cachedMeta.vScale;
Expand All @@ -293,10 +293,11 @@ module.exports = DatasetController.extend({

let i;

for (i = 0; i < start + count; i++) {
const options = me._resolveDataElementOptions(i, mode);
const vpixels = me.calculateBarValuePixels(i, options);
const ipixels = me.calculateBarIndexPixels(i, ruler, options);
for (i = 0; i < rectangles.length; i++) {
const index = start + i;
const options = me._resolveDataElementOptions(index, mode);
const vpixels = me.calculateBarValuePixels(index, options);
const ipixels = me.calculateBarIndexPixels(index, ruler, options);

const properties = {
horizontal,
Expand All @@ -316,7 +317,7 @@ module.exports = DatasetController.extend({
if (includeOptions) {
properties.options = options;
}
me._updateElement(rectangles[i], i, properties, mode);
me._updateElement(rectangles[i], index, properties, mode);
}

me._updateSharedOptions(sharedOptions, mode);
Expand Down
13 changes: 7 additions & 6 deletions src/controllers/controller.bubble.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ module.exports = DatasetController.extend({
const points = me._cachedMeta.data;

// Update Points
me.updateElements(points, 0, points.length, mode);
me.updateElements(points, 0, mode);
},

/**
* @protected
*/
updateElements: function(points, start, count, mode) {
updateElements: function(points, start, mode) {
const me = this;
const reset = mode === 'reset';
const {xScale, yScale} = me._cachedMeta;
Expand All @@ -129,9 +129,10 @@ module.exports = DatasetController.extend({
const includeOptions = me._includeOptions(mode, sharedOptions);
let i;

for (i = start; i < start + count; i++) {
for (i = 0; i < points.length; i++) {
const point = points[i];
const parsed = !reset && me._getParsed(i);
const index = start + i;
const parsed = !reset && me._getParsed(index);
const x = reset ? xScale.getPixelForDecimal(0.5) : xScale.getPixelForValue(parsed[xScale.id]);
const y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(parsed[yScale.id]);
const properties = {
Expand All @@ -141,15 +142,15 @@ module.exports = DatasetController.extend({
};

if (includeOptions) {
properties.options = i === start ? firstOpts
properties.options = i === 0 ? firstOpts
: me._resolveDataElementOptions(i, mode);

if (reset) {
properties.options.radius = 0;
}
}

me._updateElement(point, i, properties, mode);
me._updateElement(point, index, properties, mode);
}

me._updateSharedOptions(sharedOptions, mode);
Expand Down
30 changes: 20 additions & 10 deletions src/controllers/controller.doughnut.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,20 @@ module.exports = DatasetController.extend({
me.outerRadius = chart.outerRadius - chart.radiusLength * me._getRingWeightOffset(me.index);
me.innerRadius = Math.max(me.outerRadius - chart.radiusLength * chartWeight, 0);

me.updateElements(arcs, 0, arcs.length, mode);
me.updateElements(arcs, 0, mode);
},

updateElements: function(arcs, start, count, mode) {
/**
* @private
*/
_circumference: function(i, reset) {
const me = this;
const opts = me.chart.options;
const meta = me._cachedMeta;
return reset && opts.animation.animateRotate ? 0 : meta.data[i].hidden ? 0 : me.calculateCircumference(meta._parsed[i] * opts.circumference / DOUBLE_PI);
},

updateElements: function(arcs, start, mode) {
const me = this;
const reset = mode === 'reset';
const chart = me.chart;
Expand All @@ -233,20 +243,20 @@ module.exports = DatasetController.extend({
const animationOpts = opts.animation;
const centerX = (chartArea.left + chartArea.right) / 2;
const centerY = (chartArea.top + chartArea.bottom) / 2;
const meta = me.getMeta();
const innerRadius = reset && animationOpts.animateScale ? 0 : me.innerRadius;
const outerRadius = reset && animationOpts.animateScale ? 0 : me.outerRadius;
let startAngle = opts.rotation;
let i;

for (i = 0; i < start + count; ++i) {
for (i = 0; i < start; ++i) {
startAngle += me._circumference(i, reset);
}

for (i = 0; i < arcs.length; ++i) {
const index = start + i;
const circumference = me._circumference(index, reset);
const arc = arcs[i];
const circumference = reset && animationOpts.animateRotate ? 0 : arc.hidden ? 0 : me.calculateCircumference(meta._parsed[i] * opts.circumference / DOUBLE_PI);
const options = arc._options || {};
if (i < start) {
startAngle += circumference;
continue;
}
const properties = {
x: centerX + chart.offsetX,
y: centerY + chart.offsetY,
Expand All @@ -259,7 +269,7 @@ module.exports = DatasetController.extend({
};
startAngle += circumference;

me._updateElement(arc, i, properties, mode);
me._updateElement(arc, index, properties, mode);
}
},

Expand Down
15 changes: 8 additions & 7 deletions src/controllers/controller.line.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ module.exports = DatasetController.extend({

// Update Points
if (meta.visible) {
me.updateElements(points, 0, points.length, mode);
me.updateElements(points, 0, mode);
}
},

updateElements: function(points, start, count, mode) {
updateElements: function(points, start, mode) {
const me = this;
const reset = mode === 'reset';
const {xScale, yScale, _stacked} = me._cachedMeta;
Expand All @@ -101,9 +101,10 @@ module.exports = DatasetController.extend({
const includeOptions = me._includeOptions(mode, sharedOptions);
let i;

for (i = start; i < start + count; ++i) {
for (i = 0; i < points.length; ++i) {
const index = start + i;
const point = points[i];
const parsed = me._getParsed(i);
const parsed = me._getParsed(index);
const x = xScale.getPixelForValue(parsed[xScale.id]);
const y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(_stacked ? me._applyStack(yScale, parsed) : parsed[yScale.id]);
const properties = {
Expand All @@ -113,11 +114,11 @@ module.exports = DatasetController.extend({
};

if (includeOptions) {
properties.options = i === start ? firstOpts
: me._resolveDataElementOptions(i, mode);
properties.options = i === 0 ? firstOpts
: me._resolveDataElementOptions(index, mode);
}

me._updateElement(point, i, properties, mode);
me._updateElement(point, index, properties, mode);
}

me._updateSharedOptions(sharedOptions, mode);
Expand Down
15 changes: 8 additions & 7 deletions src/controllers/controller.polarArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ module.exports = DatasetController.extend({

me._updateRadius();

me.updateElements(arcs, 0, arcs.length, mode);
me.updateElements(arcs, 0, mode);
},

/**
Expand All @@ -165,7 +165,7 @@ module.exports = DatasetController.extend({
me.innerRadius = me.outerRadius - chart.radiusLength;
},

updateElements: function(arcs, start, count, mode) {
updateElements: function(arcs, start, mode) {
const me = this;
const reset = mode === 'reset';
const chart = me.chart;
Expand All @@ -184,11 +184,12 @@ module.exports = DatasetController.extend({
for (i = 0; i < start; ++i) {
angle += me._computeAngle(i);
}
for (; i < start + count; i++) {
for (i = 0; i < arcs.length; i++) {
const arc = arcs[i];
const index = start + i;
let startAngle = angle;
let endAngle = angle + me._computeAngle(i);
let outerRadius = arc.hidden ? 0 : scale.getDistanceFromCenterForValue(dataset.data[i]);
let endAngle = angle + me._computeAngle(index);
let outerRadius = arc.hidden ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
angle = endAngle;

if (reset) {
Expand All @@ -208,10 +209,10 @@ module.exports = DatasetController.extend({
outerRadius,
startAngle,
endAngle,
options: me._resolveDataElementOptions(i)
options: me._resolveDataElementOptions(index)
};

me._updateElement(arc, i, properties, mode);
me._updateElement(arc, index, properties, mode);
}
},

Expand Down
31 changes: 16 additions & 15 deletions src/controllers/controller.radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ module.exports = DatasetController.extend({
},

update: function(mode) {
var me = this;
var meta = me._cachedMeta;
var line = meta.dataset;
var points = meta.data || [];
const me = this;
const meta = me._cachedMeta;
const line = meta.dataset;
const points = meta.data || [];

const properties = {
_children: points,
Expand All @@ -100,22 +100,23 @@ module.exports = DatasetController.extend({
me._updateElement(line, undefined, properties, mode);

// Update Points
me.updateElements(points, 0, points.length, mode);
me.updateElements(points, 0, mode);

line.updateControlPoints(me.chart.chartArea);
},

updateElements: function(points, start, count, mode) {
updateElements: function(points, start, mode) {
const me = this;
const dataset = me.getDataset();
const scale = me.chart.scales.r;
const reset = mode === 'reset';
var i;
let i;

for (i = start; i < start + count; i++) {
for (i = 0; i < points.length; i++) {
const point = points[i];
const options = me._resolveDataElementOptions(i);
const pointPosition = scale.getPointPositionForValue(i, dataset.data[i]);
const index = start + i;
const options = me._resolveDataElementOptions(index);
const pointPosition = scale.getPointPositionForValue(index, dataset.data[index]);

const x = reset ? scale.xCenter : pointPosition.x;
const y = reset ? scale.yCenter : pointPosition.y;
Expand All @@ -127,18 +128,18 @@ module.exports = DatasetController.extend({
options,
};

me._updateElement(point, i, properties, mode);
me._updateElement(point, index, properties, mode);
}
},

/**
* @private
*/
_resolveDatasetElementOptions: function() {
var me = this;
var config = me._config;
var options = me.chart.options;
var values = DatasetController.prototype._resolveDatasetElementOptions.apply(me, arguments);
const me = this;
const config = me._config;
const options = me.chart.options;
const values = DatasetController.prototype._resolveDatasetElementOptions.apply(me, arguments);

values.spanGaps = valueOrDefault(config.spanGaps, options.spanGaps);
values.tension = valueOrDefault(config.lineTension, options.elements.line.tension);
Expand Down
2 changes: 1 addition & 1 deletion src/core/core.datasetController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ helpers.extend(DatasetController.prototype, {
}
me._parse(start, count);

me.updateElements(data, start, count, 'reset');
me.updateElements(elements, start, 'reset');
},

/**
Expand Down

0 comments on commit 8bc250f

Please sign in to comment.