Commit fcd4bce6 authored by Ole Laursen's avatar Ole Laursen

Fix bug when both label width and height is set (fix by Ara

Anjargolian)
parent 06c7d41a
...@@ -852,51 +852,49 @@ ...@@ -852,51 +852,49 @@
axisw = opts.labelWidth || 0, axish = opts.labelHeight || 0, axisw = opts.labelWidth || 0, axish = opts.labelHeight || 0,
f = axis.font; f = axis.font;
if (opts.labelWidth == null || opts.labelHeight == null) { ctx.save();
ctx.save(); ctx.font = f.style + " " + f.variant + " " + f.weight + " " + f.size + "px '" + f.family + "'";
ctx.font = f.style + " " + f.variant + " " + f.weight + " " + f.size + "px '" + f.family + "'";
for (var i = 0; i < ticks.length; ++i) {
var t = ticks[i];
t.lines = [];
t.width = t.height = 0;
if (!t.label) for (var i = 0; i < ticks.length; ++i) {
continue; var t = ticks[i];
t.lines = [];
t.width = t.height = 0;
// accept various kinds of newlines, including HTML ones if (!t.label)
// (you can actually split directly on regexps in Javascript, continue;
// but IE is unfortunately broken)
var lines = t.label.replace(/<br ?\/?>|\r\n|\r/g, "\n").split("\n");
for (var j = 0; j < lines.length; ++j) {
var line = { text: lines[j] },
m = ctx.measureText(line.text);
line.width = m.width;
// m.height might not be defined, not in the
// standard yet
line.height = m.height != null ? m.height : f.size;
// add a bit of margin since font rendering is // accept various kinds of newlines, including HTML ones
// not pixel perfect and cut off letters look // (you can actually split directly on regexps in Javascript,
// bad, this also doubles as spacing between // but IE is unfortunately broken)
// lines var lines = t.label.replace(/<br ?\/?>|\r\n|\r/g, "\n").split("\n");
line.height += Math.round(f.size * 0.15); for (var j = 0; j < lines.length; ++j) {
var line = { text: lines[j] },
m = ctx.measureText(line.text);
line.width = m.width;
// m.height might not be defined, not in the
// standard yet
line.height = m.height != null ? m.height : f.size;
t.width = Math.max(line.width, t.width); // add a bit of margin since font rendering is
t.height += line.height; // not pixel perfect and cut off letters look
// bad, this also doubles as spacing between
// lines
line.height += Math.round(f.size * 0.15);
t.lines.push(line); t.width = Math.max(line.width, t.width);
} t.height += line.height;
if (opts.labelWidth == null) t.lines.push(line);
axisw = Math.max(axisw, t.width);
if (opts.labelHeight == null)
axish = Math.max(axish, t.height);
} }
ctx.restore();
if (opts.labelWidth == null)
axisw = Math.max(axisw, t.width);
if (opts.labelHeight == null)
axish = Math.max(axish, t.height);
} }
ctx.restore();
axis.labelWidth = Math.ceil(axisw); axis.labelWidth = Math.ceil(axisw);
axis.labelHeight = Math.ceil(axish); axis.labelHeight = Math.ceil(axish);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment