Skip to content

Commit 40ba322

Browse files
committed
Replace plottertypes by Singleton and deprecate ispyplots et al
1 parent 3e3150e commit 40ba322

5 files changed

Lines changed: 181 additions & 124 deletions

File tree

docs/src/api.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ save
1414
default_plotter
1515
default_plotter!
1616
plottertype
17+
PlotterType
1718
PythonPlotType
1819
PyPlotType
19-
MakieType
20+
AbstractPythonPlotterType
21+
AbstractMakieType
2022
PlotsType
2123
PlutoVistaType
2224
VTKViewType

ext/GridVisualizeMakieExt.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using Interpolations: linear_interpolation
1515
using IntervalSets
1616

1717
import GridVisualize: initialize!, save, reveal, gridplot!, scalarplot!, vectorplot!, streamplot!, customplot!, movie, plot_triangulateio!
18-
using GridVisualize: MakieType, GridVisualizer, SubVisualizer
18+
using GridVisualize: AbstractMakieType, GridVisualizer, SubVisualizer
1919
using GridVisualize: isolevels, cellcolors, num_cellcolors, vectorsample, quiverdata, regionmesh, bfacesegments
2020

2121
using ExtendableGrids
@@ -24,7 +24,7 @@ using Observables
2424

2525
include("flippablelayout.jl")
2626

27-
function initialize!(p::GridVisualizer, ::Type{MakieType})
27+
function initialize!(p::GridVisualizer, ::Type{MakieType}) where {MakieType <: AbstractMakieType}
2828
XMakie = p.context[:Plotter]
2929

3030
# Prepare flippable layout
@@ -57,7 +57,7 @@ end
5757
add_scene!(ctx, ax) = ctx[:flayout][ctx[:subplot]...] = ax
5858

5959
# Revealing the visualizer just returns the figure
60-
function reveal(p::GridVisualizer, ::Type{MakieType})
60+
function reveal(p::GridVisualizer, ::Type{MakieType}) where {MakieType <: AbstractMakieType}
6161
XMakie = p.context[:Plotter]
6262
layout = p.context[:layout]
6363
# For 1D plots the legend should be rendered only once,
@@ -84,18 +84,18 @@ function reveal(p::GridVisualizer, ::Type{MakieType})
8484
end
8585
end
8686

87-
function reveal(ctx::SubVisualizer, TP::Type{MakieType})
87+
function reveal(ctx::SubVisualizer, TP::Type{MakieType}) where {MakieType <: AbstractMakieType}
8888
FlippableLayout.yieldwait(ctx[:flayout])
8989
if ctx[:show] || ctx[:reveal]
9090
return reveal(ctx[:GridVisualizer], TP)
9191
end
9292
return nothing
9393
end
9494

95-
function save(fname, p::GridVisualizer, ::Type{MakieType})
95+
function save(fname, p::GridVisualizer, ::Type{MakieType}) where {MakieType <: AbstractMakieType}
9696
return p.context[:Plotter].save(fname, p.context[:figure])
9797
end
98-
function save(fname, scene, XMakie, ::Type{MakieType})
98+
function save(fname, scene, XMakie, ::Type{MakieType}) where {MakieType <: AbstractMakieType}
9999
return isnothing(scene) ? nothing : XMakie.save(fname, scene)
100100
end
101101

@@ -107,7 +107,7 @@ function movie(
107107
file = nothing,
108108
format = "gif",
109109
kwargs...,
110-
)
110+
) where {MakieType <: AbstractMakieType}
111111
Plotter = vis.context[:Plotter]
112112
if !isnothing(file)
113113
format = lstrip(splitext(file)[2], '.')
@@ -276,7 +276,7 @@ function scenecorners1d(grid, gridscale)
276276
end
277277

278278
# 1D version
279-
function gridplot!(ctx, TP::Type{MakieType}, ::Type{Val{1}}, grid)
279+
function gridplot!(ctx, TP::Type{MakieType}, ::Type{Val{1}}, grid) where {MakieType <: AbstractMakieType}
280280
XMakie = ctx[:Plotter]
281281
nregions = num_cellregions(grid)
282282
nbregions = num_bfaceregions(grid)
@@ -354,7 +354,7 @@ end
354354
########################################################################
355355
# 1D function
356356

357-
function scalarplot!(ctx, TP::Type{MakieType}, ::Type{Val{1}}, grids, parentgrid, funcs)
357+
function scalarplot!(ctx, TP::Type{MakieType}, ::Type{Val{1}}, grids, parentgrid, funcs) where {MakieType <: AbstractMakieType}
358358
XMakie = ctx[:Plotter]
359359

