The map¶
modelmap.treemap
¶
Squarified treemap layout: pure geometry, no drawing and no files.
The algorithm is the one in Bruls, Huizing and van Wijk, "Squarified Treemaps" (2000): take the items in decreasing order and fill the rectangle with rows laid along its shorter side, adding items to the current row for as long as that does not worsen the row's worst aspect ratio.
The area of every rectangle is its share of the total, exactly: nothing here insets, pads or rounds. A drawing layer that wants gaps must draw them on top of these rectangles, not shrink them.
Group(name, size, rect, tiles=list())
dataclass
¶
A group of tiles and the rectangle they fill.
Item(key, group, size, label='')
dataclass
¶
One thing to place on the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Unique identity, for example a path. |
required |
group
|
str
|
Name of the group the item belongs to. |
required |
size
|
float
|
Size that sets the tile's area; must be positive. |
required |
label
|
str
|
Text for sorting ties and for display. |
''
|
Rect(x, y, w, h)
dataclass
¶
An axis-aligned rectangle; y grows downward, as in SVG.
aspect
property
¶
Long side over short side; 1 for a square, infinite when flat.
Tile(key, group, size, rect, label='', members=list())
dataclass
¶
A placed item, or several small items merged into one tile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The item's key; for a merged tile, a key made from the group. |
required |
group
|
str
|
Group name. |
required |
size
|
float
|
The item's size, or the sum for a merged tile. |
required |
rect
|
Rect
|
Where the tile is. |
required |
label
|
str
|
The item's label; empty for a merged tile. |
''
|
members
|
list[str]
|
Keys of the items a merged tile stands for; empty for a tile that is one item. |
list()
|
layout(items, rect, *, min_fraction=0.0)
¶
Lay out items in two levels: groups, then the items of each group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
items
|
Sequence[Item]
|
Items with positive sizes and unique keys. |
required |
rect
|
Rect
|
The canvas. |
required |
min_fraction
|
float
|
Items smaller than this share of the whole are merged into one tile per group, when a group has two or more of them, so that every tile drawn is large enough to see. |
0.0
|
Returns:
| Type | Description |
|---|---|
list[Group]
|
Groups from largest to smallest, each with its tiles from largest to smallest. Equal sizes are ordered by label, then key, so the same items always give the same layout. |
Source code in src/modelmap/treemap.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
squarify(sizes, rect)
¶
Divide a rectangle among sizes, keeping the pieces close to square.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sizes
|
Sequence[float]
|
Positive sizes, in any order. |
required |
rect
|
Rect
|
The rectangle to fill. |
required |
Returns:
| Type | Description |
|---|---|
list[Rect]
|
One rectangle per size, in the order of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a size is not positive. |
Source code in src/modelmap/treemap.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
worst(largest, smallest, total, side)
¶
The highest aspect ratio in a row, as the paper defines it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
largest
|
float
|
Largest area in the row. |
required |
smallest
|
float
|
Smallest area in the row. |
required |
total
|
float
|
Sum of the areas in the row. |
required |
side
|
float
|
Length of the side the row is laid along. |
required |
Source code in src/modelmap/treemap.py
40 41 42 43 44 45 46 47 48 | |
modelmap.render_html
¶
Draw a scan as one interactive page that works offline.
The page is a set of views, every one laid out here in Python and written into the file as plain markup:
- a top view per grouping (by store, format, family or kind);
- a view per group, where the group's records fill the square;
- a view per record, where its individual files fill the square.
Clicking a tile opens the view below it, down to the files. The script in the page only shows and hides views, moves a tooltip and copies text; it creates no markup, so a model name can never become code. The page loads nothing from the network.
The page deletes nothing itself. For each record it shows where the files
are, which other records use them, and the modelmap rm command that
removes the record, or why it cannot.
group_view(by, name)
¶
A group's view id, from the grouping and the group's name.
Source code in src/modelmap/render_html.py
90 91 92 | |
record_view(record)
¶
A record's view id: from its store and path, so it is the same in every scan.
A view named by position would open another record once one is removed.
Source code in src/modelmap/render_html.py
82 83 84 85 86 87 | |
render_html(scan, *, use_disk=False, served=False, removable=False)
¶
Draw a scan as a self-contained interactive page.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan
|
Scan
|
The scan to draw. |
required |
use_disk
|
bool
|
Size tiles by bytes allocated on disk, not apparent size. |
False
|
served
|
bool
|
Add what |
False
|
removable
|
bool
|
With |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The HTML text, ending with a newline. |
Source code in src/modelmap/render_html.py
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 | |
modelmap.render_svg
¶
Draw a scan as one static SVG: a square treemap with a header and legend.
The square is divided among the records by size. Tiles of one provider
form one block. Each <rect> carries the exact layout geometry (to a
thousandth of a unit); the gaps between tiles are strokes in the surface
color drawn over the edges, so no tile is shrunk to make room.
The picture adapts to a light or dark setting through
prefers-color-scheme. Hovering a tile in a browser shows its details
(the SVG <title>).
label_markup(r, clip_id, ink, name, detail, extra='', tag='')
¶
The label of a tile, clipped to it; nothing if no line fits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
Rect
|
The tile. |
required |
clip_id
|
str
|
Document-unique id for the clip path. |
required |
ink
|
str
|
Attribute text that sets the label color, such as
|
required |
name
|
str
|
First line, in bold. |
required |
detail
|
str
|
Second line. |
required |
extra
|
str
|
Third line. |
''
|
tag
|
str
|
A small heading above the name, such as the group's name. |
''
|
Source code in src/modelmap/render_svg.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
render_svg(scan, *, size=1000, use_disk=False)
¶
Draw a scan as an SVG document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan
|
Scan
|
The scan to draw. |
required |
size
|
int
|
Side of the square map, in SVG units. |
1000
|
use_disk
|
bool
|
Size tiles by bytes allocated on disk, not apparent size. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The SVG text, ending with a newline. |
Source code in src/modelmap/render_svg.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |