Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gr: improve PNG output (resolution) #1318

Merged
merged 1 commit into from
Dec 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gr: improve PNG output (resolution)
  • Loading branch information
jheinen committed Dec 17, 2017
commit 5be95be9aeffbe413cf7beb635dd69be25a76a0d
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