Skip to content

Commit

Permalink
Restore 0.7's maximum width for x-axis labels.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dnschnur committed May 5, 2013
1 parent e8ef708 commit 571d86e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions jquery.flot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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) {
Expand Down

1 comment on commit 571d86e

@dnschnur
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #1019

Please sign in to comment.