360360
nfuncs = length(funcs)
@@ -616,7 +616,7 @@ function set_plot_data!(ctx, key, data)
616616
return haskey(ctx, key) ? ctx[key][] = data : ctx[key] = Observable(data)
617617
end
618618

619-
function gridplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grid)
619+
function gridplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grid) where {MakieType <: AbstractMakieType}
620620
XMakie = ctx[:Plotter]
621621

622622
nregions = num_cellcolors(grid, ctx[:cellcoloring])
@@ -731,7 +731,7 @@ function makescene2d(ctx, key)
731731
end
732732

733733
# 2D function
734-
function scalarplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grids, parentgrid, funcs)
734+
function scalarplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grids, parentgrid, funcs) where {MakieType <: AbstractMakieType}
735735
XMakie = ctx[:Plotter]
736736
gridscale = ctx[:gridscale]
737737

@@ -869,7 +869,7 @@ function scalarplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grids, parentgrid
869869
end
870870

871871
# 2D vector
872-
function vectorplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grid, func)
872+
function vectorplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grid, func) where {MakieType <: AbstractMakieType}
873873
XMakie = ctx[:Plotter]
874874

875875
rc, rv = vectorsample(grid, func; gridscale = ctx[:gridscale], rasterpoints = ctx[:rasterpoints], offset = ctx[:offset])
@@ -914,7 +914,7 @@ function vectorplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grid, func)
914914
return reveal(ctx, TP)
915915
end
916916

917-
function streamplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grid, func)
917+
function streamplot!(ctx, TP::Type{MakieType}, ::Type{Val{2}}, grid, func) where {MakieType <: AbstractMakieType}
918918
XMakie = ctx[:Plotter]
919919

