"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",
--- /dev/null
+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
+ },
+ }
+ }
+ });
+}
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;
return;
}
+ const animationOptions = Object.keys(defaults.animation);
const animatedProps = this._properties;
Object.getOwnPropertyNames(config).forEach(key => {
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);
* 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)';
this.drawActiveElementsOnTop = true;
this.describe(_descriptors);
+ this.apply(_appliers);
}
/**
}
});
}
+
+ apply(appliers) {
+ appliers.forEach((apply) => apply(this));
+ }
}
// singleton instance
_scriptable: false,
_indexable: false,
}
-});
+}, [applyAnimationsDefaults, applyLayoutsDefaults, applyScaleDefaults]);
--- /dev/null
+export function applyLayoutsDefaults(defaults) {
+ defaults.set('layout', {
+ autoPadding: true,
+ padding: {
+ top: 0,
+ right: 0,
+ bottom: 0,
+ left: 0
+ }
+ });
+}
-import defaults from './core.defaults';
import {defined, each, isObject} from '../helpers/helpers.core';
import {toPadding} from '../helpers/helpers.options';
chartArea.y = y;
}
-defaults.set('layout', {
- autoPadding: true,
- padding: {
- top: 0,
- right: 0,
- bottom: 0,
- left: 0
- }
-});
-
/**
* @interface LayoutItem
* @typedef {object} LayoutItem
-import defaults from './core.defaults';
import Ticks from './core.ticks';
-defaults.set('scale', {
- display: true,
- offset: false,
- reverse: false,
- beginAtZero: false,
+export function applyScaleDefaults(defaults) {
+ defaults.set('scale', {
+ display: true,
+ offset: false,
+ reverse: false,
+ beginAtZero: false,
- /**
- * Scale boundary strategy (bypassed by min/max time options)
- * - `data`: make sure data are fully visible, ticks outside are removed
- * - `ticks`: make sure ticks are fully visible, data outside are truncated
- * @see https://github.com/chartjs/Chart.js/pull/4556
- * @since 3.0.0
- */
- bounds: 'ticks',
+ /**
+ * Scale boundary strategy (bypassed by min/max time options)
+ * - `data`: make sure data are fully visible, ticks outside are removed
+ * - `ticks`: make sure ticks are fully visible, data outside are truncated
+ * @see https://github.com/chartjs/Chart.js/pull/4556
+ * @since 3.0.0
+ */
+ bounds: 'ticks',
- /**
- * Addition grace added to max and reduced from min data value.
- * @since 3.0.0
- */
- grace: 0,
+ /**
+ * Addition grace added to max and reduced from min data value.
+ * @since 3.0.0
+ */
+ grace: 0,
- // grid line settings
- grid: {
- display: true,
- lineWidth: 1,
- drawBorder: true,
- drawOnChartArea: true,
- drawTicks: true,
- tickLength: 8,
- tickWidth: (_ctx, options) => options.lineWidth,
- tickColor: (_ctx, options) => options.color,
- offset: false,
- borderDash: [],
- borderDashOffset: 0.0,
- borderWidth: 1
- },
+ // grid line settings
+ grid: {
+ display: true,
+ lineWidth: 1,
+ drawBorder: true,
+ drawOnChartArea: true,
+ drawTicks: true,
+ tickLength: 8,
+ tickWidth: (_ctx, options) => options.lineWidth,
+ tickColor: (_ctx, options) => options.color,
+ offset: false,
+ borderDash: [],
+ borderDashOffset: 0.0,
+ borderWidth: 1
+ },
- // scale title
- title: {
- // display property
- display: false,
+ // scale title
+ title: {
+ // display property
+ display: false,
- // actual label
- text: '',
+ // actual label
+ text: '',
- // top/bottom padding
- padding: {
- top: 4,
- bottom: 4
- }
- },
+ // top/bottom padding
+ padding: {
+ top: 4,
+ bottom: 4
+ }
+ },
- // label settings
- ticks: {
- minRotation: 0,
- maxRotation: 50,
- mirror: false,
- textStrokeWidth: 0,
- textStrokeColor: '',
- padding: 3,
- display: true,
- autoSkip: true,
- autoSkipPadding: 3,
- labelOffset: 0,
- // We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
- callback: Ticks.formatters.values,
- minor: {},
- major: {},
- align: 'center',
- crossAlign: 'near',
+ // label settings
+ ticks: {
+ minRotation: 0,
+ maxRotation: 50,
+ mirror: false,
+ textStrokeWidth: 0,
+ textStrokeColor: '',
+ padding: 3,
+ display: true,
+ autoSkip: true,
+ autoSkipPadding: 3,
+ labelOffset: 0,
+ // We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
+ callback: Ticks.formatters.values,
+ minor: {},
+ major: {},
+ align: 'center',
+ crossAlign: 'near',
- showLabelBackdrop: false,
- backdropColor: 'rgba(255, 255, 255, 0.75)',
- backdropPadding: 2,
- }
-});
+ showLabelBackdrop: false,
+ backdropColor: 'rgba(255, 255, 255, 0.75)',
+ backdropPadding: 2,
+ }
+ });
-defaults.route('scale.ticks', 'color', '', 'color');
-defaults.route('scale.grid', 'color', '', 'borderColor');
-defaults.route('scale.grid', 'borderColor', '', 'borderColor');
-defaults.route('scale.title', 'color', '', 'color');
+ defaults.route('scale.ticks', 'color', '', 'color');
+ defaults.route('scale.grid', 'color', '', 'borderColor');
+ defaults.route('scale.grid', 'borderColor', '', 'borderColor');
+ defaults.route('scale.title', 'color', '', 'color');
-defaults.describe('scale', {
- _fallback: false,
- _scriptable: (name) => !name.startsWith('before') && !name.startsWith('after') && name !== 'callback' && name !== 'parser',
- _indexable: (name) => name !== 'borderDash' && name !== 'tickBorderDash',
-});
+ defaults.describe('scale', {
+ _fallback: false,
+ _scriptable: (name) => !name.startsWith('before') && !name.startsWith('after') && name !== 'callback' && name !== 'parser',
+ _indexable: (name) => name !== 'borderDash' && name !== 'tickBorderDash',
+ });
-defaults.describe('scales', {
- _fallback: 'scale',
-});
+ defaults.describe('scales', {
+ _fallback: 'scale',
+ });
-defaults.describe('scale.ticks', {
- _scriptable: (name) => name !== 'backdropPadding' && name !== 'callback',
- _indexable: (name) => name !== 'backdropPadding',
-});
+ defaults.describe('scale.ticks', {
+ _scriptable: (name) => name !== 'backdropPadding' && name !== 'callback',
+ _indexable: (name) => name !== 'backdropPadding',
+ });
+}
import {toDegrees, toRadians, _int16Range, _limitValue, HALF_PI} from '../helpers/helpers.math';
import {_alignStartEnd, _toLeftRightCenter} from '../helpers/helpers.extras';
import {createContext, toFont, toPadding, _addGrace} from '../helpers/helpers.options';
-
-import './core.scale.defaults';
-
-
import {autoSkip} from './core.scale.autoskip';
-
const reverseAlign = (align) => align === 'left' ? 'right' : align === 'right' ? 'left' : align;
const offsetFromEdge = (scale, edge, offset) => edge === 'top' || edge === 'left' ? scale[edge] + offset : scale[edge] - offset;
/**
* @type {Unit[]}
*/
-const UNITS = /** @type Unit[] */(Object.keys(INTERVALS));
+const UNITS = /** @type Unit[] */ /* #__PURE__ */ (Object.keys(INTERVALS));
/**
* @param {number} a