Skip to content

Commit d87c6bb

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

5 files changed

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

0 commit comments

Comments
 (0)