Commits

Anonymous committed bbaa15b

Fixing half-pixels bug on legend border when converting a plot in an image.

  • Participants
  • Parent commits dd65cd0

Comments (0)

Files changed (1)

File src/jqplot.toImage.js

 
             // handle the standard table legend
 
-            else if (tagname === 'table' && $(el).hasClass('jqplot-table-legend')) {
+            else if (tagname === 'table' && $(el).hasClass('jqplot-table-legend') && !$(el).hasClass('jqplot-series-hidden') {
                 newContext.strokeStyle = $(el).css('border-top-color');
                 newContext.fillStyle = $(el).css('background-color');
-                newContext.fillRect(left, top, $(el).innerWidth(), $(el).innerHeight());
+                newContext.fillRect(left-0.5, top-0.5, $(el).innerWidth(), $(el).innerHeight());
                 if (parseInt($(el).css('border-top-width'), 10) > 0) {
-                    newContext.strokeRect(left, top, $(el).innerWidth(), $(el).innerHeight());
+                    newContext.strokeRect(left-0.5, top-0.5, $(el).innerWidth(), $(el).innerHeight());
                 }
 
                 // find all the swatches
                     // get the first div and stroke it
                     var elem = $(this);
                     newContext.strokeStyle = elem.css('border-top-color');
-                    var l = left + elem.position().left;
-                    var t = top + elem.position().top;
+                    var l = 0.5+left + elem.position().left;
+                    var t = 0.5+top + elem.position().top;
                     newContext.strokeRect(l, t, elem.innerWidth(), elem.innerHeight());
 
                     // now fill the swatch
                     
-                    l += parseInt(elem.css('padding-left'), 10);
-                    t += parseInt(elem.css('padding-top'), 10);
-                    var h = elem.innerHeight() - 2 * parseInt(elem.css('padding-top'), 10);
-                    var w = elem.innerWidth() - 2 * parseInt(elem.css('padding-left'), 10);
+                    l += 0.5+parseInt(elem.css('padding-left'), 10);
+                    t += 0.5+parseInt(elem.css('padding-top'), 10);
+                    var h = elem.innerHeight() - 2 * parseInt(elem.css('padding-top'), 10)-1;
+                    var w = elem.innerWidth() - 2 * parseInt(elem.css('padding-left'), 10)-1;
 
                     var swatch = elem.children('div.jqplot-table-legend-swatch');
                     newContext.fillStyle = swatch.css('background-color');