00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef PICGEN_H
00012 #define PICGEN_H PICGEN_H
00013 #include "typedefs.h"
00014
00015 class picgen : public ostringstream{
00016 public:
00017 virtual string str(){ return ostringstream::str(); }
00018 virtual void add(int from, int duration, int height, string color, string title) {}
00019 };
00020
00021 void drawDayOutline(ostringstream& o){
00022 o << "<svg xmlns='http://www.w3.org/2000/svg' width='740' height='120'>" ;
00023 o << "<g transform='translate(10,0)'>";
00024 o << "<g style='text-anchor:middle;font-size:16px;'>";
00025 for(int j = 0; j < 25; ++j) o << "<text x='"<< (j * 30) << "' y='118'>" << j << "</text><line x1='" << (j * 30) << "' y1='100' x2='" << (j * 30) << "' y2='104' style='stroke-width:2;stroke:black' />";
00026 o << "</g>";
00027 o << "<polyline points='0,0 720,0 720,100 0,100 0,0' style='fill:none;stroke:black;stroke-width:2'/>";
00028 }
00029 const char* DayOutlineEnd = "</g></svg>";
00030
00031 class htmlBarGraph : public picgen {
00032 static const int compressh = 2;
00033 public:
00034 virtual void add(int from, int duration, int height, string color, string title) {
00035 (*this) << "<img src='images/" << color <<".gif' width='" << (duration / compressh) << "' height='" << height << "' title='" << title << "' alt='" << title << "'/>";
00036 }
00037 virtual string str(){
00038 ostringstream o;
00039 o << ostringstream::str() << "<img src='images/scale.gif' height='20' width='" << (1440 / compressh) << "' alt='scale' />";
00040 return o.str();
00041 }
00042 };
00043
00044
00045 class svgBarGraph : public picgen {
00046 public:
00047 virtual void add(int from, int duration, int height, string color, string title) {
00048 (*this) << "<rect x='" << from << "' fill='" << color <<"' width='" << duration << "' height='" << height << "' title='" << title << "' />";
00049 }
00050 virtual string str(){
00051 ostringstream o;
00052 drawDayOutline(o);
00053 o << "<g transform='scale(0.5,-1) translate(0,-100)'>" << ostringstream::str() << "</g>" << DayOutlineEnd;
00054 return o.str();
00055 }
00056 };
00057
00058
00059 class svgPlotGraph : public picgen {
00060 public:
00061 virtual void add(int from, int duration, int height, string color, string title) {
00062 (*this) << "<rect x='" << from << "' fill='" << color <<"' width='" << duration << "' height='" << height << "' title='" << title << "' />";
00063 }
00064 virtual string str(){
00065 ostringstream o;
00066 drawDayOutline(o);
00067 o << "<g transform='scale(0.0083333,-1) translate(0,-100)'><path style='stroke:#dd2200' d='M 0 0 L " << ostringstream::str() << "' /></g>" << DayOutlineEnd;
00068 return o.str();
00069 }
00070 };
00071
00072 #endif