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 @@
axisw = opts.labelWidth || 0, axish = opts.labelHeight || 0,
f = axis.font;
if (opts.labelWidth == null || opts.labelHeight == null) {
ctx.save();
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;
ctx.save();
ctx.font = f.style + " " + f.variant + " " + f.weight + " " + f.size + "px '" + f.family + "'";
if (!t.label)
continue;
for (var i = 0; i < ticks.length; ++i) {
var t = ticks[i];
t.lines = [];
t.width = t.height = 0;
// accept various kinds of newlines, including HTML ones
// (you can actually split directly on regexps in Javascript,
// 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;
if (!t.label)
continue;
// add a bit of margin since font rendering is
// not pixel perfect and cut off letters look
// bad, this also doubles as spacing between
// lines
line.height += Math.round(f.size * 0.15);
// accept various kinds of newlines, including HTML ones
// (you can actually split directly on regexps in Javascript,
// 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;
t.width = Math.max(line.width, t.width);
t.height += line.height;
// add a bit of margin since font rendering is
// 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)
axisw = Math.max(axisw, t.width);
if (opts.labelHeight == null)
axish = Math.max(axish, t.height);
t.lines.push(line);
}
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.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