/** * gog_chart_get_axes: * @chart: #GogChart * @target: #GogAxisType * * Returns: (element-type GogAxis) (transfer container): a list which the * caller must free of all axis of type @target * associated with @chart. **/ GSList * gog_chart_get_axes (GogChart const *chart, GogAxisType target) { GSList *ptr, *res = NULL; GogAxis *axis; int type; g_return_val_if_fail (GOG_IS_CHART (chart), NULL); for (ptr = GOG_OBJECT (chart)->children ; ptr != NULL ; ptr = ptr->next) { axis = ptr->data; if (GOG_IS_AXIS (axis)) { type = -1; g_object_get (G_OBJECT (axis), "type", &type, NULL); if (type < 0 || type >= GOG_AXIS_TYPES) { g_warning ("Invalid axis"); continue; } if (type == target) res = g_slist_prepend (res, axis); } } return res; }
void gog_chart_request_cardinality_update (GogChart *chart) { g_return_if_fail (GOG_IS_CHART (chart)); if (chart->cardinality_valid) { chart->cardinality_valid = FALSE; gog_object_request_update (GOG_OBJECT (chart)); } }
/** * gog_chart_foreach_elem: * @chart: #GogChart * @only_visible: whether to only apply to visible children * @handler: (scope call): callback * @data: user data * * Applies @handler to children **/ void gog_chart_foreach_elem (GogChart *chart, gboolean only_visible, GogEnumFunc handler, gpointer data) { GSList *ptr; g_return_if_fail (GOG_IS_CHART (chart)); g_return_if_fail (chart->cardinality_valid); for (ptr = chart->plots ; ptr != NULL ; ptr = ptr->next) gog_plot_foreach_elem (ptr->data, only_visible, handler, data); }
gboolean gog_chart_axis_set_assign (GogChart *chart, GogAxisSet axis_set) { GogAxis *axis; GSList *ptr; GogAxisType type; g_return_val_if_fail (GOG_IS_CHART (chart), FALSE); if (chart->axis_set == axis_set) return TRUE; chart->axis_set = axis_set; if (axis_set == GOG_AXIS_SET_UNKNOWN) return TRUE; /* Add at least 1 instance of any required axis */ for (type = 0 ; type < GOG_AXIS_TYPES ; type++) if ((axis_set & (1 << type))) { GSList *tmp = gog_chart_get_axes (chart, type); if (tmp == NULL) gog_chart_add_axis (chart, type); else g_slist_free (tmp); } /* link the plots */ for (ptr = chart->plots ; ptr != NULL ; ptr = ptr->next) if (!gog_plot_axis_set_assign (ptr->data, axis_set)) return FALSE; /* add any existing axis that do not fit this scheme to the set */ for (ptr = GOG_OBJECT (chart)->children ; ptr != NULL ; ) { axis = ptr->data; ptr = ptr->next; /* list may change under us */ if (GOG_IS_AXIS (axis)) { type = -1; g_object_get (G_OBJECT (axis), "type", &type, NULL); if (type < 0 || type >= GOG_AXIS_TYPES) { g_warning ("Invalid axis"); continue; } if (0 == (axis_set & (1 << type))) { /* We used to delete those axes but if the first plot use a restricted set, all other axes are lost, see #708292 */ chart->axis_set |= 1 << type; } } } return TRUE; }
gboolean gog_chart_axis_set_is_valid (GogChart const *chart, GogAxisSet type) { GSList *ptr; g_return_val_if_fail (GOG_IS_CHART (chart), FALSE); for (ptr = chart->plots ; ptr != NULL ; ptr = ptr->next) if (!gog_plot_axis_set_is_valid (ptr->data, type)) return FALSE; return TRUE; }
/** * gog_chart_set_position: * @chart: #GogChart * @x: * @y: * @cols: * @rows: * **/ void gog_chart_set_position (GogChart *chart, unsigned int x, unsigned int y, unsigned int cols, unsigned int rows) { g_return_if_fail (GOG_IS_CHART (chart)); if (chart->x_pos == x && chart->y_pos == y && chart->cols == cols && chart->rows == rows) return; chart->x_pos = x; chart->y_pos = y; chart->cols = cols; chart->rows = rows; gog_graph_validate_chart_layout (GOG_GRAPH (GOG_OBJECT (chart)->parent)); gog_object_emit_changed (GOG_OBJECT (chart), TRUE); }
/** * gog_chart_get_cardinality: * @chart: a #GogChart * @full: placeholder for full cardinality * @visible: placeholder for visible cardinality * * Update and cache cardinality values if required, and returns * full and visible cardinality. Full cardinality is the number of * chart elements that require a different style. Visible cardinality is * the number of chart elements shown in chart legend. * * @full and @visible may be NULL. **/ void gog_chart_get_cardinality (GogChart *chart, unsigned *full, unsigned *visible) { GSList *ptr; unsigned tmp_full, tmp_visible; g_return_if_fail (GOG_IS_CHART (chart)); if (!chart->cardinality_valid) { chart->cardinality_valid = TRUE; chart->full_cardinality = chart->visible_cardinality = 0; for (ptr = chart->plots ; ptr != NULL ; ptr = ptr->next) { gog_plot_update_cardinality (ptr->data, chart->full_cardinality); gog_plot_get_cardinality (ptr->data, &tmp_full, &tmp_visible); chart->full_cardinality += tmp_full; chart->visible_cardinality += tmp_visible; } } if (full != NULL) *full = chart->full_cardinality; if (visible != NULL) *visible = chart->visible_cardinality; }
GogChartMap * gog_chart_map_new (GogChart *chart, GogViewAllocation const *area, GogAxis *axis0, GogAxis *axis1, GogAxis *axis2, gboolean fill_area) { GogChartMap *map; GogAxisSet axis_set; g_return_val_if_fail (GOG_IS_CHART (chart), NULL); axis_set = gog_chart_get_axis_set (chart); g_return_val_if_fail (axis_set != GOG_AXIS_SET_UNKNOWN && axis_set != GOG_AXIS_SET_NONE, NULL); map = g_new (GogChartMap, 1); g_object_ref (chart); map->chart = chart; map->area = *area; map->data = NULL; map->is_valid = FALSE; map->axis_map[0] = map->axis_map[1] = map->axis_map[2] = NULL; map->ref_count = 1; switch (axis_set & GOG_AXIS_SET_FUNDAMENTAL) { case GOG_AXIS_SET_X: { XMapData *data = g_new (XMapData, 1); map->axis_map[0] = gog_axis_map_new (axis0, map->area.x, map->area.w); data->b = area->y + area->h; data->a = - area->h; map->map_2D_to_view = x_map_2D_to_view; map->map_view_to_2D = x_map_view_to_2D; map->map_2D_derivative_to_view = NULL; map->make_path = NULL; map->make_close_path = NULL; map->data = data; map->is_valid = gog_axis_map_is_valid (map->axis_map [0]); break; } case GOG_AXIS_SET_XY: case GOG_AXIS_SET_XY_pseudo_3d: case GOG_AXIS_SET_XY_COLOR: { map->axis_map[0] = gog_axis_map_new (axis0, map->area.x, map->area.w); map->axis_map[1] = gog_axis_map_new (axis1, map->area.y + map->area.h, -map->area.h); map->data = NULL; map->map_2D_to_view = xy_map_2D_to_view; map->map_2D_derivative_to_view = xy_map_2D_derivative_to_view; map->map_view_to_2D = xy_map_view_to_2D; map->make_path = xy_make_path; map->make_close_path = xy_make_close_path; map->is_valid = gog_axis_map_is_valid (map->axis_map[0]) && gog_axis_map_is_valid (map->axis_map[1]); break; } case GOG_AXIS_SET_RADAR: { GogChartMapPolarData *data = g_new (GogChartMapPolarData, 1); double minimum, maximum; double z_rotation = gog_axis_get_circular_rotation (axis0) * M_PI / 180.0; double perimeter; map->axis_map[0] = gog_axis_map_new (axis0, 0.0, 1.0); gog_axis_map_get_bounds (map->axis_map[0], &minimum, &maximum); if (gog_axis_is_discrete (axis0)) { data->th0 = go_rint (minimum); data->th1 = go_rint (maximum); calc_polygon_parameters (area, data, fill_area); gog_axis_map_free (map->axis_map[0]); map->axis_map[0] = gog_axis_map_new (axis0, - M_PI / 2.0 + z_rotation, 2.0 * M_PI * (maximum - minimum) / (maximum - minimum + 1)); } else { perimeter = gog_axis_get_polar_perimeter (axis0); minimum = minimum * 2.0 * M_PI / perimeter + z_rotation; maximum = maximum * 2.0 * M_PI / perimeter + z_rotation; data->th0 = minimum; data->th1 = maximum; calc_circle_parameters (area, data, fill_area); gog_axis_map_free (map->axis_map[0]); map->axis_map[0] = gog_axis_map_new (axis0, -minimum, minimum - maximum); } map->axis_map[1] = gog_axis_map_new (axis1, 0.0, 1.0); map->data = data; map->map_2D_to_view = polar_map_2D_to_view; map->map_2D_derivative_to_view = NULL; map->map_view_to_2D = polar_map_view_to_2D; map->make_path = polar_make_path; map->make_close_path = polar_make_close_path; map->is_valid = gog_axis_map_is_valid (map->axis_map[0]) && gog_axis_map_is_valid (map->axis_map[1]); break; } default: g_warning ("[GogChartMap::new] unimplemented for axis set %d", axis_set); map->map_2D_to_view = null_map_2D; map->map_2D_derivative_to_view = NULL; map->map_view_to_2D = null_map_2D; break; } return map; }
GogAxisSet gog_chart_get_axis_set (GogChart const *chart) { g_return_val_if_fail (GOG_IS_CHART (chart), GOG_AXIS_SET_UNKNOWN); return chart->axis_set; }
/** * gog_chart_get_plots: * @chart: #GogChart * * Returns: (element-type GogPlot) (transfer none): the list of the plots * in @chart. **/ GSList * gog_chart_get_plots (GogChart const *chart) { g_return_val_if_fail (GOG_IS_CHART (chart), NULL); return chart->plots; }
/** * gog_chart_get_grid: * @chart: #GogChart * * Returns: (transfer none): the grid associated with @chart if one exists * otherwise NULL. **/ GogGrid * gog_chart_get_grid (GogChart const *chart) { g_return_val_if_fail (GOG_IS_CHART (chart), NULL); return GOG_GRID (chart->grid); }