@@ -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+
239336func wrapTextInColor (text , c , styleType string ) string {
240337 if c == "" {
241338 return text
0 commit comments