Anonymous avatar Anonymous committed 561ba11

Fixed positioning of meter gauge label when put at bottom of plot.

Comments (0)

Files changed (2)

examples/meterGauge.html

        seriesDefaults: {
            renderer: $.jqplot.MeterGaugeRenderer,
            rendererOptions: {
-               label: 'MB/s',
-               labelPosition: 'bottom'
+               label: 'MB/s'
            }
        }
    });
            renderer: $.jqplot.MeterGaugeRenderer,
            rendererOptions: {
                label: 'Metric Tons per Year',
-               labelHeightAdjust: -15,
+               labelPosition: 'bottom',
+               labelHeightAdjust: -5,
                intervalOuterRadius: 85,
                ticks: [10000, 30000, 50000, 70000],
                intervals:[22000, 55000, 70000],
 
 <div id="chart3" class="plot" style="width:300px;height:180px;"></div>
 
-<p>The inner and outer radii of the interval band can also be specified with the "intervalInnerRadius" and "intervalOuterRadius" options.  In the plot below, the "labelHeightAdjust" option was also used to raise the gauge label by 15 pixels</p>
+<p>The inner and outer radii of the interval band can also be specified with the "intervalInnerRadius" and "intervalOuterRadius" options.  In the plot below, the "labelPosition" option was set to "bottom" to put the gauge label below the plot.  The "labelHeightAdjust" option was set to -5 to raise the label slightly (5 pixels) to place it closer to the gauge.</p>
 <p>The gauge automatically resizes to best fit the container.  The font size of the tick labels and gauge labels do not size to the container, however.  The font size of the tick labels can be controlled by styling the css ".jqplot-meterGauge-ticks" class and the gauge label by the "jqplot-meterGauge-label" class.</p>
 <div id="chart4" class="plot" style="width:500px;height:300px;"></div>
   </body>

src/plugins/jqplot.meterGaugeRenderer.js

         // Outer diameter of the meterGauge, auto computed by default
         this.diameter = null;
         // prop: padding
-        // padding between the meterGauge and plot edges.
-        this.padding = 5;
+        // padding between the meterGauge and plot edges, auto
+        // calculated by default.
+        this.padding = null;
         // prop: shadowOffset
         // offset of the shadow from the gauge ring and offset of 
         // each succesive stroke of the shadow from the last.
         var fill = (opts.fill != undefined) ? opts.fill : this.fill;
         var cw = ctx.canvas.width;
         var ch = ctx.canvas.height;
+        if (this.padding == null) {
+            this.padding = Math.round(Math.min(cw, ch)/30);
+        }
         var w = cw - offx - 2 * this.padding;
         var h = ch - offy - 2 * this.padding;
         if (this.labelPosition == 'bottom') {
             
             else if (this.label && this.labelPosition == 'bottom') {
                 var l = this._center[0] + this.canvas._offsets.left - this._labelElem.outerWidth(true)/2;
-                var t = this._center[1] + this.canvas._offsets.top + this.innerPad + 2*this.padding;
+                var t = this._center[1] + this.canvas._offsets.top + this.innerPad + + this.ringWidth + this.padding + this.labelHeightAdjust;
                 this._labelElem.css({left:l, top:t});
                 
             }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.