TTagCloud
Fuente: source/classes/tagcloud.prg
Inherits from: TControl
TTagCloud displays a weighted tag cloud where each tag is rendered in one of seven font sizes based on its weight (frequency). Tags auto-arrange in a flowing layout, highlight on mouse hover with a customizable text and background color, and respond to click events. The control is ideal for keyword navigation, category browsing, or any scenario requiring a visually weighted list.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
aItems | Array | Array of items, each { cText, nPeso, nFontIndex, nOriginalPos } |
aFonts | Array | Seven font handles, one per size level (largest to smallest) |
nHLine | Numeric | Line height for tag row wrapping (default 30) |
nClrText | Numeric | Default tag text color |
nClrTextOver | Numeric | Hover highlight text color (default orange) |
nClrPane | Numeric | Default background color |
nClrPaneOver | Numeric | Hover highlight background color |
aCoors | Array | Bounding rectangles per item, used for hit testing |
nMaxDescend | Numeric | Maximum font descent across all seven fonts |
nOver | Numeric | Index of the currently hovered item, or -1 if none |
Methods
| Method | Description |
|---|---|
New( nTop, nLeft, nW, nH, oWnd, oFont ) | Create a new TTagCloud control |
AddItem( cText, nPeso ) | Add a tag with text and weight value |
AsignFonts() | Assign font size indices to items based on sorted weights |
GetFonts() | Build the seven font sizes from the current base font |
Example: Tag Cloud with Three Tags
#include "FiveWin.ch"
function Main()
local oWnd, oTagCloud
DEFINE WINDOW oWnd TITLE "Tag Cloud" SIZE 400, 300
oTagCloud := TTagCloud():New( 10, 10, 360, 240, oWnd )
oTagCloud:AddItem( "FiveWin", 95 )
oTagCloud:AddItem( "Harbour", 80 )
oTagCloud:AddItem( "xHarbour", 60 )
oTagCloud:AsignFonts()
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- Tags are sorted internally by weight. The highest weight gets the largest font (level 1) and lower weights descend through levels 2-7.
- Call
AsignFonts()after adding all items to assign matching font sizes. Fonts are created once byGetFonts()duringNew(). - Hover tracking is handled by
MouseMove, which setsnOverand triggersRefresh()to repaint the highlighted tag. - Clicking a tag (default
LButtonUp) outputs the tag text. OverridebLClickedor subclassLButtonUpfor custom click actions.