From 0cdb97973af092c6f65212fcc5b47c7208265087 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 20 Jun 2023 11:49:53 -0700 Subject: [PATCH] libsysprof-gtk: implement some basic depth chart drawing --- src/libsysprof-gtk/sysprof-depth-layer.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/libsysprof-gtk/sysprof-depth-layer.c b/src/libsysprof-gtk/sysprof-depth-layer.c index 67829580..95c6df16 100644 --- a/src/libsysprof-gtk/sysprof-depth-layer.c +++ b/src/libsysprof-gtk/sysprof-depth-layer.c @@ -55,29 +55,37 @@ sysprof_depth_layer_snapshot (GtkWidget *widget, g_assert (SYSPROF_IS_DEPTH_LAYER (self)); g_assert (GTK_IS_SNAPSHOT (snapshot)); - if (self->series == NULL || self->color.alpha == 0) + width = gtk_widget_get_width (widget); + height = gtk_widget_get_height (widget); + + if (width == 0 || height == 0 || self->color.alpha == 0) return; - if (!(values = sysprof_xy_series_get_values (self->series, &n_values))) + if (self->series == NULL || + !(values = sysprof_xy_series_get_values (self->series, &n_values))) return; sysprof_xy_series_get_range (self->series, &min_x, NULL, &max_x, NULL); - width = gtk_widget_get_width (widget); - height = gtk_widget_get_width (widget); - - line_width = MAX (1, (max_x - min_x) / width); + /* NOTE: We might want to allow setting a "bucket size" for the + * line width here so that units get joined together. For example, + * with stack traces, we would get nano-second precision due to time + * being the X access, but that's not super helpful when you probably + * want some small quanta to be the width. + */ + line_width = MAX (1, width / (max_x - min_x)); for (guint i = 0; i < n_values; i++) { const SysprofXYSeriesValue *v = &values[i]; + int line_height = ceilf (v->y * height); gtk_snapshot_append_color (snapshot, &self->color, &GRAPHENE_RECT_INIT (v->x * width, - height, + height - line_height, line_width, - height - (v->y * height))); + line_height)); } }