1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef LEGEND_CHART_AXIS_H
6#define LEGEND_CHART_AXIS_H
7
8#include <ObjectList.h>
9
10#include "chart/ChartAxis.h"
11#include "chart/ChartDataRange.h"
12
13
14class ChartAxisLegendSource;
15class ChartLegendRenderer;
16
17
18class LegendChartAxis : public ChartAxis {
19public:
20								LegendChartAxis(
21									ChartAxisLegendSource* legendSource,
22									ChartLegendRenderer* legendRenderer);
23	virtual						~LegendChartAxis();
24
25	virtual	void				SetLocation(ChartAxisLocation location);
26	virtual	void				SetRange(const ChartDataRange& range);
27	virtual	void				SetFrame(BRect frame);
28	virtual	BSize				PreferredSize(BView* view, BSize maxSize);
29	virtual	void				Render(BView* view, BRect updateRect);
30
31private:
32			struct LegendInfo;
33			typedef BObjectList<LegendInfo> LegendList;
34private:
35			void				_InvalidateLayout();
36			bool				_ValidateLayout(BView* view);
37			int32				_EstimateMaxLegendCount(BView* view, BSize size,
38									float* _hSpacing, float* _vSpacing);
39	inline	float				_LegendPosition(double value, float legendSize,
40									float totalSize, double scale);
41	inline	void				_FilterLegends(int32 totalSize, int32 spacing,
42									float BSize::* sizeField);
43
44private:
45			ChartAxisLegendSource* fLegendSource;
46			ChartLegendRenderer* fLegendRenderer;
47			ChartAxisLocation	fLocation;
48			ChartDataRange		fRange;
49			BRect				fFrame;
50			LegendList			fLegends;
51			float				fHorizontalSpacing;
52			float				fVerticalSpacing;
53			bool				fLayoutValid;
54};
55
56
57#endif	// LEGEND_CHART_AXIS_H
58