Skip to content

Commit

Permalink
Prefix private controller methods with underscore (#7081)
Browse files Browse the repository at this point in the history
Prefix private controller methods with underscore
  • Loading branch information
benmccann committed Feb 10, 2020
1 parent 460ac02 commit 2f17dbc
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 113 deletions.
26 changes: 25 additions & 1 deletion docs/getting-started/v3-migration.md
Expand Up @@ -176,9 +176,33 @@ Animation system was completely rewritten in Chart.js v3. Each property can now

#### Renamed private APIs

* `BarController.calculateBarIndexPixels` was renamed to `BarController._calculateBarIndexPixels`
* `BarController.calculateBarValuePixels` was renamed to `BarController._calculateBarValuePixels`
* `BarController.getStackCount` was renamed to `BarController._getStackCount`
* `BarController.getStackIndex` was renamed to `BarController._getStackIndex`
* `BarController.getRuler` was renamed to `BarController._getRuler`
* `Chart.destroyDatasetMeta` was renamed to `Chart._destroyDatasetMeta`
* `Chart.drawDataset` was renamed to `Chart._drawDataset`
* `Chart.drawDatasets` was renamed to `Chart._drawDatasets`
* `Chart.eventHandler` was renamed to `Chart._eventHandler`
* `Chart.handleEvent` was renamed to `Chart._handleEvent`
* `Chart.initialize` was renamed to `Chart._initialize`
* `Chart.resetElements` was renamed to `Chart._resetElements`
* `Chart.unbindEvents` was renamed to `Chart._unbindEvents`
* `Chart.updateDataset` was renamed to `Chart._updateDataset`
* `Chart.updateDatasets` was renamed to `Chart._updateDatasets`
* `Chart.updateLayout` was renamed to `Chart._updateLayout`
* `DatasetController.destroy` was renamed to `DatasetController._destroy`
* `DatasetController.insertElements` was renamed to `DatasetController._insertElements`
* `DatasetController.onDataPop` was renamed to `DatasetController._onDataPop`
* `DatasetController.onDataPush` was renamed to `DatasetController._onDataPush`
* `DatasetController.onDataShift` was renamed to `DatasetController._onDataShift`
* `DatasetController.onDataSplice` was renamed to `DatasetController._onDataSplice`
* `DatasetController.onDataUnshift` was renamed to `DatasetController._onDataUnshift`
* `DatasetController.removeElements` was renamed to `DatasetController._removeElements`
* `DatasetController.resyncElements` was renamed to `DatasetController._resyncElements`
* `helpers._alignPixel` was renamed to `helpers.canvas._alignPixel`
* `helpers._decimalPlaces` was renamed to `helpers.math._decimalPlaces`
* `chart.initialize` was renamed to `chart._initialize` (labeled as private but not named as such)

### Changed

Expand Down
20 changes: 10 additions & 10 deletions src/controllers/controller.bar.js
Expand Up @@ -274,7 +274,7 @@ class BarController extends DatasetController {
const vscale = me._cachedMeta.vScale;
const base = vscale.getBasePixel();
const horizontal = vscale.isHorizontal();
const ruler = me.getRuler();
const ruler = me._getRuler();
const firstOpts = me._resolveDataElementOptions(start, mode);
const sharedOptions = me._getSharedOptions(mode, rectangles[start], firstOpts);
const includeOptions = me._includeOptions(mode, sharedOptions);
Expand All @@ -284,8 +284,8 @@ class BarController extends DatasetController {
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 vpixels = me._calculateBarValuePixels(index, options);
const ipixels = me._calculateBarIndexPixels(index, ruler, options);

const properties = {
horizontal,
Expand Down Expand Up @@ -357,7 +357,7 @@ class BarController extends DatasetController {
* Returns the effective number of stacks based on groups and bar visibility.
* @private
*/
getStackCount() {
_getStackCount() {
return this._getStacks().length;
}

Expand All @@ -368,7 +368,7 @@ class BarController extends DatasetController {
* @returns {number} The stack index
* @private
*/
getStackIndex(datasetIndex, name) {
_getStackIndex(datasetIndex, name) {
var stacks = this._getStacks(datasetIndex);
var index = (name !== undefined)
? stacks.indexOf(name)
Expand All @@ -382,7 +382,7 @@ class BarController extends DatasetController {
/**
* @private
*/
getRuler() {
_getRuler() {
const me = this;
const meta = me._cachedMeta;
const iScale = meta.iScale;
Expand All @@ -397,7 +397,7 @@ class BarController extends DatasetController {
pixels,
start: iScale._startPixel,
end: iScale._endPixel,
stackCount: me.getStackCount(),
stackCount: me._getStackCount(),
scale: iScale
};
}
Expand All @@ -406,7 +406,7 @@ class BarController extends DatasetController {
* Note: pixel values are not clamped to the scale area.
* @private
*/
calculateBarValuePixels(index, options) {
_calculateBarValuePixels(index, options) {
const me = this;
const meta = me._cachedMeta;
const vScale = meta.vScale;
Expand Down Expand Up @@ -460,13 +460,13 @@ class BarController extends DatasetController {
/**
* @private
*/
calculateBarIndexPixels(index, ruler, options) {
_calculateBarIndexPixels(index, ruler, options) {
var me = this;
var range = options.barThickness === 'flex'
? computeFlexCategoryTraits(index, ruler, options)
: computeFitCategoryTraits(index, ruler, options);

var stackIndex = me.getStackIndex(me.index, me._cachedMeta.stack);
var stackIndex = me._getStackIndex(me.index, me._cachedMeta.stack);
var center = range.start + (range.chunk * stackIndex) + (range.chunk / 2);
var size = Math.min(
valueOrDefault(options.maxBarThickness, Infinity),
Expand Down
3 changes: 3 additions & 0 deletions src/core/core.animator.js
Expand Up @@ -119,6 +119,9 @@ class Animator {
}
}

/**
* @private
*/
_getAnims(chart) {
const charts = this._charts;
let anims = charts.get(chart);
Expand Down
47 changes: 24 additions & 23 deletions src/core/core.controller.js
Expand Up @@ -208,6 +208,7 @@ class Chart {
this._updating = false;
this.scales = {};
this.scale = undefined;
this.$plugins = undefined;

// Add the chart instance to the global namespace
Chart.instances[me.id] = me;
Expand Down Expand Up @@ -454,7 +455,7 @@ class Chart {

if (numMeta > numData) {
for (let i = numData; i < numMeta; ++i) {
me.destroyDatasetMeta(i);
me._destroyDatasetMeta(i);
}
metasets.splice(numData, numMeta - numData);
}
Expand All @@ -473,7 +474,7 @@ class Chart {
const type = dataset.type || me.config.type;

if (meta.type && meta.type !== type) {
me.destroyDatasetMeta(i);
me._destroyDatasetMeta(i);
meta = me.getDatasetMeta(i);
}
meta.type = type;
Expand Down Expand Up @@ -504,7 +505,7 @@ class Chart {
* Reset the elements of all datasets
* @private
*/
resetElements() {
_resetElements() {
const me = this;
helpers.each(me.data.datasets, function(dataset, datasetIndex) {
me.getDatasetMeta(datasetIndex).controller.reset();
Expand All @@ -515,7 +516,7 @@ class Chart {
* Resets the chart back to its state before the initial animation
*/
reset() {
this.resetElements();
this._resetElements();
plugins.notify(this, 'reset');
}

Expand Down Expand Up @@ -543,7 +544,7 @@ class Chart {
me.getDatasetMeta(i).controller.buildOrUpdateElements();
}

me.updateLayout();
me._updateLayout();

// Can only reset the new controllers after the scales have been updated
if (me.options.animation) {
Expand All @@ -552,7 +553,7 @@ class Chart {
});
}

me.updateDatasets(mode);
me._updateDatasets(mode);

// Do this before render so that any plugins that need final scale updates can use it
plugins.notify(me, 'afterUpdate');
Expand All @@ -561,7 +562,7 @@ class Chart {

// Replay last event from before update
if (me._lastEvent) {
me.eventHandler(me._lastEvent);
me._eventHandler(me._lastEvent);
}

me.render();
Expand All @@ -574,7 +575,7 @@ class Chart {
* hook, in which case, plugins will not be called on `afterLayout`.
* @private
*/
updateLayout() {
_updateLayout() {
const me = this;

if (plugins.notify(me, 'beforeLayout') === false) {
Expand Down Expand Up @@ -605,7 +606,7 @@ class Chart {
* hook, in which case, plugins will not be called on `afterDatasetsUpdate`.
* @private
*/
updateDatasets(mode) {
_updateDatasets(mode) {
const me = this;
const isFunction = typeof mode === 'function';

Expand All @@ -614,7 +615,7 @@ class Chart {
}

for (let i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
me.updateDataset(i, isFunction ? mode({datasetIndex: i}) : mode);
me._updateDataset(i, isFunction ? mode({datasetIndex: i}) : mode);
}

plugins.notify(me, 'afterDatasetsUpdate');
Expand All @@ -625,7 +626,7 @@ class Chart {
* hook, in which case, plugins will not be called on `afterDatasetUpdate`.
* @private
*/
updateDataset(index, mode) {
_updateDataset(index, mode) {
const me = this;
const meta = me.getDatasetMeta(index);
const args = {meta, index, mode};
Expand Down Expand Up @@ -682,7 +683,7 @@ class Chart {
layers[i].draw(me.chartArea);
}

me.drawDatasets();
me._drawDatasets();

// Rest of layers
for (; i < layers.length; ++i) {
Expand Down Expand Up @@ -723,7 +724,7 @@ class Chart {
* hook, in which case, plugins will not be called on `afterDatasetsDraw`.
* @private
*/
drawDatasets() {
_drawDatasets() {
const me = this;
let metasets, i;

Expand All @@ -733,7 +734,7 @@ class Chart {

metasets = me._getSortedVisibleDatasetMetas();
for (i = metasets.length - 1; i >= 0; --i) {
me.drawDataset(metasets[i]);
me._drawDataset(metasets[i]);
}

plugins.notify(me, 'afterDatasetsDraw');
Expand All @@ -744,7 +745,7 @@ class Chart {
* hook, in which case, plugins will not be called on `afterDatasetDraw`.
* @private
*/
drawDataset(meta) {
_drawDataset(meta) {
const me = this;
const ctx = me.ctx;
const clip = meta._clip;
Expand Down Expand Up @@ -879,12 +880,12 @@ class Chart {
/**
* @private
*/
destroyDatasetMeta(datasetIndex) {
_destroyDatasetMeta(datasetIndex) {
const me = this;
const meta = me._metasets && me._metasets[datasetIndex];

if (meta) {
meta.controller.destroy();
meta.controller._destroy();
delete me._metasets[datasetIndex];
}
}
Expand All @@ -898,7 +899,7 @@ class Chart {

// dataset controllers need to cleanup associated data
for (i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
me.destroyDatasetMeta(i);
me._destroyDatasetMeta(i);
}

if (canvas) {
Expand All @@ -925,7 +926,7 @@ class Chart {
const me = this;
const listeners = me._listeners;
let listener = function() {
me.eventHandler.apply(me, arguments);
me._eventHandler.apply(me, arguments);
};

helpers.each(me.options.events, function(type) {
Expand Down Expand Up @@ -1000,14 +1001,14 @@ class Chart {
/**
* @private
*/
eventHandler(e) {
_eventHandler(e) {
const me = this;

if (plugins.notify(me, 'beforeEvent', [e]) === false) {
return;
}

me.handleEvent(e);
me._handleEvent(e);

plugins.notify(me, 'afterEvent', [e]);

Expand All @@ -1018,11 +1019,11 @@ class Chart {

/**
* Handle an event
* @private
* @param {IEvent} e the event to handle
* @return {boolean} true if the chart needs to re-render
* @private
*/
handleEvent(e) {
_handleEvent(e) {
const me = this;
const options = me.options || {};
const hoverOptions = options.hover;
Expand Down

0 comments on commit 2f17dbc

Please sign in to comment.