language
stringclasses
1 value
owner
stringlengths
2
15
repo
stringlengths
2
21
sha
stringlengths
45
45
message
stringlengths
7
36.3k
path
stringlengths
1
199
patch
stringlengths
15
102k
is_multipart
bool
2 classes
Other
chartjs
Chart.js
72c3c6d0802919eb4d24a4ef19cc465e9fa8ff1b.json
Fix memory leak (#7097)
src/core/core.controller.js
@@ -893,6 +893,7 @@ class Chart { let i, ilen; me.stop(); + Animator.remove(me); // dataset controllers need to cleanup associated data for (i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
true
Other
chartjs
Chart.js
2f17dbcd701060c47818ea12d97ae6b813518277.json
Prefix private controller methods with underscore (#7081) Prefix private controller methods with underscore
docs/getting-started/v3-migration.md
@@ -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
true
Other
chartjs
Chart.js
2f17dbcd701060c47818ea12d97ae6b813518277.json
Prefix private controller methods with underscore (#7081) Prefix private controller methods with underscore
src/controllers/controller.bar.js
@@ -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); @@ -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, @@ -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; } @@ -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) @@ -382,7 +382,7 @@ class BarController extends DatasetController { /** * @private */ - getRuler() { + _getRuler() { const me = this; const meta = me._cachedMeta; const iScale = meta.iScale; @@ -397,7 +397,7 @@ class BarController extends DatasetController { pixels, start: iScale._startPixel, end: iScale._endPixel, - stackCount: me.getStackCount(), + stackCount: me._getStackCount(), scale: iScale }; } @@ -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; @@ -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),
true
Other
chartjs
Chart.js
2f17dbcd701060c47818ea12d97ae6b813518277.json
Prefix private controller methods with underscore (#7081) Prefix private controller methods with underscore
src/core/core.animator.js
@@ -119,6 +119,9 @@ class Animator { } } + /** + * @private + */ _getAnims(chart) { const charts = this._charts; let anims = charts.get(chart);
true
Other
chartjs
Chart.js
2f17dbcd701060c47818ea12d97ae6b813518277.json
Prefix private controller methods with underscore (#7081) Prefix private controller methods with underscore
src/core/core.controller.js
@@ -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; @@ -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); } @@ -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; @@ -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(); @@ -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'); } @@ -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) { @@ -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'); @@ -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(); @@ -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) { @@ -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'; @@ -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'); @@ -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}; @@ -682,7 +683,7 @@ class Chart { layers[i].draw(me.chartArea); } - me.drawDatasets(); + me._drawDatasets(); // Rest of layers for (; i < layers.length; ++i) { @@ -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; @@ -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'); @@ -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; @@ -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]; } } @@ -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) { @@ -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) { @@ -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]); @@ -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;
true
Other
chartjs
Chart.js
2f17dbcd701060c47818ea12d97ae6b813518277.json
Prefix private controller methods with underscore (#7081) Prefix private controller methods with underscore
src/core/core.datasetController.js
@@ -10,7 +10,7 @@ const arrayEvents = ['push', 'pop', 'shift', 'splice', 'unshift']; /** * Hooks the array methods that add or remove values ('push', pop', 'shift', 'splice', * 'unshift') and notify the listener AFTER the array has been altered. Listeners are - * called on the 'onData*' callbacks (e.g. onDataPush, etc.) with same arguments. + * called on the '_onData*' callbacks (e.g. _onDataPush, etc.) with same arguments. */ function listenArrayEvents(array, listener) { if (array._chartjs) { @@ -27,7 +27,7 @@ function listenArrayEvents(array, listener) { }); arrayEvents.forEach(function(key) { - var method = 'onData' + key.charAt(0).toUpperCase() + key.slice(1); + var method = '_onData' + key.charAt(0).toUpperCase() + key.slice(1); var base = array[key]; Object.defineProperty(array, key, { @@ -322,7 +322,7 @@ class DatasetController { /** * @private */ - destroy() { + _destroy() { if (this._data) { unlistenArrayEvents(this._data, this); } @@ -427,7 +427,7 @@ class DatasetController { // Re-sync meta data in case the user replaced the data array or if we missed // any updates and so make sure that we handle number of datapoints changing. - me.resyncElements(dataChanged || labelsChanged || scaleChanged || stackChanged); + me._resyncElements(dataChanged || labelsChanged || scaleChanged || stackChanged); // if stack changed, update stack values for the whole dataset if (stackChanged) { @@ -1039,16 +1039,16 @@ class DatasetController { /** * @private */ - resyncElements(changed) { + _resyncElements(changed) { const me = this; const meta = me._cachedMeta; const numMeta = meta.data.length; const numData = me._data.length; if (numData > numMeta) { - me.insertElements(numMeta, numData - numMeta); + me._insertElements(numMeta, numData - numMeta); if (changed && numMeta) { - // insertElements parses the new elements. The old ones might need parsing too. + // _insertElements parses the new elements. The old ones might need parsing too. me._parse(0, numMeta); } } else if (numData < numMeta) { @@ -1063,7 +1063,7 @@ class DatasetController { /** * @private */ - insertElements(start, count) { + _insertElements(start, count) { const me = this; const elements = new Array(count); const meta = me._cachedMeta; @@ -1088,7 +1088,7 @@ class DatasetController { /** * @private */ - removeElements(start, count) { + _removeElements(start, count) { const me = this; if (me._parsing) { me._cachedMeta._parsed.splice(start, count); @@ -1100,38 +1100,38 @@ class DatasetController { /** * @private */ - onDataPush() { + _onDataPush() { const count = arguments.length; - this.insertElements(this.getDataset().data.length - count, count); + this._insertElements(this.getDataset().data.length - count, count); } /** * @private */ - onDataPop() { - this.removeElements(this._cachedMeta.data.length - 1, 1); + _onDataPop() { + this._removeElements(this._cachedMeta.data.length - 1, 1); } /** * @private */ - onDataShift() { - this.removeElements(0, 1); + _onDataShift() { + this._removeElements(0, 1); } /** * @private */ - onDataSplice(start, count) { - this.removeElements(start, count); - this.insertElements(start, arguments.length - 2); + _onDataSplice(start, count) { + this._removeElements(start, count); + this._insertElements(start, arguments.length - 2); } /** * @private */ - onDataUnshift() { - this.insertElements(0, arguments.length); + _onDataUnshift() { + this._insertElements(0, arguments.length); } }
true
Other
chartjs
Chart.js
2f17dbcd701060c47818ea12d97ae6b813518277.json
Prefix private controller methods with underscore (#7081) Prefix private controller methods with underscore
src/core/core.plugins.js
@@ -107,7 +107,7 @@ class PluginService { * @returns {boolean} false if any of the plugins return false, else returns true. */ notify(chart, hook, args) { - var descriptors = this.descriptors(chart); + var descriptors = this._descriptors(chart); var ilen = descriptors.length; var i, descriptor, plugin, params, method; @@ -129,10 +129,11 @@ class PluginService { /** * Returns descriptors of enabled plugins for the given chart. + * @param {Chart} chart * @returns {object[]} [{ plugin, options }] * @private */ - descriptors(chart) { + _descriptors(chart) { var cache = chart.$plugins || (chart.$plugins = {}); if (cache.id === this._cacheId) { return cache.descriptors; @@ -175,6 +176,7 @@ class PluginService { * Invalidates cache for the given chart: descriptors hold a reference on plugin option, * but in some cases, this reference can be changed by the user when updating options. * https://github.com/chartjs/Chart.js/issues/5111#issuecomment-355934167 + * @param {Chart} chart * @private */ _invalidate(chart) {
true
Other
chartjs
Chart.js
2f17dbcd701060c47818ea12d97ae6b813518277.json
Prefix private controller methods with underscore (#7081) Prefix private controller methods with underscore
test/fixtures/core.tooltip/opacity.js
@@ -85,7 +85,7 @@ module.exports = { clientX: rect.left + point.x, clientY: rect.top + point.y }; - chart.handleEvent(event); + chart._handleEvent(event); chart.tooltip.handleEvent(event); chart.tooltip.opacity = j / 10; chart.tooltip.draw(chart.ctx);
true
Other
chartjs
Chart.js
2f17dbcd701060c47818ea12d97ae6b813518277.json
Prefix private controller methods with underscore (#7081) Prefix private controller methods with underscore
test/specs/controller.bar.tests.js
@@ -67,7 +67,7 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(1); - expect(meta.controller.getStackCount()).toBe(2); + expect(meta.controller._getStackCount()).toBe(2); }); }); @@ -90,7 +90,7 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(1); - expect(meta.controller.getStackCount()).toBe(4); + expect(meta.controller._getStackCount()).toBe(4); }); }); @@ -123,7 +123,7 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(1); - expect(meta.controller.getStackCount()).toBe(1); + expect(meta.controller._getStackCount()).toBe(1); }); }); @@ -156,7 +156,7 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(1); - expect(meta.controller.getStackCount()).toBe(4); + expect(meta.controller._getStackCount()).toBe(4); }); }); @@ -179,7 +179,7 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(3); - expect(meta.controller.getStackCount()).toBe(3); + expect(meta.controller._getStackCount()).toBe(3); }); }); @@ -212,7 +212,7 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(3); - expect(meta.controller.getStackCount()).toBe(2); + expect(meta.controller._getStackCount()).toBe(2); }); }); @@ -245,7 +245,7 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(3); - expect(meta.controller.getStackCount()).toBe(4); + expect(meta.controller._getStackCount()).toBe(4); }); }); @@ -268,7 +268,7 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(3); - expect(meta.controller.getStackCount()).toBe(2); + expect(meta.controller._getStackCount()).toBe(2); }); }); @@ -301,7 +301,7 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(3); - expect(meta.controller.getStackCount()).toBe(2); + expect(meta.controller._getStackCount()).toBe(2); }); }); @@ -334,7 +334,7 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(3); - expect(meta.controller.getStackCount()).toBe(4); + expect(meta.controller._getStackCount()).toBe(4); }); }); @@ -357,8 +357,8 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(1); - expect(meta.controller.getStackIndex(0)).toBe(0); - expect(meta.controller.getStackIndex(3)).toBe(1); + expect(meta.controller._getStackIndex(0)).toBe(0); + expect(meta.controller._getStackIndex(3)).toBe(1); }); }); @@ -381,10 +381,10 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(1); - expect(meta.controller.getStackIndex(0)).toBe(0); - expect(meta.controller.getStackIndex(1)).toBe(1); - expect(meta.controller.getStackIndex(2)).toBe(2); - expect(meta.controller.getStackIndex(3)).toBe(3); + expect(meta.controller._getStackIndex(0)).toBe(0); + expect(meta.controller._getStackIndex(1)).toBe(1); + expect(meta.controller._getStackIndex(2)).toBe(2); + expect(meta.controller._getStackIndex(3)).toBe(3); }); }); @@ -417,10 +417,10 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(1); - expect(meta.controller.getStackIndex(0)).toBe(0); - expect(meta.controller.getStackIndex(1)).toBe(0); - expect(meta.controller.getStackIndex(2)).toBe(0); - expect(meta.controller.getStackIndex(3)).toBe(0); + expect(meta.controller._getStackIndex(0)).toBe(0); + expect(meta.controller._getStackIndex(1)).toBe(0); + expect(meta.controller._getStackIndex(2)).toBe(0); + expect(meta.controller._getStackIndex(3)).toBe(0); }); }); @@ -453,10 +453,10 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(1); - expect(meta.controller.getStackIndex(0)).toBe(0); - expect(meta.controller.getStackIndex(1)).toBe(1); - expect(meta.controller.getStackIndex(2)).toBe(2); - expect(meta.controller.getStackIndex(3)).toBe(3); + expect(meta.controller._getStackIndex(0)).toBe(0); + expect(meta.controller._getStackIndex(1)).toBe(1); + expect(meta.controller._getStackIndex(2)).toBe(2); + expect(meta.controller._getStackIndex(3)).toBe(3); }); }); @@ -479,10 +479,10 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(1); - expect(meta.controller.getStackIndex(0)).toBe(0); - expect(meta.controller.getStackIndex(1)).toBe(0); - expect(meta.controller.getStackIndex(2)).toBe(1); - expect(meta.controller.getStackIndex(3)).toBe(2); + expect(meta.controller._getStackIndex(0)).toBe(0); + expect(meta.controller._getStackIndex(1)).toBe(0); + expect(meta.controller._getStackIndex(2)).toBe(1); + expect(meta.controller._getStackIndex(3)).toBe(2); }); }); @@ -515,10 +515,10 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(1); - expect(meta.controller.getStackIndex(0)).toBe(0); - expect(meta.controller.getStackIndex(1)).toBe(0); - expect(meta.controller.getStackIndex(2)).toBe(1); - expect(meta.controller.getStackIndex(3)).toBe(1); + expect(meta.controller._getStackIndex(0)).toBe(0); + expect(meta.controller._getStackIndex(1)).toBe(0); + expect(meta.controller._getStackIndex(2)).toBe(1); + expect(meta.controller._getStackIndex(3)).toBe(1); }); }); @@ -551,10 +551,10 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(1); - expect(meta.controller.getStackIndex(0)).toBe(0); - expect(meta.controller.getStackIndex(1)).toBe(1); - expect(meta.controller.getStackIndex(2)).toBe(2); - expect(meta.controller.getStackIndex(3)).toBe(3); + expect(meta.controller._getStackIndex(0)).toBe(0); + expect(meta.controller._getStackIndex(1)).toBe(1); + expect(meta.controller._getStackIndex(2)).toBe(2); + expect(meta.controller._getStackIndex(3)).toBe(3); }); }); @@ -577,10 +577,10 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(1); - expect(meta.controller.getStackIndex(0)).toBe(0); - expect(meta.controller.getStackIndex(1)).toBe(0); - expect(meta.controller.getStackIndex(2)).toBe(1); - expect(meta.controller.getStackIndex(3)).toBe(1); + expect(meta.controller._getStackIndex(0)).toBe(0); + expect(meta.controller._getStackIndex(1)).toBe(0); + expect(meta.controller._getStackIndex(2)).toBe(1); + expect(meta.controller._getStackIndex(3)).toBe(1); }); }); @@ -613,10 +613,10 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(1); - expect(meta.controller.getStackIndex(0)).toBe(0); - expect(meta.controller.getStackIndex(1)).toBe(0); - expect(meta.controller.getStackIndex(2)).toBe(1); - expect(meta.controller.getStackIndex(3)).toBe(1); + expect(meta.controller._getStackIndex(0)).toBe(0); + expect(meta.controller._getStackIndex(1)).toBe(0); + expect(meta.controller._getStackIndex(2)).toBe(1); + expect(meta.controller._getStackIndex(3)).toBe(1); }); }); @@ -649,10 +649,10 @@ describe('Chart.controllers.bar', function() { }); var meta = chart.getDatasetMeta(1); - expect(meta.controller.getStackIndex(0)).toBe(0); - expect(meta.controller.getStackIndex(1)).toBe(1); - expect(meta.controller.getStackIndex(2)).toBe(2); - expect(meta.controller.getStackIndex(3)).toBe(3); + expect(meta.controller._getStackIndex(0)).toBe(0); + expect(meta.controller._getStackIndex(1)).toBe(1); + expect(meta.controller._getStackIndex(2)).toBe(2); + expect(meta.controller._getStackIndex(3)).toBe(3); }); });
true
Other
chartjs
Chart.js
2f17dbcd701060c47818ea12d97ae6b813518277.json
Prefix private controller methods with underscore (#7081) Prefix private controller methods with underscore
test/specs/core.datasetController.tests.js
@@ -12,11 +12,11 @@ describe('Chart.DatasetController', function() { var controller = chart.getDatasetMeta(0).controller; var methods = [ - 'onDataPush', - 'onDataPop', - 'onDataShift', - 'onDataSplice', - 'onDataUnshift' + '_onDataPush', + '_onDataPop', + '_onDataShift', + '_onDataSplice', + '_onDataUnshift' ]; methods.forEach(function(method) {
true
Other
chartjs
Chart.js
2f17dbcd701060c47818ea12d97ae6b813518277.json
Prefix private controller methods with underscore (#7081) Prefix private controller methods with underscore
test/utils.js
@@ -108,11 +108,11 @@ function waitForResize(chart, callback) { } function afterEvent(chart, type, callback) { - var override = chart.eventHandler; - chart.eventHandler = function(event) { + var override = chart._eventHandler; + chart._eventHandler = function(event) { override.call(this, event); if (event.type === type) { - chart.eventHandler = override; + chart._eventHandler = override; // eslint-disable-next-line callback-return callback(); }
true
Other
chartjs
Chart.js
92b2f7908e3a84c3f34f0c1574206d137284e086.json
Fix lint issues in gulpfile.js (#7076) * Fix lint issues in gulpfile.js * .eslintignore update
.eslintignore
@@ -1 +1 @@ -**/*{.,-}min.js +dist/*.js
true
Other
chartjs
Chart.js
92b2f7908e3a84c3f34f0c1574206d137284e086.json
Fix lint issues in gulpfile.js (#7076) * Fix lint issues in gulpfile.js * .eslintignore update
gulpfile.js
@@ -1,3 +1,4 @@ +/* eslint-disable no-use-before-define */ const gulp = require('gulp'); const eslint = require('gulp-eslint'); const file = require('gulp-file'); @@ -13,14 +14,14 @@ const yargs = require('yargs'); const path = require('path'); const htmllint = require('gulp-htmllint'); const typescript = require('gulp-typescript'); -const typedoc = require("gulp-typedoc"); +const typedoc = require('gulp-typedoc'); const pkg = require('./package.json'); const tsProject = typescript.createProject('./tsconfig.json'); const argv = yargs - .option('verbose', {default: false}) - .argv; + .option('verbose', {default: false}) + .argv; const srcDir = './src/'; const outDir = './dist/'; @@ -40,156 +41,156 @@ gulp.task('module-sizes', moduleSizesTask); gulp.task('size', gulp.parallel('library-size', 'module-sizes')); gulp.task('default', gulp.parallel('build')); -function run(bin, args, done) { - return new Promise(function(resolve, reject) { - const exe = '"' + process.execPath + '"'; - const src = require.resolve(bin); - const cmd = [exe, src].concat(args || []).join(' '); - const ps = exec(cmd); - - ps.stdout.pipe(process.stdout); - ps.stderr.pipe(process.stderr); - ps.on('close', function(error) { - if (error) { - reject(error); - } else { - resolve(); - } - }); - }); +function run(bin, args) { + return new Promise(function(resolve, reject) { + const exe = '"' + process.execPath + '"'; + const src = require.resolve(bin); + const cmd = [exe, src].concat(args || []).join(' '); + const ps = exec(cmd); + + ps.stdout.pipe(process.stdout); + ps.stderr.pipe(process.stderr); + ps.on('close', function(error) { + if (error) { + reject(error); + } else { + resolve(); + } + }); + }); } /** * Generates the bower.json manifest file which will be pushed along release tags. * Specs: https://github.com/bower/spec/blob/master/json.md */ function bowerTask() { - const json = JSON.stringify({ - name: pkg.name, - description: pkg.description, - homepage: pkg.homepage, - license: pkg.license, - version: pkg.version, - main: outDir + 'Chart.js', - ignore: [ - '.github', - '.codeclimate.yml', - '.gitignore', - '.npmignore', - '.travis.yml', - 'scripts' - ] - }, null, 2); - - return file('bower.json', json, { src: true }) - .pipe(gulp.dest('./')); + const json = JSON.stringify({ + name: pkg.name, + description: pkg.description, + homepage: pkg.homepage, + license: pkg.license, + version: pkg.version, + main: outDir + 'Chart.js', + ignore: [ + '.github', + '.codeclimate.yml', + '.gitignore', + '.npmignore', + '.travis.yml', + 'scripts' + ] + }, null, 2); + + return file('bower.json', json, {src: true}) + .pipe(gulp.dest('./')); } function buildTask() { - return run('rollup/dist/bin/rollup', ['-c', argv.watch ? '--watch' : '']); + return run('rollup/dist/bin/rollup', ['-c', argv.watch ? '--watch' : '']); } function packageTask() { - return merge( - // gather "regular" files landing in the package root - gulp.src([outDir + '*.js', outDir + '*.css', 'LICENSE.md']), - - // since we moved the dist files one folder up (package root), we need to rewrite - // samples src="../dist/ to src="../ and then copy them in the /samples directory. - gulp.src('./samples/**/*', { base: '.' }) - .pipe(streamify(replace(/src="((?:\.\.\/)+)dist\//g, 'src="$1'))) - ) - // finally, create the zip archive - .pipe(zip('Chart.js.zip')) - .pipe(gulp.dest(outDir)); + return merge( + // gather "regular" files landing in the package root + gulp.src([outDir + '*.js', outDir + '*.css', 'LICENSE.md']), + + // since we moved the dist files one folder up (package root), we need to rewrite + // samples src="../dist/ to src="../ and then copy them in the /samples directory. + gulp.src('./samples/**/*', {base: '.'}) + .pipe(streamify(replace(/src="((?:\.\.\/)+)dist\//g, 'src="$1'))) + ) + // finally, create the zip archive + .pipe(zip('Chart.js.zip')) + .pipe(gulp.dest(outDir)); } function lintJsTask() { - const files = [ - 'samples/**/*.html', - 'samples/**/*.js', - 'src/**/*.js', - 'test/**/*.js' - ]; - - // NOTE(SB) codeclimate has 'complexity' and 'max-statements' eslint rules way too strict - // compare to what the current codebase can support, and since it's not straightforward - // to fix, let's turn them as warnings and rewrite code later progressively. - const options = { - rules: { - 'complexity': [1, 10], - 'max-statements': [1, 30] - } - }; - - return gulp.src(files) - .pipe(eslint(options)) - .pipe(eslint.format()) - .pipe(eslint.failAfterError()); + const files = [ + 'samples/**/*.html', + 'samples/**/*.js', + 'src/**/*.js', + 'test/**/*.js' + ]; + + // NOTE(SB) codeclimate has 'complexity' and 'max-statements' eslint rules way too strict + // compare to what the current codebase can support, and since it's not straightforward + // to fix, let's turn them as warnings and rewrite code later progressively. + const options = { + rules: { + complexity: [1, 10], + 'max-statements': [1, 30] + } + }; + + return gulp.src(files) + .pipe(eslint(options)) + .pipe(eslint.format()) + .pipe(eslint.failAfterError()); } function typescriptTask() { - return tsProject.src() - .pipe(tsProject()) - .js.pipe(gulp.dest('dist')); + return tsProject.src() + .pipe(tsProject()) + .js.pipe(gulp.dest('dist')); } function lintHtmlTask() { - return gulp.src('samples/**/*.html') - .pipe(htmllint({ - failOnError: true, - })); + return gulp.src('samples/**/*.html') + .pipe(htmllint({ + failOnError: true, + })); } function docsTask(done) { - const bin = require.resolve('gitbook-cli/bin/gitbook.js'); - const cmd = argv.watch ? 'serve' : 'build'; - - return run(bin, ['install', './']) - .then(() => run(bin, [cmd, './', './dist/docs'])) - .then(() => { - const config = { - moduleResolution: "Node", - target: "ES6", - out: "./dist/docs/typedoc" - }; - gulp.src(['./src/**/*.js'], {read: false}) - .pipe(typedoc(config, done)); - }).catch((err) => { - done(new Error(err.stdout || err)); - }); + const bin = require.resolve('gitbook-cli/bin/gitbook.js'); + const cmd = argv.watch ? 'serve' : 'build'; + + return run(bin, ['install', './']) + .then(() => run(bin, [cmd, './', './dist/docs'])) + .then(() => { + const config = { + moduleResolution: 'Node', + target: 'ES6', + out: './dist/docs/typedoc' + }; + gulp.src(['./src/**/*.js'], {read: false}) + .pipe(typedoc(config, done)); + }).catch((err) => { + done(new Error(err.stdout || err)); + }); } function unittestTask(done) { - new karma.Server({ - configFile: path.join(__dirname, 'karma.conf.js'), - singleRun: !argv.watch, - args: { - coverage: !!argv.coverage, - inputs: argv.inputs, - browsers: argv.browsers, - watch: argv.watch - } - }, - // https://github.com/karma-runner/gulp-karma/issues/18 - function(error) { - error = error ? new Error('Karma returned with the error code: ' + error) : undefined; - done(error); - }).start(); + new karma.Server({ + configFile: path.join(__dirname, 'karma.conf.js'), + singleRun: !argv.watch, + args: { + coverage: !!argv.coverage, + inputs: argv.inputs, + browsers: argv.browsers, + watch: argv.watch + } + }, + // https://github.com/karma-runner/gulp-karma/issues/18 + function(error) { + error = error ? new Error('Karma returned with the error code: ' + error) : undefined; + done(error); + }).start(); } function librarySizeTask() { - return gulp.src('dist/Chart.bundle.min.js') - .pipe(size({ - gzip: true - })); + return gulp.src('dist/Chart.bundle.min.js') + .pipe(size({ + gzip: true + })); } function moduleSizesTask() { - return gulp.src(srcDir + '**/*.js') - .pipe(terser()) - .pipe(size({ - showFiles: true, - gzip: true - })); + return gulp.src(srcDir + '**/*.js') + .pipe(terser()) + .pipe(size({ + showFiles: true, + gzip: true + })); }
true
Other
chartjs
Chart.js
61aea761f487edb2796b0cea4bb836ccb49ef86c.json
Unify signature of plugin hooks (#8102)
docs/docs/getting-started/v3-migration.md
@@ -494,6 +494,7 @@ All helpers are now exposed in a flat hierarchy, e.g., `Chart.helpers.canvas.cli #### IPlugin interface +* All plugin hooks have unified signature with 3 arguments: `chart`, `args` and `options`. This means change in signature for these hooks: `beforeInit`, `afterInit`, `reset`, `beforeLayout`, `afterLayout`, `beforeRender`, `afterRender`, `beforeDraw`, `afterDraw`, `beforeDatasetsDraw`, `afterDatasetsDraw`, `beforeEvent`, `afterEvent`, `resize`, `destroy`. * `afterDatasetsUpdate`, `afterUpdate`, `beforeDatasetsUpdate`, and `beforeUpdate` now receive `args` object as second argument. `options` argument is always the last and thus was moved from 2nd to 3rd place. -* `afterEvent` and `beforeEvent` now receive a wrapped `event` as the second argument. The native event is available via `event.native`. +* `afterEvent` and `beforeEvent` now receive a wrapped `event` as the `event` property of the second argument. The native event is available via `args.event.native`. * Initial `resize` is no longer silent. Meaning that `resize` event can fire between `beforeInit` and `afterInit`
true
Other
chartjs
Chart.js
61aea761f487edb2796b0cea4bb836ccb49ef86c.json
Unify signature of plugin hooks (#8102)
src/core/core.controller.js
@@ -33,7 +33,7 @@ function onAnimationsComplete(context) { const chart = context.chart; const animationOptions = chart.options.animation; - chart._plugins.notify(chart, 'afterRender'); + chart.notifyPlugins('afterRender'); callCallback(animationOptions && animationOptions.onComplete, [context], chart); } @@ -151,7 +151,7 @@ class Chart { const me = this; // Before init plugin notification - me._plugins.notify(me, 'beforeInit'); + me.notifyPlugins('beforeInit'); if (me.options.responsive) { me.resize(); @@ -162,7 +162,7 @@ class Chart { me.bindEvents(); // After init plugin notification - me._plugins.notify(me, 'afterInit'); + me.notifyPlugins('afterInit'); return me; } @@ -221,7 +221,7 @@ class Chart { retinaScale(me, newRatio); - me._plugins.notify(me, 'resize', [newSize]); + me.notifyPlugins('resize', {size: newSize}); callCallback(options.onResize, [newSize], me); @@ -435,7 +435,7 @@ class Chart { */ reset() { this._resetElements(); - this._plugins.notify(this, 'reset'); + this.notifyPlugins('reset'); } update(mode) { @@ -458,7 +458,7 @@ class Chart { // https://github.com/chartjs/Chart.js/issues/5111#issuecomment-355934167 me._plugins.invalidate(); - if (me._plugins.notify(me, 'beforeUpdate', [args]) === false) { + if (me.notifyPlugins('beforeUpdate', args) === false) { return; } @@ -480,7 +480,7 @@ class Chart { me._updateDatasets(mode); // Do this before render so that any plugins that need final scale updates can use it - me._plugins.notify(me, 'afterUpdate', [args]); + me.notifyPlugins('afterUpdate', args); me._layers.sort(compare2Level('z', '_idx')); @@ -500,7 +500,7 @@ class Chart { _updateLayout() { const me = this; - if (me._plugins.notify(me, 'beforeLayout') === false) { + if (me.notifyPlugins('beforeLayout') === false) { return; } @@ -520,7 +520,7 @@ class Chart { item._idx = index; }); - me._plugins.notify(me, 'afterLayout'); + me.notifyPlugins('afterLayout'); } /** @@ -533,15 +533,15 @@ class Chart { const isFunction = typeof mode === 'function'; const args = {mode}; - if (me._plugins.notify(me, 'beforeDatasetsUpdate', [args]) === false) { + if (me.notifyPlugins('beforeDatasetsUpdate', args) === false) { return; } for (let i = 0, ilen = me.data.datasets.length; i < ilen; ++i) { me._updateDataset(i, isFunction ? mode({datasetIndex: i}) : mode); } - me._plugins.notify(me, 'afterDatasetsUpdate', [args]); + me.notifyPlugins('afterDatasetsUpdate', args); } /** @@ -554,18 +554,18 @@ class Chart { const meta = me.getDatasetMeta(index); const args = {meta, index, mode}; - if (me._plugins.notify(me, 'beforeDatasetUpdate', [args]) === false) { + if (me.notifyPlugins('beforeDatasetUpdate', args) === false) { return; } meta.controller._update(mode); - me._plugins.notify(me, 'afterDatasetUpdate', [args]); + me.notifyPlugins('afterDatasetUpdate', args); } render() { const me = this; - if (me._plugins.notify(me, 'beforeRender') === false) { + if (me.notifyPlugins('beforeRender') === false) { return; } @@ -593,7 +593,7 @@ class Chart { return; } - if (me._plugins.notify(me, 'beforeDraw') === false) { + if (me.notifyPlugins('beforeDraw') === false) { return; } @@ -612,7 +612,7 @@ class Chart { layers[i].draw(me.chartArea); } - me._plugins.notify(me, 'afterDraw'); + me.notifyPlugins('afterDraw'); } /** @@ -650,7 +650,7 @@ class Chart { _drawDatasets() { const me = this; - if (me._plugins.notify(me, 'beforeDatasetsDraw') === false) { + if (me.notifyPlugins('beforeDatasetsDraw') === false) { return; } @@ -659,7 +659,7 @@ class Chart { me._drawDataset(metasets[i]); } - me._plugins.notify(me, 'afterDatasetsDraw'); + me.notifyPlugins('afterDatasetsDraw'); } /** @@ -677,7 +677,7 @@ class Chart { index: meta.index, }; - if (me._plugins.notify(me, 'beforeDatasetDraw', [args]) === false) { + if (me.notifyPlugins('beforeDatasetDraw', args) === false) { return; } @@ -692,7 +692,7 @@ class Chart { unclipArea(ctx); - me._plugins.notify(me, 'afterDatasetDraw', [args]); + me.notifyPlugins('afterDatasetDraw', args); } getElementsAtEventForMode(e, mode, options, useFinalPosition) { @@ -829,7 +829,7 @@ class Chart { me.ctx = null; } - me._plugins.notify(me, 'destroy'); + me.notifyPlugins('destroy'); delete Chart.instances[me.id]; } @@ -968,6 +968,18 @@ class Chart { } } + /** + * Calls enabled plugins on the specified hook and with the given args. + * This method immediately returns as soon as a plugin explicitly returns false. The + * returned value can be used, for instance, to interrupt the current action. + * @param {string} hook - The name of the plugin method to call (e.g. 'beforeUpdate'). + * @param {Object} [args] - Extra arguments to apply to the hook call. + * @returns {boolean} false if any of the plugins return false, else returns true. + */ + notifyPlugins(hook, args) { + return this._plugins.notify(this, hook, args); + } + /** * @private */ @@ -992,14 +1004,15 @@ class Chart { */ _eventHandler(e, replay) { const me = this; + const args = {event: e, replay}; - if (me._plugins.notify(me, 'beforeEvent', [e, replay]) === false) { + if (me.notifyPlugins('beforeEvent', args) === false) { return; } const changed = me._handleEvent(e, replay); - me._plugins.notify(me, 'afterEvent', [e, replay]); + me.notifyPlugins('afterEvent', args); if (changed) { me.render();
true
Other
chartjs
Chart.js
61aea761f487edb2796b0cea4bb836ccb49ef86c.json
Unify signature of plugin hooks (#8102)
src/core/core.plugins.js
@@ -15,19 +15,19 @@ export default class PluginService { * returned value can be used, for instance, to interrupt the current action. * @param {Chart} chart - The chart instance for which plugins should be called. * @param {string} hook - The name of the plugin method to call (e.g. 'beforeUpdate'). - * @param {Array} [args] - Extra arguments to apply to the hook call. + * @param {object} [args] - Extra arguments to apply to the hook call. * @returns {boolean} false if any of the plugins return false, else returns true. */ notify(chart, hook, args) { + args = args || {}; const descriptors = this._descriptors(chart); for (let i = 0; i < descriptors.length; ++i) { const descriptor = descriptors[i]; const plugin = descriptor.plugin; const method = plugin[hook]; if (typeof method === 'function') { - const params = [chart].concat(args || []); - params.push(descriptor.options); + const params = [chart, args, descriptor.options]; if (method.apply(plugin, params) === false) { return false; } @@ -117,12 +117,14 @@ function createDescriptors(plugins, options) { * @method IPlugin#beforeInit * @desc Called before initializing `chart`. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. */ /** * @method IPlugin#afterInit * @desc Called after `chart` has been initialized and before the first update. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. */ /** @@ -148,6 +150,7 @@ function createDescriptors(plugins, options) { * @method IPlugin#reset * @desc Called during chart reset * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. * @since version 3.0.0 */ @@ -200,6 +203,7 @@ function createDescriptors(plugins, options) { * @desc Called before laying out `chart`. If any plugin returns `false`, * the layout update is cancelled until another `update` is triggered. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. * @returns {boolean} `false` to cancel the chart layout. */ @@ -208,13 +212,15 @@ function createDescriptors(plugins, options) { * @desc Called after the `chart` has been laid out. Note that this hook will not * be called if the layout update has been previously cancelled. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. */ /** * @method IPlugin#beforeRender * @desc Called before rendering `chart`. If any plugin returns `false`, * the rendering is cancelled until another `render` is triggered. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. * @returns {boolean} `false` to cancel the chart rendering. */ @@ -223,13 +229,15 @@ function createDescriptors(plugins, options) { * @desc Called after the `chart` has been fully rendered (and animation completed). Note * that this hook will not be called if the rendering has been previously cancelled. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. */ /** * @method IPlugin#beforeDraw * @desc Called before drawing `chart` at every animation frame. If any plugin returns `false`, * the frame drawing is cancelled until another `render` is triggered. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. * @returns {boolean} `false` to cancel the chart drawing. */ @@ -238,13 +246,15 @@ function createDescriptors(plugins, options) { * @desc Called after the `chart` has been drawn. Note that this hook will not be called * if the drawing has been previously cancelled. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. */ /** * @method IPlugin#beforeDatasetsDraw * @desc Called before drawing the `chart` datasets. If any plugin returns `false`, * the datasets drawing is cancelled until another `render` is triggered. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. * @returns {boolean} `false` to cancel the chart datasets drawing. */ @@ -253,6 +263,7 @@ function createDescriptors(plugins, options) { * @desc Called after the `chart` datasets have been drawn. Note that this hook * will not be called if the datasets drawing has been previously cancelled. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. */ /** @@ -302,29 +313,33 @@ function createDescriptors(plugins, options) { * @desc Called before processing the specified `event`. If any plugin returns `false`, * the event will be discarded. * @param {Chart} chart - The chart instance. - * @param {ChartEvent} event - The event object. - * @param {boolean} replay - True if this event is replayed from `Chart.update` + * @param {object} args - The call arguments. + * @param {ChartEvent} args.event - The event object. + * @param {boolean} args.replay - True if this event is replayed from `Chart.update` * @param {object} options - The plugin options. */ /** * @method IPlugin#afterEvent * @desc Called after the `event` has been consumed. Note that this hook * will not be called if the `event` has been previously discarded. * @param {Chart} chart - The chart instance. - * @param {ChartEvent} event - The event object. - * @param {boolean} replay - True if this event is replayed from `Chart.update` + * @param {object} args - The call arguments. + * @param {ChartEvent} args.event - The event object. + * @param {boolean} args.replay - True if this event is replayed from `Chart.update` * @param {object} options - The plugin options. */ /** * @method IPlugin#resize * @desc Called after the chart as been resized. * @param {Chart} chart - The chart instance. - * @param {number} size - The new canvas display size (eq. canvas.style width & height). + * @param {object} args - The call arguments. + * @param {number} args.size - The new canvas display size (eq. canvas.style width & height). * @param {object} options - The plugin options. */ /** * @method IPlugin#destroy * @desc Called after the chart as been destroyed. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. */
true
Other
chartjs
Chart.js
61aea761f487edb2796b0cea4bb836ccb49ef86c.json
Unify signature of plugin hooks (#8102)
src/plugins/plugin.legend.js
@@ -690,10 +690,10 @@ export default { }, - afterEvent(chart, e) { + afterEvent(chart, args) { const legend = chart.legend; if (legend) { - legend.handleEvent(e); + legend.handleEvent(args.event); } },
true
Other
chartjs
Chart.js
61aea761f487edb2796b0cea4bb836ccb49ef86c.json
Unify signature of plugin hooks (#8102)
src/plugins/plugin.tooltip.js
@@ -1074,22 +1074,22 @@ export default { tooltip }; - if (chart._plugins.notify(chart, 'beforeTooltipDraw', [args]) === false) { + if (chart.notifyPlugins('beforeTooltipDraw', args) === false) { return; } if (tooltip) { tooltip.draw(chart.ctx); } - chart._plugins.notify(chart, 'afterTooltipDraw', [args]); + chart.notifyPlugins('afterTooltipDraw', args); }, - afterEvent(chart, e, replay) { + afterEvent(chart, args) { if (chart.tooltip) { // If the event is replayed from `update`, we should evaluate with the final positions. - const useFinalPosition = replay; - chart.tooltip.handleEvent(e, useFinalPosition); + const useFinalPosition = args.replay; + chart.tooltip.handleEvent(args.event, useFinalPosition); } },
true
Other
chartjs
Chart.js
61aea761f487edb2796b0cea4bb836ccb49ef86c.json
Unify signature of plugin hooks (#8102)
test/specs/core.plugin.tests.js
@@ -1,31 +1,33 @@ describe('Chart.plugins', function() { - describe('Chart.plugins.notify', function() { + describe('Chart.notifyPlugins', function() { it('should call inline plugins with arguments', function() { var plugin = {hook: function() {}}; var chart = window.acquireChart({ plugins: [plugin] }); + var args = {value: 42}; spyOn(plugin, 'hook'); - chart._plugins.notify(chart, 'hook', 42); + chart.notifyPlugins('hook', args); expect(plugin.hook.calls.count()).toBe(1); expect(plugin.hook.calls.first().args[0]).toBe(chart); - expect(plugin.hook.calls.first().args[1]).toBe(42); + expect(plugin.hook.calls.first().args[1]).toBe(args); expect(plugin.hook.calls.first().args[2]).toEqual({}); }); it('should call global plugins with arguments', function() { var plugin = {id: 'a', hook: function() {}}; var chart = window.acquireChart({}); + var args = {value: 42}; spyOn(plugin, 'hook'); Chart.register(plugin); - chart._plugins.notify(chart, 'hook', 42); + chart.notifyPlugins('hook', args); expect(plugin.hook.calls.count()).toBe(1); expect(plugin.hook.calls.first().args[0]).toBe(chart); - expect(plugin.hook.calls.first().args[1]).toBe(42); + expect(plugin.hook.calls.first().args[1]).toBe(args); expect(plugin.hook.calls.first().args[2]).toEqual({}); Chart.unregister(plugin); }); @@ -39,7 +41,7 @@ describe('Chart.plugins', function() { spyOn(plugin, 'hook'); Chart.register([plugin, plugin]); - chart._plugins.notify(chart, 'hook'); + chart.notifyPlugins('hook'); expect(plugin.hook.calls.count()).toBe(1); Chart.unregister(plugin); }); @@ -80,7 +82,7 @@ describe('Chart.plugins', function() { }]; Chart.register(plugins); - var ret = chart._plugins.notify(chart, 'hook'); + var ret = chart.notifyPlugins('hook'); expect(ret).toBeTruthy(); expect(results).toEqual([4, 5, 6, 1, 2, 3]); Chart.unregister(plugins); @@ -114,7 +116,7 @@ describe('Chart.plugins', function() { spyOn(plugin, 'hook').and.callThrough(); }); - var ret = chart._plugins.notify(chart, 'hook'); + var ret = chart.notifyPlugins('hook'); expect(ret).toBeTruthy(); plugins.forEach(function(plugin) { expect(plugin.hook).toHaveBeenCalled(); @@ -149,7 +151,7 @@ describe('Chart.plugins', function() { spyOn(plugin, 'hook').and.callThrough(); }); - var ret = chart._plugins.notify(chart, 'hook'); + var ret = chart.notifyPlugins('hook'); expect(ret).toBeFalsy(); expect(plugins[0].hook).toHaveBeenCalled(); expect(plugins[1].hook).toHaveBeenCalled(); @@ -174,14 +176,14 @@ describe('Chart.plugins', function() { spyOn(plugin, 'hook'); Chart.register(plugin); - chart._plugins.notify(chart, 'hook'); - chart._plugins.notify(chart, 'hook', ['bla']); - chart._plugins.notify(chart, 'hook', ['bla', 42]); + chart.notifyPlugins('hook'); + chart.notifyPlugins('hook', {arg1: 'bla'}); + chart.notifyPlugins('hook', {arg1: 'bla', arg2: 42}); expect(plugin.hook.calls.count()).toBe(3); - expect(plugin.hook.calls.argsFor(0)[1]).toEqual({a: '123'}); + expect(plugin.hook.calls.argsFor(0)[2]).toEqual({a: '123'}); expect(plugin.hook.calls.argsFor(1)[2]).toEqual({a: '123'}); - expect(plugin.hook.calls.argsFor(2)[3]).toEqual({a: '123'}); + expect(plugin.hook.calls.argsFor(2)[2]).toEqual({a: '123'}); Chart.unregister(plugin); }); @@ -210,14 +212,14 @@ describe('Chart.plugins', function() { spyOn(plugins.b, 'hook'); spyOn(plugins.c, 'hook'); - chart._plugins.notify(chart, 'hook'); + chart.notifyPlugins('hook'); expect(plugins.a.hook).toHaveBeenCalled(); expect(plugins.b.hook).toHaveBeenCalled(); expect(plugins.c.hook).toHaveBeenCalled(); - expect(plugins.a.hook.calls.first().args[1]).toEqual({a: '123'}); - expect(plugins.b.hook.calls.first().args[1]).toEqual({b: '456'}); - expect(plugins.c.hook.calls.first().args[1]).toEqual({c: '789'}); + expect(plugins.a.hook.calls.first().args[2]).toEqual({a: '123'}); + expect(plugins.b.hook.calls.first().args[2]).toEqual({b: '456'}); + expect(plugins.c.hook.calls.first().args[2]).toEqual({c: '789'}); Chart.unregister(plugins.a); }); @@ -245,7 +247,7 @@ describe('Chart.plugins', function() { spyOn(plugins.b, 'hook'); spyOn(plugins.c, 'hook'); - chart._plugins.notify(chart, 'hook'); + chart.notifyPlugins('hook'); expect(plugins.a.hook).not.toHaveBeenCalled(); expect(plugins.b.hook).not.toHaveBeenCalled(); @@ -269,10 +271,10 @@ describe('Chart.plugins', function() { spyOn(plugin, 'hook'); - chart._plugins.notify(chart, 'hook'); + chart.notifyPlugins('hook'); expect(plugin.hook).toHaveBeenCalled(); - expect(plugin.hook.calls.first().args[1]).toEqual({a: 42}); + expect(plugin.hook.calls.first().args[2]).toEqual({a: 42}); Chart.unregister(plugin); }); @@ -286,10 +288,10 @@ describe('Chart.plugins', function() { var chart = window.acquireChart(); - chart._plugins.notify(chart, 'hook'); + chart.notifyPlugins('hook'); expect(plugin.hook).toHaveBeenCalled(); - expect(plugin.hook.calls.first().args[1]).toEqual({a: 'foobar'}); + expect(plugin.hook.calls.first().args[2]).toEqual({a: 'foobar'}); Chart.unregister(plugin); }); @@ -310,19 +312,19 @@ describe('Chart.plugins', function() { spyOn(plugin, 'hook'); - chart._plugins.notify(chart, 'hook'); + chart.notifyPlugins('hook'); expect(plugin.hook).toHaveBeenCalled(); - expect(plugin.hook.calls.first().args[1]).toEqual({foo: 'foo'}); + expect(plugin.hook.calls.first().args[2]).toEqual({foo: 'foo'}); chart.options.plugins.a = {bar: 'bar'}; chart.update(); plugin.hook.calls.reset(); - chart._plugins.notify(chart, 'hook'); + chart.notifyPlugins('hook'); expect(plugin.hook).toHaveBeenCalled(); - expect(plugin.hook.calls.first().args[1]).toEqual({bar: 'bar'}); + expect(plugin.hook.calls.first().args[2]).toEqual({bar: 'bar'}); }); it('should disable all plugins', function() { @@ -336,7 +338,7 @@ describe('Chart.plugins', function() { spyOn(plugin, 'hook'); - chart._plugins.notify(chart, 'hook'); + chart.notifyPlugins('hook'); expect(plugin.hook).not.toHaveBeenCalled(); });
true
Other
chartjs
Chart.js
61aea761f487edb2796b0cea4bb836ccb49ef86c.json
Unify signature of plugin hooks (#8102)
test/specs/platform.dom.tests.js
@@ -369,8 +369,8 @@ describe('Platform.dom', function() { it('should notify plugins about events', function(done) { var notifiedEvent; var plugin = { - afterEvent: function(chart, e) { - notifiedEvent = e; + afterEvent: function(chart, args) { + notifiedEvent = args.event; } }; var chart = acquireChart({
true
Other
chartjs
Chart.js
61aea761f487edb2796b0cea4bb836ccb49ef86c.json
Unify signature of plugin hooks (#8102)
types/core/index.d.ts
@@ -227,6 +227,8 @@ export declare class Chart< unbindEvents(): void; updateHoverStyle(items: Element, mode: 'dataset', enabled: boolean): void; + notifyPlugins(hook: string, args?: AnyObject): boolean | void; + static readonly version: string; static readonly instances: { [key: string]: Chart }; static readonly registry: Registry; @@ -562,39 +564,29 @@ export const layouts: { update(chart: Chart, width: number, height: number): void; }; -export interface PluginService { - /** - * Calls enabled plugins for `chart` on the specified hook and with the given args. - * This method immediately returns as soon as a plugin explicitly returns false. The - * returned value can be used, for instance, to interrupt the current action. - * @param {Chart} chart - The chart instance for which plugins should be called. - * @param {string} hook - The name of the plugin method to call (e.g. 'beforeUpdate'). - * @param {Array} [args] - Extra arguments to apply to the hook call. - * @returns {boolean} false if any of the plugins return false, else returns true. - */ - notify(chart: Chart, hook: string, args: any[]): boolean; - invalidate(): void; -} - export interface Plugin<O = {}> { id: string; /** * @desc Called before initializing `chart`. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. */ - beforeInit?(chart: Chart, options: O): void; + beforeInit?(chart: Chart, args: {}, options: O): boolean | void; /** * @desc Called after `chart` has been initialized and before the first update. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. */ - afterInit?(chart: Chart, options: O): void; + afterInit?(chart: Chart, args: {}, options: O): boolean | void; /** * @desc Called before updating `chart`. If any plugin returns `false`, the update * is cancelled (and thus subsequent render(s)) until another `update` is triggered. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. + * @param {UpdateMode} args.mode - The update mode * @param {object} options - The plugin options. * @returns {boolean} `false` to cancel the chart update. */ @@ -603,16 +595,19 @@ export interface Plugin<O = {}> { * @desc Called after `chart` has been updated and before rendering. Note that this * hook will not be called if the chart update has been previously cancelled. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. + * @param {UpdateMode} args.mode - The update mode * @param {object} options - The plugin options. */ - afterUpdate?(chart: Chart, args: { mode: UpdateMode }, options: O): void; + afterUpdate?(chart: Chart, args: { mode: UpdateMode }, options: O): boolean | void; /** * @desc Called during chart reset * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. * @since version 3.0.0 */ - reset?(chart: Chart, options: O): void; + reset?(chart: Chart, args: {}, options: O): void; /** * @desc Called before updating the `chart` datasets. If any plugin returns `false`, * the datasets update is cancelled until another `update` is triggered. @@ -633,7 +628,7 @@ export interface Plugin<O = {}> { * @param {object} options - The plugin options. * @since version 2.1.5 */ - afterDatasetsUpdate?(chart: Chart, args: { mode: UpdateMode }, options: O): void; + afterDatasetsUpdate?(chart: Chart, args: { mode: UpdateMode }, options: O): boolean | void; /** * @desc Called before updating the `chart` dataset at the given `args.index`. If any plugin * returns `false`, the datasets update is cancelled until another `update` is triggered. @@ -656,67 +651,75 @@ export interface Plugin<O = {}> { * @param {UpdateMode} args.mode - The update mode. * @param {object} options - The plugin options. */ - afterDatasetUpdate?(chart: Chart, args: { index: number; meta: ChartMeta, mode: UpdateMode }, options: O): void; + afterDatasetUpdate?(chart: Chart, args: { index: number; meta: ChartMeta, mode: UpdateMode }, options: O): boolean | void; /** * @desc Called before laying out `chart`. If any plugin returns `false`, * the layout update is cancelled until another `update` is triggered. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. * @returns {boolean} `false` to cancel the chart layout. */ - beforeLayout?(chart: Chart, options: O): boolean | void; + beforeLayout?(chart: Chart, args: {}, options: O): boolean | void; /** * @desc Called after the `chart` has been laid out. Note that this hook will not * be called if the layout update has been previously cancelled. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. */ - afterLayout?(chart: Chart, options: O): void; + afterLayout?(chart: Chart, args: {}, options: O): boolean | void; /** * @desc Called before rendering `chart`. If any plugin returns `false`, * the rendering is cancelled until another `render` is triggered. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. * @returns {boolean} `false` to cancel the chart rendering. */ - beforeRender?(chart: Chart, options: O): boolean | void; + beforeRender?(chart: Chart, args: {}, options: O): boolean | void; /** * @desc Called after the `chart` has been fully rendered (and animation completed). Note * that this hook will not be called if the rendering has been previously cancelled. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. */ - afterRender?(chart: Chart, options: O): void; + afterRender?(chart: Chart, args: {}, options: O): boolean | void; /** * @desc Called before drawing `chart` at every animation frame. If any plugin returns `false`, * the frame drawing is cancelled untilanother `render` is triggered. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. * @returns {boolean} `false` to cancel the chart drawing. */ - beforeDraw?(chart: Chart, options: O): boolean | void; + beforeDraw?(chart: Chart, args: {}, options: O): boolean | void; /** * @desc Called after the `chart` has been drawn. Note that this hook will not be called * if the drawing has been previously cancelled. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. */ - afterDraw?(chart: Chart, options: O): void; + afterDraw?(chart: Chart, args: {}, options: O): boolean | void; /** * @desc Called before drawing the `chart` datasets. If any plugin returns `false`, * the datasets drawing is cancelled until another `render` is triggered. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. * @returns {boolean} `false` to cancel the chart datasets drawing. */ - beforeDatasetsDraw?(chart: Chart, options: O): boolean | void; + beforeDatasetsDraw?(chart: Chart, args: {}, options: O): boolean | void; /** * @desc Called after the `chart` datasets have been drawn. Note that this hook * will not be called if the datasets drawing has been previously cancelled. * @param {Chart} chart - The chart instance. + * @param {object} args - The call arguments. * @param {object} options - The plugin options. */ - afterDatasetsDraw?(chart: Chart, options: O): void; + afterDatasetsDraw?(chart: Chart, args: {}, options: O): boolean | void; /** * @desc Called before drawing the `chart` dataset at the given `args.index` (datasets * are drawn in the reverse order). If any plugin returns `false`, the datasets drawing @@ -739,38 +742,41 @@ export interface Plugin<O = {}> { * @param {object} args.meta - The dataset metadata. * @param {object} options - The plugin options. */ - afterDatasetDraw?(chart: Chart, args: { index: number; meta: ChartMeta }, options: O): void; + afterDatasetDraw?(chart: Chart, args: { index: number; meta: ChartMeta }, options: O): boolean | void; /** * @desc Called before processing the specified `event`. If any plugin returns `false`, * the event will be discarded. * @param {Chart} chart - The chart instance. - * @param {ChartEvent} event - The event object. - * @param {object} options - The plugin options. + * @param {object} args - The call arguments. + * @param {ChartEvent} args.event - The event object. * @param {boolean} replay - True if this event is replayed from `Chart.update` + * @param {object} options - The plugin options. */ - beforeEvent?(chart: Chart, event: ChartEvent, options: O, replay: boolean): void; + beforeEvent?(chart: Chart, args: { event: ChartEvent, replay: boolean }, options: O): boolean | void; /** * @desc Called after the `event` has been consumed. Note that this hook * will not be called if the `event` has been previously discarded. * @param {Chart} chart - The chart instance. - * @param {ChartEvent} event - The event object. - * @param {object} options - The plugin options. + * @param {object} args - The call arguments. + * @param {ChartEvent} args.event - The event object. * @param {boolean} replay - True if this event is replayed from `Chart.update` + * @param {object} options - The plugin options. */ - afterEvent?(chart: Chart, event: ChartEvent, options: O, replay: boolean): void; + afterEvent?(chart: Chart, args: { event: ChartEvent, replay: boolean }, options: O): boolean | void; /** * @desc Called after the chart as been resized. * @param {Chart} chart - The chart instance. - * @param {number} size - The new canvas display size (eq. canvas.style width & height). + * @param {object} args - The call arguments. + * @param {number} args.size - The new canvas display size (eq. canvas.style width & height). * @param {object} options - The plugin options. */ - resize?(chart: Chart, size: number, options: O): void; + resize?(chart: Chart, args: { size: { width: number, height: number } }, options: O): boolean | void; /** * Called after the chart as been destroyed. * @param {Chart} chart - The chart instance. * @param {object} options - The plugin options. */ - destroy?(chart: Chart, options: O): void; + destroy?(chart: Chart, options: O): boolean | void; } export declare type ChartComponentLike = ChartComponent | ChartComponent[] | { [key: string]: ChartComponent };
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
docs/docs/configuration/legend.md
@@ -6,7 +6,7 @@ The chart legend displays data about the datasets that are appearing on the char ## Configuration options -The legend configuration is passed into the `options.legend` namespace. The global options for the chart legend is defined in `Chart.defaults.plugins.legend`. +The legend configuration is passed into the `options.plugins.legend` namespace. The global options for the chart legend is defined in `Chart.defaults.plugins.legend`. | Name | Type | Default | Description | ---- | ---- | ------- | ----------- @@ -121,10 +121,12 @@ var chart = new Chart(ctx, { type: 'bar', data: data, options: { - legend: { - display: true, - labels: { - fontColor: 'rgb(255, 99, 132)' + plugins: { + legend: { + display: true, + labels: { + fontColor: 'rgb(255, 99, 132)' + } } } } @@ -177,8 +179,10 @@ var chart = new Chart(ctx, { type: 'line', data: data, options: { - legend: { - onClick: newLegendClickHandler + plugins: { + legend: { + onClick: newLegendClickHandler + } } } });
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
docs/docs/configuration/title.md
@@ -6,7 +6,7 @@ The chart title defines text to draw at the top of the chart. ## Title Configuration -The title configuration is passed into the `options.title` namespace. The global options for the chart title is defined in `Chart.defaults.plugins.title`. +The title configuration is passed into the `options.plugins.title` namespace. The global options for the chart title is defined in `Chart.defaults.plugins.title`. | Name | Type | Default | Description | ---- | ---- | ------- | ----------- @@ -43,9 +43,11 @@ var chart = new Chart(ctx, { type: 'line', data: data, options: { - title: { - display: true, - text: 'Custom Chart Title' + plugins: { + title: { + display: true, + text: 'Custom Chart Title' + } } } }); @@ -58,12 +60,14 @@ var chart = new Chart(ctx, { type: 'line', data: data, options: { - title: { - display: true, - text: 'Custom Chart Title', - padding: { - top: 10, - bottom: 30 + plugins: { + title: { + display: true, + text: 'Custom Chart Title', + padding: { + top: 10, + bottom: 30 + } } } }
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
docs/docs/configuration/tooltip.md
@@ -4,7 +4,7 @@ title: Tooltip ## Tooltip Configuration -The tooltip configuration is passed into the `options.tooltips` namespace. The global options for the chart tooltips is defined in `Chart.defaults.plugins.tooltip`. +The tooltip configuration is passed into the `options.plugins.tooltip` namespace. The global options for the chart tooltips is defined in `Chart.defaults.plugins.tooltip`. | Name | Type | Default | Description | ---- | ---- | ------- | ----------- @@ -128,18 +128,20 @@ var chart = new Chart(ctx, { type: 'line', data: data, options: { - tooltips: { - callbacks: { - label: function(context) { - var label = context.dataset.label || ''; - - if (label) { - label += ': '; - } - if (!isNaN(context.dataPoint.y)) { - label += new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(context.dataPoint.y); + plugins: { + tooltip: { + callbacks: { + label: function(context) { + var label = context.dataset.label || ''; + + if (label) { + label += ': '; + } + if (!isNaN(context.dataPoint.y)) { + label += new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(context.dataPoint.y); + } + return label; } - return label; } } } @@ -156,16 +158,18 @@ var chart = new Chart(ctx, { type: 'line', data: data, options: { - tooltips: { - callbacks: { - labelColor: function(context) { - return { - borderColor: 'rgb(255, 0, 0)', - backgroundColor: 'rgb(255, 0, 0)' - }; - }, - labelTextColor: function(context) { - return '#543453'; + plugins: { + tooltip: { + callbacks: { + labelColor: function(context) { + return { + borderColor: 'rgb(255, 0, 0)', + backgroundColor: 'rgb(255, 0, 0)' + }; + }, + labelTextColor: function(context) { + return '#543453'; + } } } } @@ -182,14 +186,16 @@ var chart = new Chart(ctx, { type: 'line', data: data, options: { - tooltips: { - usePointStyle: true, - callbacks: { - labelPointStyle: function(context) { - return { - pointStyle: 'triangle', - rotation: 0 - }; + plugins: { + tooltip: { + usePointStyle: true, + callbacks: { + labelPointStyle: function(context) { + return { + pointStyle: 'triangle', + rotation: 0 + }; + } } } } @@ -239,77 +245,79 @@ var myPieChart = new Chart(ctx, { type: 'pie', data: data, options: { - tooltips: { - // Disable the on-canvas tooltip - enabled: false, - - custom: function(context) { - // Tooltip Element - var tooltipEl = document.getElementById('chartjs-tooltip'); - - // Create element on first render - if (!tooltipEl) { - tooltipEl = document.createElement('div'); - tooltipEl.id = 'chartjs-tooltip'; - tooltipEl.innerHTML = '<table></table>'; - document.body.appendChild(tooltipEl); - } + plugins: { + tooltip: { + // Disable the on-canvas tooltip + enabled: false, + + custom: function(context) { + // Tooltip Element + var tooltipEl = document.getElementById('chartjs-tooltip'); + + // Create element on first render + if (!tooltipEl) { + tooltipEl = document.createElement('div'); + tooltipEl.id = 'chartjs-tooltip'; + tooltipEl.innerHTML = '<table></table>'; + document.body.appendChild(tooltipEl); + } - // Hide if no tooltip - var tooltipModel = context.tooltip; - if (tooltipModel.opacity === 0) { - tooltipEl.style.opacity = 0; - return; - } + // Hide if no tooltip + var tooltipModel = context.tooltip; + if (tooltipModel.opacity === 0) { + tooltipEl.style.opacity = 0; + return; + } - // Set caret Position - tooltipEl.classList.remove('above', 'below', 'no-transform'); - if (tooltipModel.yAlign) { - tooltipEl.classList.add(tooltipModel.yAlign); - } else { - tooltipEl.classList.add('no-transform'); - } + // Set caret Position + tooltipEl.classList.remove('above', 'below', 'no-transform'); + if (tooltipModel.yAlign) { + tooltipEl.classList.add(tooltipModel.yAlign); + } else { + tooltipEl.classList.add('no-transform'); + } - function getBody(bodyItem) { - return bodyItem.lines; - } + function getBody(bodyItem) { + return bodyItem.lines; + } - // Set Text - if (tooltipModel.body) { - var titleLines = tooltipModel.title || []; - var bodyLines = tooltipModel.body.map(getBody); - - var innerHtml = '<thead>'; - - titleLines.forEach(function(title) { - innerHtml += '<tr><th>' + title + '</th></tr>'; - }); - innerHtml += '</thead><tbody>'; - - bodyLines.forEach(function(body, i) { - var colors = tooltipModel.labelColors[i]; - var style = 'background:' + colors.backgroundColor; - style += '; border-color:' + colors.borderColor; - style += '; border-width: 2px'; - var span = '<span style="' + style + '"></span>'; - innerHtml += '<tr><td>' + span + body + '</td></tr>'; - }); - innerHtml += '</tbody>'; - - var tableRoot = tooltipEl.querySelector('table'); - tableRoot.innerHTML = innerHtml; - } + // Set Text + if (tooltipModel.body) { + var titleLines = tooltipModel.title || []; + var bodyLines = tooltipModel.body.map(getBody); + + var innerHtml = '<thead>'; + + titleLines.forEach(function(title) { + innerHtml += '<tr><th>' + title + '</th></tr>'; + }); + innerHtml += '</thead><tbody>'; + + bodyLines.forEach(function(body, i) { + var colors = tooltipModel.labelColors[i]; + var style = 'background:' + colors.backgroundColor; + style += '; border-color:' + colors.borderColor; + style += '; border-width: 2px'; + var span = '<span style="' + style + '"></span>'; + innerHtml += '<tr><td>' + span + body + '</td></tr>'; + }); + innerHtml += '</tbody>'; + + var tableRoot = tooltipEl.querySelector('table'); + tableRoot.innerHTML = innerHtml; + } - var position = context.chart.canvas.getBoundingClientRect(); + var position = context.chart.canvas.getBoundingClientRect(); - // Display, position, and set styles for font - tooltipEl.style.opacity = 1; - tooltipEl.style.position = 'absolute'; - tooltipEl.style.left = position.left + window.pageXOffset + tooltipModel.caretX + 'px'; - tooltipEl.style.top = position.top + window.pageYOffset + tooltipModel.caretY + 'px'; - tooltipEl.style.font = tooltipModel.bodyFont.string; - tooltipEl.style.padding = tooltipModel.yPadding + 'px ' + tooltipModel.xPadding + 'px'; - tooltipEl.style.pointerEvents = 'none'; + // Display, position, and set styles for font + tooltipEl.style.opacity = 1; + tooltipEl.style.position = 'absolute'; + tooltipEl.style.left = position.left + window.pageXOffset + tooltipModel.caretX + 'px'; + tooltipEl.style.top = position.top + window.pageYOffset + tooltipModel.caretY + 'px'; + tooltipEl.style.font = tooltipModel.bodyFont.string; + tooltipEl.style.padding = tooltipModel.yPadding + 'px ' + tooltipModel.xPadding + 'px'; + tooltipEl.style.pointerEvents = 'none'; + } } } }
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
docs/docs/developers/updates.md
@@ -35,7 +35,7 @@ To update the options, mutating the options property in place or passing in a ne ```javascript function updateConfigByMutating(chart) { - chart.options.title.text = 'new title'; + chart.options.plugins.title.text = 'new title'; chart.update(); }
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
docs/docs/general/fonts.md
@@ -12,11 +12,13 @@ let chart = new Chart(ctx, { type: 'line', data: data, options: { - legend: { - labels: { - // This more specific font property overrides the global property - font: { - size: 14 + plugins: { + legend: { + labels: { + // This more specific font property overrides the global property + font: { + size: 14 + } } } }
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
docs/docs/general/interactions/events.md
@@ -41,4 +41,4 @@ const chart = new Chart(ctx, { } } }); -``` \ No newline at end of file +```
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
docs/docs/general/interactions/modes.md
@@ -4,7 +4,7 @@ title: Interaction Modes When configuring interaction with the graph via hover or tooltips, a number of different modes are available. -`options.hover` and `options.tooltips` extend from `options.interaction`. So if `mode`, `intersect` or any other common settings are configured only in `options.interaction`, both hover and tooltips obey that. +`options.hover` and `options.plugins.tooltip` extend from `options.interaction`. So if `mode`, `intersect` or any other common settings are configured only in `options.interaction`, both hover and tooltips obey that. The modes are detailed below and how they behave in conjunction with the `intersect` setting.
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
docs/docs/getting-started/v3-migration.md
@@ -94,6 +94,8 @@ A number of changes were made to the configuration options passed to the `Chart` * To override the platform class used in a chart instance, pass `platform: PlatformClass` in the config object. Note that the class should be passed, not an instance of the class. * `aspectRatio` defaults to 1 for doughnut, pie, polarArea, and radar charts * `TimeScale` does not read `t` from object data by default anymore. The default property is `x` or `y`, depending on the orientation. See [data structures](../general/data-structures.md) for details on how to change the default. +* `tooltips` namespace was renamed to `tooltip` to match the plugin name +* `legend`, `title` and `tooltip` namespaces were moved from `options` to `options.plugins`. #### Defaults @@ -203,7 +205,7 @@ Animation system was completely rewritten in Chart.js v3. Each property can now #### Interactions -* To allow DRY configuration, a root options scope for common interaction options was added. `options.hover` and `options.tooltips` now both extend from `options.interaction`. Defaults are defined at `defaults.interaction` level, so by default hover and tooltip interactions share the same mode etc. +* To allow DRY configuration, a root options scope for common interaction options was added. `options.hover` and `options.plugins.tooltip` now both extend from `options.interaction`. Defaults are defined at `defaults.interaction` level, so by default hover and tooltip interactions share the same mode etc. * `interactions` are now limited to the chart area * `{mode: 'label'}` was replaced with `{mode: 'index'}` * `{mode: 'single'}` was replaced with `{mode: 'nearest', intersect: true}`
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/advanced/line-gradient.html
@@ -69,13 +69,15 @@ }, options: { responsive: true, - title: { - display: true, - text: 'Chart.js Line Chart' - }, - tooltips: { - mode: 'index', - intersect: false, + plugins: { + title: { + display: true, + text: 'Chart.js Line Chart' + }, + tooltip: { + mode: 'index', + intersect: false, + }, }, hover: { mode: 'nearest',
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/advanced/radial-gradient.html
@@ -78,18 +78,22 @@ }, options: { responsive: true, - legend: { - position: 'right', - }, - title: { - display: true, - text: 'Chart.js Polar Area Chart' - }, - scale: { - ticks: { - beginAtZero: true + plugins: { + legend: { + position: 'right', }, - reverse: false + title: { + display: true, + text: 'Chart.js Polar Area Chart' + }, + }, + scales: { + r: { + ticks: { + beginAtZero: true + }, + reverse: false + } }, animation: { animateRotate: false,
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/animations/delay.html
@@ -86,13 +86,15 @@ delay }; }, - title: { - display: true, - text: 'Chart.js Bar Chart - Stacked' - }, - tooltips: { - mode: 'index', - intersect: false + plugins: { + title: { + display: true, + text: 'Chart.js Bar Chart - Stacked' + }, + tooltip: { + mode: 'index', + intersect: false + } }, responsive: true, scales: {
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/animations/drop.html
@@ -75,13 +75,15 @@ } }, responsive: true, - title: { - display: true, - text: 'Chart.js Line Chart' - }, - tooltips: { - mode: 'index', - intersect: false, + plugins: { + title: { + display: true, + text: 'Chart.js Line Chart' + }, + tooltip: { + mode: 'index', + intersect: false, + } }, hover: { mode: 'nearest',
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/animations/loop.html
@@ -78,14 +78,16 @@ } }, responsive: true, - title: { - display: true, - text: 'Chart.js Line Chart' - }, - tooltips: { - mode: 'nearest', - axis: 'x', - intersect: false, + plugins: { + title: { + display: true, + text: 'Chart.js Line Chart' + }, + tooltip: { + mode: 'nearest', + axis: 'x', + intersect: false, + }, }, hover: { mode: 'nearest',
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/area/line-stacked.html
@@ -87,12 +87,14 @@ }, options: { responsive: true, - title: { - display: true, - text: 'Chart.js Line Chart - Stacked Area' - }, - tooltips: { - mode: 'index', + plugins: { + title: { + display: true, + text: 'Chart.js Line Chart - Stacked Area' + }, + tooltip: { + mode: 'index', + } }, hover: { mode: 'index'
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/bar/border-radius.html
@@ -70,12 +70,14 @@ data: barChartData, options: { responsive: true, - legend: { - position: 'top', - }, - title: { - display: true, - text: 'Chart.js Bar Chart' + plugins: { + legend: { + position: 'top', + }, + title: { + display: true, + text: 'Chart.js Bar Chart' + } } } });
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/bar/float.html
@@ -67,12 +67,14 @@ data: barChartData, options: { responsive: true, - legend: { - position: 'top', - }, - title: { - display: true, - text: 'Chart.js Bar Chart' + plugins: { + legend: { + position: 'top', + }, + title: { + display: true, + text: 'Chart.js Bar Chart' + } } } });
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/bar/horizontal.html
@@ -74,12 +74,14 @@ } }, responsive: true, - legend: { - position: 'right', - }, - title: { - display: true, - text: 'Chart.js Horizontal Bar Chart' + plugins: { + legend: { + position: 'right', + }, + title: { + display: true, + text: 'Chart.js Horizontal Bar Chart' + } } } });
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/bar/multi-axis.html
@@ -66,13 +66,15 @@ data: barChartData, options: { responsive: true, - title: { - display: true, - text: 'Chart.js Bar Chart - Multi Axis' - }, - tooltips: { - mode: 'index', - intersect: true + plugins: { + title: { + display: true, + text: 'Chart.js Bar Chart - Multi Axis' + }, + tooltip: { + mode: 'index', + intersect: true + } }, scales: { y: {
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/bar/stacked-group.html
@@ -70,13 +70,15 @@ type: 'bar', data: barChartData, options: { - title: { - display: true, - text: 'Chart.js Bar Chart - Stacked' - }, - tooltips: { - mode: 'index', - intersect: false + plugins: { + title: { + display: true, + text: 'Chart.js Bar Chart - Stacked' + }, + tooltip: { + mode: 'index', + intersect: false + } }, responsive: true, scales: {
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/bar/stacked.html
@@ -67,13 +67,15 @@ type: 'bar', data: barChartData, options: { - title: { - display: true, - text: 'Chart.js Bar Chart - Stacked' - }, - tooltips: { - mode: 'index', - intersect: false + plugin: { + title: { + display: true, + text: 'Chart.js Bar Chart - Stacked' + }, + tooltip: { + mode: 'index', + intersect: false + }, }, responsive: true, scales: {
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/bar/vertical.html
@@ -67,12 +67,14 @@ data: barChartData, options: { responsive: true, - legend: { - position: 'top', - }, - title: { - display: true, - text: 'Chart.js Bar Chart' + plugins: { + legend: { + position: 'top', + }, + title: { + display: true, + text: 'Chart.js Bar Chart' + } } } });
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/bubble.html
@@ -107,12 +107,14 @@ data: bubbleChartData, options: { responsive: true, - title: { - display: true, - text: 'Chart.js Bubble Chart' - }, - tooltips: { - mode: 'point' + plugins: { + title: { + display: true, + text: 'Chart.js Bubble Chart' + }, + tooltip: { + mode: 'point' + } } } });
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/combo-bar-line.html
@@ -75,13 +75,15 @@ data: chartData, options: { responsive: true, - title: { - display: true, - text: 'Chart.js Combo Bar Line Chart' - }, - tooltips: { - mode: 'index', - intersect: true + plugins: { + title: { + display: true, + text: 'Chart.js Combo Bar Line Chart' + }, + tooltip: { + mode: 'index', + intersect: true + } } } });
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/doughnut.html
@@ -59,12 +59,14 @@ }, options: { responsive: true, - legend: { - position: 'top', - }, - title: { - display: true, - text: 'Chart.js Doughnut Chart' + plugins: { + legend: { + position: 'top', + }, + title: { + display: true, + text: 'Chart.js Doughnut Chart' + }, }, animation: { animateScale: true,
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/line/basic.html
@@ -63,13 +63,15 @@ }, options: { responsive: true, - title: { - display: true, - text: 'Chart.js Line Chart' - }, - tooltips: { - mode: 'index', - intersect: false, + plugins: { + title: { + display: true, + text: 'Chart.js Line Chart' + }, + tooltip: { + mode: 'index', + intersect: false, + } }, hover: { mode: 'nearest',
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/line/interpolation-modes.html
@@ -57,12 +57,14 @@ }, options: { responsive: true, - title: { - display: true, - text: 'Chart.js Line Chart - Cubic interpolation mode' - }, - tooltips: { - mode: 'index' + plugins: { + title: { + display: true, + text: 'Chart.js Line Chart - Cubic interpolation mode' + }, + tooltip: { + mode: 'index' + } }, scales: { x: {
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/line/line-styles.html
@@ -70,13 +70,15 @@ }, options: { responsive: true, - title: { - display: true, - text: 'Chart.js Line Chart' - }, - tooltips: { - mode: 'index', - intersect: false, + plugins: { + title: { + display: true, + text: 'Chart.js Line Chart' + }, + tooltip: { + mode: 'index', + intersect: false, + } }, hover: { mode: 'nearest',
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/line/point-sizes.html
@@ -90,8 +90,14 @@ }, options: { responsive: true, - legend: { - position: 'bottom', + plugins: { + legend: { + position: 'bottom', + }, + title: { + display: true, + text: 'Chart.js Line Chart - Different point sizes' + } }, hover: { mode: 'index' @@ -111,10 +117,6 @@ labelString: 'Value' } } - }, - title: { - display: true, - text: 'Chart.js Line Chart - Different point sizes' } } };
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/line/point-styles.html
@@ -48,12 +48,14 @@ }, options: { responsive: true, - title: { - display: true, - text: 'Point Style: ' + pointStyle - }, - legend: { - display: false + plugins: { + title: { + display: true, + text: 'Point Style: ' + pointStyle + }, + legend: { + display: false + }, }, elements: { point: {
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/line/skip-points.html
@@ -56,12 +56,14 @@ }, options: { responsive: true, - title: { - display: true, - text: 'Chart.js Line Chart - Skip Points' - }, - tooltips: { - mode: 'index', + plugins: { + title: { + display: true, + text: 'Chart.js Line Chart - Skip Points' + }, + tooltip: { + mode: 'index', + } }, hover: { mode: 'index'
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/multi-series-pie.html
@@ -43,47 +43,49 @@ ] }, options: { - legend: { - labels: { - generateLabels: function(chart) { - // Get the default label list - var original = Chart.defaults.controllers.pie.legend.labels.generateLabels; - var labels = original.call(this, chart); + plugins: { + legend: { + labels: { + generateLabels: function(chart) { + // Get the default label list + var original = Chart.defaults.controllers.pie.legend.labels.generateLabels; + var labels = original.call(this, chart); - // Build an array of colors used in the datasets of the chart - var datasetColors = chart.data.datasets.map(function(e) { - return e.backgroundColor; - }); - datasetColors = datasetColors.flat(); + // Build an array of colors used in the datasets of the chart + var datasetColors = chart.data.datasets.map(function(e) { + return e.backgroundColor; + }); + datasetColors = datasetColors.flat(); - // Modify the color and hide state of each label - labels.forEach(label => { - // There are twice as many labels as there are datasets. This converts the label index into the corresponding dataset index - label.datasetIndex = (label.index - label.index % 2) / 2; + // Modify the color and hide state of each label + labels.forEach(label => { + // There are twice as many labels as there are datasets. This converts the label index into the corresponding dataset index + label.datasetIndex = (label.index - label.index % 2) / 2; - // The hidden state must match the dataset's hidden state - label.hidden = !chart.isDatasetVisible(label.datasetIndex); + // The hidden state must match the dataset's hidden state + label.hidden = !chart.isDatasetVisible(label.datasetIndex); - // Change the color to match the dataset - label.fillStyle = datasetColors[label.index]; - }); + // Change the color to match the dataset + label.fillStyle = datasetColors[label.index]; + }); - return labels; + return labels; + } + }, + onClick: function(mouseEvent, legendItem, legend) { + // toggle the visibility of the dataset from what it currently is + legend.chart.getDatasetMeta( + legendItem.datasetIndex + ).hidden = legend.chart.isDatasetVisible(legendItem.datasetIndex); + legend.chart.update(); } }, - onClick: function(mouseEvent, legendItem, legend) { - // toggle the visibility of the dataset from what it currently is - legend.chart.getDatasetMeta( - legendItem.datasetIndex - ).hidden = legend.chart.isDatasetVisible(legendItem.datasetIndex); - legend.chart.update(); - } - }, - tooltips: { - callbacks: { - label: function(context) { - var labelIndex = (context.datasetIndex * 2) + context.dataIndex; - return context.chart.data.labels[labelIndex] + ': ' + context.dataset.data[context.dataIndex]; + tooltip: { + callbacks: { + label: function(context) { + var labelIndex = (context.datasetIndex * 2) + context.dataIndex; + return context.chart.data.labels[labelIndex] + ': ' + context.dataset.data[context.dataIndex]; + } } } }
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/polar-area.html
@@ -58,12 +58,14 @@ }, options: { responsive: true, - legend: { - position: 'right', - }, - title: { - display: true, - text: 'Chart.js Polar Area Chart' + plugins: { + legend: { + position: 'right', + }, + title: { + display: true, + text: 'Chart.js Polar Area Chart' + }, }, scale: { ticks: {
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/charts/radar.html
@@ -64,12 +64,14 @@ }] }, options: { - legend: { - position: 'top', - }, - title: { - display: true, - text: 'Chart.js Radar Chart' + plugins: { + legend: { + position: 'top', + }, + title: { + display: true, + text: 'Chart.js Radar Chart' + }, }, scale: { beginAtZero: true
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/legend/callbacks.html
@@ -83,20 +83,22 @@ }] }, options: { - legend: { - onHover: function(event, legendItem) { - log('onHover: ' + legendItem.text); + plugins: { + legend: { + onHover: function(event, legendItem) { + log('onHover: ' + legendItem.text); + }, + onLeave: function(event, legendItem) { + log('onLeave: ' + legendItem.text); + }, + onClick: function(event, legendItem) { + log('onClick:' + legendItem.text); + } }, - onLeave: function(event, legendItem) { - log('onLeave: ' + legendItem.text); + title: { + display: true, + text: 'Chart.js Line Chart' }, - onClick: function(event, legendItem) { - log('onClick:' + legendItem.text); - } - }, - title: { - display: true, - text: 'Chart.js Line Chart' }, scales: { x: {
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/legend/point-style.html
@@ -62,9 +62,15 @@ }, options: { responsive: true, - legend: { - labels: { - usePointStyle: false + plugins: { + legend: { + labels: { + usePointStyle: false + } + }, + title: { + display: true, + text: 'Normal Legend' } }, scales: { @@ -82,19 +88,15 @@ labelString: 'Value' } } - }, - title: { - display: true, - text: 'Normal Legend' } } }; } function createPointStyleConfig(colorName) { var config = createConfig(colorName); - config.options.legend.labels.usePointStyle = true; - config.options.title.text = 'Point Style Legend'; + config.options.plugins.legend.labels.usePointStyle = true; + config.options.plugins.title.text = 'Point Style Legend'; return config; }
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/legend/positioning.html
@@ -65,8 +65,14 @@ }, options: { responsive: true, - legend: { - position: legendPosition, + plugins: { + legend: { + position: legendPosition, + }, + title: { + display: true, + text: 'Legend Position: ' + legendPosition + } }, scales: { x: { @@ -83,10 +89,6 @@ labelString: 'Value' } } - }, - title: { - display: true, - text: 'Legend Position: ' + legendPosition } } };
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/legend/title.html
@@ -71,13 +71,19 @@ }, options: { responsive: true, - legend: { - align: align, - position: legendPosition, + plugins: { + legend: { + align: align, + position: legendPosition, + title: { + display: true, + text: 'Legend Title', + position: titlePosition, + } + }, title: { display: true, - text: 'Legend Title', - position: titlePosition, + text: 'Legend Title Position: ' + titlePosition } }, scales: { @@ -95,10 +101,6 @@ labelString: 'Value' } } - }, - title: { - display: true, - text: 'Legend Title Position: ' + titlePosition } } };
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/scales/axes-labels.html
@@ -63,13 +63,15 @@ }, options: { responsive: true, - title: { - display: true, - text: 'Chart.js Line Chart' - }, - tooltips: { - mode: 'index', - intersect: false, + plugins: { + title: { + display: true, + text: 'Chart.js Line Chart' + }, + tooltip: { + mode: 'index', + intersect: false, + } }, hover: { mode: 'nearest',
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/scales/financial.html
@@ -182,17 +182,19 @@ } } }, - tooltips: { - intersect: false, - mode: 'index', - callbacks: { - label: function(context) { - let label = context.dataset.label || ''; - if (label) { - label += ': '; + plugins: { + tooltip: { + intersect: false, + mode: 'index', + callbacks: { + label: function(context) { + let label = context.dataset.label || ''; + if (label) { + label += ': '; + } + label += context.dataPoint.y.toFixed(2); + return label; } - label += context.dataPoint.y.toFixed(2); - return label; } } }
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/scales/label-text-alignment.html
@@ -80,8 +80,14 @@ }, options: { responsive: true, - legend: { - display: false, + plugins: { + legend: { + display: false, + }, + title: { + display: true, + text: 'X Tick Alignment: ' + xAlign + ', Y Tick Alignment ' + yAlign + } }, scales: { x: { @@ -96,10 +102,6 @@ align: yAlign } } - }, - title: { - display: true, - text: 'X Tick Alignment: ' + xAlign + ', Y Tick Alignment ' + yAlign } } };
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/scales/linear/step-size.html
@@ -68,13 +68,15 @@ }, options: { responsive: true, - title: { - display: true, - text: 'Chart.js Line Chart' - }, - tooltips: { - mode: 'index', - intersect: false, + plugins: { + title: { + display: true, + text: 'Chart.js Line Chart' + }, + tooltip: { + mode: 'index', + intersect: false, + } }, hover: { mode: 'nearest',
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/scales/toggle-scale-type.html
@@ -85,7 +85,7 @@ document.getElementById('toggleScale').addEventListener('click', function() { type = type === 'linear' ? 'logarithmic' : 'linear'; - window.myLine.options.title.text = 'Chart.js Line Chart - ' + type; + window.myLine.options.plugins.title.text = 'Chart.js Line Chart - ' + type; window.myLine.options.scales.y = { display: true, type: type
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/scriptable/bar.html
@@ -52,8 +52,10 @@ }; var options = { - legend: false, - tooltips: false, + plugins: { + legend: false, + tooltip: false, + }, elements: { bar: { backgroundColor: colorize.bind(null, false),
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/scriptable/bubble.html
@@ -69,9 +69,10 @@ var options = { aspectRatio: 1, - legend: false, - tooltips: false, - + plugins: { + legend: false, + tooltip: false, + }, elements: { point: { backgroundColor: colorize.bind(null, false),
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/scriptable/line.html
@@ -64,8 +64,10 @@ }; var options = { - legend: false, - tooltips: true, + plugins: { + legend: false, + tooltip: true, + }, elements: { line: { fill: false,
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/scriptable/pie.html
@@ -57,8 +57,10 @@ }; var options = { - legend: false, - tooltips: false, + plugins: { + legend: false, + tooltip: false, + }, elements: { arc: { backgroundColor: colorize.bind(null, false, false),
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/scriptable/polar.html
@@ -56,8 +56,10 @@ }; var options = { - legend: false, - tooltips: false, + plugins: { + legend: false, + tooltip: false, + }, elements: { arc: { backgroundColor: colorize.bind(null, false, false),
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/scriptable/radar.html
@@ -68,8 +68,10 @@ }; var options = { - legend: false, - tooltips: true, + plugins: { + legend: false, + tooltip: false, + }, elements: { line: { backgroundColor: make20PercentOpaque,
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/title/alignment.html
@@ -71,8 +71,10 @@ }, options: { responsive: true, - legend: { - display: false, + plugins: { + legend: { + display: false + }, }, scales: { x: {
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/tooltips/border.html
@@ -45,27 +45,29 @@ }, options: { responsive: true, - title: { - display: true, - text: 'Sample tooltip with border' - }, - tooltips: { - position: 'nearest', - mode: 'index', - intersect: false, - yPadding: 10, - xPadding: 10, - caretSize: 8, - backgroundColor: 'rgba(72, 241, 12, 1)', - titleFont: { - color: window.chartColors.black + plugins: { + title: { + display: true, + text: 'Sample tooltip with border' }, - bodyFont: { - color: window.chartColors.black - }, - borderColor: 'rgba(0,0,0,1)', - borderWidth: 4 - }, + tooltip: { + position: 'nearest', + mode: 'index', + intersect: false, + yPadding: 10, + xPadding: 10, + caretSize: 8, + backgroundColor: 'rgba(72, 241, 12, 1)', + titleFont: { + color: window.chartColors.black + }, + bodyFont: { + color: window.chartColors.black + }, + borderColor: 'rgba(0,0,0,1)', + borderWidth: 4 + } + } } }; }
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/tooltips/callbacks.html
@@ -55,24 +55,26 @@ }, options: { responsive: true, - title: { - display: true, - text: 'Chart.js Line Chart - Custom Information in Tooltip' - }, - tooltips: { - mode: 'index', - callbacks: { - // Use the footer callback to display the sum of the items showing in the tooltip - footer: function(tooltipItems) { - var sum = 0; + plugins: { + title: { + display: true, + text: 'Chart.js Line Chart - Custom Information in Tooltip' + }, + tooltip: { + mode: 'index', + callbacks: { + // Use the footer callback to display the sum of the items showing in the tooltip + footer: function(tooltipItems) { + var sum = 0; - tooltipItems.forEach(function(tooltipItem) { - sum += tooltipItem.dataPoint.y; - }); - return 'Sum: ' + sum; + tooltipItems.forEach(function(tooltipItem) { + sum += tooltipItem.dataPoint.y; + }); + return 'Sum: ' + sum; + }, }, - }, - footerFontStyle: 'normal' + footerFontStyle: 'normal' + } }, hover: { mode: 'index',
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/tooltips/custom-line.html
@@ -153,16 +153,18 @@ type: 'line', data: lineChartData, options: { - title: { - display: true, - text: 'Chart.js Line Chart - Custom Tooltips' - }, - tooltips: { - enabled: false, - mode: 'index', - intersect: false, - position: 'nearest', - custom: customTooltips + plugins: { + title: { + display: true, + text: 'Chart.js Line Chart - Custom Tooltips' + }, + tooltip: { + enabled: false, + mode: 'index', + intersect: false, + position: 'nearest', + custom: customTooltips + } } } });
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/tooltips/custom-pie.html
@@ -137,11 +137,9 @@ }, options: { responsive: true, - legend: { - display: false - }, - tooltips: { - enabled: false, + plugins: { + legend: false, + tooltip: false } } };
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/tooltips/custom-points.html
@@ -112,15 +112,17 @@ type: 'line', data: lineChartData, options: { - title: { - display: true, - text: 'Chart.js - Custom Tooltips using Data Points' - }, - tooltips: { - enabled: false, - mode: 'index', - intersect: false, - custom: customTooltips + plugins: { + title: { + display: true, + text: 'Chart.js - Custom Tooltips using Data Points' + }, + tooltip: { + enabled: false, + mode: 'index', + intersect: false, + custom: customTooltips + } } } });
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/tooltips/interactions.html
@@ -51,13 +51,15 @@ }, options: { responsive: true, - title: { - display: true, - text: 'Mode: ' + mode + ', intersect = ' + intersect - }, - tooltips: { - mode: mode, - intersect: intersect, + plugins: { + title: { + display: true, + text: 'Mode: ' + mode + ', intersect = ' + intersect + }, + tooltip: { + mode: mode, + intersect: intersect, + } }, hover: { mode: mode,
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/tooltips/point-style.html
@@ -83,19 +83,21 @@ }, options: { responsive: true, - title: { - display: true, - text: 'Tooltip Point Styles' - }, - tooltips: { - mode: 'index', - intersect: false, - usePointStyle: true, - }, - legend: { - labels: { - usePointStyle: true - } + plugins: { + title: { + display: true, + text: 'Tooltip Point Styles' + }, + tooltip: { + mode: 'index', + intersect: false, + usePointStyle: true, + }, + legend: { + labels: { + usePointStyle: true + } + }, }, hover: { mode: 'nearest',
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/tooltips/positioning-custom.html
@@ -83,10 +83,12 @@ }, options: { responsive: true, - tooltips: { - position: 'middle', - intersect: false, - }, + plugins: { + tooltip: { + position: 'middle', + intersect: false, + } + } } }); };
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
samples/tooltips/positioning.html
@@ -51,15 +51,17 @@ }, options: { responsive: true, - title: { - display: true, - text: 'Tooltip Position: ' + position - }, - tooltips: { - position: position, - mode: 'index', - intersect: false, - }, + plugins: { + title: { + display: true, + text: 'Tooltip Position: ' + position + }, + tooltip: { + position: position, + mode: 'index', + intersect: false, + } + } } }; }
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
src/controllers/controller.bubble.js
@@ -165,11 +165,13 @@ BubbleController.defaults = { type: 'linear' } }, - tooltips: { - callbacks: { - title() { - // Title doesn't make sense for scatter since we format the data as a point - return ''; + plugins: { + tooltip: { + callbacks: { + title() { + // Title doesn't make sense for scatter since we format the data as a point + return ''; + } } } }
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
src/controllers/controller.doughnut.js
@@ -344,36 +344,6 @@ DoughnutController.defaults = { animateScale: false }, aspectRatio: 1, - legend: { - labels: { - generateLabels(chart) { - const data = chart.data; - if (data.labels.length && data.datasets.length) { - return data.labels.map((label, i) => { - const meta = chart.getDatasetMeta(0); - const style = meta.controller.getStyle(i); - - return { - text: label, - fillStyle: style.backgroundColor, - strokeStyle: style.borderColor, - lineWidth: style.borderWidth, - hidden: !chart.getDataVisibility(i), - - // Extra data used for toggling the correct item - index: i - }; - }); - } - return []; - } - }, - - onClick(e, legendItem, legend) { - legend.chart.toggleDataVisibility(legendItem.index); - legend.chart.update(); - } - }, // The percentage of the chart that we cut out of the middle. cutoutPercentage: 50, @@ -385,25 +355,57 @@ DoughnutController.defaults = { circumference: 360, // Need to override these to give a nice default - tooltips: { - callbacks: { - title() { - return ''; - }, - label(tooltipItem) { - let dataLabel = tooltipItem.label; - const value = ': ' + tooltipItem.formattedValue; - - if (isArray(dataLabel)) { - // show value on first line of multiline label - // need to clone because we are changing the value - dataLabel = dataLabel.slice(); - dataLabel[0] += value; - } else { - dataLabel += value; + plugins: { + legend: { + labels: { + generateLabels(chart) { + const data = chart.data; + if (data.labels.length && data.datasets.length) { + return data.labels.map((label, i) => { + const meta = chart.getDatasetMeta(0); + const style = meta.controller.getStyle(i); + + return { + text: label, + fillStyle: style.backgroundColor, + strokeStyle: style.borderColor, + lineWidth: style.borderWidth, + hidden: !chart.getDataVisibility(i), + + // Extra data used for toggling the correct item + index: i + }; + }); + } + return []; } + }, - return dataLabel; + onClick(e, legendItem, legend) { + legend.chart.toggleDataVisibility(legendItem.index); + legend.chart.update(); + } + }, + tooltip: { + callbacks: { + title() { + return ''; + }, + label(tooltipItem) { + let dataLabel = tooltipItem.label; + const value = ': ' + tooltipItem.formattedValue; + + if (isArray(dataLabel)) { + // show value on first line of multiline label + // need to clone because we are changing the value + dataLabel = dataLabel.slice(); + dataLabel[0] += value; + } else { + dataLabel += value; + } + + return dataLabel; + } } } }
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
src/controllers/controller.polarArea.js
@@ -172,46 +172,49 @@ PolarAreaController.defaults = { }, startAngle: 0, - legend: { - labels: { - generateLabels(chart) { - const data = chart.data; - if (data.labels.length && data.datasets.length) { - return data.labels.map((label, i) => { - const meta = chart.getDatasetMeta(0); - const style = meta.controller.getStyle(i); - - return { - text: label, - fillStyle: style.backgroundColor, - strokeStyle: style.borderColor, - lineWidth: style.borderWidth, - hidden: !chart.getDataVisibility(i), - - // Extra data used for toggling the correct item - index: i - }; - }); + plugins: { + legend: { + labels: { + generateLabels(chart) { + const data = chart.data; + if (data.labels.length && data.datasets.length) { + return data.labels.map((label, i) => { + const meta = chart.getDatasetMeta(0); + const style = meta.controller.getStyle(i); + + return { + text: label, + fillStyle: style.backgroundColor, + strokeStyle: style.borderColor, + lineWidth: style.borderWidth, + hidden: !chart.getDataVisibility(i), + + // Extra data used for toggling the correct item + index: i + }; + }); + } + return []; } - return []; + }, + + onClick(e, legendItem, legend) { + legend.chart.toggleDataVisibility(legendItem.index); + legend.chart.update(); } }, - onClick(e, legendItem, legend) { - legend.chart.toggleDataVisibility(legendItem.index); - legend.chart.update(); - } - }, - - // Need to override these to give a nice default - tooltips: { - callbacks: { - title() { - return ''; - }, - label(context) { - return context.chart.data.labels[context.dataIndex] + ': ' + context.formattedValue; + // Need to override these to give a nice default + tooltip: { + callbacks: { + title() { + return ''; + }, + label(context) { + return context.chart.data.labels[context.dataIndex] + ': ' + context.formattedValue; + } } } } + };
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
src/controllers/controller.scatter.js
@@ -24,13 +24,15 @@ ScatterController.defaults = { fill: false }, - tooltips: { - callbacks: { - title() { - return ''; // doesn't make sense for scatter since data are formatted as a point - }, - label(item) { - return '(' + item.label + ', ' + item.formattedValue + ')'; + plugins: { + tooltip: { + callbacks: { + title() { + return ''; // doesn't make sense for scatter since data are formatted as a point + }, + label(item) { + return '(' + item.label + ', ' + item.formattedValue + ')'; + } } } }
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
src/core/core.config.js
@@ -99,6 +99,21 @@ function mergeConfig(...args/* config objects ... */) { }); } +function includePluginDefaults(options) { + options.plugins = options.plugins || {}; + options.plugins.title = (options.plugins.title !== false) && merge(Object.create(null), [ + defaults.plugins.title, + options.plugins.title + ]); + + options.plugins.tooltip = (options.plugins.tooltip !== false) && merge(Object.create(null), [ + defaults.interaction, + defaults.plugins.tooltip, + options.interaction, + options.plugins.tooltip + ]); +} + function includeDefaults(config, options) { options = options || {}; @@ -119,16 +134,9 @@ function includeDefaults(config, options) { options.scales = scaleConfig; - options.title = (options.title !== false) && merge(Object.create(null), [ - defaults.plugins.title, - options.title - ]); - options.tooltips = (options.tooltips !== false) && merge(Object.create(null), [ - defaults.interaction, - defaults.plugins.tooltip, - options.interaction, - options.tooltips - ]); + if (options.plugins !== false) { + includePluginDefaults(options); + } return options; }
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
src/plugins/plugin.legend.js
@@ -654,7 +654,7 @@ export default { _element: Legend, beforeInit(chart) { - const legendOpts = resolveOptions(chart.options.legend); + const legendOpts = resolveOptions(chart.options.plugins.legend); if (legendOpts) { createNewLegendAndAttach(chart, legendOpts); @@ -665,7 +665,7 @@ export default { // This ensures that if the legend position changes (via an option update) // the layout system respects the change. See https://github.com/chartjs/Chart.js/issues/7527 beforeUpdate(chart) { - const legendOpts = resolveOptions(chart.options.legend); + const legendOpts = resolveOptions(chart.options.plugins.legend); const legend = chart.legend; if (legendOpts) {
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
src/plugins/plugin.title.js
@@ -230,15 +230,15 @@ export default { _element: Title, beforeInit(chart) { - const titleOpts = chart.options.title; + const titleOpts = chart.options.plugins.title; if (titleOpts) { createNewTitleBlockAndAttach(chart, titleOpts); } }, beforeUpdate(chart) { - const titleOpts = chart.options.title; + const titleOpts = chart.options.plugins.title; const titleBlock = chart.titleBlock; if (titleOpts) {
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
src/plugins/plugin.tooltip.js
@@ -392,7 +392,7 @@ export class Tooltip extends Element { initialize() { const me = this; const chartOpts = me._chart.options; - me.options = resolveOptions(chartOpts.tooltips, chartOpts.font); + me.options = resolveOptions(chartOpts.plugins.tooltip, chartOpts.font); me._cachedAnimations = undefined; } @@ -1048,7 +1048,7 @@ export default { positioners, afterInit(chart) { - const tooltipOpts = chart.options.tooltips; + const tooltipOpts = chart.options.plugins.tooltip; if (tooltipOpts) { chart.tooltip = new Tooltip({_chart: chart});
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
test/fixtures/core.layouts/long-labels.js
@@ -8,8 +8,8 @@ module.exports = { labels: ['tick1 is very long one', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6 is very long one'] }, options: { - legend: { - display: false + plugins: { + legend: false }, scales: { x: {
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
test/fixtures/core.layouts/scriptable.js
@@ -21,8 +21,8 @@ module.exports = { }; } }, - legend: { - display: false + plugins: { + legend: false }, scales: { x: {
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
test/fixtures/plugin.filler/fill-radar-boundary-start.json
@@ -20,8 +20,10 @@ "options": { "responsive": false, "spanGaps": false, - "legend": false, - "title": false, + "plugins": { + "legend": false, + "title": false + }, "scale": { "display": false },
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
test/fixtures/plugin.filler/fill-radar-dataset-spline.json
@@ -28,8 +28,10 @@ "options": { "responsive": false, "spanGaps": false, - "legend": false, - "title": false, + "plugins": { + "legend": false, + "title": false + }, "scale": { "display": false },
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
test/fixtures/plugin.legend/legend-doughnut-bottom-center-mulitiline.json
@@ -10,9 +10,11 @@ }] }, "options": { - "legend": { - "position": "bottom", - "align": "center" + "plugins": { + "legend": { + "position": "bottom", + "align": "center" + } } } },
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
test/fixtures/plugin.legend/legend-doughnut-bottom-center-single.json
@@ -10,9 +10,11 @@ }] }, "options": { - "legend": { - "position": "bottom", - "align": "center" + "plugins": { + "legend": { + "position": "bottom", + "align": "center" + } } } },
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
test/fixtures/plugin.legend/legend-doughnut-bottom-end-mulitiline.json
@@ -10,9 +10,11 @@ }] }, "options": { - "legend": { - "position": "bottom", - "align": "end" + "plugins": { + "legend": { + "position": "bottom", + "align": "end" + } } } },
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
test/fixtures/plugin.legend/legend-doughnut-bottom-start-mulitiline.json
@@ -10,9 +10,11 @@ }] }, "options": { - "legend": { - "position": "bottom", - "align": "start" + "plugins": { + "legend": { + "position": "bottom", + "align": "start" + } } } },
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
test/fixtures/plugin.legend/legend-doughnut-left-center-mulitiline.json
@@ -10,9 +10,11 @@ }] }, "options": { - "legend": { - "position": "left", - "align": "center" + "plugins": { + "legend": { + "position": "left", + "align": "center" + } } } },
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
test/fixtures/plugin.legend/legend-doughnut-left-center-single.json
@@ -10,9 +10,11 @@ }] }, "options": { - "legend": { - "position": "left", - "align": "center" + "plugins": { + "legend": { + "position": "left", + "align": "center" + } } } },
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
test/fixtures/plugin.legend/legend-doughnut-left-default-center.json
@@ -10,8 +10,10 @@ }] }, "options": { - "legend": { - "position": "left" + "plugins": { + "legend": { + "position": "left" + } } } },
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
test/fixtures/plugin.legend/legend-doughnut-left-end-mulitiline.json
@@ -10,9 +10,11 @@ }] }, "options": { - "legend": { - "position": "left", - "align": "end" + "plugins": { + "legend": { + "position": "left", + "align": "end" + } } } },
true
Other
chartjs
Chart.js
913a01a3a629c5249850c66857ca5f7c76b9f322.json
Move title, tooltip and legend to options.plugins (#8089) * Move title, tooltip and legend to options.plugins * Update tooltip.md * Update legend.md and title.md * Add migration notes * typo * Types * Restore plurals * One more s, restore tabs * All plugins disabled * lint * cc
test/fixtures/plugin.legend/legend-doughnut-left-start-mulitiline.json
@@ -10,9 +10,11 @@ }] }, "options": { - "legend": { - "position": "left", - "align": "start" + "plugins": { + "legend": { + "position": "left", + "align": "start" + } } } },
true