Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move scale defaults to separate file #8692

Merged
merged 2 commits into from
Mar 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
90 changes: 90 additions & 0 deletions src/core/core.scale.defaults.js
Original file line number Diff line number Diff line change
@@ -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',
});
91 changes: 1 addition & 90 deletions src/core/core.scale.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
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, valueOrDefault} from '../helpers/helpers.core';
import {_factorize, 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';

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;
Expand All @@ -15,94 +14,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
Expand Down