if (xScale.options.barThickness) {
return xScale.options.barThickness;
}
- return ruler.barWidth;
+ return xScale.options.stacked ? ruler.categoryWidth * xScale.options.barPercentage : ruler.barWidth;
},
// Get stack index from the given dataset index accounting for stacks and the fact that not all bars are visible
var leftTick = xScale.getPixelForValue(null, index, datasetIndex, me.chart.isCombo);
leftTick -= me.chart.isCombo ? (ruler.tickWidth / 2) : 0;
+ if (xScale.options.stacked) {
+ return leftTick + (ruler.categoryWidth / 2) + ruler.categorySpacing;
+ }
+
return leftTick +
(ruler.barWidth / 2) +
ruler.categorySpacing +
if (yScale.options.barThickness) {
return yScale.options.barThickness;
}
- return ruler.barHeight;
+ return yScale.options.stacked ? ruler.categoryHeight * yScale.options.barPercentage : ruler.barHeight;
},
// Get stack index from the given dataset index accounting for stacks and the fact that not all bars are visible
var topTick = yScale.getPixelForValue(null, index, datasetIndex, me.chart.isCombo);
topTick -= me.chart.isCombo ? (ruler.tickHeight / 2) : 0;
+ if (yScale.options.stacked) {
+ return topTick + (ruler.categoryHeight / 2) + ruler.categorySpacing;
+ }
+
return topTick +
(ruler.barHeight / 2) +
ruler.categorySpacing +
});
});
+ it('should update elements when only the category scale is stacked', function() {
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [{
+ data: [20, -10, 10, -10],
+ label: 'dataset1'
+ }, {
+ data: [10, 15, 0, -14],
+ label: 'dataset2'
+ }],
+ labels: ['label1', 'label2', 'label3', 'label4']
+ },
+ options: {
+ scales: {
+ xAxes: [{
+ type: 'category',
+ stacked: true
+ }],
+ yAxes: [{
+ type: 'linear'
+ }]
+ }
+ }
+ });
+
+ var meta0 = chart.getDatasetMeta(0);
+
+ [
+ {b: 290, w: 83, x: 86, y: 32},
+ {b: 290, w: 83, x: 202, y: 419},
+ {b: 290, w: 83, x: 318, y: 161},
+ {b: 290, w: 83, x: 434, y: 419}
+ ].forEach(function(values, i) {
+ expect(meta0.data[i]._model.base).toBeCloseToPixel(values.b);
+ expect(meta0.data[i]._model.width).toBeCloseToPixel(values.w);
+ expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x);
+ expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y);
+ });
+
+ var meta1 = chart.getDatasetMeta(1);
+
+ [
+ {b: 290, w: 83, x: 86, y: 161},
+ {b: 290, w: 83, x: 202, y: 97},
+ {b: 290, w: 83, x: 318, y: 290},
+ {b: 290, w: 83, x: 434, y: 471}
+ ].forEach(function(values, i) {
+ expect(meta1.data[i]._model.base).toBeCloseToPixel(values.b);
+ expect(meta1.data[i]._model.width).toBeCloseToPixel(values.w);
+ expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x);
+ expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y);
+ });
+ });
+
it('should update elements when the scales are stacked and data is strings', function() {
var chart = window.acquireChart({
type: 'bar',