Implement non-uniform polar heatmaps with the GR backend

This commit is contained in:
Felix Hagemann 2021-02-13 17:56:03 +01:00
parent d196952571
commit 9b174084f7

View File

@ -1578,10 +1578,8 @@ function gr_add_series(sp, series)
GR.gr3.clear() GR.gr3.clear()
dmin, dmax = GR.gr3.volume(y.v, 0) dmin, dmax = GR.gr3.volume(y.v, 0)
elseif st === :heatmap elseif st === :heatmap
if !ispolar(series)
# `z` is already transposed, so we need to reverse before passing its size. # `z` is already transposed, so we need to reverse before passing its size.
x, y = heatmap_edges(x, xscale, y, yscale, reverse(size(z))) x, y = heatmap_edges(x, xscale, y, yscale, reverse(size(z)))
end
gr_draw_heatmap(series, x, y, z, clims) gr_draw_heatmap(series, x, y, z, clims)
elseif st === :image elseif st === :image
gr_draw_image(series, x, y, z, clims) gr_draw_image(series, x, y, z, clims)
@ -1751,10 +1749,9 @@ end
function gr_draw_heatmap(series, x, y, z, clims) function gr_draw_heatmap(series, x, y, z, clims)
fillgrad = _as_gradient(series[:fillcolor]) fillgrad = _as_gradient(series[:fillcolor])
if !ispolar(series)
GR.setspace(clims..., 0, 90) GR.setspace(clims..., 0, 90)
w, h = length(x) - 1, length(y) - 1 w, h = length(x) - 1, length(y) - 1
if is_uniformly_spaced(x) && is_uniformly_spaced(y) if !ispolar(series) && is_uniformly_spaced(x) && is_uniformly_spaced(y)
# For uniformly spaced data use GR.drawimage, which can be # For uniformly spaced data use GR.drawimage, which can be
# much faster than GR.nonuniformcellarray, especially for # much faster than GR.nonuniformcellarray, especially for
# pdf output, and also supports alpha values. # pdf output, and also supports alpha values.
@ -1769,24 +1766,16 @@ function gr_draw_heatmap(series, x, y, z, clims)
end end
z_normalized = get_z_normalized.(z, clims...) z_normalized = get_z_normalized.(z, clims...)
rgba = Int32[round(Int32, 1000 + _i * 255) for _i in z_normalized] rgba = Int32[round(Int32, 1000 + _i * 255) for _i in z_normalized]
if !ispolar(series)
GR.nonuniformcellarray(x, y, w, h, rgba) GR.nonuniformcellarray(x, y, w, h, rgba)
end
else else
phimin, phimax = 0.0, 360.0 # nonuniform polar array is not yet supported in GR.jl if y[1] < 0
nx, ny = length(series[:x]), length(series[:y]) @warn "'y[1] < 0' (rmin) is not yet supported."
end
xmin, xmax, ymin, ymax = gr_xy_axislims(series[:subplot]) xmin, xmax, ymin, ymax = gr_xy_axislims(series[:subplot])
GR.setwindow(-ymax, ymax, -ymax, ymax) GR.setwindow(-ymax, ymax, -ymax, ymax)
if ymin > 0 GR.nonuniformpolarcellarray(rad2deg.(x), y, w, h, rgba)
@warn "'ymin[1] > 0' (rmin) is not yet supported."
end end
if series[:y][end] != ny
@warn "Right now only the maximum value of y (r) is taken into account."
end
z_normalized = get_z_normalized.(z, clims...)
rgba = Int32[round(Int32, 1000 + _i * 255) for _i in z_normalized]
GR.polarcellarray(0, 0, phimin, phimax, 0, ymax, nx, ny, rgba)
# Right now only the maximum value of y (r) is taken into account.
# This is certainly not perfect but nonuniform polar array is not yet supported in GR.jl
end end
end end