@@ -15,13 +15,26 @@ initialize!(p, ::Type{UnicodePlotsType}) = nothing
1515
1616
1717function reveal (p:: GridVisualizer , :: Type{UnicodePlotsType} )
18- return p. context[:figure ]
18+ layout = p. context[:layout ]
19+ subplots = @views p. subplots[:]
20+
21+ if layout == (1 , 1 )
22+ display (subplots[1 ][:figure ])
23+ else
24+ if ! isdefined (Main, :Term )
25+ @warn " A GridVisualizer with multiple UnicodePlots requires 'Term.jl' to be loaded: add Term.jl to your environment."
26+ else
27+ grid_plot = UnicodePlots. gridplot (map (subplot -> subplot[:figure ], subplots), layout = p. context[:layout ])
28+ display (grid_plot)
29+ end
30+ end
31+ return nothing
1932end
2033
2134
2235function reveal (ctx:: SubVisualizer , TP:: Type{UnicodePlotsType} )
2336 if ctx[:show ] || ctx[:reveal ]
24- display (ctx[:figure ] )
37+ return reveal (ctx[:GridVisualizer ], TP )
2538 end
2639 return nothing
2740end
@@ -65,7 +78,8 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid)
6578 end
6679
6780 # determine resolution (divided by 10, to reduce pixel count in the terminal)
68- resolution = ctx[:size ] ./ 10
81+ layout = ctx[:layout ]
82+ resolution = ctx[:size ] ./ 10 ./ (layout[2 ], layout[1 ])
6983 legend_space = 4
7084 aspect = ctx[:aspect ] * resolution[1 ] / (resolution[1 ] + legend_space)
7185
@@ -216,7 +230,8 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{1}}, grid)
216230 end
217231
218232 # determine resolution (divided by 10, to reduce pixel count in the terminal)
219- resolution = (Int (round (ctx[:size ][1 ] / 10 )), 5 )
233+ layout = ctx[:layout ]
234+ resolution = (Int (round (ctx[:size ][1 ] / 10 / layout[2 ])), 5 )
220235
221236 # create UnicodePlots.Canvas
222237 legend_space = 5
@@ -306,7 +321,8 @@ function scalarplot!(
306321 )
307322
308323 nfuncs = length (funcs)
309- resolution = @. Int (round (ctx[:size ] ./ 10 )) # reduce pixel count in the terminal
324+ layout = ctx[:layout ]
325+ resolution = @. Int (round (ctx[:size ] ./ 10 ./ (layout[2 ], layout[1 ]))) # reduce pixel count in the terminal
310326 ylim = ctx[:limits ]
311327
312328 if ylim[1 ] > ylim[2 ]
@@ -341,7 +357,8 @@ function scalarplot!(
341357 )
342358
343359 func = funcs[1 ]
344- resolution = @. Int (round (ctx[:size ] ./ 10 )) # reduce pixel count in the terminal
360+ layout = ctx[:layout ]
361+ resolution = @. Int (round (ctx[:size ] ./ 10 ./ (layout[2 ], layout[1 ]))) # reduce pixel count in the terminal
345362 ylim = ctx[:limits ]
346363 colormap = ctx[:colormap ]
347364
0 commit comments