Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"version": "4.0.0-dev",
"license": "MIT",
"type": "module",
"sideEffects": [
"./auto/auto.js",
"./dist/chart.umd.js"
],
"jsdelivr": "dist/chart.umd.js",
"unpkg": "dist/chart.umd.js",
"main": "dist/chart.js",
Expand Down
72 changes: 72 additions & 0 deletions src/core/core.animations.defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const numbers = ['x', 'y', 'borderWidth', 'radius', 'tension'];
const colors = ['color', 'borderColor', 'backgroundColor'];

export function applyAnimationsDefaults(defaults) {
defaults.set('animation', {
delay: undefined,
duration: 1000,
easing: 'easeOutQuart',
fn: undefined,
from: undefined,
loop: undefined,
to: undefined,
type: undefined,
});

defaults.describe('animation', {
_fallback: false,
_indexable: false,
_scriptable: (name) => name !== 'onProgress' && name !== 'onComplete' && name !== 'fn',
});

defaults.set('animations', {
colors: {
type: 'color',
properties: colors
},
numbers: {
type: 'number',
properties: numbers
},
});

defaults.describe('animations', {
_fallback: 'animation',
});

defaults.set('transitions', {
active: {
animation: {
duration: 400
}
},
resize: {
animation: {
duration: 0
}
},
show: {
animations: {
colors: {
from: 'transparent'
},
visible: {
type: 'boolean',
duration: 0 // show immediately
},
}
},
hide: {
animations: {
colors: {
to: 'transparent'
},
visible: {
type: 'boolean',
easing: 'linear',
fn: v => v | 0 // for keeping the dataset visible all the way through the animation
},
}
}
});
}
74 changes: 1 addition & 73 deletions src/core/core.animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,79 +3,6 @@ import Animation from './core.animation';
import defaults from './core.defaults';
import {isArray, isObject} from '../helpers/helpers.core';

const numbers = ['x', 'y', 'borderWidth', 'radius', 'tension'];
const colors = ['color', 'borderColor', 'backgroundColor'];

defaults.set('animation', {
delay: undefined,
duration: 1000,
easing: 'easeOutQuart',
fn: undefined,
from: undefined,
loop: undefined,
to: undefined,
type: undefined,
});

const animationOptions = Object.keys(defaults.animation);

defaults.describe('animation', {
_fallback: false,
_indexable: false,
_scriptable: (name) => name !== 'onProgress' && name !== 'onComplete' && name !== 'fn',
});

defaults.set('animations', {
colors: {
type: 'color',
properties: colors
},
numbers: {
type: 'number',
properties: numbers
},
});

defaults.describe('animations', {
_fallback: 'animation',
});

defaults.set('transitions', {
active: {
animation: {
duration: 400
}
},
resize: {
animation: {
duration: 0
}
},
show: {
animations: {
colors: {
from: 'transparent'
},
visible: {
type: 'boolean',
duration: 0 // show immediately
},
}
},
hide: {
animations: {
colors: {
to: 'transparent'
},
visible: {
type: 'boolean',
easing: 'linear',
fn: v => v | 0 // for keeping the dataset visible all the way through the animation
},
}
}
});

export default class Animations {
constructor(chart, config) {
this._chart = chart;
Expand All @@ -88,6 +15,7 @@ export default class Animations {
return;
}

const animationOptions = Object.keys(defaults.animation);
const animatedProps = this._properties;

Object.getOwnPropertyNames(config).forEach(key => {
Expand Down
12 changes: 10 additions & 2 deletions src/core/core.defaults.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {getHoverColor} from '../helpers/helpers.color';
import {isObject, merge, valueOrDefault} from '../helpers/helpers.core';
import {applyAnimationsDefaults} from './core.animations.defaults';
import {applyLayoutsDefaults} from './core.layouts.defaults';
import {applyScaleDefaults} from './core.scale.defaults';

export const overrides = Object.create(null);
export const descriptors = Object.create(null);
Expand Down Expand Up @@ -33,7 +36,7 @@ function set(root, scope, values) {
* Note: class is exported for typedoc
*/
export class Defaults {
constructor(_descriptors) {
constructor(_descriptors, _appliers) {
this.animation = undefined;
this.backgroundColor = 'rgba(0,0,0,0.1)';
this.borderColor = 'rgba(0,0,0,0.1)';
Expand Down Expand Up @@ -77,6 +80,7 @@ export class Defaults {
this.drawActiveElementsOnTop = true;

this.describe(_descriptors);
this.apply(_appliers);
}

/**
Expand Down Expand Up @@ -151,6 +155,10 @@ export class Defaults {
}
});
}

apply(appliers) {
appliers.forEach((apply) => apply(this));
}
}

// singleton instance
Expand All @@ -164,4 +172,4 @@ export default /* #__PURE__ */ new Defaults({
_scriptable: false,
_indexable: false,
}
});
}, [applyAnimationsDefaults, applyLayoutsDefaults, applyScaleDefaults]);
11 changes: 11 additions & 0 deletions src/core/core.layouts.defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function applyLayoutsDefaults(defaults) {
defaults.set('layout', {
autoPadding: true,
padding: {
top: 0,
right: 0,
bottom: 0,
left: 0
}
});
}
11 changes: 0 additions & 11 deletions src/core/core.layouts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import defaults from './core.defaults';
import {defined, each, isObject} from '../helpers/helpers.core';
import {toPadding} from '../helpers/helpers.options';

Expand Down Expand Up @@ -259,16 +258,6 @@ function placeBoxes(boxes, chartArea, params, stacks) {
chartArea.y = y;
}

defaults.set('layout', {
autoPadding: true,
padding: {
top: 0,
right: 0,
bottom: 0,
left: 0
}
});

/**
* @interface LayoutItem
* @typedef {object} LayoutItem
Expand Down
Loading