static void graph_setup_chart (GogGraph *graph, CutRunContext *run_context) { GogChart *chart; GogPlot *pie; GOData *data; GogSeries *series; gchar **legends; double *values; gint n = 0; chart = GOG_CHART(gog_object_get_child_by_name(GOG_OBJECT(graph), "Chart")); pie = gog_plot_new_by_name("GogPiePlot"); gog_object_add_by_name(GOG_OBJECT(chart), "Plot", GOG_OBJECT(pie)); legends = g_new0(gchar *, CUT_TEST_RESULT_LAST); values = g_new0(double, CUT_TEST_RESULT_LAST); #define STATUS(status) (CUT_TEST_RESULT_ ## status) #define SET_DATA(status, n_statuses) G_STMT_START \ { \ const gchar *name; \ name = cut_test_result_status_to_signal_name(STATUS(status)); \ legends[STATUS(status)] = g_strdup(name); \ values[STATUS(status)] = \ cut_run_context_get_n_ ## n_statuses(run_context); \ n++; \ } G_STMT_END \ SET_DATA(SUCCESS, successes); SET_DATA(NOTIFICATION, notifications); SET_DATA(OMISSION, omissions); SET_DATA(PENDING, pendings); SET_DATA(FAILURE, failures); SET_DATA(ERROR, errors); #undef STATUS #undef SET_DATA series = gog_plot_new_series(pie); data = go_data_vector_str_new((const gchar * const *)legends, n, (GDestroyNotify)g_strfreev); gog_series_set_dim(series, 0, data, NULL); data = go_data_vector_val_new(values, n, g_free); gog_series_set_dim(series, 1, data, NULL); gog_object_add_by_name(GOG_OBJECT(chart), "Legend", NULL); }
static gboolean zx_grid_3d_can_add (GogObject const *parent) { return (GOG_CHART (parent)->axis_set == GOG_AXIS_SET_XYZ && NULL == gog_object_get_child_by_name (parent, "ZX-Backplane")); }
static void gog_chart_view_3d_process (GogView *view, GogViewAllocation *bbox) { /* A XYZ axis set in supposed. If new sets (cylindrical, spherical or other are added, we'll need to change this code */ GogViewAllocation tmp = *bbox; GogAxis *axisX, *axisY, *axisZ, *ref = NULL; GSList *axes; double xmin, xmax, ymin, ymax, zmin, zmax; double o[3], x[3], y[3], z[3], tg, d; Gog3DBox *box; Gog3DBoxView *box_view; GogChart *chart = GOG_CHART (gog_view_get_model (view)); GogObject *obj = gog_object_get_child_by_name (GOG_OBJECT (chart), "3D-Box"); GSList *ptr; GogView *child; GogViewPadding padding; GogAxisMetrics xm, ym, zm; if (!obj) { obj = g_object_new (GOG_3D_BOX_TYPE, NULL); gog_object_add_by_name (GOG_OBJECT (chart), "3D-Box", obj); } box = GOG_3D_BOX (obj); box_view = GOG_3D_BOX_VIEW (gog_view_find_child_view (view, obj)); /* Only use the first of the axes. */ axes = gog_chart_get_axes (chart, GOG_AXIS_X); axisX = GOG_AXIS (axes->data); xm = gog_axis_get_metrics (axisX); if (xm != GOG_AXIS_METRICS_DEFAULT) ref = gog_axis_get_ref_axis (axisX); g_slist_free (axes); gog_axis_get_bounds (axisX, &xmin, &xmax); axes = gog_chart_get_axes (chart, GOG_AXIS_Y); axisY = GOG_AXIS (axes->data); ym = gog_axis_get_metrics (axisY); if (ym != GOG_AXIS_METRICS_DEFAULT && ref == NULL) ref = gog_axis_get_ref_axis (axisY); g_slist_free (axes); gog_axis_get_bounds (axisY, &ymin, &ymax); axes = gog_chart_get_axes (chart, GOG_AXIS_Z); axisZ = GOG_AXIS (axes->data); zm = gog_axis_get_metrics (axisZ); if (zm != GOG_AXIS_METRICS_DEFAULT && ref == NULL) ref = gog_axis_get_ref_axis (axisZ); g_slist_free (axes); gog_axis_get_bounds (axisZ, &zmin, &zmax); /* define the 3d box */ if (ref == NULL) { box_view->dz = tmp.h; if (ymax - ymin > xmax - xmin) { box_view->dy = tmp.w; box_view->dx = (xmax - xmin) / (ymax - ymin) * tmp.w; } else { box_view->dx = tmp.w; box_view->dy = (ymax - ymin) / (xmax - xmin) * tmp.w; } } else { double ref_length, ref_tick_dist, xspan, yspan, zspan; gog_axis_get_bounds (ref, &ref_length, &xspan); ref_length -= xspan; ref_tick_dist = gog_axis_get_major_ticks_distance (ref); xspan = xmax - xmin; if (xm == GOG_AXIS_METRICS_RELATIVE_TICKS) { double ratio, tick_dist = gog_axis_get_major_ticks_distance (axisX); g_object_get (axisX, "metrics-ratio", &ratio, NULL); xspan = (xmax - xmin) / tick_dist * ref_tick_dist * ratio; } yspan = ymax - ymin; if (ym == GOG_AXIS_METRICS_RELATIVE_TICKS) { double ratio, tick_dist = gog_axis_get_major_ticks_distance (axisY); g_object_get (axisY, "metrics-ratio", &ratio, NULL); yspan = (ymax - ymin) / tick_dist * ref_tick_dist * ratio; } zspan = zmax - zmin; if (zm == GOG_AXIS_METRICS_RELATIVE_TICKS) { double ratio, tick_dist = gog_axis_get_major_ticks_distance (axisZ); g_object_get (axisZ, "metrics-ratio", &ratio, NULL); zspan = (zmax - zmin) / tick_dist * ref_tick_dist * ratio; } if (ref == axisZ) { gboolean xrel = FALSE; box_view->dz = tmp.h; switch (xm) { case GOG_AXIS_METRICS_RELATIVE: case GOG_AXIS_METRICS_RELATIVE_TICKS: box_view->dx = xspan / zspan * tmp.h; if (box_view->dx > tmp.w) { box_view->dz *= tmp.w / box_view->dx; box_view->dx = tmp.w; } xrel = TRUE; break; default: box_view->dx = tmp.w; break; } switch (ym) { case GOG_AXIS_METRICS_RELATIVE: case GOG_AXIS_METRICS_RELATIVE_TICKS: box_view->dy = yspan / zspan * box_view->dz; if (box_view->dy > tmp.w) { box_view->dz *= tmp.w / box_view->dy; if (xrel) box_view->dx *= tmp.w / box_view->dy; box_view->dy = tmp.w; } break; default: box_view->dy = tmp.w; break; } } else { if (yspan > xspan) { box_view->dy = tmp.w; box_view->dx = xspan / yspan * tmp.w; } else { box_view->dx = tmp.w; box_view->dy = yspan / xspan * tmp.w; } if (zm == GOG_AXIS_METRICS_DEFAULT) box_view->dz = tmp.h; else box_view->dz = (ref == axisX)? zspan / xspan * box_view->dx: zspan / yspan * box_view->dy; } } /* now compute the position of each vertex, ignoring the fov */ go_matrix3x3_transform (&box->mat, -box_view->dx, -box_view->dy, -box_view->dz, o, o + 1, o + 2); go_matrix3x3_transform (&box->mat, box_view->dx, -box_view->dy, -box_view->dz, x, x + 1, x + 2); go_matrix3x3_transform (&box->mat, -box_view->dx, box_view->dy, -box_view->dz, y, y + 1, y + 2); go_matrix3x3_transform (&box->mat, -box_view->dx, -box_view->dy, box_view->dz, z, z + 1, z + 2); /* for each diagonal, we need to take the vertex closer to the view point */ if (o[1] > 0) { o[0] = -o[0]; o[1] = -o[1]; o[2] = -o[2]; } if (x[1] > 0) { x[0] = -x[0]; x[1] = -x[1]; x[2] = -x[2]; } if (y[1] > 0) { y[0] = -y[0]; y[1] = -y[1]; y[2] = -y[2]; } if (z[1] > 0) { z[0] = -z[0]; z[1] = -z[1]; z[2] = -z[2]; } /* if the fov is positive, calculate the position of the viewpoint */ if (box->fov > 0.) { tg = tan (box->fov / 2.); box_view->r = -sqrt (o[0] * o[0] + o[2] * o[2]) / tg + o[1]; d = -sqrt (x[0] * x[0] + x[2] * x[2]) / tg + x[1]; if (d < box_view->r) box_view->r = d; d = -sqrt (y[0] * y[0] + y[2] * y[2]) / tg + y[1]; if (d < box_view->r) box_view->r = d; d = -sqrt (z[0] *z[0] + z[2] * z[2]) / tg + z[1]; if (d < box_view->r) box_view->r = d; /* also calculate the reduction factor we need to make things fit in the bbox */ xmax = fabs (o[0]) / (1. - o[1] / box_view->r); zmax = fabs (o[2]) / (1. - o[1] / box_view->r); d = fabs (x[0]) / (1. - x[1] / box_view->r); if (d > xmax) xmax = d; d = fabs (x[2]) / (1. - x[1] / box_view->r); if (d > zmax) zmax = d; d = fabs (y[0]) / (1. - y[1] / box_view->r); if (d > xmax) xmax = d; d = fabs (y[2]) / (1. - y[1] / box_view->r); if (d > zmax) zmax = d; d = fabs (z[0]) / (1. - z[1] / box_view->r); if (d > xmax) xmax = d; d = fabs (z[2]) / (1. - z[1] / box_view->r); if (d > zmax) zmax = d; } else { /* calculate the reduction factor we need to make things fit in the bbox */ xmax = fabs (o[0]); zmax = fabs (o[2]); d = fabs (x[0]); if (d > xmax) xmax = d; d = fabs (x[2]); if (d > zmax) zmax = d; d = fabs (y[0]); if (d > xmax) xmax = d; d = fabs (y[2]); if (d > zmax) zmax = d; d = fabs (z[0]); if (d > xmax) xmax = d; d = fabs (z[2]); if (d > zmax) zmax = d; } /* use d and tg as x and z ratios, respectively */ d = xmax / tmp.w; tg = zmax / tmp.h; box_view->ratio = (d > tg)? d: tg; gog_view_padding_request (view, bbox, &padding); if (!chart->is_plot_area_manual) { bbox->x += padding.wl; bbox->w -= padding.wl + padding.wr; bbox->y += padding.ht; bbox->h -= padding.ht + padding.hb; } else { tmp.x -= padding.wl; tmp.w += padding.wl + padding.wr; tmp.y -= padding.ht; tmp.h += padding.ht + padding.hb; } /* Recalculating ratio */ d = xmax / bbox->w; tg = zmax / bbox->h; box_view->ratio = (d > tg)? d: tg; for (ptr = view->children; ptr != NULL ; ptr = ptr->next) { child = ptr->data; if (GOG_POSITION_IS_PADDING (child->model->position)) { gog_view_size_allocate (child, &tmp); } } /* by default, overlay all GOG_POSITION_SPECIAL children in residual */ for (ptr = view->children; ptr != NULL ; ptr = ptr->next) { child = ptr->data; if (GOG_POSITION_IS_SPECIAL (child->model->position)) gog_view_size_allocate (child, bbox); } }