Skip to content

Commit

Permalink
Fix errors reported by TypeScript compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Feb 3, 2020
1 parent 1c18a74 commit b8552ad
Show file tree
Hide file tree
Showing 28 changed files with 542 additions and 117 deletions.
127 changes: 127 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
"rollup-plugin-istanbul": "^2.0.1",
"rollup-plugin-node-resolve": "^5.0.0",
"rollup-plugin-terser": "^5.1.3",
"typedoc": "^0.16.9",
"typescript": "^3.7.5",
"yargs": "^14.0.0"
},
"dependencies": {
Expand Down
21 changes: 10 additions & 11 deletions src/core/core.animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const interpolators = {

class Animation {
constructor(cfg, target, prop, to) {
const me = this;
let from = cfg.from;

if (from === undefined) {
Expand All @@ -34,16 +33,16 @@ class Animation {
to = from;
}

me._active = true;
me._fn = cfg.fn || interpolators[cfg.type || typeof from];
me._easing = helpers.easing.effects[cfg.easing || 'linear'];
me._start = Math.floor(Date.now() + (cfg.delay || 0));
me._duration = Math.floor(cfg.duration);
me._loop = !!cfg.loop;
me._target = target;
me._prop = prop;
me._from = from;
me._to = to;
this._active = true;
this._fn = cfg.fn || interpolators[cfg.type || typeof from];
this._easing = helpers.easing.effects[cfg.easing || 'linear'];
this._start = Math.floor(Date.now() + (cfg.delay || 0));
this._duration = Math.floor(cfg.duration);
this._loop = !!cfg.loop;
this._target = target;
this._prop = prop;
this._from = from;
this._to = to;
}

active() {
Expand Down
5 changes: 5 additions & 0 deletions src/core/core.animator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import helpers from '../helpers';

/**
* @typedef { import("./core.controller") } Chart
*/

function drawFPS(chart, count, date, lastDate) {
const fps = (1000 / (date - lastDate)) | 0;
const ctx = chart.ctx;
Expand All @@ -21,6 +25,7 @@ class Animator {
this._request = null;
this._charts = new Map();
this._running = false;
this._lastDate = undefined;
}

/**
Expand Down
46 changes: 27 additions & 19 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,35 @@ class Chart {

config = initConfig(config);
const initialCanvas = getCanvas(item);
me._initializePlatform(initialCanvas, config);
this.platform = me._initializePlatform(initialCanvas, config);

const context = me.platform.acquireContext(initialCanvas, config);
const canvas = context && context.canvas;
const height = canvas && canvas.height;
const width = canvas && canvas.width;

me.id = helpers.uid();
me.ctx = context;
me.canvas = canvas;
me.config = config;
me.width = width;
me.height = height;
me.aspectRatio = height ? width / height : null;
me.options = config.options;
me._bufferedRender = false;
me._layers = [];
me._metasets = [];
this.id = helpers.uid();
this.ctx = context;
this.canvas = canvas;
this.config = config;
this.width = width;
this.height = height;
this.aspectRatio = height ? width / height : null;
this.options = config.options;
this._bufferedRender = false;
this._layers = [];
this._metasets = [];
this.boxes = [];
this.currentDevicePixelRatio = undefined;
this.chartArea = undefined;
this.data = undefined;
this.active = undefined;
this.lastActive = undefined;
this._lastEvent = undefined;
this._listeners = {};
this._sortedMetasets = [];
this._updating = false;
this.scales = {};

// Add the chart instance to the global namespace
Chart.instances[me.id] = me;
Expand Down Expand Up @@ -250,17 +261,14 @@ class Chart {
* @private
*/
_initializePlatform(canvas, config) {
const me = this;

if (config.platform) {
me.platform = new config.platform();
return new config.platform();
} else if (!isDomSupported()) {
me.platform = new BasicPlatform();
return new BasicPlatform();
} else if (window.OffscreenCanvas && canvas instanceof window.OffscreenCanvas) {
me.platform = new BasicPlatform();
} else {
me.platform = new DomPlatform();
return new BasicPlatform();
}
return new DomPlatform();
}

clear() {
Expand Down
12 changes: 7 additions & 5 deletions src/core/core.element.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {isNumber} from '../helpers/helpers.math';

class Element {

constructor(configuration) {
if (configuration) {
extend(this, configuration);
}
constructor(cfg) {
this.x = undefined;
this.y = undefined;
this.hidden = undefined;

// this.hidden = false; we assume Element has an attribute called hidden, but do not initialize to save memory
if (cfg) {
extend(this, cfg);
}
}

tooltipPosition() {
Expand Down
4 changes: 4 additions & 0 deletions src/core/core.interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import helpers from '../helpers/index';
import {_isPointInArea} from '../helpers/helpers.canvas';
import {_lookup, _rlookup} from '../helpers/helpers.collection';

/**
* @typedef { import("./core.controller") } Chart
*/

/**
* Helper function to get relative position for an event
* @param {Event|IEvent} e - The event to get the position for
Expand Down
4 changes: 4 additions & 0 deletions src/core/core.layouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import defaults from './core.defaults';
import helpers from '../helpers';

/**
* @typedef { import("./core.controller") } Chart
*/

const extend = helpers.extend;

const STATIC_POSITIONS = ['left', 'top', 'right', 'bottom'];
Expand Down

0 comments on commit b8552ad

Please sign in to comment.