From e2145e3b55355f99327a1b5b46999f9c691b08bd Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Thu, 20 Feb 2020 09:18:21 -0800 Subject: [PATCH] Turn on excludeNotExported (#7121) --- babel.config.json | 4 ++-- karma.conf.js | 2 +- src/controllers/controller.bar.js | 4 +--- src/controllers/controller.bubble.js | 5 +---- src/controllers/controller.doughnut.js | 4 +--- src/controllers/controller.horizontalBar.js | 4 +--- src/controllers/controller.line.js | 4 +--- src/controllers/controller.polarArea.js | 4 +--- src/controllers/controller.radar.js | 4 +--- src/core/core.adapters.js | 2 +- src/core/core.animation.js | 4 +--- src/core/core.animator.js | 10 ++++++---- src/core/core.controller.js | 19 +++++++++---------- src/core/core.datasetController.js | 12 +++++------- src/core/core.defaults.js | 6 ++++-- src/core/core.element.js | 7 +++---- src/core/core.plugins.js | 2 +- src/core/core.scale.js | 4 +--- src/elements/element.arc.js | 8 +++----- src/elements/element.line.js | 8 +++----- src/elements/element.point.js | 8 +++----- src/elements/element.rectangle.js | 8 +++----- src/plugins/plugin.legend.js | 5 +---- src/plugins/plugin.title.js | 5 +---- src/plugins/plugin.tooltip.js | 2 +- src/scales/scale.category.js | 9 ++++----- src/scales/scale.linear.js | 10 +++++----- src/scales/scale.linearbase.js | 4 +--- src/scales/scale.logarithmic.js | 9 ++++----- src/scales/scale.radialLinear.js | 9 ++++----- src/scales/scale.time.js | 9 ++++----- tsconfig.json | 1 + 32 files changed, 79 insertions(+), 117 deletions(-) diff --git a/babel.config.json b/babel.config.json index 7d471fa0b..8f0b771eb 100644 --- a/babel.config.json +++ b/babel.config.json @@ -1,8 +1,8 @@ { "presets": ["@babel/preset-env"], "plugins": [ - "@babel/plugin-transform-object-assign", - "@babel/plugin-proposal-class-properties" + "@babel/plugin-proposal-class-properties", + "@babel/plugin-transform-object-assign" ], "env": { "test": { diff --git a/karma.conf.js b/karma.conf.js index 629bf2c06..9a37cbf1a 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,9 +1,9 @@ /* eslint-disable import/no-commonjs */ +const babel = require('rollup-plugin-babel'); const commonjs = require('rollup-plugin-commonjs'); const resolve = require('rollup-plugin-node-resolve'); const builds = require('./rollup.config'); -const babel = require('rollup-plugin-babel'); module.exports = function(karma) { const args = karma.args || {}; diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 6edea91f0..67b09bcdb 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -179,7 +179,7 @@ function isFloatBar(custom) { return custom && custom.barStart !== undefined && custom.barEnd !== undefined; } -class BarController extends DatasetController { +export default class BarController extends DatasetController { /** * Overriding primitive data parsing since we support mixed primitive/array @@ -510,5 +510,3 @@ BarController.prototype._dataElementOptions = [ 'maxBarThickness', 'minBarLength' ]; - -export default BarController; diff --git a/src/controllers/controller.bubble.js b/src/controllers/controller.bubble.js index 2739c4000..4f5455c9e 100644 --- a/src/controllers/controller.bubble.js +++ b/src/controllers/controller.bubble.js @@ -30,7 +30,7 @@ defaults.set('bubble', { } }); -class BubbleController extends DatasetController { +export default class BubbleController extends DatasetController { /** * Parse array of objects @@ -186,6 +186,3 @@ BubbleController.prototype._dataElementOptions = [ 'pointStyle', 'rotation' ]; - - -export default BubbleController; diff --git a/src/controllers/controller.doughnut.js b/src/controllers/controller.doughnut.js index 1d987adbf..184742881 100644 --- a/src/controllers/controller.doughnut.js +++ b/src/controllers/controller.doughnut.js @@ -128,7 +128,7 @@ function getRatioAndOffset(rotation, circumference, cutout) { return {ratioX, ratioY, offsetX, offsetY}; } -class DoughnutController extends DatasetController { +export default class DoughnutController extends DatasetController { constructor(chart, datasetIndex) { super(chart, datasetIndex); @@ -356,5 +356,3 @@ DoughnutController.prototype._dataElementOptions = [ 'hoverBorderColor', 'hoverBorderWidth', ]; - -export default DoughnutController; diff --git a/src/controllers/controller.horizontalBar.js b/src/controllers/controller.horizontalBar.js index 52664d411..cedffa678 100644 --- a/src/controllers/controller.horizontalBar.js +++ b/src/controllers/controller.horizontalBar.js @@ -40,7 +40,7 @@ defaults.set('horizontalBar', { } }); -class HorizontalBarController extends BarController { +export default class HorizontalBarController extends BarController { /** * @private @@ -56,5 +56,3 @@ class HorizontalBarController extends BarController { return this._cachedMeta.yAxisID; } } - -export default HorizontalBarController; diff --git a/src/controllers/controller.line.js b/src/controllers/controller.line.js index 5dd458477..5a74b8b62 100644 --- a/src/controllers/controller.line.js +++ b/src/controllers/controller.line.js @@ -24,7 +24,7 @@ defaults.set('line', { } }); -class LineController extends DatasetController { +export default class LineController extends DatasetController { constructor(chart, datasetIndex) { super(chart, datasetIndex); @@ -195,5 +195,3 @@ LineController.prototype._dataElementOptions = { radius: 'pointRadius', rotation: 'pointRotation' }; - -export default LineController; diff --git a/src/controllers/controller.polarArea.js b/src/controllers/controller.polarArea.js index 10a51a479..0e1e3ad46 100644 --- a/src/controllers/controller.polarArea.js +++ b/src/controllers/controller.polarArea.js @@ -88,7 +88,7 @@ function getStartAngleRadians(deg) { return toRadians(deg) - 0.5 * Math.PI; } -class PolarAreaController extends DatasetController { +export default class PolarAreaController extends DatasetController { constructor(chart, datasetIndex) { super(chart, datasetIndex); @@ -243,5 +243,3 @@ PolarAreaController.prototype._dataElementOptions = [ 'hoverBorderColor', 'hoverBorderWidth' ]; - -export default PolarAreaController; diff --git a/src/controllers/controller.radar.js b/src/controllers/controller.radar.js index ce75db82a..f53bf7567 100644 --- a/src/controllers/controller.radar.js +++ b/src/controllers/controller.radar.js @@ -18,7 +18,7 @@ defaults.set('radar', { } }); -class RadarController extends DatasetController { +export default class RadarController extends DatasetController { /** * @private @@ -147,5 +147,3 @@ RadarController.prototype._dataElementOptions = { radius: 'pointRadius', rotation: 'pointRotation' }; - -export default RadarController; diff --git a/src/core/core.adapters.js b/src/core/core.adapters.js index ea26870fd..5a13a8304 100644 --- a/src/core/core.adapters.js +++ b/src/core/core.adapters.js @@ -24,7 +24,7 @@ function abstract() { * @memberof Chart._adapters._date */ -class DateAdapter { +export class DateAdapter { constructor(options) { this.options = options || {}; diff --git a/src/core/core.animation.js b/src/core/core.animation.js index 59bb03015..8fc7c11cb 100644 --- a/src/core/core.animation.js +++ b/src/core/core.animation.js @@ -19,7 +19,7 @@ const interpolators = { } }; -class Animation { +export default class Animation { constructor(cfg, target, prop, to) { const currentValue = target[prop]; @@ -80,5 +80,3 @@ class Animation { me._target[prop] = me._fn(from, to, factor); } } - -export default Animation; diff --git a/src/core/core.animator.js b/src/core/core.animator.js index 1da383039..b034b7e13 100644 --- a/src/core/core.animator.js +++ b/src/core/core.animator.js @@ -18,7 +18,10 @@ function drawFPS(chart, count, date, lastDate) { ctx.restore(); } -class Animator { +/** + * Please use the module's default export which provides a singleton instance + */ +export class Animator { constructor() { this._request = null; this._charts = new Map(); @@ -220,6 +223,5 @@ class Animator { } } -const instance = new Animator(); - -export default instance; +// singleton instance +export default new Animator(); diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 33cc21495..7b684b08a 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -173,9 +173,17 @@ function getCanvas(item) { return item; } -class Chart { +export default class Chart { + static version = version; + /** + * NOTE(SB) We actually don't use this container anymore but we need to keep it + * for backward compatibility. Though, it can still be useful for plugins that + * would need to work on multiple charts?! + */ + static instances = {}; + constructor(item, config) { const me = this; @@ -1073,12 +1081,3 @@ class Chart { return changed; } } - -/** - * NOTE(SB) We actually don't use this container anymore but we need to keep it - * for backward compatibility. Though, it can still be useful for plugins that - * would need to work on multiple charts?! - */ -Chart.instances = {}; - -export default Chart; diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index 08bb7ea95..bf14736a1 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -210,7 +210,9 @@ function getFirstScaleId(chart, axis) { return Object.keys(scales).filter(key => scales[key].axis === axis).shift(); } -class DatasetController { +export default class DatasetController { + + static extend = helpers.inherits; constructor(chart, datasetIndex) { this.chart = chart; @@ -829,7 +831,7 @@ class DatasetController { const chart = me.chart; const datasetOpts = me._config; // @ts-ignore - const options = chart.options.elements[me.datasetElementType.prototype._type] || {}; + const options = chart.options.elements[me.datasetElementType._type] || {}; const elementOptions = me._datasetElementOptions; const values = {}; const context = me._getContext(undefined, active); @@ -863,7 +865,7 @@ class DatasetController { const chart = me.chart; const datasetOpts = me._config; // @ts-ignore - const options = chart.options.elements[me.dataElementType.prototype._type] || {}; + const options = chart.options.elements[me.dataElementType._type] || {}; const elementOptions = me._dataElementOptions; const values = {}; const context = me._getContext(index, active); @@ -1128,8 +1130,6 @@ class DatasetController { } } -DatasetController.extend = helpers.inherits; - /** * Element type used to generate a meta dataset (e.g. Chart.element.Line). */ @@ -1170,5 +1170,3 @@ DatasetController.prototype._dataElementOptions = [ 'borderWidth', 'pointStyle' ]; - -export default DatasetController; diff --git a/src/core/core.defaults.js b/src/core/core.defaults.js index 3b60e87d3..33214dac8 100644 --- a/src/core/core.defaults.js +++ b/src/core/core.defaults.js @@ -1,6 +1,9 @@ import {merge} from '../helpers/helpers.core'; -class Defaults { +/** + * Please use the module's default export which provides a singleton instance + */ +export class Defaults { constructor() { this.color = 'rgba(0,0,0,0.1)'; this.elements = {}; @@ -35,7 +38,6 @@ class Defaults { /** * @param {string} scope * @param {*} values - * @private */ set(scope, values) { return merge(this[scope] || (this[scope] = {}), values); diff --git a/src/core/core.element.js b/src/core/core.element.js index 77cbc8ccb..54f4d77e9 100644 --- a/src/core/core.element.js +++ b/src/core/core.element.js @@ -1,7 +1,9 @@ import {inherits} from '../helpers/helpers.core'; import {isNumber} from '../helpers/helpers.math'; -class Element { +export default class Element { + + static extend = inherits; /** * @param {object} [cfg] optional configuration @@ -27,6 +29,3 @@ class Element { return isNumber(this.x) && isNumber(this.y); } } - -Element.extend = inherits; -export default Element; diff --git a/src/core/core.plugins.js b/src/core/core.plugins.js index f530ac9ff..9709fbe2e 100644 --- a/src/core/core.plugins.js +++ b/src/core/core.plugins.js @@ -14,7 +14,7 @@ defaults.set('plugins', {}); * @namespace Chart.plugins * @since 2.1.0 */ -class PluginService { +export class PluginService { constructor() { /** * Globally registered plugins. diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 1b9d31e01..63fc8973f 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -223,7 +223,7 @@ function skip(ticks, newTicks, spacing, majorStart, majorEnd) { } } -class Scale extends Element { +export default class Scale extends Element { // eslint-disable-next-line max-statements constructor(cfg) { @@ -1572,5 +1572,3 @@ class Scale extends Element { } Scale.prototype._draw = Scale.prototype.draw; - -export default Scale; diff --git a/src/elements/element.arc.js b/src/elements/element.arc.js index 5860216f1..8c972b521 100644 --- a/src/elements/element.arc.js +++ b/src/elements/element.arc.js @@ -84,7 +84,9 @@ function drawBorder(ctx, vm, arc) { ctx.stroke(); } -class Arc extends Element { +export default class Arc extends Element { + + static _type = 'arc'; constructor(cfg) { super(); @@ -184,7 +186,3 @@ class Arc extends Element { ctx.restore(); } } - -Arc.prototype._type = 'arc'; - -export default Arc; diff --git a/src/elements/element.line.js b/src/elements/element.line.js index 7836b3fa1..eacb96fbb 100644 --- a/src/elements/element.line.js +++ b/src/elements/element.line.js @@ -196,7 +196,9 @@ function _getInterpolationMethod(options) { return _pointInLine; } -class Line extends Element { +export default class Line extends Element { + + static _type = 'line'; constructor(cfg) { super(); @@ -355,7 +357,3 @@ class Line extends Element { ctx.restore(); } } - -Line.prototype._type = 'line'; - -export default Line; diff --git a/src/elements/element.point.js b/src/elements/element.point.js index e3c7c4e8e..6fc760f06 100644 --- a/src/elements/element.point.js +++ b/src/elements/element.point.js @@ -18,7 +18,9 @@ defaults.set('elements', { } }); -class Point extends Element { +export default class Point extends Element { + + static _type = 'point'; constructor(cfg) { super(); @@ -89,7 +91,3 @@ class Point extends Element { return options.radius + options.hitRadius; } } - -Point.prototype._type = 'point'; - -export default Point; diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index b9bab5ac8..57a933c26 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -126,7 +126,9 @@ function inRange(bar, x, y) { && (skipY || y >= bounds.top && y <= bounds.bottom); } -class Rectangle extends Element { +export default class Rectangle extends Element { + + static _type = 'rectangle'; constructor(cfg) { super(); @@ -194,7 +196,3 @@ class Rectangle extends Element { return axis === 'x' ? this.width / 2 : this.height / 2; } } - -Rectangle.prototype._type = 'rectangle'; - -export default Rectangle; diff --git a/src/plugins/plugin.legend.js b/src/plugins/plugin.legend.js index 1a40e55c9..1b8a27cd4 100644 --- a/src/plugins/plugin.legend.js +++ b/src/plugins/plugin.legend.js @@ -95,10 +95,7 @@ function getBoxWidth(labelOpts, fontSize) { labelOpts.boxWidth; } -/** - * IMPORTANT: this class is exposed publicly as Chart.Legend, backward compatibility required! - */ -class Legend extends Element { +export class Legend extends Element { constructor(config) { super(); diff --git a/src/plugins/plugin.title.js b/src/plugins/plugin.title.js index 65b9bf5ba..9f4ce932a 100644 --- a/src/plugins/plugin.title.js +++ b/src/plugins/plugin.title.js @@ -14,10 +14,7 @@ defaults.set('title', { weight: 2000 // by default greater than legend (1000) to be above }); -/** - * IMPORTANT: this class is exposed publicly as Chart.Title, backward compatibility required! - */ -class Title extends Element { +export class Title extends Element { constructor(config) { super(); diff --git a/src/plugins/plugin.tooltip.js b/src/plugins/plugin.tooltip.js index 85664e721..75415ebb3 100644 --- a/src/plugins/plugin.tooltip.js +++ b/src/plugins/plugin.tooltip.js @@ -449,7 +449,7 @@ function getBeforeAfterBodyLines(callback) { return pushOrConcat([], splitNewlines(callback)); } -class Tooltip extends Element { +export class Tooltip extends Element { constructor(config) { super(); diff --git a/src/scales/scale.category.js b/src/scales/scale.category.js index a30409a6a..9a2e1fb59 100644 --- a/src/scales/scale.category.js +++ b/src/scales/scale.category.js @@ -3,7 +3,10 @@ import Scale from '../core/core.scale'; const defaultConfig = { }; -class CategoryScale extends Scale { +export default class CategoryScale extends Scale { + + // INTERNAL: static default options, registered in src/index.js + static _defaults = defaultConfig; constructor(cfg) { super(cfg); @@ -106,7 +109,3 @@ class CategoryScale extends Scale { return this.bottom; } } - -// INTERNAL: static default options, registered in src/index.js -CategoryScale._defaults = defaultConfig; -export default CategoryScale; diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 8d7f0c4c3..abf878dd2 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -9,7 +9,11 @@ const defaultConfig = { } }; -class LinearScale extends LinearScaleBase { +export default class LinearScale extends LinearScaleBase { + + // INTERNAL: static default options, registered in src/index.js + static _defaults = defaultConfig; + determineDataLimits() { const me = this; const options = me.options; @@ -70,7 +74,3 @@ class LinearScale extends LinearScaleBase { return this.getPixelForValue(ticks[index].value); } } - -// INTERNAL: static default options, registered in src/index.js -LinearScale._defaults = defaultConfig; -export default LinearScale; diff --git a/src/scales/scale.linearbase.js b/src/scales/scale.linearbase.js index d8b2e360a..69a2ae1a0 100644 --- a/src/scales/scale.linearbase.js +++ b/src/scales/scale.linearbase.js @@ -106,7 +106,7 @@ function generateTicks(generationOptions, dataRange) { return ticks; } -class LinearScaleBase extends Scale { +export default class LinearScaleBase extends Scale { constructor(cfg) { super(cfg); @@ -302,5 +302,3 @@ class LinearScaleBase extends Scale { return new Intl.NumberFormat(this.options.locale).format(value); } } - -export default LinearScaleBase; diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 2b21b78e5..261174d44 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -57,7 +57,10 @@ const defaultConfig = { } }; -class LogarithmicScale extends Scale { +export default class LogarithmicScale extends Scale { + + // INTERNAL: static default options, registered in src/index.js + static _defaults = defaultConfig; constructor(cfg) { super(cfg); @@ -194,7 +197,3 @@ class LogarithmicScale extends Scale { return Math.pow(10, me._startValue + decimal * me._valueRange); } } - -// INTERNAL: static default options, registered in src/index.js -LogarithmicScale._defaults = defaultConfig; -export default LogarithmicScale; diff --git a/src/scales/scale.radialLinear.js b/src/scales/scale.radialLinear.js index bf74e92fc..0b82e5d93 100644 --- a/src/scales/scale.radialLinear.js +++ b/src/scales/scale.radialLinear.js @@ -290,7 +290,10 @@ function numberOrZero(param) { return isNumber(param) ? param : 0; } -class RadialLinearScale extends LinearScaleBase { +export default class RadialLinearScale extends LinearScaleBase { + + // INTERNAL: static default options, registered in src/index.js + static _defaults = defaultConfig; constructor(cfg) { super(cfg); @@ -540,7 +543,3 @@ class RadialLinearScale extends LinearScaleBase { */ _drawTitle() {} } - -// INTERNAL: static default options, registered in src/index.js -RadialLinearScale._defaults = defaultConfig; -export default RadialLinearScale; diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index 7f4fcd6a7..9b25dc5b2 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -564,7 +564,10 @@ const defaultConfig = { } }; -class TimeScale extends Scale { +export default class TimeScale extends Scale { + + // INTERNAL: static default options, registered in src/index.js + static _defaults = defaultConfig; /** * @param {object} props @@ -844,7 +847,3 @@ class TimeScale extends Scale { return capacity > 0 ? capacity : 1; } } - -// INTERNAL: static default options, registered in src/index.js -TimeScale._defaults = defaultConfig; -export default TimeScale; diff --git a/tsconfig.json b/tsconfig.json index 67450a43d..0997d3393 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,6 +13,7 @@ "typedocOptions": { "name": "Chart.js", "excludeExternals": true, + "excludeNotExported": true, "includeVersion": true, "inputFiles": ["./src"], "out": "./dist/docs/typedoc" -- 2.47.2