summaryrefslogtreecommitdiffstats
path: root/grapher/GraphWidget.cxx
diff options
context:
space:
mode:
authorTim Moore <timoore@redhat.com>2009-04-22 10:20:20 +0200
committerTim Moore <timoore@redhat.com>2009-07-28 10:13:54 +0200
commitd982d13c99f7c4119a9ceea1749a54cca7e53d38 (patch)
tree97cc1c185099bb45c79d79551a1bb69e72030d81 /grapher/GraphWidget.cxx
parent89fc05fd9c7c04de6568b9ef31e1feb9c092da95 (diff)
downloadsystemtap-steved-d982d13c99f7c4119a9ceea1749a54cca7e53d38.tar.gz
systemtap-steved-d982d13c99f7c4119a9ceea1749a54cca7e53d38.tar.xz
systemtap-steved-d982d13c99f7c4119a9ceea1749a54cca7e53d38.zip
Tweaks to grapher axis drawing
* grapher/GraphWidget.cxx (on_expose_event): Don't draw axis labels that would overlap others.
Diffstat (limited to 'grapher/GraphWidget.cxx')
-rw-r--r--grapher/GraphWidget.cxx22
1 files changed, 15 insertions, 7 deletions
diff --git a/grapher/GraphWidget.cxx b/grapher/GraphWidget.cxx
index 38f8078d..34b4daf4 100644
--- a/grapher/GraphWidget.cxx
+++ b/grapher/GraphWidget.cxx
@@ -210,7 +210,7 @@ namespace systemtap
// Draw axes
double diff = _right - _left;
double majorUnit = pow(10.0, floor(log(diff) / log(10.0)));
- double startTime = floor(_left / majorUnit) * majorUnit;
+ double startTime = ceil(_left / majorUnit) * majorUnit;
cr->save();
cr->set_source_rgba(1.0, 1.0, 1.0, .9);
cr->set_line_cap(Cairo::LINE_CAP_BUTT);
@@ -226,15 +226,23 @@ namespace systemtap
std::valarray<double> dash(1);
dash[0] = height / 10;
cr->set_dash(dash, 0.0);
- for (double tickVal = startTime; tickVal < _right; tickVal += majorUnit)
+ double prevTextAdvance = 0;
+ for (double tickVal = startTime; tickVal <= _right; tickVal += majorUnit)
{
- cr->move_to((tickVal - _left) * horizScale + 20.0, graphHeight - 5);
+ double x = (tickVal - _left) * horizScale + 20.0;
+ cr->move_to(x, 0.0);
+ cr->line_to(x, height);
+ cr->move_to(x, graphHeight - 5);
std::ostringstream stream;
stream << std::fixed << std::setprecision(0) << tickVal;
- cr->show_text(stream.str());
- cr->move_to((tickVal - _left) * horizScale + 20.0, 0.0);
- cr->line_to((tickVal - _left) * horizScale + 20.0, height);
- cr->stroke();
+ Cairo::TextExtents extents;
+ cr->get_text_extents(stream.str(), extents);
+ // Room for this label?
+ if (x + extents.x_bearing > prevTextAdvance)
+ {
+ cr->show_text(stream.str());
+ prevTextAdvance = x + extents.x_advance;
+ }
}
cr->stroke();
cr->restore();