diff --git a/flamegraph.pl b/flamegraph.pl index 7dd41e7..bb7ec4c 100755 --- a/flamegraph.pl +++ b/flamegraph.pl @@ -415,6 +415,24 @@ my $inc = <= width) { + for (var x = len - 3; x > 3; x -= 3) { + if (textObj.getSubStringLength(0, x + 4) <= width) { + textObj.textContent = textString.substring(0,x) + ".."; + return; + } + } + textObj.textContent = ""; + } + } function zoom_reset(e) { if (e.attributes != undefined) { if (e.attributes["_orig_x"] != undefined) { @@ -444,6 +462,7 @@ my $inc = <ymin || parseFloat(a["x"].value) < xmin || parseFloat(a["x"].value) > xmax) { @@ -468,14 +487,17 @@ my $inc = < @@ -541,14 +563,19 @@ while (my ($id, $node) = each %Node) { } my $chars = int( ($x2 - $x1) / ($fontsize * $fontwidth)); - if ($chars >= 3) { # room for one char plus two dots - my $text = substr $func, 0, $chars; - substr($text, -2, 2) = ".." if $chars < length $func; - $text =~ s/&/&/g; - $text =~ s//>/g; - $im->stringTTF($black, $fonttype, $fontsize, 0.0, $x1 + 3, 3 + ($y1 + $y2) / 2, $text, ""); + my $text; + if ($chars > length $func) { + $text = $func; + } elsif ($chars <= 2) { + $text = "" + } else { + $text = substr $func, 0, $chars - 2; + $text .= ".."; } + $text =~ s/&/&/g; + $text =~ s//>/g; + $im->stringTTF($black, $fonttype, $fontsize, 0.0, $x1 + 3, 3 + ($y1 + $y2) / 2, $text, "", "func=\"$func\""); $im->group_end($nameattr); }