Logo Search packages:      
Sourcecode: ygraph version File versions  Download package

void plot_range_set ( Plot plot,
gint  mode 
)

Calculate the maximum and minimum values of a collection of datasets to be displayed in a single window.

Parameters:
plot The Plot.
mode Either APPEND_DATA, INIT_DATA or RESCALE_DATA, depending on whether data is being appended to an existing plot or a new plot is being initialised.

Definition at line 85 of file axis.c.

References _Plot::data, global_x_range, global_y_range, plot_get_data_index(), _DataSet::x_range, _Plot::x_range, _DataSet::y_range, and _Plot::y_range.

Referenced by axis_set_from_dialog(), axis_toggle_log_state(), plot_data_append(), plot_data_init(), plot_window_reconfigure(), and scale_set_from_entry().

{
  DataSet* data_set;
  guint i;

  if (plot->data == NULL)
    return;

  if (mode != RESCALE_DATA)
    {
      if (plot->data->len == 0)
        {
          /*
           * If there's no data, draw a plot of default size.
           */
          plot->x_range[0] = 0;
          plot->x_range[1] = 1;
          plot->y_range[0] = 0;
          plot->y_range[1] = 1;
        }
      else if (plot->data->len == 1)
        {
          /*
           * If there's only one dataset, then the ranges of the plot window are
           * the ranges of that set.
           */
          data_set = plot_get_data_index(plot, 0);

          plot->x_range[0] = data_set->x_range[0];
          plot->x_range[1] = data_set->x_range[1];
          plot->y_range[0] = data_set->y_range[0];
          plot->y_range[1] = data_set->y_range[1];
        }
      else if (mode == APPEND_DATA)
        {
          /*
           * If we're just appending a set, then compare the range of the new
           * set to the existing values.
           */
          data_set = plot_get_data_index(plot, plot->data->len-1);

          plot->x_range[0] = MIN(plot->x_range[0], data_set->x_range[0]);
          plot->x_range[1] = MAX(plot->x_range[1], data_set->x_range[1]);
          plot->y_range[0] = MIN(plot->y_range[0], data_set->y_range[0]);
          plot->y_range[1] = MAX(plot->y_range[1], data_set->y_range[1]);
        }
      else
        {
          plot->x_range[0] = G_MAXDOUBLE;
          plot->x_range[1] = -G_MAXDOUBLE;
          plot->y_range[0] = G_MAXDOUBLE;
          plot->y_range[1] = -G_MAXDOUBLE;

          for (i=0; i<plot->data->len; ++i)
            {
              data_set = plot_get_data_index(plot, i);
              
              plot->x_range[0] = MIN(plot->x_range[0], data_set->x_range[0]);
              plot->x_range[1] = MAX(plot->x_range[1], data_set->x_range[1]);
              plot->y_range[0] = MIN(plot->y_range[0], data_set->y_range[0]);
              plot->y_range[1] = MAX(plot->y_range[1], data_set->y_range[1]);
            }
        }

      if (mode == INIT_DATA)
        {
          if (global_x_range != NULL)
            {
              plot->x_range[0] = global_x_range[0];
              plot->x_range[1] = global_x_range[1];
            }
          if (global_y_range != NULL)
            {
              plot->y_range[0] = global_y_range[0];
              plot->y_range[1] = global_y_range[1];
            }
        }
    }
  /* Check if the range is 0.0 (or even less, which should not happen) */
  if (plot->x_range[1] <= plot->x_range[0])
    plot->x_range[1] = plot->x_range[0] + AXIS_EPSILON;
  if (plot->y_range[1] <= plot->y_range[0])
    plot->y_range[1] = plot->y_range[0] + AXIS_EPSILON;
}


Generated by  Doxygen 1.6.0   Back to index