Skip to content

Commit

Permalink
enable precompilation and use requires for Juno (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC authored Jun 6, 2017
1 parent 8d80856 commit b81b17a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
1 change: 0 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ julia 0.6.0-pre
MacroTools
DataStructures
Requires
Juno
Crayons
10 changes: 4 additions & 6 deletions src/PGFPlotsX.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
__precompile__()

module PGFPlotsX

import MacroTools: prewalk, @capture

using DataStructures
using Requires
import Juno: Juno, @render, media, Media, Hiccup

const DEBUG = haskey(ENV, "PGFPLOTSX_DEBUG")
const CUSTOM_PREAMBLE_PATH = joinpath(@__DIR__, "..", "deps", "custom_preamble.tex")
Expand Down Expand Up @@ -69,16 +70,13 @@ A `TikzElement` is a component of a `TikzPicture`. It can be a node or an `Axis`
abstract type TikzElement <: OptionType end

include("axislike.jl")

include("tikzpicture.jl")
include("tikzdocument.jl")
include("requires.jl")
include("build.jl")

function __init__()
if DEFAULT_ENGINE == "pdflatex"
latexengine!(PDFLATEX)
end
if DEFAULT_ENGINE == "PDFLATEX"
latexengine!(PDFLATEX)
end

end # module
6 changes: 3 additions & 3 deletions src/axiselements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ end



Coordinates(x::AbstractVector, y::AbstractVector; kwargs...) = Coordinates(transpose(hcat(x, y)); kwargs...)
Coordinates(x::AbstractVector, y::AbstractVector; kwargs...) = Coordinates(permutedims(hcat(x, y), (2,1)); kwargs...)

Coordinates(x::AbstractVector, y::AbstractVector, z::AbstractVector; metadata = nothing) = Coordinates(transpose(hcat(x, y, z)); metadata = metadata)
Coordinates(x::AbstractVector, y::AbstractVector, z::AbstractVector; metadata = nothing) = Coordinates(permutedims(hcat(x, y, z), (2,1)); metadata = metadata)

Coordinates(x::AbstractVector, f::Function; metadata = nothing) = Coordinates(x, f.(x); metadata = metadata)

Expand Down Expand Up @@ -265,7 +265,7 @@ function print_tex(io::IO, v::AbstractVector, ::Table)

println(io)

v_mat = hcat(vs...)'
v_mat = permutedims(hcat(vs...), (2,1))

for j in 1:size(v_mat, 2)
for i in 1:size(v_mat, 1)
Expand Down
18 changes: 10 additions & 8 deletions src/tikzdocument.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,23 @@ if HAVE_PDFTOSVG
end
end

media(_SHOWABLE, Media.Plot)

_JUNO_PNG = false
_JUNO_DPI = 150
show_juno_png(v::Bool) = global _JUNO_PNG = v
dpi_juno_png(dpi::Int) = global _JUNO_DPI = dpi

function Media.render(pane::Juno.PlotPane, p::_SHOWABLE)
f = tempname() * (_JUNO_PNG ? ".png" : ".svg")
save(f, p; dpi = _JUNO_DPI)
Media.render(pane, Hiccup.div(style="background-color:#ffffff",
Hiccup.img(src = f)))
@require Juno begin
import Media
import Hiccup
Media.media(_SHOWABLE, Media.Plot)
function Media.render(pane::Juno.PlotPane, p::_SHOWABLE)
f = tempname() * (_JUNO_PNG ? ".png" : ".svg")
save(f, p; dpi = _JUNO_DPI)
Media.render(pane, Hiccup.div(style="background-color:#ffffff",
Hiccup.img(src = f)))
end
end


if HAVE_PDFTOPPM
function savepng(filename::String, td::TikzDocument; latex_engine = latexengine(),
buildflags = vcat(DEFAULT_FLAGS, CUSTOM_FLAGS),
Expand Down

0 comments on commit b81b17a

Please sign in to comment.