From b81b17a9f0d3a3dc3ff4688e5f05b9856bf676eb Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Tue, 6 Jun 2017 12:27:04 +0200 Subject: [PATCH] enable precompilation and use requires for Juno (#10) --- REQUIRE | 1 - src/PGFPlotsX.jl | 10 ++++------ src/axiselements.jl | 6 +++--- src/tikzdocument.jl | 18 ++++++++++-------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/REQUIRE b/REQUIRE index 59a4bd29..e5ee1a03 100644 --- a/REQUIRE +++ b/REQUIRE @@ -2,5 +2,4 @@ julia 0.6.0-pre MacroTools DataStructures Requires -Juno Crayons diff --git a/src/PGFPlotsX.jl b/src/PGFPlotsX.jl index 0e7a37bc..08f75976 100644 --- a/src/PGFPlotsX.jl +++ b/src/PGFPlotsX.jl @@ -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") @@ -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 diff --git a/src/axiselements.jl b/src/axiselements.jl index 4218acdb..85978f5b 100644 --- a/src/axiselements.jl +++ b/src/axiselements.jl @@ -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) @@ -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) diff --git a/src/tikzdocument.jl b/src/tikzdocument.jl index dd44d014..9599d396 100644 --- a/src/tikzdocument.jl +++ b/src/tikzdocument.jl @@ -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),