Skip to content
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
Prev Previous commit
Next Next commit
Coderev, add tests
  • Loading branch information
Dave Salomon committed Dec 10, 2018
commit e3181a9466f0fd96d6d38f4eab9ead91c780668d
2 changes: 1 addition & 1 deletion docs/axes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The following properties are common to all axes provided by Chart.js.

| Name | Type | Default | Description
| ---- | ---- | ------- | -----------
| `display` | `Boolean (or "auto")` | `true` | If set to `false` the axis is hidden from view. Overrides *gridLines.display*, *scaleLabel.display*, and *ticks.display*.
| `display` | `Boolean`/`String` | `true` | Controls the axis global visibility (visible when `true`, hidden when `false`). When `display: 'auto'`, the axis is visible only if at least one associated dataset is visible.
| `callbacks` | `Object` | | Callback functions to hook into the axis lifecycle. [more...](#callbacks)
| `weight` | `Number` | `0` | The weight used to sort the axis. Higher weights are further away from the chart area.

Expand Down
2 changes: 1 addition & 1 deletion src/core/core.scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ module.exports = Element.extend({
var tickOpts = opts.ticks;
var scaleLabelOpts = opts.scaleLabel;
var gridLineOpts = opts.gridLines;
var display = this._isVisible();
var display = me._isVisible();
var position = opts.position;
var isHorizontal = me.isHorizontal();

Expand Down
130 changes: 130 additions & 0 deletions test/specs/core.scale.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,134 @@ describe('Core.scale', function() {
})).toEqual(test.expected);
});
});

describe('given the axes display option is set to auto', function() {
describe('for the x axes', function() {
it('should draw the axes if at least one associated dataset is visible', function() {
var chart = window.acquireChart({
type: 'line',
data: {
datasets: [{
data: [100, 200, 100, 50],
xAxisId: 'foo',
hidden: true,
labels: ['Q1', 'Q2', 'Q3', 'Q4']
}, {
data: [100, 200, 100, 50],
xAxisId: 'foo',
labels: ['Q1', 'Q2', 'Q3', 'Q4']
}]
},
options: {
scales: {
xAxes: [{
id: 'foo',
display: 'auto'
}],
yAxes: [{
type: 'category',
id: 'yScale0'
}]
}
}
});

var scale = chart.scales.foo;
scale.ctx = window.createMockContext();
chart.draw();

expect(scale.ctx.getCalls().length > 0).toBe(true);
});

it('should not draw the axes if no associated datasets are visible', function() {
var chart = window.acquireChart({
type: 'line',
data: {
datasets: [{
data: [100, 200, 100, 50],
xAxisId: 'foo',
hidden: true,
labels: ['Q1', 'Q2', 'Q3', 'Q4']
}]
},
options: {
scales: {
xAxes: [{
id: 'foo',
display: 'auto'
}]
}
}
});

var scale = chart.scales.foo;
scale.ctx = window.createMockContext();
chart.draw();

expect(scale.ctx.getCalls().length).toBe(0);
});
});

describe('for the y axes', function() {
it('should draw the axes if at least one associated dataset is visible', function() {
var chart = window.acquireChart({
type: 'line',
data: {
datasets: [{
data: [100, 200, 100, 50],
yAxisId: 'foo',
hidden: true,
labels: ['Q1', 'Q2', 'Q3', 'Q4']
}, {
data: [100, 200, 100, 50],
yAxisId: 'foo',
labels: ['Q1', 'Q2', 'Q3', 'Q4']
}]
},
options: {
scales: {
yAxes: [{
id: 'foo',
display: 'auto'
}]
}
}
});

var scale = chart.scales.foo;
scale.ctx = window.createMockContext();
chart.draw();

expect(scale.ctx.getCalls().length > 0).toBe(true);
});

it('should not draw the axes if no associated datasets are visible', function() {
var chart = window.acquireChart({
type: 'line',
data: {
datasets: [{
data: [100, 200, 100, 50],
yAxisId: 'foo',
hidden: true,
labels: ['Q1', 'Q2', 'Q3', 'Q4']
}]
},
options: {
scales: {
yAxes: [{
id: 'foo',
display: 'auto'
}]
}
}
});

var scale = chart.scales.foo;
scale.ctx = window.createMockContext();
chart.draw();

expect(scale.ctx.getCalls().length).toBe(0);
});
});
});
});