Skip to content

Commit

Permalink
Merge pull request #56 from pablosanjose/vegalite
Browse files Browse the repository at this point in the history
Initial VegaLite support
  • Loading branch information
pablosanjose authored May 7, 2020
2 parents d75d9bd + d41009b commit 2f09597
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Quantica.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module Quantica
using Requires

function __init__()
@require Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" include("plot.jl")
@require Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" include("plot_makie.jl")
@require VegaLite = "112f6efa-9a02-5b7d-90c0-432ed331239a" include("plot_vegalite.jl")
end

using StaticArrays, NearestNeighbors, SparseArrays, LinearAlgebra, OffsetArrays,
Expand Down
File renamed without changes.
49 changes: 49 additions & 0 deletions src/plot_vegalite.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using .VegaLite

"""
vlplot(b::Bandstructure{1}; size = 640, points = false, labels = ("φ/2π", "ε"), scaling = (1/2π, 1))
Plots the 1D bandstructure `b` using VegaLite.
# Options:
- `size`: the `(width, height)` of the plot (or `width == height` if a single number)
- `points`: whether to plot a point at each sampled energy/momentum
- `labels`: labels for the x and y axes
- `scaling`: `(scalex, scaley)` scalings for the x (Bloch phase) and y (energy) variables
"""
function VegaLite.vlplot(b::Bandstructure; size = 640, points = false, labels = ("φ/2π", "ε"), scaling = (1/2π, 1))
sizex, sizey = make_it_two(size)
labelx, labely = labels
scalingx, scalingy = make_it_two(scaling)
table = bandtable(b, (scalingx, scalingy))
p = table |> @vlplot(
mark = {
:line,
point = points
},
selection = {
grid = {type = :interval, bind = :scales}
},
width = sizex,
height = sizey,
x = {
:phi,
title = labelx
},
y = {
:energy,
title = labely
},
color = "band:n"
)
end

make_it_two(x::Number) = (x, x)
make_it_two(x::Tuple{Number,Number}) = x

function bandtable(b::Bandstructure{1}, (scalingx, scalingy) = (1, 1))
ks = vertices(b.kmesh)
table = [(phi = v[1] * scalingx, energy = v[2] * scalingy, band = i)
for (i, bnd) in enumerate(bands(b)) for v in vertices(bnd)]
return table
end

0 comments on commit 2f09597

Please sign in to comment.