From 0c6f37fff744e8f00c57c51407136cc39d506409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Wed, 5 Aug 2015 17:40:44 +0200 Subject: [PATCH] Add support for mirror option --- docs/00-Getting-Started.md | 6 ++++++ src/scales/scale.linear.js | 22 +++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/docs/00-Getting-Started.md b/docs/00-Getting-Started.md index 49b39a7cc..a678a46d6 100644 --- a/docs/00-Getting-Started.md +++ b/docs/00-Getting-Started.md @@ -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%>", diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index ceeae97c1..8ab840eb9 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -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";