*/
Bar.prototype._horizontal = false;
+ /**
+ * Whether the bars should be stacked or not.
+ *
+ * @type {Bool}
+ * @protected
+ */
+ Bar.prototype._stacked = null;
+
/** @override */
Bar.prototype.TYPE = 'bar';
Bar.prototype.create = function(Klass, data) {
var chart = Base.prototype.create.apply(this, arguments);
chart.setHorizontal(data.horizontal);
+ chart.setStacked(data.stacked);
return chart;
};
return this._horizontal;
};
+ /**
+ * Get whether the bars should be stacked or not.
+ *
+ * @returns {Bool}
+ */
+ Bar.prototype.getStacked = function() {
+ return this._stacked;
+ };
+
/**
* Set whether the bars should be displayed horizontally or not.
*
this._horizontal = Boolean(horizontal);
};
+ /**
+ * Set whether the bars should be stacked or not.
+ *
+ * @method setStacked
+ * @param {Bool} stacked True if the chart should be stacked or false otherwise.
+ */
+ Bar.prototype.setStacked = function(stacked) {
+ this._stacked = Boolean(stacked);
+ };
+
return Bar;
});
return axisLabels[index] || '';
};
}
+ config.options.scales.xAxes[i].stacked = this._isStacked('x');
}.bind(this));
this._chart.getYAxes().forEach(function(axis, i) {
return axisLabels[parseInt(value, 10)] || '';
};
}
+ config.options.scales.yAxes[i].stacked = this._isStacked('y');
}.bind(this));
config.options.tooltips = {
return smooth;
};
+ /**
+ * Verify if the bar chart is stacked or not.
+ *
+ * @protected
+ * @param {String} xy The axis of the serie.
+ * @returns {Bool}
+ */
+ Output.prototype._isStacked = function(xy) {
+ var stacked = false;
+ var chartType = this._getChartType();
+
+ // Check if the axis matches the chart type to avoid set stacked on a unused axis.
+ if (chartType === Bar.prototype.TYPE && xy == 'x') {
+ stacked = this._chart.getStacked();
+ } else if (chartType === 'horizontalBar' && xy == 'y') {
+ stacked = this._chart.getStacked();
+ }
+
+ return stacked;
+ };
+
/** @override */
Output.prototype.update = function() {
$.extend(true, this._config, this._makeConfig());
/** @var bool Whether the bars should be displayed horizontally or not. */
protected $horizontal = false;
-
+ /** @var bool Whether the chart should be stacked or not. */
+ protected $stacked = null;
/**
* Add the horizontal to the parent and return the serialized data.
*
public function jsonSerialize() { // @codingStandardsIgnoreLine (CONTRIB-6469).
$data = parent::jsonSerialize();
$data['horizontal'] = $this->get_horizontal();
+ $data['stacked'] = $this->get_stacked();
return $data;
}
}
/**
- * Get Set whether the bars should be displayed horizontally or not.
+ * Get whether the bars should be stacked or not.
+ *
+ * @return bool
+ */
+ public function get_stacked() {
+ return $this->stacked;
+ }
+
+ /**
+ * Set whether the bars should be displayed horizontally or not.
*
* @param bool $horizontal True if the bars should be displayed horizontally, false otherwise.
*/
public function set_horizontal($horizontal) {
$this->horizontal = $horizontal;
}
+
+ /**
+ * Set whether the bars should be stacked or not.
+ *
+ * @param bool $stacked True if the chart should be stacked or false otherwise.
+ */
+ public function set_stacked($stacked) {
+ $this->stacked = $stacked;
+ }
}