Skip to content

Commit 370d801

Browse files
committed
Allow user to select any Makie flavor
1 parent 16c3df5 commit 370d801

File tree

3 files changed

+58
-59
lines changed

3 files changed

+58
-59
lines changed

docs/src/library.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ Private = false
1414
## Plotting
1515

1616
To reduce package load times, certain plotting functions are only available when
17-
the user explicitly executes "`using GLMakie`".
17+
the user explicitly loads Makie, e.g., with `using GLMakie` or `using WGLMakie`.

src/Plotting.jl

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
"""Plotting functions for lattices and spins on lattices.
2-
"""
1+
# Plotting functions for lattices and spins on lattices.
32

43
function _setup_scene(; show_axis=false, ortho=false)
5-
fig = GLMakie.Figure()
6-
ax = GLMakie.LScene(fig[1, 1]; show_axis)
4+
fig = Makie.Figure()
5+
ax = Makie.LScene(fig[1, 1]; show_axis)
76
if ortho
8-
_ = GLMakie.cam3d!(ax.scene, projectiontype=GLMakie.Makie.Orthographic)
7+
_ = Makie.cam3d!(ax.scene, projectiontype=Makie.Orthographic)
98
end
109
return fig, ax
1110
end
1211

1312
#=
1413
function plot_lattice!(ax, lattice::Lattice; colors=:Set1_9, markersize=200, linecolor=:grey, linewidth=1.0, kwargs...)
1514
unique_types = unique(lattice.types)
16-
colors = GLMakie.resample_cmap(colors, 9)
15+
colors = Makie.resample_cmap(colors, 9)
1716
1817
# Plot markers at each site
19-
pts = GLMakie.Point3f0.(vec(lattice))
18+
pts = Makie.Point3f0.(vec(lattice))
2019
for (i, type) in enumerate(unique_types)
2120
bs = findall(isequal(type), lattice.types)
22-
GLMakie.scatter!(ax, pts; label=type, color=colors[i], markersize=markersize, kwargs...)
21+
Makie.scatter!(ax, pts; label=type, color=colors[i], markersize=markersize, kwargs...)
2322
end
2423
2524
# For some odd reason, the sites will not appear unless this happens afterwards
@@ -31,7 +30,7 @@ function plot_lattice(lattice::Lattice; kwargs...)
3130
fig, ax = _setup_scene()
3231
plot_lattice!(ax, lattice; kwargs...)
3332
# TODO: Markers are often way too big.
34-
fig[1, 2] = GLMakie.Legend(fig, ax, "Species")
33+
fig[1, 2] = Makie.Legend(fig, ax, "Species")
3534
fig
3635
end
3736
@@ -48,7 +47,7 @@ colors=:Set1_9, markersize=20, linecolor=:grey, linewidth=1.0, kwargs...
4847
- `markersize=20` : Sets the size of the atomic sites
4948
- `colors=:Set1_9` : Sets the colors used for the atomic sites
5049
51-
Additional keyword arguments are given to `GLMakie.scatter!` which
50+
Additional keyword arguments are given to `Makie.scatter!` which
5251
draws the points.
5352
"""
5453
plot_lattice(cryst::Crystal, latsize=(3,3,3); kwargs...) = plot_lattice(Lattice(cryst, latsize); kwargs...)
@@ -62,7 +61,7 @@ function plot_bonds(lattice::Lattice, ints::Vector{<:AbstractInteractionCPU};
6261
# TODO: Make selectable in GUI
6362
b = 1
6463
65-
colors = GLMakie.resample_cmap(colors, 8)
64+
colors = Makie.resample_cmap(colors, 8)
6665
# Sort interactions so that longer bonds are plotted first
6766
sorted_ints = sort(
6867
ints,
@@ -76,36 +75,36 @@ function plot_bonds(lattice::Lattice, ints::Vector{<:AbstractInteractionCPU};
7675
# Plot the lattice
7776
plot_lattice!(ax, lattice; kwargs...)
7877
79-
toggles = Vector{GLMakie.Toggle}()
80-
labels = Vector{GLMakie.Label}()
78+
toggles = Vector{Makie.Toggle}()
79+
labels = Vector{Makie.Label}()
8180
cent_cell = CartesianIndex(div.(lattice.size .+ 1, 2)...)
8281
cent_pt = lattice[cent_cell, b]
8382
for (n, int) in enumerate(sorted_ints)
8483
if !isa(int, AbstractPairIntCPU)
8584
continue
8685
end
8786
88-
pts = Vector{GLMakie.Point3f0}()
87+
pts = Vector{Makie.Point3f0}()
8988
for (bond, _) in sublat_bonds(int.bondtable, b)
9089
new_cell = offsetc(cent_cell, bond.n, lattice.size)
9190
bond_pt = lattice[new_cell, bond.j]
92-
push!(pts, GLMakie.Point3f0(cent_pt))
93-
push!(pts, GLMakie.Point3f0(bond_pt))
91+
push!(pts, Makie.Point3f0(cent_pt))
92+
push!(pts, Makie.Point3f0(bond_pt))
9493
end
9594
if length(pts) == 0
9695
continue
9796
end
9897
9998
color = colors[mod1(n, 8)]
100-
seg = GLMakie.linesegments!(pts; linewidth=bondwidth, label=int.label, color=color)
101-
tog = GLMakie.Toggle(fig, active=true)
102-
GLMakie.connect!(seg.visible, tog.active)
99+
seg = Makie.linesegments!(pts; linewidth=bondwidth, label=int.label, color=color)
100+
tog = Makie.Toggle(fig, active=true)
101+
Makie.connect!(seg.visible, tog.active)
103102
push!(toggles, tog)
104-
push!(labels, GLMakie.Label(fig, int.label))
103+
push!(labels, Makie.Label(fig, int.label))
105104
end
106-
GLMakie.axislegend()
105+
Makie.axislegend()
107106
if length(toggles) > 0
108-
fig[1, 2] = GLMakie.grid!(hcat(toggles, labels), tellheight=false)
107+
fig[1, 2] = Makie.grid!(hcat(toggles, labels), tellheight=false)
109108
end
110109
fig
111110
end
@@ -204,29 +203,29 @@ end
204203
function plot_cells!(ax, sys::System; color=:grey, linewidth=1.0, kwargs...)
205204
lattice(i, j, k) = sys.crystal.latvecs * Vec3(i, j, k)
206205
207-
pts = Vector{GLMakie.Point3f0}()
206+
pts = Vector{Makie.Point3f0}()
208207
nx, ny, nz = lattice.size
209208
for j in 1:ny
210209
for k in 1:nz
211210
bot_pt, top_pt = lattice(1, j, k), lattice(nx, j, k)
212-
push!(pts, GLMakie.Point3f0(bot_pt))
213-
push!(pts, GLMakie.Point3f0(top_pt))
211+
push!(pts, Makie.Point3f0(bot_pt))
212+
push!(pts, Makie.Point3f0(top_pt))
214213
end
215214
for i in 1:nx
216215
left_pt, right_pt = lattice(i, j, 1), lattice(i, j, nz)
217-
push!(pts, GLMakie.Point3f0(left_pt))
218-
push!(pts, GLMakie.Point3f0(right_pt))
216+
push!(pts, Makie.Point3f0(left_pt))
217+
push!(pts, Makie.Point3f0(right_pt))
219218
end
220219
end
221220
for k in 1:nz
222221
for i in 1:nx
223222
left_pt, right_pt = lattice(i, 1, k), lattice(i, ny, k)
224-
push!(pts, GLMakie.Point3f0(left_pt))
225-
push!(pts, GLMakie.Point3f0(right_pt))
223+
push!(pts, Makie.Point3f0(left_pt))
224+
push!(pts, Makie.Point3f0(right_pt))
226225
end
227226
end
228227
229-
GLMakie.linesegments!(ax, pts; color=color, linewidth=linewidth)
228+
Makie.linesegments!(ax, pts; color=color, linewidth=linewidth)
230229
end
231230
=#
232231

@@ -240,16 +239,16 @@ end
240239
plot_spins(sys::System; linecolor=:grey, arrowcolor=:red, linewidth=0.1,
241240
arrowsize=0.3, arrowlength=1.0, kwargs...)
242241
243-
Plot the spin configuration defined by `sys`. `kwargs` are passed to `GLMakie.arrows`.
242+
Plot the spin configuration defined by `sys`. `kwargs` are passed to `Makie.arrows`.
244243
"""
245244
function plot_spins(sys::System; linecolor=:grey, arrowcolor=:red,
246245
linewidth=0.1, arrowsize=0.2, arrowlength=0.2, ortho=false, kwargs...)
247246

