Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
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` | `true` | If set to `false` the axis is hidden from view. Overrides *gridLines.display*, *scaleLabel.display*, and *ticks.display*.
| `display` | `Boolean (or "auto")` | `true` | If set to `false` the axis is hidden from view. Overrides *gridLines.display*, *scaleLabel.display*, and *ticks.display*.
| `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
31 changes: 29 additions & 2 deletions 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 = opts.display;
var display = this._isVisible();
var position = opts.position;
var isHorizontal = me.isHorizontal();

Expand Down Expand Up @@ -680,12 +680,39 @@ module.exports = Element.extend({
return result;
},

/**
* @private
*/
_isVisible: function() {
var me = this;
var chart = me.chart;
var display = me.options.display;
var i, ilen, meta;

if (display !== 'auto') {
return !!display;
}

// When 'auto', the scale is visible if at least one associated dataset is visible.
for (i = 0, ilen = chart.data.datasets.length; i < ilen; ++i) {
if (chart.isDatasetVisible(i)) {
meta = chart.getDatasetMeta(i);
if (meta.xAxisID === me.id || meta.yAxisID === me.id) {
return true;
}
}
}

return false;
},

// Actually draw the scale on the canvas
// @param {rectangle} chartArea : the area of the chart to draw full grid lines on
draw: function(chartArea) {
var me = this;
var options = me.options;
if (!options.display) {

if (!me._isVisible()) {
return;
}

Expand Down