Skip to content

Commit c6d7a08

Browse files
committed
UnicodePlots: Enable multiplot layout by reducing the resolution
1 parent aa66288 commit c6d7a08

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## [1.19.0] - 2026-04-17
4+
- `UnicodePlots` does support multiplots if the package `Term` is loaded.
5+
36
## [1.18.0] - 2026-04-15
47
- new UnicodePlots.jl extension that at the moment supports gridplot and scalarplot in 1D and 2D
58

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GridVisualize"
22
uuid = "5eed8a63-0fb0-45eb-886d-8d5a387d12b8"
3+
version = "1.19.0"
34
authors = ["Juergen Fuhrmann <juergen.fuhrmann@wias-berlin.de>", "Patrick Jaap <patrick.jaap@wias-berlin.de>"]
4-
version = "1.18.1"
55

66
[deps]
77
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"

ext/GridVisualizeUnicodePlotsExt.jl

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,26 @@ initialize!(p, ::Type{UnicodePlotsType}) = nothing
1515

1616

1717
function 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
1932
end
2033

2134

2235
function 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
2740
end
@@ -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

Comments
 (0)