Skip to content

Commit 7f97adf

Browse files
kurkleetimberg
authored andcommitted
Move scale defining options up from ticks (#6738)
* Move scale defining options up from `ticks` * Include `ticks.reverse` in v3-migration
1 parent aa3e4c4 commit 7f97adf

File tree

138 files changed

+413
-637
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+413
-637
lines changed

docs/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ var myChart = new Chart(ctx, {
4444
options: {
4545
scales: {
4646
yAxes: [{
47-
ticks: {
48-
beginAtZero: true
49-
}
47+
beginAtZero: true
5048
}]
5149
}
5250
}

docs/axes/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Axes are an integral part of a chart. They are used to determine how data maps t
55
In a radial chart, such as a radar chart or a polar area chart, there is a single axis that maps points in the angular and radial directions. These are known as ['radial axes'](./radial/README.md#radial-axes).
66

77
Scales in Chart.js >v2.0 are significantly more powerful, but also different than those of v1.0.
8+
89
* Multiple X & Y axes are supported.
910
* A built-in label auto-skip feature detects would-be overlapping ticks and labels and removes every nth label to keep things displaying normally.
1011
* Scale titles are supported.
@@ -21,6 +22,7 @@ The following properties are common to all axes provided by Chart.js.
2122
| `weight` | `number` | `0` | The weight used to sort the axis. Higher weights are further away from the chart area.
2223

2324
### Callbacks
25+
2426
There are a number of config callbacks that can be used to change parameters in the scale at different points in the update process.
2527

2628
| Name | Arguments | Description
@@ -48,11 +50,10 @@ For example, to set the minimum value of 0 for all linear scales, you would do t
4850

4951
```javascript
5052
Chart.scaleService.updateScaleDefaults('linear', {
51-
ticks: {
52-
min: 0
53-
}
53+
min: 0
5454
});
5555
```
5656

5757
## Creating New Axes
58+
5859
To create a new axis, see the [developer docs](../developers/axes.md).

docs/axes/cartesian/category.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ let chart = new Chart(ctx, {
5959
options: {
6060
scales: {
6161
xAxes: [{
62-
ticks: {
63-
min: 'March'
64-
}
62+
min: 'March'
6563
}]
6664
}
6765
}

docs/axes/cartesian/linear.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@
22

33
The linear scale is use to chart numerical data. It can be placed on either the x or y axis. The scatter chart type automatically configures a line chart to use one of these scales for the x axis. As the name suggests, linear interpolation is used to determine where a value lies on the axis.
44

5+
## Configuration Options
6+
7+
| Name | Type | Description
8+
| ---- | ---- | -----------
9+
| `beginAtZero` | `boolean` | if true, scale will include 0 if it is not already included.
10+
| `suggestedMax` | `number` | Adjustment used when calculating the maximum data value. [more...](#axis-range-settings)
11+
| `suggestedMin` | `number` | Adjustment used when calculating the minimum data value. [more...](#axis-range-settings)
12+
513
## Tick Configuration Options
614

715
The following options are provided by the linear scale. They are all located in the `ticks` sub options. These options extend the [common tick configuration](README.md#tick-configuration).
816

917
| Name | Type | Default | Description
1018
| ---- | ---- | ------- | -----------
11-
| `beginAtZero` | `boolean` | | if true, scale will include 0 if it is not already included.
1219
| `maxTicksLimit` | `number` | `11` | Maximum number of ticks and gridlines to show.
1320
| `precision` | `number` | | if defined and `stepSize` is not specified, the step size will be rounded to this many decimal places.
1421
| `stepSize` | `number` | | User defined fixed step size for the scale. [more...](#step-size)
15-
| `suggestedMax` | `number` | | Adjustment used when calculating the maximum data value. [more...](#axis-range-settings)
16-
| `suggestedMin` | `number` | | Adjustment used when calculating the minimum data value. [more...](#axis-range-settings)
1722

1823
## Axis Range Settings
1924

@@ -22,8 +27,8 @@ Given the number of axis range settings, it is important to understand how they
2227
The `suggestedMax` and `suggestedMin` settings only change the data values that are used to scale the axis. These are useful for extending the range of the axis while maintaining the auto fit behaviour.
2328

2429
```javascript
25-
let minDataValue = Math.min(mostNegativeValue, options.ticks.suggestedMin);
26-
let maxDataValue = Math.max(mostPositiveValue, options.ticks.suggestedMax);
30+
let minDataValue = Math.min(mostNegativeValue, options.suggestedMin);
31+
let maxDataValue = Math.max(mostPositiveValue, options.suggestedMax);
2732
```
2833

2934
In this example, the largest positive value is 50, but the data maximum is expanded out to 100. However, because the lowest data value is below the `suggestedMin` setting, it is ignored.
@@ -41,10 +46,8 @@ let chart = new Chart(ctx, {
4146
options: {
4247
scales: {
4348
yAxes: [{
44-
ticks: {
45-
suggestedMin: 50,
46-
suggestedMax: 100
47-
}
49+
suggestedMin: 50,
50+
suggestedMax: 100
4851
}]
4952
}
5053
}
@@ -54,6 +57,7 @@ let chart = new Chart(ctx, {
5457
In contrast to the `suggested*` settings, the `min` and `max` settings set explicit ends to the axes. When these are set, some data points may not be visible.
5558

5659
## Step Size
60+
5761
If set, the scale ticks will be enumerated by multiple of `stepSize`, having one tick per increment. If not set, the ticks are labeled automatically using the nice numbers algorithm.
5862

5963
This example sets up a chart with a y axis that creates ticks at `0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5`.
@@ -62,9 +66,9 @@ This example sets up a chart with a y axis that creates ticks at `0, 0.5, 1, 1.5
6266
let options = {
6367
scales: {
6468
yAxes: [{
69+
max: 5,
70+
min: 0,
6571
ticks: {
66-
max: 5,
67-
min: 0,
6872
stepSize: 0.5
6973
}
7074
}]

docs/axes/radial/linear.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,30 @@ The following additional configuration options are provided by the radial linear
88

99
The axis has configuration properties for ticks, angle lines (line that appear in a radar chart outward from the center), pointLabels (labels around the edge in a radar chart). The following sections define each of the properties in those sections.
1010

11-
| Name | Type | Description
12-
| ---- | ---- | -----------
13-
| `angleLines` | `object` | Angle line configuration. [more...](#angle-line-options)
14-
| `gridLines` | `object` | Grid line configuration. [more...](../styling.md#grid-line-configuration)
15-
| `pointLabels` | `object` | Point label configuration. [more...](#point-label-options)
16-
| `ticks` | `object` | Tick configuration. [more...](#tick-options)
11+
| Name | Type | Default | Description
12+
| ---- | ---- | ------- | -----------
13+
| `angleLines` | `object` | | Angle line configuration. [more...](#angle-line-options)
14+
| `beginAtZero` | `boolean` | `false` | if true, scale will include 0 if it is not already included.
15+
| `gridLines` | `object` | | Grid line configuration. [more...](../styling.md#grid-line-configuration)
16+
| `min` | `number` | | User defined minimum number for the scale, overrides minimum value from data. [more...](#axis-range-settings)
17+
| `max` | `number` | | User defined maximum number for the scale, overrides maximum value from data. [more...](#axis-range-settings)
18+
| `pointLabels` | `object` | | Point label configuration. [more...](#point-label-options)
19+
| `suggestedMax` | `number` | | Adjustment used when calculating the maximum data value. [more...](#axis-range-settings)
20+
| `suggestedMin` | `number` | | Adjustment used when calculating the minimum data value. [more...](#axis-range-settings)
21+
| `ticks` | `object` | | Tick configuration. [more...](#tick-options)
1722

1823
## Tick Options
24+
1925
The following options are provided by the linear scale. They are all located in the `ticks` sub options. The [common tick configuration](../styling.md#tick-configuration) options are supported by this axis.
2026

2127
| Name | Type | Default | Description
2228
| ---- | ---- | ------- | -----------
2329
| `backdropColor` | `Color` | `'rgba(255, 255, 255, 0.75)'` | Color of label backdrops.
2430
| `backdropPaddingX` | `number` | `2` | Horizontal padding of label backdrop.
2531
| `backdropPaddingY` | `number` | `2` | Vertical padding of label backdrop.
26-
| `beginAtZero` | `boolean` | `false` | if true, scale will include 0 if it is not already included.
27-
| `min` | `number` | | User defined minimum number for the scale, overrides minimum value from data. [more...](#axis-range-settings)
28-
| `max` | `number` | | User defined maximum number for the scale, overrides maximum value from data. [more...](#axis-range-settings)
2932
| `maxTicksLimit` | `number` | `11` | Maximum number of ticks and gridlines to show.
3033
| `precision` | `number` | | if defined and `stepSize` is not specified, the step size will be rounded to this many decimal places.
3134
| `stepSize` | `number` | | User defined fixed step size for the scale. [more...](#step-size)
32-
| `suggestedMax` | `number` | | Adjustment used when calculating the maximum data value. [more...](#axis-range-settings)
33-
| `suggestedMin` | `number` | | Adjustment used when calculating the minimum data value. [more...](#axis-range-settings)
3435
| `showLabelBackdrop` | `boolean` | `true` | If true, draw a background behind the tick labels.
3536

3637
## Axis Range Settings
@@ -58,10 +59,8 @@ let chart = new Chart(ctx, {
5859
},
5960
options: {
6061
scale: {
61-
ticks: {
62-
suggestedMin: 50,
63-
suggestedMax: 100
64-
}
62+
suggestedMin: 50,
63+
suggestedMax: 100
6564
}
6665
}
6766
});
@@ -77,9 +76,9 @@ This example sets up a chart with a y axis that creates ticks at `0, 0.5, 1, 1.5
7776
```javascript
7877
let options = {
7978
scale: {
79+
max: 5,
80+
min: 0,
8081
ticks: {
81-
max: 5,
82-
min: 0,
8382
stepSize: 0.5
8483
}
8584
}

docs/charts/bar.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,15 @@ A bar chart provides a way of showing data values represented as vertical bars.
4242
"options": {
4343
"scales": {
4444
"yAxes": [{
45-
"ticks": {
46-
"beginAtZero": true
47-
}
45+
"beginAtZero": true
4846
}]
4947
}
5048
}
5149
}
5250
{% endchartjs %}
5351

5452
## Example Usage
53+
5554
```javascript
5655
var myBarChart = new Chart(ctx, {
5756
type: 'bar',
@@ -302,16 +301,15 @@ A horizontal bar chart is a variation on a vertical bar chart. It is sometimes u
302301
"options": {
303302
"scales": {
304303
"xAxes": [{
305-
"ticks": {
306-
"beginAtZero": true
307-
}
304+
"beginAtZero": true
308305
}]
309306
}
310307
}
311308
}
312309
{% endchartjs %}
313310

314311
## Example
312+
315313
```javascript
316314
var myBarChart = new Chart(ctx, {
317315
type: 'horizontalBar',
@@ -321,6 +319,7 @@ var myBarChart = new Chart(ctx, {
321319
```
322320

323321
### Config Options
322+
324323
The configuration options for the horizontal bar chart are the same as for the [bar chart](#scale-configuration). However, any options specified on the x axis in a bar chart, are applied to the y axis in a horizontal bar chart.
325324

326325
The default horizontal bar configuration is specified in `Chart.defaults.horizontalBar`.

docs/charts/mixed.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ At this point we have a chart rendering how we'd like. It's important to note th
6262
"options": {
6363
"scales": {
6464
"yAxes": [{
65-
"ticks": {
66-
"beginAtZero": true
67-
}
65+
"beginAtZero": true
6866
}]
6967
}
7068
}

docs/charts/radar.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,8 @@ options = {
172172
angleLines: {
173173
display: false
174174
},
175-
ticks: {
176-
suggestedMin: 50,
177-
suggestedMax: 100
178-
}
175+
suggestedMin: 50,
176+
suggestedMax: 100
179177
}
180178
};
181179
```

docs/getting-started/usage.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ var myChart = new Chart(ctx, {
5454
options: {
5555
scales: {
5656
yAxes: [{
57-
ticks: {
58-
beginAtZero: true
59-
}
57+
beginAtZero: true
6058
}]
6159
}
6260
}

docs/getting-started/v3-migration.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ Chart.js is no longer providing the `Chart.bundle.js` and `Chart.bundle.min.js`.
3737
* `scales.[x/y]Axes.categoryPercentage` was moved to dataset option `categoryPercentage`
3838
* `scales.[x/y]Axes.minBarLength` was moved to dataset option `minBarLength`
3939
* `scales.[x/y]Axes.maxBarThickness` was moved to dataset option `maxBarThickness`
40+
* `scales.[x/y]Axes.ticks.beginAtZero` was renamed to `scales.[x/y]Axes.beginAtZero`
41+
* `scales.[x/y]Axes.ticks.max` was renamed to `scales.[x/y]Axes.max`
42+
* `scales.[x/y]Axes.ticks.min` was renamed to `scales.[x/y]Axes.min`
43+
* `scales.[x/y]Axes.ticks.reverse` was renamed to `scales.[x/y]Axes.reverse`
44+
* `scales.[x/y]Axes.ticks.suggestedMax` was renamed to `scales.[x/y]Axes.suggestedMax`
45+
* `scales.[x/y]Axes.ticks.suggestedMin` was renamed to `scales.[x/y]Axes.suggestedMin`
4046
* `scales.[x/y]Axes.time.format` was renamed to `scales.[x/y]Axes.time.parser`
41-
* `scales.[x/y]Axes.time.min` was renamed to `scales.[x/y]Axes.ticks.min`
42-
* `scales.[x/y]Axes.time.max` was renamed to `scales.[x/y]Axes.ticks.max`
47+
* `scales.[x/y]Axes.time.max` was renamed to `scales.[x/y]Axes.max`
48+
* `scales.[x/y]Axes.time.min` was renamed to `scales.[x/y]Axes.min`
4349

4450
## Developer migration
4551

samples/charts/line/interpolation-modes.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@
7676
display: true,
7777
labelString: 'Value'
7878
},
79-
ticks: {
80-
suggestedMin: -10,
81-
suggestedMax: 200,
82-
}
79+
suggestedMin: -10,
80+
suggestedMax: 200,
8381
}]
8482
}
8583
}

samples/charts/radar.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@
7272
text: 'Chart.js Radar Chart'
7373
},
7474
scale: {
75-
ticks: {
76-
beginAtZero: true
77-
}
75+
beginAtZero: true
7876
}
7977
}
8078
};

samples/scales/gridlines-display.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
}],
6161
yAxes: [{
6262
gridLines: gridlines,
63+
min: 0,
64+
max: 100,
6365
ticks: {
64-
min: 0,
65-
max: 100,
6666
stepSize: 10
6767
}
6868
}]

samples/scales/gridlines-style.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
drawBorder: false,
5050
color: ['pink', 'red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'purple']
5151
},
52+
min: 0,
53+
max: 100,
5254
ticks: {
53-
min: 0,
54-
max: 100,
5555
stepSize: 10
5656
}
5757
}]

samples/scales/linear/min-max-suggested.html

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,11 @@
4545
},
4646
scales: {
4747
yAxes: [{
48-
ticks: {
49-
// the data minimum used for determining the ticks is Math.min(dataMin, suggestedMin)
50-
suggestedMin: 10,
48+
// the data minimum used for determining the ticks is Math.min(dataMin, suggestedMin)
49+
suggestedMin: 10,
5150

52-
// the data maximum used for determining the ticks is Math.max(dataMax, suggestedMax)
53-
suggestedMax: 50
54-
}
51+
// the data maximum used for determining the ticks is Math.max(dataMax, suggestedMax)
52+
suggestedMax: 50
5553
}]
5654
}
5755
}

samples/scales/linear/min-max.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@
4545
},
4646
scales: {
4747
yAxes: [{
48-
ticks: {
49-
min: 10,
50-
max: 50
51-
}
48+
min: 10,
49+
max: 50
5250
}]
5351
}
5452
}

samples/scales/linear/step-size.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,9 @@
9494
display: true,
9595
labelString: 'Value'
9696
},
97+
min: 0,
98+
max: 100,
9799
ticks: {
98-
min: 0,
99-
max: 100,
100-
101100
// forces step size to be 5 units
102101
stepSize: 5
103102
}

samples/scales/non-numeric-y.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@
5454
display: true,
5555
labelString: 'Request State'
5656
},
57-
ticks: {
58-
reverse: true
59-
}
57+
reverse: true
6058
}]
6159
}
6260
}

0 commit comments

Comments
 (0)