Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

chart.h

00001 /*
00002  * ===========================
00003  * VDK Component Library
00004  * Version 0.2
00005  * ===========================
00006  * Copyright (C) 1998, Mario Motta
00007  * Developed by Mario Motta <mmotta@guest.net>
00008  * ===========================================
00009  * This library is a component of:
00010  * VDK Visual Development Kit
00011  * Version 0.4.1
00012  * Copyright (C) 1998, Mario Motta
00013  * Developed by Mario Motta <mmotta@guest.net>
00014  * ===========================================
00015  * This library is free software; you can redistribute it and/or
00016  * modify it under the terms of the GNU Library General Public
00017  * License as published by the Free Software Foundation; either
00018  * version 2 of the License, or (at your option) any later version.
00019  *
00020  * This library is distributed in the hope that it will be useful,
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00023  * Library General Public License for more details.
00024  *
00025  * You should have received a copy of the GNU Library General Public
00026  * License along with this library; if not, write to the Free Software
00027  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00028  * 02111-130
00029  */ 
00030 
00031 #ifndef CHART_H
00032 #define CHART_H
00033 #include <vdk/vdk.h>
00038 class Coord 
00039 { 
00040 public:
00041 double x,y; 
00042  Coord(double x = 0.0, double y = 0.0):x(x),y(y) {}
00043  ~Coord() {}
00044 };
00045 
00046 typedef VDKValueList<Coord> CoordList;
00047 typedef VDKValueListIterator<Coord> CoordListIterator;
00048 typedef VDKArray<double>    Darray;
00049 
00050 class VDKChart;
00052 
00056 class Series: public CoordList
00057 {
00058   Coord max,min;
00059   VDKString title;
00060  public:
00064   VDKReadWriteValueProp<Series,VDKRgb> Color;
00072   VDKReadWriteValueProp<Series,GdkLineStyle> LineStyle;
00076   VDKReadWriteValueProp<Series,int> LineWidth;
00085   VDKReadWriteValueProp<Series,GdkCapStyle> LineCapStyle;
00093   VDKReadWriteValueProp<Series,GdkJoinStyle> LineJoinStyle;
00098   Series(char* title): 
00099     CoordList(),
00100     title(title),
00101     Color("Color",this,VDKRgb(0,0,0)),
00102     LineStyle("LineStyle",this,GDK_LINE_SOLID),
00103     LineWidth("LineWidth",this,1),
00104     LineCapStyle("LineCapStyle",this,GDK_CAP_NOT_LAST),
00105     LineJoinStyle("LineJoinStyle",this,GDK_JOIN_MITER)
00106     {}
00110   ~Series() {}
00116   void Add(double x, double y);
00123   void Add(double* x, double* y, int n);
00127   Coord Min() { return min; }
00131   Coord Max() { return max; }
00135   char* Title() { return (char*) title; }
00139   bool operator==(Series& s) { return title == s.title; }
00140 };
00141 
00142 typedef VDKList<Series> SeriesList;
00143 typedef VDKListiterator<Series> SeriesListIterator;
00144 
00146 
00150 class ChartAxis
00151 {
00152   VDKRect  domain;
00153   VDKChart* owner;
00154  public:
00155   ChartAxis():owner((VDKChart*) NULL) {}
00156   ChartAxis(VDKChart* owner,int w, int h);
00157   ChartAxis(ChartAxis& a);
00158   ~ChartAxis() {}
00159   void Draw();
00160   VDKRect& Domain() { return domain; }
00161 };
00162 
00163 enum 
00164 {
00165   chart_class = 4096,
00166   linechart_class,
00167   scatteredchart_class,
00168   barchart_class
00169 };
00170 
00172 
00192 class VDKChart: public VDKCanvas
00193 {
00194   
00195  protected:
00196   GtkWidget *tip_window;
00197   VDKPoint size;
00198   double xn1,yn1,xn2,yn2,xv1,yv1,xv2,yv2,kx,ky;
00199   Coord domainmax,domainmin;
00200   SeriesList series;
00201   bool OnConfigure(VDKObject* sender, GdkEvent* event);
00202   bool OnClick(VDKObject* sender, GdkEvent* event);
00203   bool OnClickRelease(VDKObject* sender, GdkEvent* event);
00204   ChartAxis axis;
00205   void ComputeDomainLimits(Series* s);
00206   virtual void DrawChart();
00207   void DrawTitle();
00208   void DrawTicks();
00209   void DrawLabels();
00210  public:
00215   VDKReadWriteValueProp<VDKChart, int> ChartBorder;
00219   VDKReadWriteValueProp<VDKChart, VDKString> Title;
00223   VDKReadWriteValueProp<VDKChart, VDKString> LabelX;
00227   VDKReadWriteValueProp<VDKChart, VDKString> LabelY;
00231   VDKReadWriteValueProp<VDKChart, int> LabelXDigits;
00235   VDKReadWriteValueProp<VDKChart, int> LabelYDigits;
00242   VDKChart(VDKForm* owner, int w = 100, int h = 100);
00246   virtual ~VDKChart();
00250   virtual int isA() { return chart_class; }
00259   void AddSeries(Series* s);
00263   void Clear();
00264   void SetChartBorder(int b);
00265   int  GetChartBorder() { return ChartBorder; }
00269   GdkGC* GC() { return gc; }
00274   void SetColor(VDKRgb rgb);
00278   void SetLineAttributes(gint lineWidth, 
00279                          GdkLineStyle lineStyle,
00280                          GdkCapStyle capStyle,
00281                          GdkJoinStyle joinStyle);
00291   virtual void Plot(VDKPoint& p , int i, Series* s) {}
00292   DECLARE_EVENT_LIST(VDKChart);
00293 };
00295 
00299 class VDKLineChart: public VDKChart
00300 {
00301  public:
00302   VDKLineChart(VDKForm* owner, int w = 100, int h = 100):
00303     VDKChart(owner,w,h) {}
00304   virtual ~VDKLineChart() {}
00308   virtual void Plot(VDKPoint& p, int t, Series*);
00312   virtual int isA() { return linechart_class; }
00313 };
00315 
00319 class VDKScatteredChart: public VDKChart
00320 {
00321  public:
00322   VDKScatteredChart(VDKForm* owner, int w = 100, int h = 100):
00323     VDKChart(owner,w,h) {}
00324   virtual ~VDKScatteredChart() {}
00325   virtual void Plot(VDKPoint& p, int t, Series*);
00326   virtual int isA() { return scatteredchart_class; }
00327 };
00328 
00330 
00335 class VDKBarChart: public VDKChart
00336 {
00337  public:
00341   VDKReadWriteValueProp<VDKBarChart,int> BarWidth;
00342   /*
00343     Sets/gets label flag
00344    */
00345   VDKReadWriteValueProp<VDKBarChart,bool> Labels;
00346 
00347   VDKBarChart(VDKForm* owner, int w = 100, int h = 100):
00348     VDKChart(owner,w,h),
00349     BarWidth("BarWidth",this,20),
00350     Labels("Labels",this,true)
00351     {}
00352   virtual ~VDKBarChart() {}
00356   virtual void Plot(VDKPoint& p, int t, Series*);
00360   virtual int isA() { return barchart_class; }
00361 };
00362 
00363 #endif
00364 
00365 

Generated on Tue Oct 26 18:58:51 2004 for vdk 2.4.0 by  doxygen 1.3.9.1