libsysprof-gtk: implement some basic depth chart drawing

This commit is contained in:
Christian Hergert
2023-06-20 11:49:53 -07:00
parent c2a8b04cf7
commit 0cdb97973a

View File

@ -55,29 +55,37 @@ sysprof_depth_layer_snapshot (GtkWidget *widget,
g_assert (SYSPROF_IS_DEPTH_LAYER (self)); g_assert (SYSPROF_IS_DEPTH_LAYER (self));
g_assert (GTK_IS_SNAPSHOT (snapshot)); 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; 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; return;
sysprof_xy_series_get_range (self->series, &min_x, NULL, &max_x, NULL); sysprof_xy_series_get_range (self->series, &min_x, NULL, &max_x, NULL);
width = gtk_widget_get_width (widget); /* NOTE: We might want to allow setting a "bucket size" for the
height = gtk_widget_get_width (widget); * line width here so that units get joined together. For example,
* with stack traces, we would get nano-second precision due to time
line_width = MAX (1, (max_x - min_x) / width); * 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++) for (guint i = 0; i < n_values; i++)
{ {
const SysprofXYSeriesValue *v = &values[i]; const SysprofXYSeriesValue *v = &values[i];
int line_height = ceilf (v->y * height);
gtk_snapshot_append_color (snapshot, gtk_snapshot_append_color (snapshot,
&self->color, &self->color,
&GRAPHENE_RECT_INIT (v->x * width, &GRAPHENE_RECT_INIT (v->x * width,
height, height - line_height,
line_width, line_width,
height - (v->y * height))); line_height));
} }
} }