Skip to content

Commit cf170e4

Browse files
Merge pull request #33 from AlexanderGrooff/subgraphs
2 parents 31df468 + 19c22d0 commit cf170e4

29 files changed

Lines changed: 1191 additions & 16 deletions

.air.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Air configuration for mermaid-ascii web server live reloads
2+
3+
root = "."
4+
tmp_dir = "tmp"
5+
6+
[build]
7+
cmd = "go build -o tmp/mermaid-ascii ./"
8+
bin = "tmp/mermaid-ascii web"
9+
full_bin = ""
10+
include_ext = ["go", "tmpl", "html"]
11+
exclude_dir = ["tmp", "testdata", "vendor"]
12+
exclude_file = []
13+
exclude_regex = []
14+
include_dir = [".", "cmd", "templates"]
15+
delay = 1000
16+
kill_delay = 500
17+
send_interrupt = false
18+
stop_on_error = true
19+
20+
[log]
21+
time = false
22+
23+
[color]
24+
main = "white"
25+
watcher = "cyan"
26+
build = "yellow"
27+
runner = "green"
28+
29+
[misc]
30+
clean_on_exit = false

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Dev artifacts
22
.direnv
33
*.mermaid
4+
/tmp
5+
.playwright-mcp
46

57
# Editor
68
.idea

.goreleaser.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ builds:
2020
- darwin
2121

2222
archives:
23-
- format: tar.gz
23+
- formats:
24+
- tar.gz
2425
# this name template makes the OS and Arch compatible with the results of `uname`.
2526
name_template: >-
2627
{{ .ProjectName }}_
@@ -32,7 +33,8 @@ archives:
3233
# use zip for windows archives
3334
format_overrides:
3435
- goos: windows
35-
format: zip
36+
formats:
37+
- zip
3638

3739
changelog:
3840
sort: asc

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ repos:
33
rev: v0.5.0
44
hooks:
55
- id: go-fmt
6-
- id: go-imports
76
- id: no-go-testing
87
- id: golangci-lint
98
- id: go-unit-tests

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ clean:
1616
.PHONY: uninstall
1717
uninstall:
1818
$(RM) $(PREFIX)/mermaid-ascii
19+
20+
dev:
21+
air

cmd/draw.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func drawMap(properties *graphProperties) string {
155155
g.setStyleClasses(properties)
156156
g.paddingX = properties.paddingX
157157
g.paddingY = properties.paddingY
158+
g.setSubgraphs(properties.subgraphs)
158159
g.createMapping()
159160
d := g.draw()
160161
if Coords {
@@ -236,6 +237,102 @@ func drawBox(n *node, g graph) *drawing {
236237
return &boxDrawing
237238
}
238239

240+
func drawSubgraph(sg *subgraph, g graph) *drawing {
241+
// Calculate dimensions
242+
width := sg.maxX - sg.minX
243+
height := sg.maxY - sg.minY
244+
245+
if width <= 0 || height <= 0 {
246+
return mkDrawing(0, 0)
247+
}
248+
249+
from := drawingCoord{0, 0}
250+
to := drawingCoord{width, height}
251+
subgraphDrawing := *(mkDrawing(width, height))
252+
253+
log.Debugf("Drawing subgraph %s from (%d,%d) to (%d,%d)", sg.name, from.x, from.y, to.x, to.y)
254+
255+
if !useAscii {
256+
// Draw top border
257+
for x := from.x + 1; x < to.x; x++ {
258+
subgraphDrawing[x][from.y] = "─"
259+
}
260+
// Draw bottom border
261+
for x := from.x + 1; x < to.x; x++ {
262+
subgraphDrawing[x][to.y] = "─"
263+
}
264+
// Draw left border
265+
for y := from.y + 1; y < to.y; y++ {
266+
subgraphDrawing[from.x][y] = "│"
267+
}
268+
// Draw right border
269+
for y := from.y + 1; y < to.y; y++ {
270+
subgraphDrawing[to.x][y] = "│"
271+
}
272+
// Draw corners
273+
subgraphDrawing[from.x][from.y] = "┌"
274+
subgraphDrawing[to.x][from.y] = "┐"
275+
subgraphDrawing[from.x][to.y] = "└"
276+
subgraphDrawing[to.x][to.y] = "┘"
277+
} else {
278+
// Draw top border
279+
for x := from.x + 1; x < to.x; x++ {
280+
subgraphDrawing[x][from.y] = "-"
281+
}
282+
// Draw bottom border
283+
for x := from.x + 1; x < to.x; x++ {
284+
subgraphDrawing[x][to.y] = "-"
285+
}
286+
// Draw left border
287+
for y := from.y + 1; y < to.y; y++ {
288+
subgraphDrawing[from.x][y] = "|"
289+
}
290+
// Draw right border
291+
for y := from.y + 1; y < to.y; y++ {
292+
subgraphDrawing[to.x][y] = "|"
293+
}
294+
// Draw corners
295+
subgraphDrawing[from.x][from.y] = "+"
296+
subgraphDrawing[to.x][from.y] = "+"
297+
subgraphDrawing[from.x][to.y] = "+"
298+
subgraphDrawing[to.x][to.y] = "+"
299+
}
300+
301+
// NOTE: Label is now drawn separately in drawSubgraphLabel to prevent arrows from overwriting it
302+
303+
return &subgraphDrawing
304+
}
305+
306+
func drawSubgraphLabel(sg *subgraph, g graph) (*drawing, drawingCoord) {
307+
// Calculate dimensions
308+
width := sg.maxX - sg.minX
309+
height := sg.maxY - sg.minY
310+
311+
if width <= 0 || height <= 0 {
312+
return mkDrawing(0, 0), drawingCoord{0, 0}
313+
}
314+
315+
from := drawingCoord{0, 0}
316+
to := drawingCoord{width, height}
317+
labelDrawing := *(mkDrawing(width, height))
318+
319+
// Draw label centered at top
320+
labelY := from.y + 1
321+
labelX := from.x + width/2 - len(sg.name)/2
322+
if labelX < from.x+1 {
323+
labelX = from.x + 1
324+
}
325+
for i, char := range sg.name {
326+
if labelX+i < to.x {
327+
labelDrawing[labelX+i][labelY] = string(char)
328+
}
329+
}
330+
331+
// Return label drawing and its offset position
332+
offset := drawingCoord{sg.minX, sg.minY}
333+
return &labelDrawing, offset
334+
}
335+
239336
func wrapTextInColor(text, c, styleType string) string {
240337
if c == "" {
241338
return text

0 commit comments

Comments
 (0)