make GR use hascolorbar

This commit is contained in:
Daniel Schwabeneder 2017-09-09 10:05:58 +02:00
parent da5a538f89
commit 7dfa1ec984
2 changed files with 29 additions and 23 deletions

View File

@ -341,7 +341,7 @@ function gr_draw_markers(series::Series, x, y, clims)
mz = normalize_zvals(series[:marker_z], clims)
GR.setfillintstyle(GR.INTSTYLE_SOLID)
gr_draw_markers(series, x, y, series[:markersize], mz)
if mz != nothing
if hascolorbar(series[:subplot])
GR.setscale(0)
gr_colorbar(series[:subplot], clims)
end
@ -447,15 +447,12 @@ end
# add the colorbar
function gr_colorbar(sp::Subplot)
if sp[:colorbar] != :none
gr_set_viewport_cmap(sp)
GR.colorbar()
gr_set_viewport_plotarea()
end
end
function gr_colorbar(sp::Subplot, clims)
if sp[:colorbar] != :none
xmin, xmax = gr_xy_axislims(sp)[1:2]
gr_set_viewport_cmap(sp)
l = zeros(Int32, 1, 256)
@ -466,7 +463,6 @@ function gr_colorbar(sp::Subplot, clims)
GR.axes(0, ztick, xmax, clims[1], 0, 1, 0.005)
gr_set_viewport_plotarea()
end
end
gr_view_xcenter() = 0.5 * (viewport_plotarea[1] + viewport_plotarea[2])
gr_view_ycenter() = 0.5 * (viewport_plotarea[3] + viewport_plotarea[4])
@ -677,14 +673,11 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
# reduced from before... set some flags based on the series in this subplot
# TODO: can these be generic flags?
outside_ticks = false
cmap = false
cmap = hascolorbar(sp)
draw_axes = sp[:framestyle] != :none
# axes_2d = true
for series in series_list(sp)
st = series[:seriestype]
if st in (:contour, :surface, :heatmap) || series[:marker_z] != nothing
cmap = true
end
if st == :pie
draw_axes = false
end
@ -698,7 +691,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
end
end
if cmap && sp[:colorbar] != :none
if cmap
# note: add extra midpadding on the right for the colorbar
viewport_plotarea[2] -= 0.1
end
@ -983,7 +976,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
end
# create the colorbar of contour levels
if sp[:colorbar] != :none
if cmap
gr_set_viewport_cmap(sp)
l = round.(Int32, 1000 + (h - ignorenan_minimum(h)) / (ignorenan_maximum(h) - ignorenan_minimum(h)) * 255)
GR.setwindow(xmin, xmax, zmin, zmax)

View File

@ -561,6 +561,19 @@ end
_update_clims(zmin, zmax, emin, emax) = min(zmin, emin), max(zmax, emax)
function hascolorbar(sp::Subplot)
cbar = sp[:colorbar]
hascbar = false
if cbar != :none
for series in series_list(sp)
if series[:seriestype] in (:heatmap, :contour, :surface) || series[:marker_z] != nothing || series[:line_z] != nothing
hascbar = true
end
end
end
hascbar
end
# ---------------------------------------------------------------
makekw(; kw...) = KW(kw)