Skip to content

Commit 592aa38

Browse files
committed
Allow core.scale to be checked by TypeScript compiler
1 parent 12333b0 commit 592aa38

File tree

1 file changed

+92
-13
lines changed

1 file changed

+92
-13
lines changed

src/core/core.scale.js

Lines changed: 92 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,82 @@ function skip(ticks, newTicks, spacing, majorStart, majorEnd) {
228228

229229
class Scale extends Element {
230230

231+
constructor(cfg) {
232+
super();
233+
234+
/** @type {string} */
235+
this.id = cfg.id;
236+
this.type = cfg.type;
237+
/** @type {object} */
238+
this.options = cfg.options;
239+
this.ctx = cfg.ctx;
240+
this.chart = cfg.chart;
241+
242+
// implements box
243+
/** @type {number | undefined} */
244+
this.top = undefined;
245+
/** @type {number | undefined} */
246+
this.bottom = undefined;
247+
/** @type {number | undefined} */
248+
this.left = undefined;
249+
/** @type {number | undefined} */
250+
this.right = undefined;
251+
/** @type {number | undefined} */
252+
this.width = undefined;
253+
/** @type {number | undefined} */
254+
this.height = undefined;
255+
this.margins = {
256+
left: 0,
257+
right: 0,
258+
top: 0,
259+
bottom: 0
260+
};
261+
// TODO: make maxWidth, maxHeight private
262+
/** @type {number | undefined} */
263+
this.maxWidth = undefined;
264+
/** @type {number | undefined} */
265+
this.maxHeight = undefined;
266+
/** @type {number | undefined} */
267+
this.paddingTop = undefined;
268+
/** @type {number | undefined} */
269+
this.paddingBottom = undefined;
270+
/** @type {number | undefined} */
271+
this.paddingLeft = undefined;
272+
/** @type {number | undefined} */
273+
this.paddingRight = undefined;
274+
275+
// scale-specific properties
276+
/** @type {string | undefined} */
277+
this.axis = undefined;
278+
/** @type {number | undefined} */
279+
this.labelRotation = undefined;
280+
this.min = undefined;
281+
this.max = undefined;
282+
/** @type {object[]} */
283+
this.ticks = null;
284+
/** @type {object[]} */
285+
this._gridLineItems = null;
286+
/** @type {object[]} */
287+
this._labelItems = null;
288+
/** @type {object} */
289+
this._labelSizes = null;
290+
/** @type {number | undefined} */
291+
this._length = undefined;
292+
/** @type {object} */
293+
this._longestTextCache = {};
294+
/** @type {number | undefined} */
295+
this._maxLabelLines = undefined;
296+
/** @type {number | undefined} */
297+
this._startPixel = undefined;
298+
/** @type {number | undefined} */
299+
this._endPixel = undefined;
300+
this._reversePixels = undefined;
301+
this._userMax = undefined;
302+
this._userMin = undefined;
303+
this._ticksLength = undefined;
304+
this._borderValue = undefined;
305+
}
306+
231307
/**
232308
* Parse a supported input value to internal representation.
233309
* @param {*} raw
@@ -303,7 +379,7 @@ class Scale extends Element {
303379
* Get the padding needed for the scale
304380
* @method getPadding
305381
* @private
306-
* @returns {Padding} the necessary padding
382+
* @returns {object} the necessary padding
307383
*/
308384
getPadding() {
309385
const me = this;
@@ -357,7 +433,6 @@ class Scale extends Element {
357433
me.beforeUpdate();
358434

359435
// Absorb the master measurements
360-
// TODO: make maxWidth, maxHeight private
361436
me.maxWidth = maxWidth;
362437
me.maxHeight = maxHeight;
363438
me.margins = helpers.extend({
@@ -370,7 +445,6 @@ class Scale extends Element {
370445
me.ticks = null;
371446
me._labelSizes = null;
372447
me._maxLabelLines = 0;
373-
me._longestTextCache = me._longestTextCache || {};
374448
me._gridLineItems = null;
375449
me._labelItems = null;
376450

@@ -495,7 +569,12 @@ class Scale extends Element {
495569
beforeBuildTicks() {
496570
helpers.callback(this.options.beforeBuildTicks, [this]);
497571
}
498-
buildTicks() {}
572+
/**
573+
* @return {object[]} the ticks
574+
*/
575+
buildTicks() {
576+
throw new Error('buildTicks must be overriden by a child class');
577+
}
499578
afterBuildTicks() {
500579
helpers.callback(this.options.afterBuildTicks, [this]);
501580
}
@@ -804,17 +883,17 @@ class Scale extends Element {
804883
* Returns the location of the given data point. Value can either be an index or a numerical value
805884
* The coordinate (0, 0) is at the upper-left corner of the canvas
806885
* @param value
807-
* @param index
808-
* @param datasetIndex
809886
*/
810-
getPixelForValue() {}
887+
// eslint-disable-next-line no-unused-vars
888+
getPixelForValue(value) {}
811889

812890
/**
813891
* Used to get the data value from a given pixel. This is the inverse of getPixelForValue
814892
* The coordinate (0, 0) is at the upper-left corner of the canvas
815893
* @param pixel
816894
*/
817-
getValueForPixel() {}
895+
// eslint-disable-next-line no-unused-vars
896+
getValueForPixel(pixel) {}
818897

819898
/**
820899
* Returns the location of the tick at the given index
@@ -1063,8 +1142,8 @@ class Scale extends Element {
10631142
});
10641143
}
10651144

1066-
items.ticksLength = ticksLength;
1067-
items.borderValue = borderValue;
1145+
me._ticksLength = ticksLength;
1146+
me._borderValue = borderValue;
10681147

10691148
return items;
10701149
}
@@ -1209,10 +1288,10 @@ class Scale extends Element {
12091288
const firstLineWidth = axisWidth;
12101289
context = {
12111290
scale: me,
1212-
tick: me.ticks[items.ticksLength - 1],
1291+
tick: me.ticks[me._ticksLength - 1],
12131292
};
1214-
const lastLineWidth = resolve([gridLines.lineWidth, 1], context, items.ticksLength - 1);
1215-
const borderValue = items.borderValue;
1293+
const lastLineWidth = resolve([gridLines.lineWidth, 1], context, me._ticksLength - 1);
1294+
const borderValue = me._borderValue;
12161295
let x1, x2, y1, y2;
12171296

12181297
if (me.isHorizontal()) {

0 commit comments

Comments
 (0)