Commits

Anonymous committed fd3ee33

Working out prefix option for tick label formatting.

Comments (0)

Files changed (2)

src/jqplot.axisTickRenderer.js

         // prop: formatter
         // A class of a formatter for the tick text.  sprintf by default.
         this.formatter = $.jqplot.DefaultTickFormatter;
+        // prop: prefix
+        // string appended to the tick label if no formatString is specified.
+        this.prefix = '';
         // prop: formatString
         // string passed to the formatter.
         this.formatString = '';
         if (!this.label) {
             this.label = this.formatter(this.formatString, this.value);
         }
+        // add prefix if needed
+        if (this.prefix && !this.formatString) {
+            this.label = this.prefix + this.label;
+        }
         style ='style="position:absolute;';
         if (Number(this.label)) {
             style +='white-space:nowrap;';
     $.jqplot.DefaultTickFormatter = function (format, val) {
         if (typeof val == 'number') {
             if (!format) {
-                format = '%.1f';
+                format = $.jqplot.config.defaultTickFormatString;
             }
             return $.jqplot.sprintf(format, val);
         }

src/plugins/jqplot.canvasAxisTickRenderer.js

         // prop: formatString
         // string passed to the formatter.
         this.formatString = '';
+        // prop: prefix
+        // string appended to the tick label if no formatString is specified.
+        this.prefix = '';
         // prop: fontFamily
         // css spec for the font-family css attribute.
         this.fontFamily = '"Trebuchet MS", Arial, Helvetica, sans-serif';
         if (!this.label) {
             this.label = this.formatter(this.formatString, this.value);
         }
+        // add prefix if needed
+        if (this.prefix && !this.formatString) {
+            this.label = this.prefix + this.label;
+        }
         // create a canvas here, but can't draw on it untill it is appended
         // to dom for IE compatability.
         var domelem = document.createElement('canvas');