pull/172/head
Matti Pastell 2019-02-08 16:03:23 +02:00
commit f1a85d3726
4 changed files with 36 additions and 54 deletions

View File

@ -6,6 +6,7 @@ using Requires
function __init__()
@require Plots="91a5bcdd-55d7-5caf-9e0b-520d859cae80" Base.include(Main, "plots.jl")
@require Gadfly="c91e804a-d5a3-530f-b6f0-dfbca275c004" Base.include(Main, "gadfly.jl")
end
"""

View File

@ -1,46 +1,49 @@
module GadflyPlots
import Gadfly
import Weave
try
import Cairo
catch
@warn("Cairo.jl is required to be installed to generate raster images")
end
Gadfly.set_default_plot_format(:svg)
function Base.display(report::Report, m::MIME"image/png", p::Gadfly.Plot)
function Base.display(report::Weave.Report, m::MIME"image/png", p::Gadfly.Plot)
display(report, MIME("image/svg+xml"), p)
end
#Gadfly doesn't call the default display methods, this catches
#all Gadfly plots
function Base.display(report::Report, m::MIME"image/svg+xml", p::Gadfly.Plot)
function Base.display(report::Weave.Report, m::MIME"image/svg+xml", p::Gadfly.Plot)
chunk = report.cur_chunk
full_name, rel_name = get_figname(report, chunk)
docformat = formats[report.formatdict[:doctype]]
push!(report.figures, rel_name)
report.fignum += 1
w = chunk.options[:fig_width]Gadfly.inch
h = chunk.options[:fig_height]Gadfly.inch
format = chunk.options[:fig_ext]
dpi = chunk.options[:dpi]
#This is probably not the correct way to handle different formats, but it works.
if format == ".png"
try
Gadfly.draw(Gadfly.PNG(full_name, w, h, dpi=dpi), p)
catch
Gadfly.draw(Gadfly.PNG(full_name, w, h), p) #Compose < 0.3.1, Gadfly < 0.3.1
end
full_name, rel_name = Weave.get_figname(report, chunk, ext = format)
push!(report.figures, rel_name)
report.fignum += 1
if format == ".svg"
Gadfly.draw(Gadfly.SVG(full_name, w, h), p)
elseif format == ".js.svg"
Gadfly.draw(Gadfly.SVGJS(full_name, w, h), p)
elseif format == ".png"
Gadfly.draw(Gadfly.PNG(full_name, w, h, dpi=dpi), p)
elseif format == ".pdf"
Gadfly.draw(Gadfly.PDF(full_name, w, h), p)
elseif format == ".ps"
Gadfly.draw(Gadfly.PS(full_name, w, h), p)
elseif format == ".svg"
Gadfly.draw(Gadfly.SVG(full_name, w, h), p)
elseif format == ".js.svg"
Gadfly.draw(Gadfly.SVGJS(full_name, w, h), p)
elseif format == ".tex"
Gadfly.draw(Gadfly.PGF(full_name, w, h, true ), p)
else
@warn("Can't save figure. Unsupported format")
@warn("Can't save figure. Unsupported format, $format")
end
end
end

View File

@ -1,30 +1,12 @@
# Gadfly
```{julia;term=true;fig_width=5}
```{julia;fig_ext=".svg";dpi=300}
using Gadfly
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
y = 20
plot(x=x, y = cos(x), Geom.line)
```
```julia
x = linspace(0, 200)
println(x)
```
~~~{julia;term=true;fig_width=5}
using Gadfly
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
y = 20
plot(x=x, y = cos(x), Geom.line)
~~~
~~~julia
x = linspace(0, 200)
println(x)
~~~
x = collect(range(0, stop=2π, length=200))
plot(
layer(x=x, y = sin.(x), Geom.line),
layer(x=x, y = cos.(x), Geom.line, Theme(default_color=colorant"red")),
Guide.manual_color_key("Legend", ["sin", "cos"], ["deepskyblue", "red"])
)
```

View File

@ -39,16 +39,12 @@ using Test
include("plotsjl_test.jl")
end
#@testset "Caching" begin
# @info("Test: Caching")
# include("cache_test.jl")
#end
@testset "Gadfly" begin
@info("Test: Weaving with Gadfly.jl")
include("cache_test.jl")
end
end
#@info("Test: Chunk options with Gadfly")
#include("chunk_opts_gadfly.jl")
#@info("Test: Weaving with Plots.jl")
#include("plotsjl_test.jl")
#include("publish_test.jl")