Skip to content

Commit ce74eb7

Browse files
kurkleetimberg
authored andcommitted
Convert axis options from arrays to objects (#6773)
* Convert axis options from arrays to objects * Updated all chart type defaults * Throw errors when axis type or position are not specified * Avoid raising unnecessary errors when merging options into the default configs * Fix additional tests * Ensure scale defaults are set if type is not explicitly defined * Another step * Include `scale` as `firstIDs.r` * update docs * Update for buildOrUpdateScales * Update migration guide * Add test back
1 parent 18e3bc0 commit ce74eb7

File tree

211 files changed

+1911
-2130
lines changed

Some content is hidden

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

211 files changed

+1911
-2130
lines changed

docs/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ var myChart = new Chart(ctx, {
4343
},
4444
options: {
4545
scales: {
46-
yAxes: [{
46+
y: {
4747
beginAtZero: true
48-
}]
48+
}
4949
}
5050
}
5151
});

docs/axes/cartesian/README.md

+8-9
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ The following options are common to all cartesian axes but do not apply to other
3838
| `padding` | `number` | `0` | Padding between the tick label and the axis. When set on a vertical axis, this applies in the horizontal (X) direction. When set on a horizontal axis, this applies in the vertical (Y) direction.
3939

4040
### Axis ID
41-
The properties `dataset.xAxisID` or `dataset.yAxisID` have to match the scale properties `scales.xAxes.id` or `scales.yAxes.id`. This is especially needed if multi-axes charts are used.
41+
42+
The properties `dataset.xAxisID` or `dataset.yAxisID` have to match to `scales` property. This is especially needed if multi-axes charts are used.
4243

4344
```javascript
4445
var myChart = new Chart(ctx, {
@@ -54,11 +55,10 @@ var myChart = new Chart(ctx, {
5455
},
5556
options: {
5657
scales: {
57-
yAxes: [{
58-
id: 'first-y-axis',
58+
'first-y-axis': {
5959
type: 'linear'
60-
}, {
61-
id: 'second-y-axis',
60+
},
61+
'second-y-axis': {
6262
type: 'linear'
6363
}]
6464
}
@@ -93,12 +93,11 @@ var myChart = new Chart(ctx, {
9393
},
9494
options: {
9595
scales: {
96-
yAxes: [{
97-
id: 'left-y-axis',
96+
'left-y-axis': {
9897
type: 'linear',
9998
position: 'left'
100-
}, {
101-
id: 'right-y-axis',
99+
},
100+
'right-y-axis': {
102101
type: 'linear',
103102
position: 'right'
104103
}]

docs/axes/cartesian/category.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ let chart = new Chart(ctx, {
2525
data: ...
2626
options: {
2727
scales: {
28-
xAxes: [{
28+
x: {
2929
type: 'category',
3030
labels: ['January', 'February', 'March', 'April', 'May', 'June']
31-
}]
31+
}
3232
}
3333
}
3434
});
@@ -58,9 +58,9 @@ let chart = new Chart(ctx, {
5858
},
5959
options: {
6060
scales: {
61-
xAxes: [{
61+
x: {
6262
min: 'March'
63-
}]
63+
}
6464
}
6565
}
6666
});

docs/axes/cartesian/linear.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ let chart = new Chart(ctx, {
4545
},
4646
options: {
4747
scales: {
48-
yAxes: [{
48+
y: {
4949
suggestedMin: 50,
5050
suggestedMax: 100
51-
}]
51+
}
5252
}
5353
}
5454
});
@@ -65,13 +65,13 @@ This example sets up a chart with a y axis that creates ticks at `0, 0.5, 1, 1.5
6565
```javascript
6666
let options = {
6767
scales: {
68-
yAxes: [{
68+
y: {
6969
max: 5,
7070
min: 0,
7171
ticks: {
7272
stepSize: 0.5
7373
}
74-
}]
74+
}
7575
}
7676
};
7777
```

