Commits

Kang-min Liu  committed df44e9e

let point label of a negative bar (of a barchart) positioned in the opposite location.

When it's normally above the point (north), it should be beneath the point (south) when it's a negative point.

  • Participants
  • Parent commits a806b42

Comments (0)

Files changed (2)

File examples/barTest.html

   <script class="code" type="text/javascript">$(document).ready(function(){
         plot6 = $.jqplot('chart6', [[1,2,3,4]], {seriesDefaults:{renderer:$.jqplot.PieRenderer}});
     });</script> 
+
+  <script class="code" type="text/javascript">$(document).ready(function(){
+        var s1 = [2, -6, 7, -5];
+        var ticks = ['a', 'b', 'c', 'd'];
+
+        plot7 = $.jqplot('chart7', [s1], {
+            seriesDefaults:{
+                renderer:$.jqplot.BarRenderer,
+                rendererOptions: { fillToZero: true },
+                pointLabels: { show: true }
+            },
+            axes: {
+                xaxis: {
+                    renderer: $.jqplot.CategoryAxisRenderer,
+                    ticks: ticks
+                }
+            }
+        });
+    });</script> 
   
     <script type="text/javascript">    
         $(document).ready(function(){
     
     <div id="chart5" style="margin-top:20px; margin-left:20px; width:300px; height:300px;"></div>
 <pre class="code"></pre>
-        
+
 <p>A pie chart is added to test for incompatibilities.</p>
         <div id="chart6" style="margin-top:20px; margin-left:20px; width:300px; height:200px;"></div>
 <pre class="code"></pre>
+
+
+    <p>The nex example shows the placement of point labels on negative bars. They shou be placed on the opposite position. That is, if it is placed 'north' to the positive bars, then it should be placed 'south' to the negative bars.</p>
+    <div id="chart7" style="margin-top:20px; margin-left:20px; width:300px; height:300px;"></div>
+<pre class="code"></pre>
+        
+
   </body>
-</html>
+</html>

File src/plugins/jqplot.pointLabels.js

                     elem.html(label);
                 }
                 var location = p.location;
-                if (this.waterfall && parseInt(label, 10) < 0) {
+                if ((this.fillToZero && pd[i][1] < 0) || (this.waterfall && parseInt(label, 10) < 0)) {
                     location = oppositeLocations[locationIndicies[location]];
                 }
                 var ell = xax.u2p(pd[i][0]) + p.xOffset(elem, location);
     
     $.jqplot.postSeriesInitHooks.push($.jqplot.PointLabels.init);
     $.jqplot.postDrawSeriesHooks.push($.jqplot.PointLabels.draw);
-})(jQuery);
+})(jQuery);