#!/usr/local/Hughes/bin/lite

/*
** Demo of the Hughes Tech Graph module  (htg)
**
** This demo plots 3 data series against eachother on a set scale of 0
** to 10.
*/


modload "mod_graph";

/*
** Create the graph canvas 400x300 pixels in size.  Use a grey colour
** (rgb 210,210,210) as the background and a dark blue (rgb 50,50,100)
** as the foreground.  Give the graph a nice look with a 5 pixel wide
** frame as the border of the canvas
*/
$graph =  htgCreateGraph(500,350,
		210,210,210,
		50,50,100,
		HTG_BORDER_BEVEL_IN, 3,
		0,HTG_UNSIGNED);



/*
** Add the data series and the X axis 'ticks' to the graph.  The income
** data (series 1) is to be drawn in Green (rgb 0,170,0), the expense
** data in series 2 is shown in Red (rgb 255,0,0) and the profit is
** shown in Blue
*/
$data1 = [ "5","8","8","6","5","4","3","4","5" ];
$data2 = [ "4","5","7","6","3","1","2","4","3" ];
$data3 = [ "1","3","1","0","2","3","1","0","2" ];
htgAddBarGraphData($graph,"Income", $data1, 0,170,0, 100);
htgAddBarGraphData($graph,"Expense",$data2, 255,0,0, 70);
htgAddBarGraphData($graph,"Profit",$data3, 0,0,210, 30);
htgAddLineGraphData($graph,"",$data3, 0,0,210);

$xTicks = [ "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep"];
htgAddTicks($graph,$xTicks, HTG_X_AXIS);



/*
** Set a few options on the graph.  Each of these options consumes
** canvas space but the graph will scale itself to whatever space is
** left.  
**
** First, force a know scale on the Y axis.  
**
** Second add a title to the graph with a framed border box 1 pixel
** wide.  The title is centered on the graph and uses the MEDIUM_BOLD
** font.
** 
** Third add 'dash marks' to the graph so we can see the data values better
**
** Finally, add a legend to the graph in a 3 pixel frame using the
** SMALL font.
*/

htgSetGraphRange($graph,0,10);

htgSetGraphTitle($graph,"XYZ Corp Financial Report", HTG_BORDER_BEVEL_IN, 4, 
	HTG_ALIGN_CENTER, HTG_FONT_MEDIUM_BOLD);

htgSetFlag($graph,HTG_DASH_MARKS);

htgCreateLegend($graph,HTG_BORDER_FRAME_IN, 3, HTG_FONT_SMALL);


/*
** Now we plot the data as a line graph, output it to a file and delete
** the internal representation of the graph.
*/
htgPlotGraph($graph);
htgOutputGraph($graph,"/tmp/test.gif");
htgDestroyGraph($graph);
echo("\nTest image saved as /tmp/test.gif\n\n");
