From e4b08c1bbc30fd03839f49c919fd1314003b38c0 Mon Sep 17 00:00:00 2001 From: Jacco van den Berg Date: Fri, 26 Aug 2022 00:58:48 +0200 Subject: [PATCH] start moving lecacy scale hooks to plugin --- src/core/core.scale.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 4ad607903fd..2897782f16c 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -370,7 +370,7 @@ export default class Scale extends Element { // Any function can be extended by the scale type beforeUpdate() { - call(this.options.beforeUpdate, [this]); + this._callHooks('beforeUpdate'); } /** @@ -489,13 +489,11 @@ export default class Scale extends Element { } afterUpdate() { - call(this.options.afterUpdate, [this]); + this._callHooks('afterUpdate'); } - // - beforeSetDimensions() { - call(this.options.beforeSetDimensions, [this]); + this._callHooks('beforeSetDimensions'); } setDimensions() { // Set the unconstrained dimension before label rotation @@ -519,7 +517,7 @@ export default class Scale extends Element { this.paddingBottom = 0; } afterSetDimensions() { - call(this.options.afterSetDimensions, [this]); + this._callHooks('afterSetDimension'); } _callHooks(name) { @@ -536,10 +534,10 @@ export default class Scale extends Element { this._callHooks('afterDataLimits'); } - // beforeBuildTicks() { this._callHooks('beforeBuildTicks'); } + /** * @return {object[]} the ticks */ @@ -551,8 +549,9 @@ export default class Scale extends Element { } beforeTickToLabelConversion() { - call(this.options.beforeTickToLabelConversion, [this]); + this._callHooks('beforeTickToLabelConversion'); } + /** * Convert ticks to label strings * @param {Tick[]} ticks @@ -566,14 +565,13 @@ export default class Scale extends Element { } } afterTickToLabelConversion() { - call(this.options.afterTickToLabelConversion, [this]); + this._callHooks('afterTickToLabelConversion'); } - // - beforeCalculateLabelRotation() { - call(this.options.beforeCalculateLabelRotation, [this]); + this._callHooks('beforeCalculateLabelRotation'); } + calculateLabelRotation() { const options = this.options; const tickOpts = options.ticks; @@ -612,16 +610,17 @@ export default class Scale extends Element { this.labelRotation = labelRotation; } + afterCalculateLabelRotation() { - call(this.options.afterCalculateLabelRotation, [this]); + this._callHooks('afterCalculateLabelRotation'); } - afterAutoSkip() {} - // + afterAutoSkip() {} beforeFit() { - call(this.options.beforeFit, [this]); + this._callHooks('beforeFit'); } + fit() { // Reset const minSize = { @@ -741,7 +740,7 @@ export default class Scale extends Element { } afterFit() { - call(this.options.afterFit, [this]); + this._callHooks('afterFit'); } // Shared Methods