248247
fig, ax = _setup_scene(; ortho)
249248

250-
pts = GLMakie.Point3f0.(spin_vector_origins(sys, arrowlength)[:])
251-
vecs = GLMakie.Vec3f0.(sys.dipoles[:])
252-
GLMakie.arrows!(
249+
pts = Makie.Point3f0.(spin_vector_origins(sys, arrowlength)[:])
250+
vecs = Makie.Vec3f0.(sys.dipoles[:])
251+
Makie.arrows!(
253252
ax, pts, vecs;
254253
linecolor, arrowcolor, linewidth, arrowsize,
255254
lengthscale=arrowlength, kwargs...
@@ -268,7 +267,7 @@ Produce an animation of constant-energy Landau-Lifshitz dynamics of the given `s
268267
- `Δt::Float64`: The integration timestep size.
269268
- `nframes::Int`: The number of frames to produce in the animation.
270269
271-
Other keyword arguments are passed to `GLMakie.arrows`.
270+
Other keyword arguments are passed to `Makie.arrows`.
272271
"""
273272
function anim_integration(
274273
sys::System, fname, steps_per_frame, Δt, nframes;
@@ -277,9 +276,9 @@ function anim_integration(
277276
)
278277
fig, ax = _setup_scene()
279278

280-
pts = GLMakie.Point3f0.(spin_vector_origins(sys, arrowlength)[:])
281-
vecs = GLMakie.Observable(GLMakie.Vec3f0.(view(sys.dipoles,:)))
282-
GLMakie.arrows!(
279+
pts = Makie.Point3f0.(spin_vector_origins(sys, arrowlength)[:])
280+
vecs = Makie.Observable(Makie.Vec3f0.(view(sys.dipoles,:)))
281+
Makie.arrows!(
283282
ax, pts, vecs;
284283
linecolor=linecolor, arrowcolor=arrowcolor, linewidth=linewidth, arrowsize=arrowsize,
285284
lengthscale=arrowlength, kwargs...
@@ -289,11 +288,11 @@ function anim_integration(
289288
framerate = 30
290289
integrator = ImplicitMidpoint(Δt)
291290

292-
GLMakie.record(fig, fname, 1:nframes; framerate=framerate) do frame
291+
Makie.record(fig, fname, 1:nframes; framerate=framerate) do frame
293292
for _ in 1:steps_per_frame
294293
step!(sys, integrator)
295294
end
296-
vecs[] = GLMakie.Vec3f0.(sys.dipoles[:])
295+
vecs[] = Makie.Vec3f0.(sys.dipoles[:])
297296
end
298297
end
299298

@@ -310,9 +309,9 @@ function live_integration(
310309
)
311310
fig, ax = _setup_scene()
312311

313-
pts = GLMakie.Point3f0.(spin_vector_origins(sys, arrowlength)[:])
314-
vecs = GLMakie.Observable(GLMakie.Vec3f0.(view(sys.dipoles,:)))
315-
GLMakie.arrows!(
312+
pts = Makie.Point3f0.(spin_vector_origins(sys, arrowlength)[:])
313+
vecs = Makie.Observable(Makie.Vec3f0.(view(sys.dipoles,:)))
314+
Makie.arrows!(
316315
ax, pts, vecs;
317316
linecolor=linecolor, arrowcolor=arrowcolor, linewidth=linewidth, arrowsize=arrowsize,
318317
lengthscale=arrowlength, kwargs...
@@ -325,7 +324,7 @@ function live_integration(
325324
for step in 1:steps_per_frame
326325
step!(sys, integrator)
327326
end
328-
vecs[] = GLMakie.Vec3f0.(sys.dipoles[:])
327+
vecs[] = Makie.Vec3f0.(sys.dipoles[:])
329328
sleep(1/framerate)
330329
end
331330
end
@@ -342,10 +341,10 @@ function live_langevin_integration(
342341
arrowlength=0.2, λ=0.1, framerate=30, kwargs...
343342
)
344343
fig, ax = _setup_scene(; show_axis=false)
345-
pts = GLMakie.Point3f0.(spin_vector_origins(sys, arrowlength)[:])
346-
vecs = GLMakie.Observable(GLMakie.Vec3f0.(view(sys.dipoles,:)))
344+
pts = Makie.Point3f0.(spin_vector_origins(sys, arrowlength)[:])
345+
vecs = Makie.Observable(Makie.Vec3f0.(view(sys.dipoles,:)))
347346

348-
GLMakie.arrows!(
347+
Makie.arrows!(
349348
ax, pts, vecs;
350349
linecolor=linecolor, arrowcolor=arrowcolor, linewidth=linewidth, arrowsize=arrowsize,
351350
lengthscale=arrowlength, kwargs...
@@ -358,7 +357,7 @@ function live_langevin_integration(
358357
for _ in 1:steps_per_frame
359358
step!(sys, integrator)
360359
end
361-
vecs[] = GLMakie.Vec3f0.(sys.dipoles[:])
360+
vecs[] = Makie.Vec3f0.(sys.dipoles[:])
362361
sleep(1/framerate)
363362
end
364363
end
@@ -381,23 +380,23 @@ function plot_3d_structure_factor(sfactor::Array{Float64, 5}, iz)
381380
ky = 1:sampy*Ly
382381
ω = 1:T
383382

384-
lsgrid = GLMakie.labelslidergrid!(
383+
lsgrid = Makie.labelslidergrid!(
385384
fig,
386385
["kx", "ky", "ω"],
387386
[1:sampx*Lx, 1:sampy*Ly, 1:T]
388387
)
389388
fig[2, 1] = lsgrid.layout
390-
volslices = GLMakie.volumeslices!(ax, kx, ky, ω, sfactor)
389+
volslices = Makie.volumeslices!(ax, kx, ky, ω, sfactor)
391390

392391
# See: http://makie.juliaplots.org/stable/plotting_functions/volumeslices.html
393392
sl_yz, sl_xz, sl_xy = lsgrid.sliders
394-
GLMakie.on(sl_yz.value) do v; volslices[:update_yz][](v) end
395-
GLMakie.on(sl_xz.value) do v; volslices[:update_xz][](v) end
396-
GLMakie.on(sl_xy.value) do v; volslices[:update_xy][](v) end
393+
Makie.on(sl_yz.value) do v; volslices[:update_yz][](v) end
394+
Makie.on(sl_xz.value) do v; volslices[:update_xz][](v) end
395+
Makie.on(sl_xy.value) do v; volslices[:update_xy][](v) end
397396

398-
GLMakie.set_close_to!(sl_yz, .5Lx)
399-
GLMakie.set_close_to!(sl_xz, .5Ly)
400-
GLMakie.set_close_to!(sl_xy, .5T)
397+
Makie.set_close_to!(sl_yz, .5Lx)
398+
Makie.set_close_to!(sl_xz, .5Ly)
399+
Makie.set_close_to!(sl_xy, .5T)
401400

402401
fig
403402
end

src/Sunny.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ include("MonteCarlo/WangLandau.jl")
110110
include("MonteCarlo/ParallelWangLandau.jl")
111111
export propose_uniform, propose_flip, propose_delta, @mix_proposals, LocalSampler
112112

113-
# GLMakie is an optional dependency
113+
# Makie (e.g., WGLMakie or GLMakie) is an optional dependency
114114
function __init__()
115-
@require GLMakie="e9467ef8-e4e7-5192-8a1a-b1aee30e663a" begin
115+
@require Makie="ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" begin
116116
include("Plotting.jl")
117117
export plot_spins
118118
# plot_lattice, plot_bonds, plot_all_bonds, anim_integration, live_integration, live_langevin_integration

0 commit comments

Comments
 (0)