]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Logarithmic scale now has labels
authorEvert Timberg <evert.timberg@gmail.com>
Sun, 20 Sep 2015 23:06:09 +0000 (19:06 -0400)
committerEvert Timberg <evert.timberg@gmail.com>
Sun, 20 Sep 2015 23:06:09 +0000 (19:06 -0400)
src/scales/scale.logarithmic.js

index 20545846eba44c26e18494b8a96dc2b362a16564..b7e0defb56abece0072be26bcffecdf3b772bc78 100644 (file)
                        zeroLineColor: "rgba(0,0,0,0.25)",
                },
 
+               // scale label
+               scaleLabel: {
+                       fontColor: '#666',
+                       fontFamily: 'Helvetica Neue',
+                       fontSize: 12,
+                       fontStyle: 'normal',
+
+                       // actual label
+                       labelString: '',
+
+                       // display property
+                       show: false,
+               },
+
                // scale numbers
                reverse: false,
                override: null,
                                minSize.height = maxHeight; // fill all the height
                        }
 
+                       // Are we showing a label for the scale?
+                       if (this.options.scaleLabel.show) {
+                               if (this.isHorizontal()) {
+                                       minSize.height += (this.options.scaleLabel.fontSize * 1.5);
+                               } else {
+                                       minSize.width += (this.options.scaleLabel.fontSize * 1.5);
+                               }
+                       }
+
                        this.paddingLeft = 0;
                        this.paddingRight = 0;
                        this.paddingTop = 0;
                                                        }
                                                }, this);
                                        }
+
+                                       if (this.options.scaleLabel.show) {
+                                               // Draw the scale label
+                                               this.ctx.textAlign = "center";
+                                               this.ctx.textBaseline = 'middle';
+                                               this.ctx.font = helpers.fontString(this.options.scaleLabel.fontSize, this.options.scaleLabel.fontStyle, this.options.scaleLabel.fontFamily);
+
+                                               var scaleLabelX = this.left + ((this.right - this.left) / 2); // midpoint of the width
+                                               var scaleLabelY = this.options.position == 'bottom' ? this.bottom - (this.options.scaleLabel.fontSize / 2) : this.top + (this.options.scaleLabel.fontSize / 2);
+
+                                               this.ctx.fillText(this.options.scaleLabel.labelString, scaleLabelX, scaleLabelY);
+                                       }
                                } else {
                                        // Vertical
                                        if (this.options.gridLines.show) {
                                                        this.ctx.fillText(label, labelStartX, yValue);
                                                }, this);
                                        }
+
+                                       if (this.options.scaleLabel.show) {
+                                               // Draw the scale label
+                                               var scaleLabelX = this.options.position == 'left' ? this.left + (this.options.scaleLabel.fontSize / 2) : this.right - (this.options.scaleLabel.fontSize / 2);
+                                               var scaleLabelY = this.top + ((this.bottom - this.top) / 2);
+                                               var rotation = this.options.position == 'left' ? -0.5 * Math.PI : 0.5 * Math.PI;
+
+                                               this.ctx.save();
+                                               this.ctx.translate(scaleLabelX, scaleLabelY);
+                                               this.ctx.rotate(rotation);
+                                               this.ctx.textAlign = "center";
+                                               this.ctx.font = helpers.fontString(this.options.scaleLabel.fontSize, this.options.scaleLabel.fontStyle, this.options.scaleLabel.fontFamily);
+                                               this.ctx.textBaseline = 'middle';
+                                               this.ctx.fillText(this.options.scaleLabel.labelString, 0, 0);
+                                               this.ctx.restore();
+                                       }
                                }
                        }
                }