Add support for mirror option

This commit is contained in:
Michaël Gallego 2015-08-05 17:40:44 +02:00
parent 31c5e45bd4
commit 0c6f37fff7
2 changed files with 23 additions and 5 deletions

View File

@ -364,6 +364,12 @@ the following options.
labels: {
// Boolean - if true show labels
show: true,
// Boolean - if true the chart will mirror the axis labels. If the labels are on the left, mirroring the axis will render them to the right
mirror: false,
// Number - controls the padding between the label and the axis
padding: 10,
// String - template string for labels
template: "<%=value%>",

View File

@ -28,11 +28,13 @@
// label settings
labels: {
show: true,
mirror: false,
padding: 10,
template: "<%=value.toLocaleString()%>",
fontSize: 12,
fontStyle: "normal",
fontColor: "#666",
fontFamily: "Helvetica Neue",
fontFamily: "Helvetica Neue"
}
};
@ -548,12 +550,22 @@
var labelStartX;
if (this.options.position == "left") {
labelStartX = this.right - 10;
this.ctx.textAlign = "right";
if (this.options.labels.mirror) {
labelStartX = this.right + this.options.labels.padding;
this.ctx.textAlign = "left";
} else {
labelStartX = this.right - this.options.labels.padding;
this.ctx.textAlign = "right";
}
} else {
// right side
labelStartX = this.left + 5;
this.ctx.textAlign = "left";
if (this.options.labels.mirror) {
labelStartX = this.left - this.options.labels.padding;
this.ctx.textAlign = "right";
} else {
labelStartX = this.left + this.options.labels.padding;
this.ctx.textAlign = "left";
}
}
this.ctx.textBaseline = "middle";