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

Default beginAtZero to true for linear axes #6914

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions docs/getting-started/v3-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Animation system was completely rewritten in Chart.js v3. Each property can now

#### Scales

* Linear/Radial linear `beginAtZero` now defaults to `true` instead of `false`.
* `Scale.getLabelForIndex` was replaced by `scale.getLabelForValue`
* `Scale.getPixelForValue` now has only one parameter. For the `TimeScale` that parameter must be millis since the epoch

Expand Down
1 change: 0 additions & 1 deletion src/controllers/controller.polarArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ defaults._set('polarArea', {
angleLines: {
display: false
},
beginAtZero: true,
gridLines: {
circular: true
},
Expand Down
1 change: 1 addition & 0 deletions src/scales/scale.linear.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import LinearScaleBase from './scale.linearbase';
import Ticks from '../core/core.ticks';

const defaultConfig = {
beginAtZero: true,
ticks: {
callback: Ticks.formatters.linear
}
Expand Down
1 change: 1 addition & 0 deletions src/scales/scale.radialLinear.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const defaultConfig = {

// Boolean - Whether to animate scaling the chart from the centre
animate: true,
beginAtZero: true,
position: 'chartArea',

angleLines: {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/controller.bubble/radius-scriptable.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
title: false,
scales: {
x: {display: false},
y: {display: false}
y: {beginAtZero: false, display: false}
},
elements: {
point: {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/controller.line/borderCapStyle/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
},
scales: {
x: {display: false},
y: {display: false}
y: {beginAtZero: false, display: false}
}
}
},
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/controller.line/clip/default-x-max.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
"display": false
}
},
"y": {"ticks": {"display": false}}
"y": {
"beginAtZero": false,
"ticks": {"display": false}
}
},
"layout": {
"padding": 24
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/controller.line/clip/default-x-min.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
"display": false
}
},
"y": {"ticks": {"display": false}}
"y": {
"beginAtZero": false,
"ticks": {"display": false}
}
},
"layout": {
"padding": 24
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/controller.line/clip/default-x.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
"display": false
}
},
"y": {"ticks": {"display": false}}
"y": {
"beginAtZero": false,
"ticks": {"display": false}
}
},
"layout": {
"padding": 24
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/controller.line/clip/default-y-max.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"scales": {
"x": {"ticks": {"display": false}},
"y": {
"beginAtZero": false,
"max": 6,
"ticks": {
"display": false
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/element.point/point-style-circle.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"scales": {
"x": {"display": false},
"y": {"display": false}
"y": {"display": false, "beginAtZero": false}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/element.point/point-style-cross-rot.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"scales": {
"x": {"display": false},
"y": {"display": false}
"y": {"display": false, "beginAtZero": false}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/element.point/point-style-cross.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"scales": {
"x": {"display": false},
"y": {"display": false}
"y": {"display": false, "beginAtZero": false}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/element.point/point-style-dash.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"scales": {
"x": {"display": false},
"y": {"display": false}
"y": {"display": false, "beginAtZero": false}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/element.point/point-style-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {
},
scales: {
x: {display: false},
y: {display: false}
y: {display: false, beginAtZero: false}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/element.point/point-style-line.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"scales": {
"x": {"display": false},
"y": {"display": false}
"y": {"display": false, "beginAtZero": false}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/element.point/point-style-rect-rot.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"scales": {
"x": {"display": false},
"y": {"display": false}
"y": {"display": false, "beginAtZero": false}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/element.point/point-style-rect-rounded.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"scales": {
"x": {"display": false},
"y": {"display": false}
"y": {"display": false, "beginAtZero": false}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/element.point/point-style-rect.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"scales": {
"x": {"display": false},
"y": {"display": false}
"y": {"display": false, "beginAtZero": false}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/element.point/point-style-star.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"scales": {
"x": {"display": false},
"y": {"display": false}
"y": {"display": false, "beginAtZero": false}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/element.point/point-style-triangle.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"scales": {
"x": {"display": false},
"y": {"display": false}
"y": {"display": false, "beginAtZero": false}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/element.point/rotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
},
scales: {
x: {display: false},
y: {display: false}
y: {display: false, beginAtZero: false}
}
}
},
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/scale.radialLinear/gridlines-no-z.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"legend": false,
"title": false,
"scale": {
"beginAtZero": false,
"gridLines": {
"color": "rgba(0, 0, 0, 1)",
"lineWidth": 1
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/scale.radialLinear/gridlines-z.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"legend": false,
"title": false,
"scale": {
"beginAtZero": false,
"gridLines": {
"color": "rgba(0, 0, 0, 1)",
"lineWidth": 1,
Expand Down
2 changes: 2 additions & 0 deletions test/specs/controller.bar.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ describe('Chart.controllers.bar', function() {
},
y: {
type: 'linear',
beginAtZero: false,
display: false
}
}
Expand Down Expand Up @@ -773,6 +774,7 @@ describe('Chart.controllers.bar', function() {
},
y: {
type: 'linear',
beginAtZero: false,
display: false
}
}
Expand Down
1 change: 1 addition & 0 deletions test/specs/controller.line.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ describe('Chart.controllers.line', function() {
display: false
},
y: {
beginAtZero: false,
display: false
}
}
Expand Down
30 changes: 30 additions & 0 deletions test/specs/core.tooltip.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ describe('Core.Tooltip', function() {
labels: ['Point 1', 'Point 2', 'Point 3']
},
options: {
scales: {
y: {
beginAtZero: false,
}
},
tooltips: {
mode: 'index',
intersect: false,
Expand Down Expand Up @@ -227,6 +232,11 @@ describe('Core.Tooltip', function() {
labels: ['Point 1', 'Point 2', 'Point 3']
},
options: {
scales: {
y: {
beginAtZero: false,
}
},
tooltips: {
mode: 'nearest',
intersect: true
Expand Down Expand Up @@ -345,6 +355,11 @@ describe('Core.Tooltip', function() {
labels: ['Point 1', 'Point 2', 'Point 3']
},
options: {
scales: {
y: {
beginAtZero: false,
}
},
tooltips: {
mode: 'index',
callbacks: {
Expand Down Expand Up @@ -506,6 +521,11 @@ describe('Core.Tooltip', function() {
labels: ['Point 1', 'Point 2', 'Point 3']
},
options: {
scales: {
y: {
beginAtZero: false,
}
},
tooltips: {
mode: 'index',
itemSort: function(a, b) {
Expand Down Expand Up @@ -587,6 +607,11 @@ describe('Core.Tooltip', function() {
labels: ['Point 1', 'Point 2', 'Point 3']
},
options: {
scales: {
y: {
beginAtZero: false,
}
},
tooltips: {
mode: 'index',
reverse: true
Expand Down Expand Up @@ -668,6 +693,11 @@ describe('Core.Tooltip', function() {
labels: ['Point 1', 'Point 2', 'Point 3']
},
options: {
scales: {
y: {
beginAtZero: false,
}
},
tooltips: {
mode: 'index'
}
Expand Down
10 changes: 7 additions & 3 deletions test/specs/scale.linear.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Linear Scale', function() {
},
offset: false,
reverse: false,
beginAtZero: false,
beginAtZero: true,
scaleLabel: Chart.defaults.scale.scaleLabel,
ticks: {
minRotation: 0,
Expand Down Expand Up @@ -210,7 +210,8 @@ describe('Linear Scale', function() {
options: {
scales: {
y: {
type: 'linear'
type: 'linear',
beginAtZero: false,
}
}
}
Expand Down Expand Up @@ -673,6 +674,7 @@ describe('Linear Scale', function() {
scales: {
y: {
type: 'linear',
beginAtZero: false,
}
}
}
Expand Down Expand Up @@ -751,7 +753,9 @@ describe('Linear Scale', function() {
},
options: {
scales: {
y: {}
y: {
beginAtZero: false,
}
}
}
});
Expand Down
13 changes: 10 additions & 3 deletions test/specs/scale.radialLinear.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('Test the radial linear scale', function() {
position: 'chartArea',
offset: false,
reverse: false,
beginAtZero: false,
beginAtZero: true,
scaleLabel: Chart.defaults.scale.scaleLabel,
ticks: {
backdropColor: 'rgba(255,255,255,0.75)',
Expand Down Expand Up @@ -144,7 +144,11 @@ describe('Test the radial linear scale', function() {
labels: ['label1', 'label2', 'label3', 'label4', 'label5', 'label6', 'label7', 'label8']
},
options: {
scales: {}
scales: {
r: {
beginAtZero: false,
}
}
}
});

Expand All @@ -161,7 +165,9 @@ describe('Test the radial linear scale', function() {
},
options: {
scales: {
rScale: {}
rScale: {
beginAtZero: false,
}
}
}
});
Expand Down Expand Up @@ -281,6 +287,7 @@ describe('Test the radial linear scale', function() {
},
options: {
scale: {
beginAtZero: false,
pointLabels: {
display: false
}
Expand Down