docs/axes/cartesian/time.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,19 @@ var chart = new Chart(ctx, {
6767
data: data,
6868
options: {
6969
scales: {
70-
xAxes: [{
70+
x: {
7171
type: 'time',
7272
time: {
7373
unit: 'month'
7474
}
75-
}]
75+
}
7676
}
7777
}
7878
});
7979
```
8080

8181
### Display Formats
82+
8283
The following display formats are used to configure how different time units are formed into strings for the axis tick marks. See [Moment.js](https://momentjs.com/docs/#/displaying/format/) for the allowable format strings.
8384

8485
Name | Default | Example
@@ -101,14 +102,14 @@ var chart = new Chart(ctx, {
101102
data: data,
102103
options: {
103104
scales: {
104-
xAxes: [{
105+
x: {
105106
type: 'time',
106107
time: {
107108
displayFormats: {
108109
quarter: 'MMM YYYY'
109110
}
110111
}
111-
}]
112+
}
112113
}
113114
}
114115
});
@@ -127,10 +128,10 @@ var chart = new Chart(ctx, {
127128
data: data,
128129
options: {
129130
scales: {
130-
xAxes: [{
131+
x: {
131132
type: 'time',
132133
distribution: 'series'
133-
}]
134+
}
134135
}
135136
}
136137
});

docs/axes/labelling.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ var chart = new Chart(ctx, {
3131
data: data,
3232
options: {
3333
scales: {
34-
yAxes: [{
34+
y: {
3535
ticks: {
3636
// Include a dollar sign in the ticks
3737
callback: function(value, index, values) {
3838
return '$' + value;
3939
}
4040
}
41-
}]
41+
}
4242
}
4343
}
4444
});

docs/charts/bar.md

+15-10
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ A bar chart provides a way of showing data values represented as vertical bars.
4141
},
4242
"options": {
4343
"scales": {
44-
"yAxes": [{
44+
"y": {
4545
"beginAtZero": true
46-
}]
46+
}
4747
}
4848
}
4949
}
@@ -160,14 +160,17 @@ data: {
160160
}]
161161
};
162162
```
163+
163164
### barThickness
165+
164166
If this value is a number, it is applied to the width of each bar, in pixels. When this is enforced, `barPercentage` and `categoryPercentage` are ignored.
165167

166168
If set to `'flex'`, the base sample widths are calculated automatically based on the previous and following samples so that they take the full available widths without overlap. Then, bars are sized using `barPercentage` and `categoryPercentage`. There is no gap when the percentage options are 1. This mode generates bars with different widths when data are not evenly spaced.
167169

168170
If not set (default), the base sample widths are calculated using the smallest interval that prevents bar overlapping, and bars are sized using `barPercentage` and `categoryPercentage`. This mode always generates bars equally sized.
169171

170172
## Scale Configuration
173+
171174
The bar chart sets unique default values for the following configuration from the associated `scale` options:
172175

173176
| Name | Type | Default | Description
@@ -180,16 +183,17 @@ The bar chart sets unique default values for the following configuration from th
180183
```javascript
181184
options = {
182185
scales: {
183-
xAxes: [{
186+
x: {
184187
gridLines: {
185188
offsetGridLines: true
186189
}
187-
}]
190+
}
188191
}
189192
};
190193
```
191194

192195
### offsetGridLines
196+
193197
If true, the bars for a particular data point fall between the grid lines. The grid line will move to the left by one half of the tick interval, which is the space between the grid lines. If false, the grid line will go right down the middle of the bars. This is set to true for a category scale in a bar chart while false for other scales or chart types by default.
194198

195199
## Default Options
@@ -249,12 +253,12 @@ var stackedBar = new Chart(ctx, {
249253
data: data,
250254
options: {
251255
scales: {
252-
xAxes: [{
256+
x: {
253257
stacked: true
254-
}],
255-
yAxes: [{
258+
},
259+
y: {
256260
stacked: true
257-
}]
261+
}
258262
}
259263
}
260264
});
@@ -267,6 +271,7 @@ The following dataset properties are specific to stacked bar charts.
267271
| `stack` | `string` | The ID of the group to which this dataset belongs to (when stacked, each group will be a separate stack).
268272

