From 571d86e936a5b27cb7fc54dc16a4ea74842c11ec Mon Sep 17 00:00:00 2001 From: David Schnur Date: Sun, 5 May 2013 16:58:06 -0400 Subject: [PATCH] Restore 0.7's maximum width for x-axis labels. Flot 0.7 calculated x-axis label dimensions by assigning each label a fixed width, then measuring the height as determined by the browser. A side-effect of this technique is that x-axis label divs received a fixed width. The rewrite of the text system in 0.8 accidentally removed this feature; this patch restores it. --- jquery.flot.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/jquery.flot.js b/jquery.flot.js index 81eb981..16ed7ae 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -1284,8 +1284,11 @@ Licensed under the MIT license. function measureTickLabels(axis) { - var opts = axis.options, ticks = axis.ticks || [], - axisw = opts.labelWidth || 0, axish = opts.labelHeight || 0, + var opts = axis.options, + ticks = axis.ticks || [], + labelWidth = opts.labelWidth || 0, + labelHeight = opts.labelHeight || 0, + maxWidth = labelWidth || axis.direction == "x" ? Math.floor(surface.width / (ticks.length || 1)) : null; legacyStyles = axis.direction + "Axis " + axis.direction + axis.n + "Axis", layer = "flot-" + axis.direction + "-axis flot-" + axis.direction + axis.n + "-axis " + legacyStyles, font = opts.font || "flot-tick-label tickLabel"; @@ -1297,16 +1300,14 @@ Licensed under the MIT license. if (!t.label) continue; - var info = surface.getTextInfo(layer, t.label, font); + var info = surface.getTextInfo(layer, t.label, font, null, maxWidth); - if (opts.labelWidth == null) - axisw = Math.max(axisw, info.width); - if (opts.labelHeight == null) - axish = Math.max(axish, info.height); + labelWidth = Math.max(labelWidth, info.width); + labelHeight = Math.max(labelHeight, info.height); } - axis.labelWidth = Math.ceil(axisw); - axis.labelHeight = Math.ceil(axish); + axis.labelWidth = opts.labelWidth || labelWidth; + axis.labelHeight = opts.labelHeight || labelHeight; } function allocateAxisBoxFirstPhase(axis) {