920920
rc, rv = vectorsample(
@@ -1080,7 +1080,7 @@ pgup/pgdown: coarse control control value
10801080
h: print this message
10811081
"""
10821082

1083-
function gridplot!(ctx, TP::Type{MakieType}, ::Type{Val{3}}, grid)
1083+
function gridplot!(ctx, TP::Type{MakieType}, ::Type{Val{3}}, grid) where {MakieType <: AbstractMakieType}
10841084
function make_mesh(pts, fcs)
10851085
if pkgversion(GeometryBasics) < v"0.5"
10861086
return GeometryBasics.Mesh(meta(pts; normals = normals(pts, fcs)), fcs)
@@ -1273,7 +1273,7 @@ function gridplot!(ctx, TP::Type{MakieType}, ::Type{Val{3}}, grid)
12731273
end
12741274

12751275
# 3d function
1276-
function scalarplot!(ctx, TP::Type{MakieType}, ::Type{Val{3}}, grids, parentgrid, funcs)
1276+
function scalarplot!(ctx, TP::Type{MakieType}, ::Type{Val{3}}, grids, parentgrid, funcs) where {MakieType <: AbstractMakieType}
12771277
levels, crange, colorbarticks = isolevels(ctx, funcs)
12781278
ctx[:crange] = crange
12791279
ctx[:colorbarticks] = colorbarticks
@@ -1514,7 +1514,7 @@ end
15141514
# Thanks! lines(x, y, axis = (targetlimits = lims,)) indeed makes the limits update.^
15151515
# I found that autolimits!(axis) gave good results, even better than me manually computing limits!
15161516

1517-
function customplot!(ctx, TP::Type{MakieType}, func)
1517+
function customplot!(ctx, TP::Type{MakieType}, func) where {MakieType <: AbstractMakieType}
15181518
XMakie = ctx[:Plotter]
15191519
if !haskey(ctx, :scene)
15201520
ctx[:scene] = XMakie.Axis(
@@ -1539,7 +1539,7 @@ function plot_triangulateio!(
15391539
voronoi = nothing,
15401540
circumcircles = false,
15411541
kwargs...
1542-
)
1542+
) where {MakieType <: AbstractMakieType}
15431543
XMakie = ctx[:Plotter]
15441544

15451545
function frgb(Plotter, i, max; pastel = false)

src/GridVisualize.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ include("dispatch.jl")
2222
include("common.jl")
2323
include("pycommon.jl")
2424
include("slice_plots.jl")
25+
include("deprecated.jl")
2526

2627
export scalarplot, scalarplot!
2728
export gridplot, gridplot!
@@ -31,11 +32,10 @@ export customplot, customplot!
3132
export quiverdata, vectorsample
3233
export plot_triangulateio, plot_triangulateio!
3334
export save, reveal
34-
export isplots, isvtkview, ispyplot, ispythonplot, ismakie, isplutovista
3535
export GridVisualizer, SubVisualizer
3636
export plottertype, available_kwargs
3737
export default_plotter!, default_plotter
38-
export PyPlotType, PythonPlotType, MakieType, PlotsType, VTKViewType, PlutoVistaType, MeshCatType
38+
export PlotterType, PyPlotType, PythonPlotType, AbstractPythonPlotterType, AbstractMakieType, PlotsType, VTKViewType, PlutoVistaType, MeshCatType, UnicodePlotsType
3939
export movie
4040

4141
end

src/deprecated.jl

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
2+
"""
3+
$(SIGNATURES)
4+
5+
Heuristically check if Plotter is VTKView
6+
"""
7+
function isvtkview(Plotter)
8+
Base.depwarn(
9+
"The function `isvtkview(Plotter)` will be deprecated in a future release. "
10+
* "Please use `plottertype(Plotter) isa VTKViewType` instead.",
11+
:isvtkview
12+
)
13+
return plottertype(Plotter) isa VTKViewType
14+
end
15+
16+
"""
17+
$(SIGNATURES)
18+
19+
Heuristically check if Plotter is PyPlot
20+
"""
21+
function ispyplot(Plotter)
22+
Base.depwarn(
23+
"The function `ispyplot(Plotter)` will be deprecated in a future release. "
24+
* "Please use `plottertype(Plotter) isa PyPlotType` instead.",
25+
:ispyplot
26+
)
27+
plottertype(Plotter) isa PyPlotType
28+
end
29+
30+
"""
31+
$(SIGNATURES)
32+
33+
Heuristically check if Plotter is PythonPlot
34+
"""
35+
function ispythonplot(Plotter)
36+
Base.depwarn(
37+
"The function `ispythonplot(Plotter)` will be deprecated in a future release. "
38+
* "Please use `plottertype(Plotter) isa PythonPlotType` instead.",
39+
:is
40+
)
41+
plottertype(Plotter) isa PythonPlotType
42+
end
43+
44+
"""
45+
$(SIGNATURES)
46+
47+
Heuristically check if Plotter is Plots
48+
"""
49+
function isplots(Plotter)
50+
Base.depwarn(
51+
"The function `isplots(Plotter)` will be deprecated in a future release. "
52+
* "Please use `plottertype(Plotter) isa PlotsType` instead.",
53+
:isplots
54+
)
55+
plottertype(Plotter) isa PlotsType
56+
end
57+
58+
"""
59+
$(SIGNATURES)
60+
61+
Heuristically check if Plotter is Makie/WGLMakie
62+
"""
63+
function ismakie(Plotter)
64+
Base.depwarn(
65+
"The function `is(Plotter)` will be deprecated in a future release. "
66+
* "Please use `plottertype(Plotter) <: UnionMakieType` instead.",
67+
:ismakie
68+
)
69+
plottertype(Plotter) <: UnionMakieType
70+
end
71+
72+
"""
73+
$(SIGNATURES)
74+
75+
Heuristically check if Plotter is MeshCat
76+
"""
77+
function ismeshcat(Plotter)
78+
Base.depwarn(
79+
"The function `ismeshcat(Plotter)` will be deprecated in a future release. "
80+
* "Please use `plottertype(Plotter) isa MeshCatType` instead.",
81+
:ismeshcat
82+
)
83+
plottertype(Plotter) isa MeshCatType
84+
end
85+
86+
"""
87+
$(SIGNATURES)
88+
89+
Heuristically check if Plotter is PlutoVista
90+
"""
91+
function isplutovista(Plotter)
92+
Base.depwarn(
93+
"The function `isplutovista(Plotter)` will be deprecated in a future release. "
94+
* "Please use `plottertype(Plotter) isa PlutoVistaType` instead.",
95+
:isplutovista
96+
)
97+
plottertype(Plotter) isa PlutoVistaType
98+
end
99+
100+
"""
101+
$(SIGNATURES)
102+
103+
Heuristically check if Plotter is UnicodePlots
104+
"""
105+
function isunicodeplots(Plotter)
106+
Base.depwarn(
107+
"The function `isunicodeplots(Plotter)` will be deprecated in a future release. "
108+
* "Please use `plottertype(Plotter) isa UnicodePlotsType` instead.",
109+
:is
110+
)
111+
plottertype(Plotter) isa UnicodePlotsType
112+
end
113+
114+
115+
const MakieType = UnionMakieType
116+
Base.@deprecate_binding MakieType UnionMakieType
117+
118+
119+
export isplots, isvtkview, ispyplot, ispythonplot, ismakie, isplutovista
120+
export MakieType

0 commit comments

Comments
 (0)