Improved GR output

- slightly reduced the nominal marker size
- use character height as line spacing criterion when plotting legends
- use GR surface function for filled contours
- avoid calling GR setwindow/adjust* functions with Inf arguments
- corrected bounding box for legend
This commit is contained in:
Josef Heinen 2016-06-10 12:05:58 +02:00
parent cf4d78c87c
commit df33ed40d6

View File

@ -43,7 +43,7 @@ supportedTypes(::GRBackend) = [
:scatter, :scatter,
#:histogram2d, :hexbin, #:histogram2d, :hexbin,
# :sticks, # :sticks,
# :hline, :vline, # :hline, :vline,
:heatmap, :pie, :image, :heatmap, :pie, :image,
:contour, :path3d, :scatter3d, :surface, :wireframe, :contour, :path3d, :scatter3d, :surface, :wireframe,
:shape :shape
@ -324,7 +324,7 @@ end
function gr_draw_markers(series::Series, x = series.d[:x], y = series.d[:y]) function gr_draw_markers(series::Series, x = series.d[:x], y = series.d[:y])
d = series.d d = series.d
msize = 0.5 * d[:markersize] msize = 0.4 * d[:markersize]
mz = normalize_zvals(d[:marker_z]) mz = normalize_zvals(d[:marker_z])
GR.setmarkercolorind(gr_getcolorind(d[:markercolor])) GR.setmarkercolorind(gr_getcolorind(d[:markercolor]))
gr_setmarkershape(d) gr_setmarkershape(d)
@ -493,7 +493,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
# winheight_px = sp.plt[:size][2] # winheight_px = sp.plt[:size][2]
# px_per_pt = px / pt # px_per_pt = px / pt
# pointsize_mult = px_per_pt / winheight_px # pointsize_mult = px_per_pt / winheight_px
# @show winheight_px px_per_pt pointsize_mult # @show winheight_px px_per_pt pointsize_mult
# end # end
# #
@ -696,44 +696,46 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
for axis_idx = 1:num_axes for axis_idx = 1:num_axes
xmin, xmax, ymin, ymax = extrema[axis_idx,:] xmin, xmax, ymin, ymax = extrema[axis_idx,:]
# NOTE: for log axes, the major_x and major_y - if non-zero (omit labels) - control the minor grid lines (1 = draw 9 minor grid lines, 2 = no minor grid lines) if xmax > xmin && ymax > ymin
# NOTE: for log axes, the x_tick and y_tick - if non-zero (omit axes) - only affect the output appearance (1 = nomal, 2 = scientiic notation) # NOTE: for log axes, the major_x and major_y - if non-zero (omit labels) - control the minor grid lines (1 = draw 9 minor grid lines, 2 = no minor grid lines)
if scale & GR.OPTION_X_LOG == 0 # NOTE: for log axes, the x_tick and y_tick - if non-zero (omit axes) - only affect the output appearance (1 = nomal, 2 = scientiic notation)
# xmin, xmax = GR.adjustlimits(xmin, xmax) if scale & GR.OPTION_X_LOG == 0
majorx = 1 #5 # xmin, xmax = GR.adjustlimits(xmin, xmax)
xtick = GR.tick(xmin, xmax) / majorx majorx = 1 #5
else xtick = GR.tick(xmin, xmax) / majorx
# log axis else
# xtick = majorx = 1 # log axis
xtick = 2 # scientific notation # xtick = majorx = 1
majorx = 2 # no minor grid lines xtick = 2 # scientific notation
end majorx = 2 # no minor grid lines
if scale & GR.OPTION_Y_LOG == 0 end
# ymin, ymax = GR.adjustlimits(ymin, ymax) if scale & GR.OPTION_Y_LOG == 0
majory = 1 #5 # ymin, ymax = GR.adjustlimits(ymin, ymax)
ytick = GR.tick(ymin, ymax) / majory majory = 1 #5
else ytick = GR.tick(ymin, ymax) / majory
# log axis else
# ytick = majory = 1 # log axis
ytick = 2 # scientific notation # ytick = majory = 1
majory = 2 # no minor grid lines ytick = 2 # scientific notation
end majory = 2 # no minor grid lines
xorg = (scale & GR.OPTION_FLIP_X == 0) ? (xmin,xmax) : (xmax,xmin) end
yorg = (scale & GR.OPTION_FLIP_Y == 0) ? (ymin,ymax) : (ymax,ymin) xorg = (scale & GR.OPTION_FLIP_X == 0) ? (xmin,xmax) : (xmax,xmin)
# if scale & GR.OPTION_FLIP_X == 0 yorg = (scale & GR.OPTION_FLIP_Y == 0) ? (ymin,ymax) : (ymax,ymin)
# xorg = (xmin, xmax) # if scale & GR.OPTION_FLIP_X == 0
# else # xorg = (xmin, xmax)
# xorg = (xmax, xmin) # else
# end # xorg = (xmax, xmin)
# if scale & GR.OPTION_FLIP_Y == 0 # end
# yorg = (ymin, ymax) # if scale & GR.OPTION_FLIP_Y == 0
# else # yorg = (ymin, ymax)
# yorg = (ymax, ymin) # else
# end # yorg = (ymax, ymin)
# end
extrema[axis_idx,:] = [xmin, xmax, ymin, ymax] extrema[axis_idx,:] = [xmin, xmax, ymin, ymax]
GR.setwindow(xmin, xmax, ymin, ymax) GR.setwindow(xmin, xmax, ymin, ymax)
GR.setscale(scale) GR.setscale(scale)
end
# window_diag = sqrt((viewport_plotarea[2] - viewport_plotarea[1])^2 + (viewport_plotarea[4] - viewport_plotarea[3])^2) # window_diag = sqrt((viewport_plotarea[2] - viewport_plotarea[1])^2 + (viewport_plotarea[4] - viewport_plotarea[3])^2)
# charheight = max(0.018 * window_diag, 0.01) # charheight = max(0.018 * window_diag, 0.01)
@ -836,7 +838,9 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
# end # end
GR.savestate() GR.savestate()
xmin, xmax, ymin, ymax = extrema[gr_getaxisind(d),:] xmin, xmax, ymin, ymax = extrema[gr_getaxisind(d),:]
GR.setwindow(xmin, xmax, ymin, ymax) if xmax > xmin && ymax > ymin
GR.setwindow(xmin, xmax, ymin, ymax)
end
if st in [:path, :polar] if st in [:path, :polar]
GR.setlinetype(gr_linetype[d[:linestyle]]) GR.setlinetype(gr_linetype[d[:linestyle]])
GR.setlinewidth(d[:linewidth]) GR.setlinewidth(d[:linewidth])
@ -1029,13 +1033,17 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
x, y, z = d[:x], d[:y], transpose_z(d, d[:z].surf, false) x, y, z = d[:x], d[:y], transpose_z(d, d[:z].surf, false)
# zmin, zmax = gr_getzlims(d, minimum(z), maximum(z), false) # zmin, zmax = gr_getzlims(d, minimum(z), maximum(z), false)
zmin, zmax = gr_lims(zaxis, false) zmin, zmax = gr_lims(zaxis, false)
GR.setspace(zmin, zmax, 0, 90)
if typeof(d[:levels]) <: Array if typeof(d[:levels]) <: Array
h = d[:levels] h = d[:levels]
else else
h = linspace(zmin, zmax, d[:levels]) h = linspace(zmin, zmax, d[:levels])
end end
GR.contour(x, y, h, reshape(z, length(x) * length(y)), 1000) GR.setspace(zmin, zmax, 0, 90)
if d[:fillrange] != nothing
GR.surface(x, y, z, GR.OPTION_CELL_ARRAY)
else
GR.contour(x, y, h, reshape(z, length(x) * length(y)), 1000)
end
GR.setviewport(viewport_plotarea[2] + 0.02, viewport_plotarea[2] + 0.05, viewport_plotarea[3], viewport_plotarea[4]) GR.setviewport(viewport_plotarea[2] + 0.02, viewport_plotarea[2] + 0.05, viewport_plotarea[3], viewport_plotarea[4])
l = round(Int32, 1000 + (h - minimum(h)) / (maximum(h) - minimum(h)) * 255) l = round(Int32, 1000 + (h - minimum(h)) / (maximum(h) - minimum(h)) * 255)
GR.setwindow(xmin, xmax, zmin, zmax) GR.setwindow(xmin, xmax, zmin, zmax)
@ -1234,13 +1242,13 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
lab = series.d[:label] lab = series.d[:label]
end end
tbx, tby = GR.inqtext(0, 0, lab) tbx, tby = GR.inqtext(0, 0, lab)
w = max(w, tbx[3]) w = max(w, tbx[3] - tbx[1])
end end
if w > 0 if w > 0
xpos = viewport_plotarea[2] - 0.05 - w xpos = viewport_plotarea[2] - 0.05 - w
ypos = viewport_plotarea[4] - 0.06 ypos = viewport_plotarea[4] - 0.06
# dy = 0.03 * sqrt((viewport_plotarea[2] - viewport_plotarea[1])^2 + (viewport_plotarea[4] - viewport_plotarea[3])^2) # dy = 0.03 * sqrt((viewport_plotarea[2] - viewport_plotarea[1])^2 + (viewport_plotarea[4] - viewport_plotarea[3])^2)
dy = 0.03 * window_diag dy = _gr_point_mult[1] * sp[:legendfont].pointsize * 1.75
GR.setfillintstyle(GR.INTSTYLE_SOLID) GR.setfillintstyle(GR.INTSTYLE_SOLID)
GR.setfillcolorind(gr_getcolorind(sp[:background_color_legend])) GR.setfillcolorind(gr_getcolorind(sp[:background_color_legend]))
GR.fillrect(xpos - 0.08, xpos + w + 0.02, ypos + dy, ypos - dy * n) GR.fillrect(xpos - 0.08, xpos + w + 0.02, ypos + dy, ypos - dy * n)