Skip to content

Commit

Permalink
gr: improve PNG output (resolution)
Browse files Browse the repository at this point in the history
  • Loading branch information
jheinen committed Dec 17, 2017
1 parent 61be113 commit 5be95be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/backends/gr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ function gr_set_gradient(c)
end

# this is our new display func... set up the viewport_canvas, compute bounding boxes, and display each subplot
function gr_display(plt::Plot)
function gr_display(plt::Plot, fmt="")
GR.clearws()

# collect some monitor/display sizes in meters and pixels
Expand All @@ -554,17 +554,25 @@ function gr_display(plt::Plot)
# compute the viewport_canvas, normalized to the larger dimension
viewport_canvas = Float64[0,1,0,1]
w, h = plt[:size]
if !haskey(ENV, "PLOTS_TEST")
dpi_factor = plt[:dpi] / DPI
if fmt == "png"
dpi_factor *= 6
end
else
dpi_factor = 1
end
gr_plot_size[:] = [w, h]
if w > h
ratio = float(h) / w
msize = display_width_ratio * w
msize = display_width_ratio * w * dpi_factor
GR.setwsviewport(0, msize, 0, msize * ratio)
GR.setwswindow(0, 1, 0, ratio)
viewport_canvas[3] *= ratio
viewport_canvas[4] *= ratio
else
ratio = float(w) / h
msize = display_height_ratio * h
msize = display_height_ratio * h * dpi_factor
GR.setwsviewport(0, msize * ratio, 0, msize)
GR.setwswindow(0, ratio, 0, 1)
viewport_canvas[1] *= ratio
Expand Down Expand Up @@ -1335,7 +1343,7 @@ for (mime, fmt) in _gr_mimeformats
env = get(ENV, "GKSwstype", "0")
ENV["GKSwstype"] = $fmt
ENV["GKS_FILEPATH"] = filepath
gr_display(plt)
gr_display(plt, $fmt)
GR.emergencyclosegks()
write(io, readstring(filepath))
rm(filepath)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ default(show=false, reuse=true)
img_eps = isinteractive() ? 1e-2 : 10e-2

@testset "GR" begin
ENV["PLOTS_TEST"] = "true"
ENV["GKSwstype"] = "100"
@test gr() == Plots.GRBackend()
@test backend() == Plots.GRBackend()
Expand Down

0 comments on commit 5be95be

Please sign in to comment.