/*****************************************************************************/
/*
                                   Graph.h
*/
/*****************************************************************************/

#ifndef GRAPH_H_LOADED
#define GRAPH_H_LOADED 1

#include "wasd.h"

/* can grow beyond this initial size */
#define GRAPH_CLICK_SIZE 2048
#define GRAPH_PLOT_SIZE 65535

/* these correspond to the colours used in the original GIF */
#define COLOUR_BLACK 0
#define COLOUR_S_BLACK "rgb(0,0,0)"
#define COLOUR_RED 1
#define COLOUR_S_RED "rgb(255,0,0)"
#define COLOUR_GREEN 2
#define COLOUR_S_GREEN "rgb(0,255,0)"
#define COLOUR_BLUE 3
#define COLOUR_S_BLUE "rgb(0,0,255)"
#define COLOUR_YELLOW 4
#define COLOUR_S_YELLOW "rgb(255,255,0)"
#define COLOUR_MAGENTA 5
#define COLOUR_S_MAGENTA "rgb(255,0,255)"
#define COLOUR_CYAN 6
#define COLOUR_S_CYAN "rgb(0,255,255)"
#define COLOUR_WHITE 7
#define COLOUR_S_WHITE "rgb(255,255,255)"
#define COLOUR_GREY 8
#define COLOUR_S_GREY "rgb(192,192,192)"
#define COLOUR_DRED 9
#define COLOUR_S_DRED "rgb(128,0,0)"
#define COLOUR_DGREEN 10
#define COLOUR_S_DGREEN "rgb(0,128,0)"
#define COLOUR_DBLUE 11
#define COLOUR_S_DBLUE "rgb(0,0,128)"
#define COLOUR_DYELLOW 12
#define COLOUR_S_DYELLOW "rgb(128,128,0)"
#define COLOUR_DMAGENTA 13
#define COLOUR_S_DMAGENTA "rgb(128,0,128)"
#define COLOUR_DCYAN 14
#define COLOUR_S_DCYAN "rgb(128,128,128)"
#define COLOUR_DWHITE 15
#define COLOUR_S_DWHITE "rgb(250,240,230)"

#define GRAPH_XAXIS_TOP 1
#define GRAPH_XAXIS_BOTTOM 2
#define GRAPH_YAXIS_LEFT 1
#define GRAPH_YAXIS_RIGHT 2

#define ACTIVITY_DAYS 28
#define MINUTES_IN_DAY 1440
#define MINUTES_IN_HOUR 60

#define ACTIVITY_MASK       0x0fffffff
#define ACTIVITY_STARTUP    0x80000000
#define ACTIVITY_EXIT       0x40000000
#define ACTIVITY_EXIT_ERROR 0x20000000
#define ACTIVITY_DELPRC     0x10000000

/**************/
/* structures */
/**************/

#ifndef __VAX
#   pragma member_alignment __save
#   pragma member_alignment
#endif

typedef struct GraphStruct GRAPH_STRUCT;

struct GraphStruct
{
   BOOL  Stroke;

   int  Day,
        FillColour,
        Height,
        Hour,
        MaxRequests,
        MaxYRequests,
        NumberOfHours,
        NumberOfMinutes,
        Month,
        ProblemCount,
        StrokeColour,
        StrokeWidth,
        Width,
        Year;

   ulong  CurrentAbsDay,
          CurrentAbsHour,
          CurrentAbsMinute,
          EndMinute,
          FirstDataAbsHour,
          StartAbsDay,
          StartHour,
          StartMinute,
          StartSecond;

   ulong  EndTime64 [2],
          MaxBytes [2],
          PeakBytes [2],
          StartTime64 [2];

   ushort  EndNumTime [7],
           StartNumTime [7];

   void  *RequestPtr;

   STR_DSC  *ClickPtr,
            *PlotPtr;
};

typedef struct ActivityGblSecStruct ACTIVITY_GBLSEC;

struct ActivityGblSecStruct
{
   ulong  GblSecVersion;

   ulong  ClearAbsDay,
          StartAbsDay,
          StartMinute;
   ulong  StartTime64 [2];

   /* plus one day to provide 'elbow room' */
   ulong  RequestCount [(ACTIVITY_DAYS+1) * MINUTES_IN_DAY];
   ulong  ByteCount [(ACTIVITY_DAYS+1) * MINUTES_IN_DAY][2];
   ushort  ConnectPeak [(ACTIVITY_DAYS+1) * MINUTES_IN_DAY],
                        RequestPeak [(ACTIVITY_DAYS+1) * MINUTES_IN_DAY];
};

#ifndef __VAX
#   pragma member_alignment __restore
#endif

/***********************/
/* function prototypes */
/***********************/

ulong GraphActivityAbsHour (ulong*);
ulong GraphActivityAbsMinute (ulong*);
void GraphActivityClearDay ();
ulong GraphActivityDataIdx (ulong, ulong);
int GraphActivityDataScan (int, int, int, int,
                           uint*, uint*, uint*,
                           ulong*, ulong*, ulong*);
void GraphActivityEvent (ulong);
int GraphActivityGblSecInit ();
void GraphActivityMaxima (uint*, uint*, ulong*);
int GraphActivityOffsetTime (int, ulong*, ulong*);
void GraphActivityReport (REQUEST_STRUCT*);
void GraphActivityUpdate (REQUEST_STRUCT*, BOOL);

char* GraphColorString (int);
char* GraphActivityPeriod (ulong*, ulong*);

char* GraphActivityClick (GRAPH_STRUCT*);
char* GraphActivityPlot (GRAPH_STRUCT*);
void GraphDrawBlock (GRAPH_STRUCT*, int, int, int, int, int);
void GraphDrawBorder (GRAPH_STRUCT*, int, int);
void GraphDrawLine (GRAPH_STRUCT*, int, int, int, int, int, int);
void GraphGraduateXAxis (GRAPH_STRUCT*, int, int, int, int);
void GraphGraduateYAxis (GRAPH_STRUCT*, int, int, int, int);
void GraphSetFillColour (GRAPH_STRUCT*, int);
void GraphSetStrokeColour (GRAPH_STRUCT*, int);
void GraphSetStrokeWidth (GRAPH_STRUCT*, int);

#endif /* GRAPH_H_LOADED */

/*****************************************************************************/
