mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 12:19:08 +02:00
Move scale defaults to separate file (#8692)
This commit is contained in:
parent
bd9bc69c0c
commit
9499a1e1ef
90
src/core/core.scale.defaults.js
Normal file
90
src/core/core.scale.defaults.js
Normal file
@ -0,0 +1,90 @@
|
||||
import defaults from './core.defaults';
|
||||
import Ticks from './core.ticks';
|
||||
|
||||
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',
|
||||
|
||||
/**
|
||||
* 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,
|
||||
borderColor: (_ctx, options) => options.color,
|
||||
borderWidth: (_ctx, options) => options.lineWidth
|
||||
},
|
||||
|
||||
// scale title
|
||||
title: {
|
||||
// display property
|
||||
display: false,
|
||||
|
||||
// actual label
|
||||
text: '',
|
||||
|
||||
// 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',
|
||||
}
|
||||
});
|
||||
|
||||
defaults.route('scale.ticks', 'color', '', 'color');
|
||||
defaults.route('scale.grid', 'color', '', '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('scales', {
|
||||
_fallback: 'scale',
|
||||
});
|
@ -1,13 +1,16 @@
|
||||
import defaults from './core.defaults';
|
||||
import Element from './core.element';
|
||||
import {_alignPixel, _measureText, renderText, clipArea, unclipArea} from '../helpers/helpers.canvas';
|
||||
import {callback as call, each, finiteOrDefault, isArray, isFinite, isNullOrUndef, isObject} from '../helpers/helpers.core';
|
||||
import {toDegrees, toRadians, _int16Range, _limitValue, HALF_PI} from '../helpers/helpers.math';
|
||||
import {_alignStartEnd, _toLeftRightCenter} from '../helpers/helpers.extras';
|
||||
import {toFont, toPadding} from '../helpers/helpers.options';
|
||||
import Ticks from './core.ticks';
|
||||
|
||||
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;
|
||||
|
||||
@ -16,94 +19,6 @@ const offsetFromEdge = (scale, edge, offset) => edge === 'top' || edge === 'left
|
||||
* @typedef {{value:number | string, label?:string, major?:boolean, $context?:any}} Tick
|
||||
*/
|
||||
|
||||
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',
|
||||
|
||||
/**
|
||||
* 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,
|
||||
borderColor: (_ctx, options) => options.color,
|
||||
borderWidth: (_ctx, options) => options.lineWidth
|
||||
},
|
||||
|
||||
// scale title
|
||||
title: {
|
||||
// display property
|
||||
display: false,
|
||||
|
||||
// actual label
|
||||
text: '',
|
||||
|
||||
// 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',
|
||||
}
|
||||
});
|
||||
|
||||
defaults.route('scale.ticks', 'color', '', 'color');
|
||||
defaults.route('scale.grid', 'color', '', '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('scales', {
|
||||
_fallback: 'scale',
|
||||
});
|
||||
|
||||
/**
|
||||
* Returns a new array containing numItems from arr
|
||||
* @param {any[]} arr
|
||||
|
Loading…
Reference in New Issue
Block a user