From f99a225ffc395c7e08f6c8bb9df5173be5fa5897 Mon Sep 17 00:00:00 2001 From: David Schnur Date: Tue, 2 Apr 2013 17:39:53 -0400 Subject: [PATCH] Set the text baseline only once. The setting is the same for everything, so there's no reason to re-set it every time. --- jquery.flot.canvas.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/jquery.flot.canvas.js b/jquery.flot.canvas.js index d9671d5..cfbcbf8 100644 --- a/jquery.flot.canvas.js +++ b/jquery.flot.canvas.js @@ -68,6 +68,19 @@ browser, but needs to redraw with canvas text when exporting as an image. context.save(); + // TODO: Comments in Ole's implementation indicate that some + // browsers differ in their interpretation of 'top'; so far I + // don't see this, but it requires more testing. We'll stick + // with top until this can be verified. + + // Original comment was: + // Top alignment would be more natural, but browsers can differ a + // pixel or two in where they consider the top to be, so instead + // we middle align to minimize variation between browsers and + // compensate when calculating the coordinates. + + context.textBaseline = "top"; + for (var layerKey in cache) { if (hasOwnProperty.call(cache, layerKey)) { var layerCache = cache[layerKey]; @@ -100,20 +113,6 @@ browser, but needs to redraw with canvas text when exporting as an image. updateStyles = false; } - // TODO: Comments in Ole's implementation indicate that - // some browsers differ in their interpretation of 'top'; - // so far I don't see this, but it requires more testing. - // We'll stick with top until this can be verified. - - // Original comment was: - // Top alignment would be more natural, but browsers can - // differ a pixel or two in where they consider the top to - // be, so instead we middle align to minimize variation - // between browsers and compensate when calculating the - // coordinates. - - context.textBaseline = "top"; - for (var i = 0; i < lines.length; ++i) { var line = lines[i],