/*
   File:        splot.h
   Author(s):   Andrew Moore
   Created:     Sat Oct 25 08:23:58 EDT 2003
   Description: time Series Plot
   Copyright (c) Carnegie Mellon University
*/

#ifndef splot_H
#define splot_H

#include "agbox.h"
#include "ongr.h"

typedef struct curveset
{
  dym *row_cnum_to_height;
  imat *row_cnum_to_defined;
  string_array *cnum_to_name;
  dyv *cnum_to_min_height;
  dyv *cnum_to_max_height;
  ivec *cnum_to_minmax_defined;
  double max_sum_heights;

} curveset;

typedef struct splot
{
  curveset *plots;
  string_array *row_to_label;
  curveset *bars;  /* May be NULL meaning "no bars needed" */
  sa_array *row_to_events; /* May be NULL meaning "no events needed" */
  imat *same_scale_pnums; /* if there exists i such that
                             pnum1 == same_scale_pnums[i][0] and
                             pnum2 == same_scale_pnums[i][1] 
                             that means that plot numbers pnum1 and pnum2
                             must be rendered with the same vertical axis */

} splot;

curveset *mk_curveset(int num_rows,string_array *cnum_to_name);
void free_curveset(curveset *x);
void fprintf_curveset(FILE *s,char *m1,curveset *x,char *m2);
void pcurveset(curveset *x);
curveset *mk_copy_curveset(curveset *old);

int curveset_num_curves(curveset *cs);
int curveset_num_rows(curveset *cs);

void curveset_set(curveset *cs,int row,int cnum,double height);

splot *mk_splot(curveset *plots,string_array *row_to_label,
		curveset *bars,sa_array *row_to_events);

void free_splot(splot *x);
void fprintf_splot(FILE *s,char *m1,splot *x,char *m2);
void psplot(splot *x);
splot *mk_copy_splot(splot *old);

int splot_num_rows(splot *sp);

/*
                                                   (total_width,total_height)
         +----------------------------------+-----+
         | bar key                          |     | barkey_height
         +----------------------------------+-----+
         | bars                             |     | bars_height
         |                                  |     |
         +----------------------------------+-----+ 
         | events                           |     | events_height
         |                                  |     |
         +----------------------------------+-----+ 
         | plots                            |plot | plots_height
         |                                  |key  |
         +----------------------------------+-----+ 
         | labels                           |     | labels_height
         |                                  |     |
         +----------------------------------+-----+
     (0,0)   labels_width                    ck_width
*/

void render_splot(splot *sp,int start_row,int num_rows);
int row_from_mouse(int start_row,int num_rows,int *r_button);

/*********** splot construction **************/

splot *mk_empty_splot(int num_rows,string_array *plot_to_name,
		      string_array *barsegment_to_name, /* Maybe NULL meaning
                                                           "no bars" */
		      bool use_events);
  
void splot_plots_set(splot *sp,int row,int plot_line_number,double value);

void splot_bars_set(splot *sp,int row,int bar_segment_number,double value);

void splot_label_set(splot *sp,int row,char *label);

void splot_add_event(splot *sp,int row,char *event_name);

void splot_plots_same_scale(splot *sp,int pnum1,int pnum2);

int splot_name_to_pnum(splot *sp,char *name);

void splot_plots_same_scale_using_names(splot *sp,char *name,
					char *same_scale_name);

void splot_plots_set_using_name(splot *sp,int row,char *name,double value);

/*********** splot browsing **************/

typedef struct bopt
{
  char *psname;
  int count;
  string_array *hide_plotnames;
  bool hide_bars;
  int initial_start_row;
  int initial_num_rows;
} bopt;

bopt *mk_bopt(char *psname,int count,string_array *hide_plotnames,
	      bool hide_bars,int initial_start_row,int initial_num_rows);

bopt *mk_bopt_from_args(int argc,char *argv[],
			int initial_start_row,int initial_num_rows);

void free_bopt(bopt *x);

void fprintf_bopt(FILE *s,char *m1,bopt *x,char *m2);

void pbopt(bopt *x);

bopt *mk_copy_bopt(bopt *old);

/* bo may be NULL meaning "use all default options */
void browse_splot(splot *sp,bopt *bo);

#endif /* ifndef splot_H */
