Skip to content

Commit 49d522b

Browse files
committed
WIP: Add unicode multiplot
To achieve this, we need to set the size of the subplots and hand over independent Gridvisualizers for the subplots
1 parent 011d489 commit 49d522b

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

ext/GridVisualizeUnicodePlotsExt.jl

Lines changed: 15 additions & 2 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])
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

src/dispatch.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ function GridVisualizer(; Plotter::Union{Module, Nothing} = default_plotter(), k
269269
default_ctx = Dict{Symbol, Any}(k => v[1] for (k, v) in default_plot_kwargs())
270270
_update_context!(default_ctx, kwargs)
271271
layout = default_ctx[:layout]
272+
273+
# fit the default size to the layout
274+
subplot_ctx = deepcopy(default_ctx)
275+
@show subplot_ctx[:size] = default_ctx[:size] ./ (layout[2], layout[1])
276+
272277
if isnothing(Plotter)
273278
default_ctx = nothing
274279
end
@@ -281,7 +286,7 @@ function GridVisualizer(; Plotter::Union{Module, Nothing} = default_plotter(), k
281286
ctx[:subplot] = i
282287
ctx[:iplot] = layout[2] * (i[1] - 1) + i[2]
283288
ctx[:Plotter] = Plotter
284-
ctx[:GridVisualizer] = p
289+
ctx[:GridVisualizer] = GridVisualizer(Plotter, layout, subplot_ctx)
285290
end
286291
initialize!(p, plottertype(Plotter))
287292
end

0 commit comments

Comments
 (0)