Skip to content

Commit 9499a1e

Browse files
authored
Move scale defaults to separate file (#8692)
1 parent bd9bc69 commit 9499a1e

File tree

2 files changed

+95
-90
lines changed

2 files changed

+95
-90
lines changed

src/core/core.scale.defaults.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import defaults from './core.defaults';
2+
import Ticks from './core.ticks';
3+
4+
defaults.set('scale', {
5+
display: true,
6+
offset: false,
7+
reverse: false,
8+
beginAtZero: false,
9+
10+
/**
11+
* Scale boundary strategy (bypassed by min/max time options)
12+
* - `data`: make sure data are fully visible, ticks outside are removed
13+
* - `ticks`: make sure ticks are fully visible, data outside are truncated
14+
* @see https://github.com/chartjs/Chart.js/pull/4556
15+
* @since 3.0.0
16+
*/
17+
bounds: 'ticks',
18+
19+
/**
20+
* Addition grace added to max and reduced from min data value.
21+
* @since 3.0.0
22+
*/
23+
grace: 0,
24+
25+
// grid line settings
26+
grid: {
27+
display: true,
28+
lineWidth: 1,
29+
drawBorder: true,
30+
drawOnChartArea: true,
31+
drawTicks: true,
32+
tickLength: 8,
33+
tickWidth: (_ctx, options) => options.lineWidth,
34+
tickColor: (_ctx, options) => options.color,
35+
offset: false,
36+
borderDash: [],
37+
borderDashOffset: 0.0,
38+
borderColor: (_ctx, options) => options.color,
39+
borderWidth: (_ctx, options) => options.lineWidth
40+
},
41+
42+
// scale title
43+
title: {
44+
// display property
45+
display: false,
46+
47+
// actual label
48+
text: '',
49+
50+
// top/bottom padding
51+
padding: {
52+
top: 4,
53+
bottom: 4
54+
}
55+
},
56+
57+
// label settings
58+
ticks: {
59+
minRotation: 0,
60+
maxRotation: 50,
61+
mirror: false,
62+
textStrokeWidth: 0,
63+
textStrokeColor: '',
64+
padding: 3,
65+
display: true,
66+
autoSkip: true,
67+
autoSkipPadding: 3,
68+
labelOffset: 0,
69+
// We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
70+
callback: Ticks.formatters.values,
71+
minor: {},
72+
major: {},
73+
align: 'center',
74+
crossAlign: 'near',
75+
}
76+
});
77+
78+
defaults.route('scale.ticks', 'color', '', 'color');
79+
defaults.route('scale.grid', 'color', '', 'borderColor');
80+
defaults.route('scale.title', 'color', '', 'color');
81+
82+
defaults.describe('scale', {
83+
_fallback: false,
84+
_scriptable: (name) => !name.startsWith('before') && !name.startsWith('after') && name !== 'callback' && name !== 'parser',
85+
_indexable: (name) => name !== 'borderDash' && name !== 'tickBorderDash',
86+
});
87+
88+
defaults.describe('scales', {
89+
_fallback: 'scale',
90+
});

src/core/core.scale.js

Lines changed: 5 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import defaults from './core.defaults';
21
import Element from './core.element';
32
import {_alignPixel, _measureText, renderText, clipArea, unclipArea} from '../helpers/helpers.canvas';
43
import {callback as call, each, finiteOrDefault, isArray, isFinite, isNullOrUndef, isObject} from '../helpers/helpers.core';
54
import {toDegrees, toRadians, _int16Range, _limitValue, HALF_PI} from '../helpers/helpers.math';
65
import {_alignStartEnd, _toLeftRightCenter} from '../helpers/helpers.extras';
76
import {toFont, toPadding} from '../helpers/helpers.options';
8-
import Ticks from './core.ticks';
7+
8+
import './core.scale.defaults';
9+
10+
911
import {autoSkip} from './core.scale.autoskip';
1012

13+
1114
const reverseAlign = (align) => align === 'left' ? 'right' : align === 'right' ? 'left' : align;
1215
const offsetFromEdge = (scale, edge, offset) => edge === 'top' || edge === 'left' ? scale[edge] + offset : scale[edge] - offset;
1316

@@ -16,94 +19,6 @@ const offsetFromEdge = (scale, edge, offset) => edge === 'top' || edge === 'left
1619
* @typedef {{value:number | string, label?:string, major?:boolean, $context?:any}} Tick
1720
*/
1821

19-
defaults.set('scale', {
20-
display: true,
21-
offset: false,
22-
reverse: false,
23-
beginAtZero: false,
24-
25-
/**
26-
* Scale boundary strategy (bypassed by min/max time options)
27-
* - `data`: make sure data are fully visible, ticks outside are removed
28-
* - `ticks`: make sure ticks are fully visible, data outside are truncated
29-
* @see https://github.com/chartjs/Chart.js/pull/4556
30-
* @since 3.0.0
31-
*/
32-
bounds: 'ticks',
33-
34-
/**
35-
* Addition grace added to max and reduced from min data value.
36-
* @since 3.0.0
37-
*/
38-
grace: 0,
39-
40-
// grid line settings
41-
grid: {
42-
display: true,
43-
lineWidth: 1,
44-
drawBorder: true,
45-
drawOnChartArea: true,
46-
drawTicks: true,
47-
tickLength: 8,
48-
tickWidth: (_ctx, options) => options.lineWidth,
49-
tickColor: (_ctx, options) => options.color,
50-
offset: false,
51-
borderDash: [],
52-
borderDashOffset: 0.0,
53-
borderColor: (_ctx, options) => options.color,
54-
borderWidth: (_ctx, options) => options.lineWidth
55-
},
56-
57-
// scale title
58-
title: {
59-
// display property
60-
display: false,
61-
62-
// actual label
63-
text: '',
64-
65-
// top/bottom padding
66-
padding: {
67-
top: 4,
68-
bottom: 4
69-
}
70-
},
71-
72-
// label settings
73-
ticks: {
74-
minRotation: 0,
75-
maxRotation: 50,
76-
mirror: false,
77-
textStrokeWidth: 0,
78-
textStrokeColor: '',
79-
padding: 3,
80-
display: true,
81-
autoSkip: true,
82-
autoSkipPadding: 3,
83-
labelOffset: 0,
84-
// We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
85-
callback: Ticks.formatters.values,
86-
minor: {},
87-
major: {},
88-
align: 'center',
89-
crossAlign: 'near',
90-
}
91-
});
92-
93-
defaults.route('scale.ticks', 'color', '', 'color');
94-
defaults.route('scale.grid', 'color', '', 'borderColor');
95-
defaults.route('scale.title', 'color', '', 'color');
96-
97-
defaults.describe('scale', {
98-
_fallback: false,
99-
_scriptable: (name) => !name.startsWith('before') && !name.startsWith('after') && name !== 'callback' && name !== 'parser',
100-
_indexable: (name) => name !== 'borderDash' && name !== 'tickBorderDash',
101-
});
102-
103-
defaults.describe('scales', {
104-
_fallback: 'scale',
105-
});
106-
10722
/**
10823
* Returns a new array containing numItems from arr
10924
* @param {any[]} arr

0 commit comments

Comments
 (0)