00001
00002 #pragma once
00003
00004 #include <atlbase.h>
00005
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 class TreeMapItem;
00028
00031 struct LayoutRectangle
00032 {
00035 float left;
00038 float top;
00041 float right;
00044 float bottom;
00045 };
00046
00049 class TreeMapLayout
00050 {
00051 public:
00054 virtual ~TreeMapLayout() { };
00059 virtual void UpdateLayout(TreeMapItem* item, LayoutRectangle rc) = 0;
00060 };
00061
00065 class TreeMapSliceLayout : public TreeMapLayout
00066 {
00067 public:
00072 void UpdateLayout(TreeMapItem* item, LayoutRectangle rc);
00073
00080 void UpdateSliceLayout(CSimpleValArray<TreeMapItem*>& items, int startIdx, int endIdx, LayoutRectangle rc);
00086 float GetChildrenSum(const CSimpleValArray<TreeMapItem*>& items, int startIdx, int endIdx) const;
00087 };
00088
00092 class TreeMapSquaredLayout : public TreeMapSliceLayout
00093 {
00094 public:
00099 void UpdateLayout(TreeMapItem* item, LayoutRectangle rc);
00100
00107 void UpdateSquaredLayout(CSimpleValArray<TreeMapItem*>& items, int startIdx, int endIdx, LayoutRectangle rc);
00114 float GetNormAspect(float big, float smal, float a, float b) const;
00115 };
00116
00121 class TreeMapStripLayout : public TreeMapSliceLayout
00122 {
00123 public:
00128 void UpdateLayout(TreeMapItem* item, LayoutRectangle rc);
00129
00136 void UpdateStripLayout(CSimpleValArray<TreeMapItem*>& items, int startIdx, int endIdx, LayoutRectangle rc);
00143 int UpdateOneLayoutStrip(CSimpleValArray<TreeMapItem*>& items, LayoutRectangle rcBox, int startIdx, int endIdx);
00150 float ComputeHorizontalBoxLayout(CSimpleValArray<TreeMapItem*>& items, LayoutRectangle rcBox, int startIdx, int nItems);
00156 float ComputeAverageAspectRatio(CSimpleValArray<TreeMapItem*>& items, int startIdx, int nItems);
00157 };
00158
00161 struct TreeMapItemInfo
00162 {
00165 TreeMapItemInfo();
00172 TreeMapItemInfo(LPCTSTR _name, unsigned long _order, unsigned int _depth, float _size);
00173
00176 TCHAR name[60];
00179 LayoutRectangle rc;
00182 unsigned int depth;
00185 unsigned long order;
00188 float size;
00189 };
00190
00193 class TreeMapItem
00194 {
00195 public:
00198 TreeMapItem();
00205 TreeMapItem(LPCTSTR name, DWORD order, UINT depth, float size);
00206
00209 ~TreeMapItem();
00210
00213 TreeMapItemInfo itemInfo;
00216 CSimpleValArray<TreeMapItem*> children;
00217 };
00218
00221 class TreeMap
00222 {
00223 public:
00226 TreeMap();
00229 ~TreeMap();
00230
00233 TreeMapLayout* layout;
00236 TreeMapItem* root;
00237
00242 float layoutSpacing;
00243
00246 void Prepare(void);
00249 void Destroy(void);
00250
00254 void SetLayoutSpacing(float spacing) { layoutSpacing = spacing; }
00257 float GetLayoutSpacing(void) const { return layoutSpacing; }
00258
00262 void SetLayout(TreeMapLayout* _layout);
00263
00267 void UpdateLayout(LayoutRectangle rc);
00271 void Render(LayoutRectangle rc);
00272
00273 private:
00278 void UpdateLayoutItem(TreeMapItem* item, LayoutRectangle rc);
00282 void RenderItem(const TreeMapItem* item);
00286 void ClearCalculation(TreeMapItem* item);
00290 float SizeCalculation(TreeMapItem* item);
00291 };
00292