269273
## Horizontal Bar Chart
274+
270275
A horizontal bar chart is a variation on a vertical bar chart. It is sometimes used to show trend data, and the comparison of multiple data sets side by side.
271276
{% chartjs %}
272277
{
@@ -300,9 +305,9 @@ A horizontal bar chart is a variation on a vertical bar chart. It is sometimes u
300305
},
301306
"options": {
302307
"scales": {
303-
"xAxes": [{
308+
"x": {
304309
"beginAtZero": true
305-
}]
310+
}
306311
}
307312
}
308313
}

docs/charts/line.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ var stackedLine = new Chart(ctx, {
211211
data: data,
212212
options: {
213213
scales: {
214-
yAxes: [{
214+
y: {
215215
stacked: true
216-
}]
216+
}
217217
}
218218
}
219219
});

docs/charts/mixed.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ At this point we have a chart rendering how we'd like. It's important to note th
6161
},
6262
"options": {
6363
"scales": {
64-
"yAxes": [{
64+
"y": {
6565
"beginAtZero": true
66-
}]
66+
}
6767
}
6868
}
6969
}

docs/charts/scatter.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ var scatterChart = new Chart(ctx, {
2222
},
2323
options: {
2424
scales: {
25-
xAxes: [{
25+
x: {
2626
type: 'linear',
2727
position: 'bottom'
28-
}]
28+
}
2929
}
3030
}
3131
});

docs/developers/axes.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ var lineChart = new Chart(ctx, {
2424
type: 'line',
2525
options: {
2626
scales: {
27-
yAxes: [{
27+
y: {
2828
type: 'myScale' // this is the same key that was passed to the registerScaleType function
29-
}]
29+
}
3030
}
3131
}
3232
});

docs/developers/updates.md

+14-15
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ function updateConfigAsNewObject(chart) {
4545
text: 'Chart.js'
4646
},
4747
scales: {
48-
xAxes: [{
48+
x: {
4949
display: true
50-
}],
51-
yAxes: [{
50+
},
51+
y: {
5252
display: true
53-
}]
53+
}
5454
}
5555
};
5656
chart.update();
@@ -64,30 +64,29 @@ Variables referencing any one from `chart.scales` would be lost after updating s
6464

6565
```javascript
6666
function updateScales(chart) {
67-
var xScale = chart.scales['x-axis-0'];
68-
var yScale = chart.scales['y-axis-0'];
67+
var xScale = chart.scales.x;
68+
var yScale = chart.scales.y;
6969
chart.options.scales = {
70-
xAxes: [{
71-
id: 'newId',
70+
newId: {
7271
display: true
73-
}],
74-
yAxes: [{
72+
},
73+
y: {
7574
display: true,
7675
type: 'logarithmic'
77-
}]
76+
}
7877
};
7978
chart.update();
8079
// need to update the reference
81-
xScale = chart.scales['newId'];
82-
yScale = chart.scales['y-axis-0'];
80+
xScale = chart.scales.newId;
81+
yScale = chart.scales.y;
8382
}
8483
```
8584

86-
You can also update a specific scale either by specifying its index or id.
85+
You can also update a specific scale either by its id.
8786

8887
```javascript
8988
function updateScale(chart) {
90-
chart.options.scales.yAxes[0] = {
89+
chart.options.scales.y = {
9190
type: 'logarithmic'
9291
};
9392
chart.update();

docs/getting-started/usage.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ var myChart = new Chart(ctx, {
5353
},
5454
options: {
5555
scales: {
56-
yAxes: [{
56+
y: {
5757
beginAtZero: true
58-
}]
58+
}
5959
}
6060
}
6161
});

0 commit comments

Comments
 (0)