/*****************************************************************************/
/*
                                   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 */
/**************/

#pragma member_alignment __save
#pragma member_alignment

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;

   int64  EndTime64,
          MaxBytes64,
          PeakBytes64,
          StartTime64;

   ushort  EndTime7 [7],
           StartTime7 [7];

   void  *RequestPtr;

   STR_DSC  *ClickPtr,
            *PlotPtr;
};

typedef struct ActivityGblSecStruct ACTIVITY_GBLSEC;

struct ActivityGblSecStruct
{
   ulong  GblSecVersion;

   ulong  ClearAbsDay,
          StartAbsDay,
          StartMinute;
   int64  StartTime64;

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

#pragma member_alignment __restore

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

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

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

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 */

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