mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 20:29:12 +02:00
Better sizing when not displaying
This commit is contained in:
parent
a2e1a97382
commit
4f8f182d21
@ -173,39 +173,41 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Increase sizes here
|
// Increase sizes here
|
||||||
if (this.isHorizontal()) {
|
if (this.options.display) {
|
||||||
// Labels
|
if (this.isHorizontal()) {
|
||||||
|
// Labels
|
||||||
|
|
||||||
// Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
|
// Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
|
||||||
this.lineWidths = [0];
|
this.lineWidths = [0];
|
||||||
var totalHeight = this.legendItems.length ? this.options.labels.fontSize + (this.options.labels.padding) : 0;
|
var totalHeight = this.legendItems.length ? this.options.labels.fontSize + (this.options.labels.padding) : 0;
|
||||||
|
|
||||||
ctx.textAlign = "left";
|
ctx.textAlign = "left";
|
||||||
ctx.textBaseline = 'top';
|
ctx.textBaseline = 'top';
|
||||||
ctx.font = labelFont;
|
ctx.font = labelFont;
|
||||||
|
|
||||||
helpers.each(this.legendItems, function(legendItem, i) {
|
helpers.each(this.legendItems, function(legendItem, i) {
|
||||||
var width = this.options.labels.boxWidth + (this.options.labels.fontSize / 2) + ctx.measureText(legendItem.text).width;
|
var width = this.options.labels.boxWidth + (this.options.labels.fontSize / 2) + ctx.measureText(legendItem.text).width;
|
||||||
if (this.lineWidths[this.lineWidths.length - 1] + width >= this.width) {
|
if (this.lineWidths[this.lineWidths.length - 1] + width >= this.width) {
|
||||||
totalHeight += this.options.labels.fontSize + (this.options.labels.padding);
|
totalHeight += this.options.labels.fontSize + (this.options.labels.padding);
|
||||||
this.lineWidths[this.lineWidths.length] = this.left;
|
this.lineWidths[this.lineWidths.length] = this.left;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the hitbox width and height here. Final position will be updated in `draw`
|
// Store the hitbox width and height here. Final position will be updated in `draw`
|
||||||
this.legendHitBoxes[i] = {
|
this.legendHitBoxes[i] = {
|
||||||
left: 0,
|
left: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
width: width,
|
width: width,
|
||||||
height: this.options.labels.fontSize,
|
height: this.options.labels.fontSize,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.lineWidths[this.lineWidths.length - 1] += width + this.options.labels.padding;
|
this.lineWidths[this.lineWidths.length - 1] += width + this.options.labels.padding;
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
this.minSize.height += totalHeight;
|
this.minSize.height += totalHeight;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// TODO vertical
|
// TODO vertical
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.width = this.minSize.width;
|
this.width = this.minSize.width;
|
||||||
|
Loading…
Reference in New Issue
Block a user