Class TTreeMap

Unit

Declaration

type TTreeMap = class(TGraphicControl)

Description

A control that displays weighted items as a squarified treemap.

Populate the control through its TTreeMap.Items container, then let the control lay the items out and paint them. Items that have children are drawn as nested treemaps. Hovering and selection are tracked automatically and reported through TTreeMap.OnClickItem and TTreeMap.OnDblClickItem; painting can be customized through TTreeMap.OnDrawItem.

Wrap bulk changes to TTreeMap.Items in TTreeMap.BeginUpdate/TTreeMap.EndUpdate to avoid intermediate repaints.

Hierarchy

Overview

Methods

Public constructor Create(aowner: TComponent); override;
Public destructor Destroy; override;
Public procedure CalculateTreemap(aitems: TTreeMapContainer; arect: TRect);
Public procedure DrawTreemap(acanvas: TCanvas; arect: TRect; aitems: TTreeMapContainer);
Public function GetItemAt(x,y: integer): TTreeMapItem;
Public procedure BeginUpdate;
Public procedure EndUpdate;
Public procedure ClearSelection;
Public procedure SetSelected(const Value: TTreeMapItem; selected: boolean);
Public procedure Repaint; override;

Properties

Public property Items: TTreeMapContainer read fItems;
Published property MaxItems: integer read fMaxItems write SetMaxItems default 200;
Published property MinArea: integer read fMinArea write SetMinArea default 64*64;
Published property BackgroundColor: TColor read fBackgroundColor write fBackgroundColor default clBtnFace;
Published property SelectionColor: TColor read fSelectionColor write SetSelectionColor default $FFFFFF;
Published property BorderSize: integer read fBorderSize write SetBorderSize default 1;
Published property Font: TFont read fFont write SetFont;
Published property Images: TImageList read fImages write fImages;
Published property OnDrawItem: TOnDrawTreeMapItemEvent read fOnDrawItem write fOnDrawItem;
Published property OnClickItem: TOnTreeMapItemClickEvent read fOnClickItem write fOnClickItem;
Published property OnDblClickItem: TOnTreeMapItemClickEvent read fOnDblClickItem write fOnDblClickItem;

Description

Methods

Public constructor Create(aowner: TComponent); override;

Creates the control, its default painter and an empty item container.

Public destructor Destroy; override;

Destroys the control and frees the items it owns.

Public procedure CalculateTreemap(aitems: TTreeMapContainer; arect: TRect);

Recalculates the treemap layout for aitems within arect.

Called internally when a relayout is required, but exposed so the same layout algorithm can be applied to arbitrary containers – for example to render a treemap onto another canvas together with TTreeMap.DrawTreemap.

Parameters
aitems
The container whose items are laid out; each item's TTreeMapItem.Rect is updated in place.
arect
The rectangle the items are laid out within.
Public procedure DrawTreemap(acanvas: TCanvas; arect: TRect; aitems: TTreeMapContainer);

Draws aitems as a treemap onto acanvas within arect.

This is the control's main drawing routine, but it can also render a treemap onto any canvas and for containers not managed by the control. The layout is (re)calculated first if required.

Parameters
acanvas
The target canvas.
arect
The rectangle to draw within.
aitems
The container of items to draw.
Public function GetItemAt(x,y: integer): TTreeMapItem;

Returns the item at control coordinates (x, y), searching nested children, or Nil if no item covers that point.

Parameters
x
Horizontal position in control coordinates.
y
Vertical position in control coordinates.
Returns

The item at the given position, or Nil.

Public procedure BeginUpdate;

Suspends repainting while TTreeMap.Items is being modified. Must be paired with a later TTreeMap.EndUpdate. Useful when adding or removing many items at once.

Public procedure EndUpdate;

Resumes repainting after TTreeMap.BeginUpdate, forces a relayout and repaints the control.

Public procedure ClearSelection;

Clears the selected state of every item, including nested children, and repaints the control.

Public procedure SetSelected(const Value: TTreeMapItem; selected: boolean);

Sets or clears the selected state of a single item, repainting if the state actually changed.

Parameters
Value
The item to update. Ignored when Nil.
selected
True to select the item, False to deselect it.
Public procedure Repaint; override;

Repaints the control immediately, re-rendering the offscreen surface.

Properties

Public property Items: TTreeMapContainer read fItems;

The items rendered by the control. The container may hold a flat list or a hierarchy (items with TTreeMapItem.Children). The control owns and frees the items it contains. Runtime-only and read-only, so it is not published.

Published property MaxItems: integer read fMaxItems write SetMaxItems default 200;

The maximum number of items laid out within a container. Items beyond this count are ignored by the layout. Changing it forces a relayout.

Published property MinArea: integer read fMinArea write SetMinArea default 64*64;

The smallest rectangle area, in square pixels, that is still laid out. Layout stops subdividing once the available area drops below this value. Changing it forces a relayout.

Published property BackgroundColor: TColor read fBackgroundColor write fBackgroundColor default clBtnFace;

Color used to clear the background behind the tiles.

Published property SelectionColor: TColor read fSelectionColor write SetSelectionColor default $FFFFFF;

Border color drawn around a selected tile by the default painter.

Published property BorderSize: integer read fBorderSize write SetBorderSize default 1;

Tile border thickness, in pixels, used by the default painter.

Published property Font: TFont read fFont write SetFont;

Base font used by the default painter, which derives several sizes from its name.

Published property Images: TImageList read fImages write fImages;

Image list whose icons can be shown on tiles via TTreeMapItem.ImageIndex.

Published property OnDrawItem: TOnDrawTreeMapItemEvent read fOnDrawItem write fOnDrawItem;

Handler invoked to paint each item. When unassigned, an internal default painter is used. See TOnDrawTreeMapItemEvent.

Published property OnClickItem: TOnTreeMapItemClickEvent read fOnClickItem write fOnClickItem;

Handler invoked on a single click on an item. See TOnTreeMapItemClickEvent.

Published property OnDblClickItem: TOnTreeMapItemClickEvent read fOnDblClickItem write fOnDblClickItem;

Handler invoked on a double click on an item. See TOnTreeMapItemClickEvent.


Generated by PasDoc 1.0.4.