Skip to content

Commit

Permalink
refactor: rewrite canvas helpers to ts (#11100)
Browse files Browse the repository at this point in the history
* refactor: rewrite canvas helpers to ts

* refactor: review fixes

* refactor: rm src/helpers/types.ts temporary entry point
  • Loading branch information
dangreen committed Feb 15, 2023
1 parent 22c6906 commit 1324672
Show file tree
Hide file tree
Showing 12 changed files with 374 additions and 362 deletions.
5 changes: 3 additions & 2 deletions src/core/core.scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const offsetFromEdge = (scale, edge, offset) => edge === 'top' || edge === 'left
const getTicksLimit = (ticksLength, maxTicksLimit) => Math.min(maxTicksLimit || ticksLength, ticksLength);

/**
* @typedef { import('./core.controller.js').default } Chart
* @typedef { import('../types/index.js').Chart } Chart
* @typedef {{value:number | string, label?:string, major?:boolean, $context?:any}} Tick
*/

Expand Down Expand Up @@ -120,6 +120,7 @@ function createTickContext(parent, index, tick) {
}

function titleAlign(align, position, reverse) {
/** @type {CanvasTextAlign} */
let ret = _toLeftRightCenter(align);
if ((reverse && position !== 'right') || (!reverse && position === 'right')) {
ret = reverseAlign(ret);
Expand Down Expand Up @@ -839,7 +840,7 @@ export default class Scale extends Element {
} else if (isArray(label)) {
// if it is an array let's measure each element
for (j = 0, jlen = label.length; j < jlen; ++j) {
nestedLabel = label[j];
nestedLabel = /** @type {string} */ (label[j]);
// Undefined labels and arrays should not be measured
if (!isNullOrUndef(nestedLabel) && !isArray(nestedLabel)) {
width = _measureText(ctx, cache.data, cache.gc, width, nestedLabel);
Expand Down
3 changes: 3 additions & 0 deletions src/elements/element.line.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function lineTo(ctx, previous, target) {
ctx.lineTo(target.x, target.y);
}

/**
* @returns {any}
*/
function getLineMethod(options) {
if (options.stepped) {
return _steppedLineTo;
Expand Down

0 comments on commit 1324672

Please sign in to comment.