1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef CHART_H 6 #define CHART_H 7 8 #include <View.h> 9 10 #include <ObjectList.h> 11 12 #include "chart/ChartDataRange.h" 13 #include "chart/ChartDefs.h" 14 15 16 class ChartAxis; 17 class ChartDataSource; 18 class ChartRenderer; 19 class ChartRendererDataSourceConfig; 20 21 22 class Chart : public BView { 23 public: 24 Chart(ChartRenderer* renderer, 25 const char* name = NULL); 26 virtual ~Chart(); 27 28 bool AddDataSource(ChartDataSource* dataSource, 29 int32 index, 30 ChartRendererDataSourceConfig* config 31 = NULL); 32 bool AddDataSource(ChartDataSource* dataSource, 33 ChartRendererDataSourceConfig* config 34 = NULL); 35 bool RemoveDataSource( 36 ChartDataSource* dataSource); 37 ChartDataSource* RemoveDataSource(int32 index); 38 void RemoveAllDataSources(); 39 40 void SetAxis(ChartAxisLocation location, 41 ChartAxis* axis); 42 43 inline ChartDataRange Domain() const; 44 inline ChartDataRange Range() const; 45 46 inline ChartDataRange DisplayDomain() const; 47 inline ChartDataRange DisplayRange() const; 48 49 void SetDisplayDomain(ChartDataRange domain); 50 void SetDisplayRange(ChartDataRange range); 51 52 double DomainZoomLimit() const; 53 void SetDomainZoomLimit(double limit); 54 55 virtual void DomainChanged(); 56 virtual void RangeChanged(); 57 58 virtual void MessageReceived(BMessage* message); 59 60 virtual void MouseDown(BPoint where); 61 virtual void MouseUp(BPoint where); 62 virtual void MouseMoved(BPoint where, uint32 code, 63 const BMessage* dragMessage); 64 virtual void FrameResized(float newWidth, float newHeight); 65 virtual void Draw(BRect updateRect); 66 virtual void ScrollTo(BPoint where); 67 68 virtual BSize MinSize(); 69 virtual BSize MaxSize(); 70 virtual BSize PreferredSize(); 71 72 virtual void DoLayout(); 73 74 private: 75 typedef BObjectList<ChartDataSource> DataSourceList; 76 77 struct AxisInfo { 78 ChartAxis* axis; 79 BRect frame; 80 81 AxisInfo(); 82 void SetFrame(float left, float top, float right, 83 float bottom); 84 void SetRange(const ChartDataRange& range); 85 void Render(BView* view, const BRect& updateRect); 86 }; 87 88 private: 89 void _UpdateDomainAndRange(); 90 void _UpdateScrollBar(bool horizontal); 91 void _ScrollTo(float value, bool horizontal); 92 void _Zoom(float x, float steps); 93 94 private: 95 ChartRenderer* fRenderer; 96 DataSourceList fDataSources; 97 AxisInfo fLeftAxis; 98 AxisInfo fTopAxis; 99 AxisInfo fRightAxis; 100 AxisInfo fBottomAxis; 101 ChartDataRange fDomain; 102 ChartDataRange fRange; 103 ChartDataRange fDisplayDomain; 104 ChartDataRange fDisplayRange; 105 BRect fChartFrame; 106 float fHScrollSize; 107 float fVScrollSize; 108 float fHScrollValue; 109 float fVScrollValue; 110 int32 fIgnoreScrollEvent; 111 double fDomainZoomLimit; 112 BPoint fLastMousePos; 113 BPoint fDraggingStartPos; 114 float fDraggingStartScrollValue; 115 }; 116 117 118 ChartDataRange 119 Chart::Domain() const 120 { 121 return fDomain; 122 } 123 124 125 ChartDataRange 126 Chart::Range() const 127 { 128 return fRange; 129 } 130 131 132 ChartDataRange 133 Chart::DisplayDomain() const 134 { 135 return fDisplayDomain; 136 } 137 138 139 ChartDataRange 140 Chart::DisplayRange() const 141 { 142 return fDisplayRange; 143 } 144 145 146 #endif // CHART_H 147