diff options
author | Steven Rostedt <srostedt@redhat.com> | 2009-12-30 23:30:07 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2009-12-30 23:30:07 -0500 |
commit | e44ef8e27c0e6241c71b8e30048d2076e267ce0e (patch) | |
tree | ace5323f94600c51571b76556b92e4277f03b889 | |
parent | 9c3489c441867fae0bcebdd5fa008ce182bc90d4 (diff) |
trace-graph: Work on fixing the zooming and horizontal scrolling
For some reason zooming in too much will cause the horizontal
scrolling to get out of sync. This is probably a rounding error
or some other strange bug. This patch cleans some of the code
up and fixes parts of it. But there's still a bug to swat.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-graph.c | 85 |
1 files changed, 44 insertions, 41 deletions
diff --git a/trace-graph.c b/trace-graph.c index a92293f..8505169 100644 --- a/trace-graph.c +++ b/trace-graph.c | |||
@@ -30,7 +30,7 @@ | |||
30 | #include "trace-local.h" | 30 | #include "trace-local.h" |
31 | #include "trace-graph.h" | 31 | #include "trace-graph.h" |
32 | 32 | ||
33 | #define DEBUG_LEVEL 1 | 33 | #define DEBUG_LEVEL 2 |
34 | #if DEBUG_LEVEL > 0 | 34 | #if DEBUG_LEVEL > 0 |
35 | # define dprintf(l, x...) \ | 35 | # define dprintf(l, x...) \ |
36 | do { \ | 36 | do { \ |
@@ -460,13 +460,23 @@ motion_notify_event(GtkWidget *widget, GdkEventMotion *event, gpointer data) | |||
460 | return TRUE; | 460 | return TRUE; |
461 | } | 461 | } |
462 | 462 | ||
463 | static void update_graph(struct graph_info *ginfo, gdouble percent) | 463 | static int update_graph(struct graph_info *ginfo, gdouble percent) |
464 | { | 464 | { |
465 | ginfo->full_width *= percent; | 465 | gint full_width = ginfo->full_width * percent; |
466 | ginfo->resolution = | 466 | gdouble resolution = (gdouble)full_width / (gdouble)(ginfo->end_time - |
467 | (gdouble)ginfo->full_width / (gdouble)(ginfo->end_time - | 467 | ginfo->start_time); |
468 | ginfo->start_time); | 468 | |
469 | ginfo->start_x *= percent; | 469 | /* Check if we are too big */ |
470 | if (!resolution || full_width <= 0) | ||
471 | return -1; | ||
472 | |||
473 | ginfo->full_width = full_width; | ||
474 | ginfo->resolution = resolution; | ||
475 | ginfo->start_x = (ginfo->view_start_time - ginfo->start_time) * | ||
476 | ginfo->resolution; | ||
477 | |||
478 | dprintf(1, "new resolution = %f\n", resolution); | ||
479 | return 0; | ||
470 | } | 480 | } |
471 | 481 | ||
472 | static void update_graph_to_start_x(struct graph_info *ginfo) | 482 | static void update_graph_to_start_x(struct graph_info *ginfo) |
@@ -479,10 +489,10 @@ static void update_graph_to_start_x(struct graph_info *ginfo) | |||
479 | return; | 489 | return; |
480 | } | 490 | } |
481 | 491 | ||
482 | ginfo->view_start_time = ginfo->start_x / ginfo->resolution + | 492 | ginfo->view_start_time = (gdouble)ginfo->start_x / ginfo->resolution + |
483 | ginfo->start_time; | 493 | ginfo->start_time; |
484 | 494 | ||
485 | ginfo->view_end_time = width / ginfo->resolution + | 495 | ginfo->view_end_time = (gdouble)width / ginfo->resolution + |
486 | ginfo->view_start_time; | 496 | ginfo->view_start_time; |
487 | 497 | ||
488 | g_assert (ginfo->view_start_time < ginfo->end_time); | 498 | g_assert (ginfo->view_start_time < ginfo->end_time); |
@@ -499,6 +509,7 @@ static void reset_graph(struct graph_info *ginfo, gdouble view_width) | |||
499 | 509 | ||
500 | static void zoom_in_window(struct graph_info *ginfo, gint start, gint end) | 510 | static void zoom_in_window(struct graph_info *ginfo, gint start, gint end) |
501 | { | 511 | { |
512 | guint64 start_time; | ||
502 | gdouble view_width; | 513 | gdouble view_width; |
503 | gdouble new_width; | 514 | gdouble new_width; |
504 | gdouble select_width; | 515 | gdouble select_width; |
@@ -510,26 +521,22 @@ static void zoom_in_window(struct graph_info *ginfo, gint start, gint end) | |||
510 | g_assert(start < end); | 521 | g_assert(start < end); |
511 | g_assert(ginfo->vadj); | 522 | g_assert(ginfo->vadj); |
512 | 523 | ||
513 | dprintf(1, "*** started with "); | 524 | start_time = ginfo->start_time + |
514 | print_time(start / ginfo->resolution + ginfo->view_start_time); | 525 | (ginfo->start_x + start) / ginfo->resolution; |
515 | dprintf(1, "\n"); | ||
516 | 526 | ||
517 | view_width = gtk_adjustment_get_page_size(ginfo->vadj); | 527 | view_width = gtk_adjustment_get_page_size(ginfo->vadj); |
518 | select_width = end - start; | 528 | select_width = end - start; |
519 | percent = view_width / select_width; | 529 | percent = view_width / select_width; |
520 | 530 | ||
521 | update_graph(ginfo, percent); | 531 | dprintf(1, "view width=%f select width=%f percent=%f\n", |
532 | view_width, select_width, percent); | ||
533 | |||
534 | if (update_graph(ginfo, percent) < 0) | ||
535 | return; | ||
522 | 536 | ||
523 | curr_width = ginfo->draw->allocation.width; | 537 | curr_width = ginfo->draw->allocation.width; |
524 | new_width = curr_width * percent; | 538 | new_width = curr_width * percent; |
525 | 539 | ||
526 | dprintf(1, "width=%d\n", ginfo->draw->allocation.width); | ||
527 | if (ginfo->vadj) { | ||
528 | dprintf(1, "adj:%f-%f\n", gtk_adjustment_get_upper(ginfo->vadj), | ||
529 | gtk_adjustment_get_lower(ginfo->vadj)); | ||
530 | } else | ||
531 | dprintf(1, "no adjustment\n"); | ||
532 | |||
533 | ginfo->draw_width = new_width; | 540 | ginfo->draw_width = new_width; |
534 | dprintf(1, "zoom in draw_width=%d full_width=%d\n", | 541 | dprintf(1, "zoom in draw_width=%d full_width=%d\n", |
535 | ginfo->draw_width, ginfo->full_width); | 542 | ginfo->draw_width, ginfo->full_width); |
@@ -550,6 +557,7 @@ static void zoom_in_window(struct graph_info *ginfo, gint start, gint end) | |||
550 | 557 | ||
551 | mid = start + (end - start) / 2; | 558 | mid = start + (end - start) / 2; |
552 | mid *= percent; | 559 | mid *= percent; |
560 | mid += ginfo->start_x; | ||
553 | 561 | ||
554 | /* | 562 | /* |
555 | * mid now points to the center of the viewable area | 563 | * mid now points to the center of the viewable area |
@@ -568,27 +576,18 @@ static void zoom_in_window(struct graph_info *ginfo, gint start, gint end) | |||
568 | 576 | ||
569 | new_start = mid - MAX_WIDTH / 2; | 577 | new_start = mid - MAX_WIDTH / 2; |
570 | new_end = new_start + MAX_WIDTH; | 578 | new_end = new_start + MAX_WIDTH; |
579 | |||
571 | if (new_start < 0) { | 580 | if (new_start < 0) { |
572 | /* First check if there's a start available in full */ | 581 | mid += new_start; |
573 | if (ginfo->start_x) { | ||
574 | ginfo->start_x += new_start; | ||
575 | if (ginfo->start_x < 0) { | ||
576 | new_start = ginfo->start_x; | ||
577 | ginfo->start_x = 0; | ||
578 | } else | ||
579 | new_start = 0; | ||
580 | } | ||
581 | new_end += -new_start; | ||
582 | new_start = 0; | 582 | new_start = 0; |
583 | } else if (new_end > ginfo->full_width) { | 583 | } else if (new_end > ginfo->full_width) { |
584 | new_start -= new_end - ginfo->full_width; | 584 | new_start -= new_end - ginfo->full_width; |
585 | mid += new_end - ginfo->full_width; | ||
585 | new_end = ginfo->full_width; | 586 | new_end = ginfo->full_width; |
586 | g_assert(new_start >= 0); | 587 | g_assert(new_start >= 0); |
587 | } | 588 | } |
588 | 589 | ||
589 | ginfo->start_x += new_start; | 590 | ginfo->start_x = new_start; |
590 | |||
591 | update_graph_to_start_x(ginfo); | ||
592 | 591 | ||
593 | dprintf(1, "new start/end =%d/%d full:%d start_time:", | 592 | dprintf(1, "new start/end =%d/%d full:%d start_time:", |
594 | new_start, new_end, ginfo->full_width); | 593 | new_start, new_end, ginfo->full_width); |
@@ -596,10 +595,15 @@ static void zoom_in_window(struct graph_info *ginfo, gint start, gint end) | |||
596 | dprintf(1, "\n"); | 595 | dprintf(1, "\n"); |
597 | 596 | ||
598 | /* Adjust start to be the location for the vadj */ | 597 | /* Adjust start to be the location for the vadj */ |
599 | start = (mid - new_start) / percent - (end - start) / 2; | 598 | start = (mid - new_start) - view_width / 2; |
600 | } | 599 | } else |
600 | start *= percent; | ||
601 | |||
602 | update_graph_to_start_x(ginfo); | ||
603 | |||
604 | ginfo->vadj_value = start; | ||
605 | ginfo->vadj_value = (start_time - ginfo->view_start_time) * ginfo->resolution; | ||
601 | 606 | ||
602 | ginfo->vadj_value = (gdouble)start * view_width / select_width; | ||
603 | if (ginfo->vadj_value > (ginfo->draw_width - view_width)) | 607 | if (ginfo->vadj_value > (ginfo->draw_width - view_width)) |
604 | ginfo->vadj_value = ginfo->draw_width - view_width; | 608 | ginfo->vadj_value = ginfo->draw_width - view_width; |
605 | 609 | ||
@@ -623,13 +627,11 @@ static void zoom_in_window(struct graph_info *ginfo, gint start, gint end) | |||
623 | static gboolean | 627 | static gboolean |
624 | value_changed(GtkWidget *widget, gpointer data) | 628 | value_changed(GtkWidget *widget, gpointer data) |
625 | { | 629 | { |
626 | #if 0 | 630 | // struct graph_info *ginfo = data; |
627 | struct graph_info *ginfo = data; | ||
628 | GtkAdjustment *adj = GTK_ADJUSTMENT(widget); | 631 | GtkAdjustment *adj = GTK_ADJUSTMENT(widget); |
629 | 632 | ||
630 | printf("value = %f\n", | 633 | dprintf(2, "value = %f\n", |
631 | gtk_adjustment_get_value(adj)); | 634 | gtk_adjustment_get_value(adj)); |
632 | #endif | ||
633 | 635 | ||
634 | return TRUE; | 636 | return TRUE; |
635 | 637 | ||
@@ -660,7 +662,8 @@ static void zoom_out_window(struct graph_info *ginfo, gint start, gint end) | |||
660 | curr_width = ginfo->draw->allocation.width; | 662 | curr_width = ginfo->draw->allocation.width; |
661 | new_width = curr_width / divider; | 663 | new_width = curr_width / divider; |
662 | 664 | ||
663 | update_graph(ginfo, 1 / divider); | 665 | if (update_graph(ginfo, 1 / divider) < 0) |
666 | return; | ||
664 | 667 | ||
665 | dprintf(1, "width=%d\n", ginfo->draw->allocation.width); | 668 | dprintf(1, "width=%d\n", ginfo->draw->allocation.width); |
666 | 669 | ||