Commits

cleonello  committed 561ba11

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

  • Participants
  • Parent commits 81a478b

Comments (0)

Files changed (2)

File 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>

File 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});
                 
             }