diff options
author | Steven Rostedt <srostedt@redhat.com> | 2010-02-08 14:47:16 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2010-02-10 10:58:40 -0500 |
commit | 7d359f826170f08cc97a683cb48e4051c7a79117 (patch) | |
tree | fc9a2db447b36e52b06ada3ea3d564e1d2195d42 | |
parent | a96c7ce3e6106ac1677fbc948250c8881a45b252 (diff) |
trace-graph: Fix printing of event labels
Make the printing of event labels a bit more sophisicated. That is
to print the event label when there is enough room before and
after the event. If one label is small, let another larger label
use up that space.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-graph.c | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/trace-graph.c b/trace-graph.c index 6f31862..026d940 100644 --- a/trace-graph.c +++ b/trace-graph.c | |||
@@ -1364,7 +1364,9 @@ static void set_color(GtkWidget *widget, GdkGC *gc, gint c) | |||
1364 | gdk_gc_set_foreground(gc, &color); | 1364 | gdk_gc_set_foreground(gc, &color); |
1365 | } | 1365 | } |
1366 | 1366 | ||
1367 | static void draw_event_label(struct graph_info *ginfo, gint i, | 1367 | #define LABEL_SPACE 3 |
1368 | |||
1369 | static gint draw_event_label(struct graph_info *ginfo, gint i, | ||
1368 | gint p1, gint p2, gint p3, | 1370 | gint p1, gint p2, gint p3, |
1369 | gint width_16, PangoFontDescription *font) | 1371 | gint width_16, PangoFontDescription *font) |
1370 | { | 1372 | { |
@@ -1373,18 +1375,22 @@ static void draw_event_label(struct graph_info *ginfo, gint i, | |||
1373 | struct trace_seq s; | 1375 | struct trace_seq s; |
1374 | gint text_width; | 1376 | gint text_width; |
1375 | gint text_height; | 1377 | gint text_height; |
1378 | gint start, end; | ||
1376 | gint x, y; | 1379 | gint x, y; |
1377 | gint ret; | 1380 | gint ret; |
1378 | 1381 | ||
1382 | /* | ||
1383 | * We are testing if we can print the label at p2. | ||
1384 | * p1 has the start of the area that we can print. | ||
1385 | * p3 is the location of the next label. | ||
1386 | * We will not print any label unless we have enough | ||
1387 | * room to print a minimum of 16 characters. | ||
1388 | */ | ||
1389 | if (p3 - p1 < width_16 || | ||
1390 | p3 - p2 < width_16 / 2) | ||
1391 | return p2; | ||
1379 | 1392 | ||
1380 | /* No room to print */ | 1393 | /* Now get p2's drawing size */ |
1381 | if ((p2 > width_16 && ((p3 - p2) < width_16 / 2 || | ||
1382 | (p2 - p1) < width_16 / 2)) || | ||
1383 | (p2 <= width_16 && (p1 || (p3 - p2) < width_16))) | ||
1384 | return; | ||
1385 | |||
1386 | /* Check if we can show some data */ | ||
1387 | |||
1388 | trace_seq_init(&s); | 1394 | trace_seq_init(&s); |
1389 | 1395 | ||
1390 | /* | 1396 | /* |
@@ -1396,34 +1402,41 @@ static void draw_event_label(struct graph_info *ginfo, gint i, | |||
1396 | ret = trace_graph_plot_display_last_event(ginfo, plot, &s, | 1402 | ret = trace_graph_plot_display_last_event(ginfo, plot, &s, |
1397 | convert_x_to_time(ginfo, p2-1)); | 1403 | convert_x_to_time(ginfo, p2-1)); |
1398 | if (!ret) | 1404 | if (!ret) |
1399 | return; | 1405 | return p2; |
1400 | 1406 | ||
1401 | layout = gtk_widget_create_pango_layout(ginfo->draw, s.buffer); | 1407 | layout = gtk_widget_create_pango_layout(ginfo->draw, s.buffer); |
1402 | pango_layout_set_font_description(layout, font); | 1408 | pango_layout_set_font_description(layout, font); |
1403 | |||
1404 | pango_layout_get_pixel_size(layout, &text_width, &text_height); | 1409 | pango_layout_get_pixel_size(layout, &text_width, &text_height); |
1405 | 1410 | ||
1406 | if ((p2 > text_width && ((p3 - p2) < text_width || | 1411 | /* Lets see if we can print this info */ |
1407 | (p2 - p1) < text_width)) || | 1412 | if (p2 < text_width) |
1408 | (p2 < text_width && (p1 || (p3 - p2 < (text_width + | 1413 | start = 1; |
1409 | text_width / 2))))) { | 1414 | else |
1415 | start = p2 - text_width / 2; | ||
1416 | end = start + text_width; | ||
1417 | |||
1418 | if (start < p1 || end > p3) { | ||
1410 | g_object_unref(layout); | 1419 | g_object_unref(layout); |
1411 | return; | 1420 | return p2; |
1412 | } | 1421 | } |
1413 | 1422 | ||
1414 | x = p2 - text_width / 2; | 1423 | /* Display the info */ |
1415 | if (x < 0) | 1424 | x = start; |
1416 | x = 1; | ||
1417 | 1425 | ||
1418 | y = (PLOT_TOP(i) - text_height + 5); | 1426 | y = (PLOT_TOP(i) - text_height + 5); |
1419 | gdk_draw_layout(ginfo->curr_pixmap, ginfo->draw->style->black_gc, | 1427 | gdk_draw_layout(ginfo->curr_pixmap, ginfo->draw->style->black_gc, |
1420 | x, y, layout); | 1428 | x, y, layout); |
1421 | 1429 | ||
1422 | |||
1423 | gdk_draw_line(ginfo->curr_pixmap, ginfo->draw->style->black_gc, | 1430 | gdk_draw_line(ginfo->curr_pixmap, ginfo->draw->style->black_gc, |
1424 | p2, PLOT_TOP(i) - 5, p2, PLOT_TOP(i) - 1); | 1431 | p2, PLOT_TOP(i) - 5, p2, PLOT_TOP(i) - 1); |
1425 | 1432 | ||
1426 | g_object_unref(layout); | 1433 | g_object_unref(layout); |
1434 | |||
1435 | /* | ||
1436 | * Set the next p1 to start after the end of what was displayed | ||
1437 | * plus a little padding. | ||
1438 | */ | ||
1439 | return end + LABEL_SPACE; | ||
1427 | } | 1440 | } |
1428 | 1441 | ||
1429 | static gint draw_plot_line(struct graph_info *ginfo, int i, | 1442 | static gint draw_plot_line(struct graph_info *ginfo, int i, |
@@ -1539,8 +1552,8 @@ static void draw_plot(struct graph_info *ginfo, gint i, | |||
1539 | 1552 | ||
1540 | /* first record, continue */ | 1553 | /* first record, continue */ |
1541 | if (p2) | 1554 | if (p2) |
1542 | draw_event_label(ginfo, i, | 1555 | p2 = draw_event_label(ginfo, i, |
1543 | p1, p2, p3, width_16, font); | 1556 | p1, p2, p3, width_16, font); |
1544 | 1557 | ||
1545 | p1 = p2; | 1558 | p1 = p2; |
1546 | p2 = p3; | 1559 | p2 = p3; |