Example #1
0
static void
gog_pie_series_update (GogObject *obj)
{
	double *vals = NULL, total;
	int len = 0;
	GogPieSeries *series = GOG_PIE_SERIES (obj);
	unsigned old_num = series->base.num_elements;
	GogShowNegsMode mode = GOG_PIE_PLOT (series->base.plot)->show_negatives;

	if (series->base.values[1].data != NULL) {
		vals = go_data_get_values (series->base.values[1].data);
		len = go_data_get_vector_size (series->base.values[1].data);
	}
	series->base.num_elements = len;

	for (total = 0. ; len-- > 0 ;) {
		double val = vals[len];
		if (go_finite (val)) {
			if (val < 0)
				val = (mode == GOG_SHOW_NEGS_SKIP)? 0.: -val;
			total += val;
		}
	}
	series->total = total;

	/* queue plot for redraw */
	gog_object_request_update (GOG_OBJECT (series->base.plot));
	if (old_num != series->base.num_elements)
		gog_plot_request_cardinality_update (series->base.plot);

	if (series_parent_klass->update)
		series_parent_klass->update (obj);
}
Example #2
0
static void
gog_xy_dropbar_view_render (GogView *view, GogViewAllocation const *bbox)
{
	GogXYDropBarPlot const *model = GOG_XY_DROPBAR_PLOT (view->model);
	GogPlot *plot = GOG_PLOT (model);
	GogSeries const *series;
	GogAxisMap *x_map, *y_map, *val_map, *index_map;
	GogViewAllocation work;
	double *pos_vals, *start_vals, *end_vals;
	unsigned i;
	GSList *ptr;
	unsigned n, tmp, num_series;
	GOStyle *neg_style;

	for (num_series = 0, ptr = plot->series ; ptr != NULL ; ptr = ptr->next, num_series++);
	if (num_series < 1)
		return;

	x_map = gog_axis_map_new (GOG_PLOT (model)->axis[0],
				  view->allocation.x, view->allocation.w);
	y_map = gog_axis_map_new (GOG_PLOT (model)->axis[1], view->allocation.y + view->allocation.h,
				  -view->allocation.h);

	if (!(gog_axis_map_is_valid (x_map) &&
	      gog_axis_map_is_valid (y_map))) {
		gog_axis_map_free (x_map);
		gog_axis_map_free (y_map);
		return;
	}

	work.w = view->allocation.w * model->width / 100.;
	for (ptr = plot->series ; ptr != NULL ; ptr = ptr->next) {
		series = ptr->data;
		if (!gog_series_is_valid (GOG_SERIES (series)))
			continue;
		neg_style = go_style_dup ((GOG_STYLED_OBJECT (series))->style);
		neg_style->line.color ^= 0xffffff00;
		neg_style->fill.pattern.back ^= 0xffffff00;
		neg_style->fill.pattern.fore ^= 0xffffff00;
		pos_vals = go_data_get_values (series->values[0].data);
		n = go_data_get_vector_size (series->values[1].data);
		start_vals = go_data_get_values (series->values[1].data);
		tmp = go_data_get_vector_size (series->values[1].data);
		if (n > tmp)
			n = tmp;
		end_vals = go_data_get_values (series->values[2].data);
		tmp = go_data_get_vector_size (series->values[2].data);
		if (n > tmp)
			n = tmp;

		if (model->horizontal) {
			index_map = y_map;
			val_map = x_map;
		} else {
			index_map = x_map;
			val_map = y_map;
		}
		for (i = 0; i < n; i++) {
			work.x = pos_vals[i];
			work.y = start_vals[i];
			work.h = end_vals[i] - work.y;
			if (!gog_axis_map_finite (index_map, work.x) ||
				!gog_axis_map_finite (val_map, start_vals[i]) ||
				!gog_axis_map_finite (val_map, end_vals[i]))
				continue;
			gog_renderer_push_style (view->renderer, (start_vals[i] <= end_vals[i])?
						GOG_STYLED_OBJECT (series)->style: neg_style);
			barcol_draw_rect (view->renderer, model->horizontal, x_map, y_map, &work);
			gog_renderer_pop_style (view->renderer);
		}
		g_object_unref (neg_style);
	}

	gog_axis_map_free (x_map);
	gog_axis_map_free (y_map);
}
Example #3
0
static void
gog_xy_dropbar_plot_update (GogObject *obj)
{
	GogXYDropBarPlot *model = GOG_XY_DROPBAR_PLOT (obj);
	GogSeries const *series = NULL;
	double x_min, x_max, y_min, y_max, tmp_min, tmp_max;
	GSList *ptr;
	unsigned xaxis, yaxis;

	if (model->horizontal) {
		xaxis = 1;
		yaxis = 0;
	} else {
		xaxis = 0;
		yaxis = 1;
	}
	x_min = y_min =  DBL_MAX;
	x_max = y_max = -DBL_MAX;
	gog_xy_dropbar_plot_clear_formats (model);
	for (ptr = model->base.series ; ptr != NULL ; ptr = ptr->next) {
		series = ptr->data;
		if (!gog_series_is_valid (GOG_SERIES (series)))
			continue;

		go_data_get_bounds (series->values[1].data, &tmp_min, &tmp_max);
		if (y_min > tmp_min) y_min = tmp_min;
		if (y_max < tmp_max) y_max = tmp_max;
		if (model->y.fmt == NULL) {
			model->y.fmt = go_data_preferred_fmt (series->values[1].data);
			model->y.date_conv = go_data_date_conv (series->values[1].data);
		}
		go_data_get_bounds (series->values[2].data, &tmp_min, &tmp_max);
		if (y_min > tmp_min)
			y_min = tmp_min;
		if (y_max < tmp_max)
			y_max = tmp_max;

		if (series->values[0].data != NULL) {
			go_data_get_bounds (series->values[0].data, &tmp_min, &tmp_max);

			if (!go_finite (tmp_min) || !go_finite (tmp_max) ||
			    tmp_min > tmp_max) {
				tmp_min = 0;
				tmp_max = go_data_get_vector_size (series->values[1].data);
			} else if (model->x.fmt == NULL) {
				model->x.fmt = go_data_preferred_fmt (series->values[0].data);
				model->x.date_conv = go_data_date_conv (series->values[0].data);
			}
		} else {
			tmp_min = 0;
			tmp_max = go_data_get_vector_size (series->values[1].data);
		}

		if (x_min > tmp_min)
			x_min = tmp_min;
		if (x_max < tmp_max)
			x_max = tmp_max;
	}
	/* make room for bar width, this is approximate since real width is larger */
	tmp_max = (x_max - x_min) * model->width / 200.;
	x_min -= tmp_max;
	x_max += tmp_max;
	if (model->x.minima != x_min || model->x.maxima != x_max) {
		model->x.minima = x_min;
		model->x.maxima = x_max;
		gog_axis_bound_changed (model->base.axis[xaxis], GOG_OBJECT (model));
	}
	if (model->y.minima != y_min || model->y.maxima != y_max) {
		model->y.minima = y_min;
		model->y.maxima = y_max;
		gog_axis_bound_changed (model->base.axis[yaxis], GOG_OBJECT (model));
	}
	gog_object_emit_changed (GOG_OBJECT (obj), FALSE);
	if (gog_xy_dropbar_parent_klass->update)
		gog_xy_dropbar_parent_klass->update (obj);
}