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