gr: fix image and alpha; switch transpose_z to use permutedims

This commit is contained in:
Thomas Breloff 2016-08-11 16:20:43 -04:00
parent 56bd8006bc
commit f68f82e3f4
3 changed files with 16 additions and 15 deletions

View File

@ -199,14 +199,14 @@ function gr_polaraxes(rmin, rmax)
GR.drawarc(-r, r, -r, r, 0, 359) GR.drawarc(-r, r, -r, r, 0, 359)
end end
end end
for alpha in 0:45:315 for α in 0:45:315
a = alpha + 90 a = α + 90
sinf = sin(a * pi / 180) sinf = sin(a * pi / 180)
cosf = cos(a * pi / 180) cosf = cos(a * pi / 180)
GR.polyline([sinf, 0], [cosf, 0]) GR.polyline([sinf, 0], [cosf, 0])
GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_HALF) GR.settextalign(GR.TEXT_HALIGN_CENTER, GR.TEXT_VALIGN_HALF)
x, y = GR.wctondc(1.1 * sinf, 1.1 * cosf) x, y = GR.wctondc(1.1 * sinf, 1.1 * cosf)
GR.textext(x, y, string(alpha, "^o")) GR.textext(x, y, string(α, "^o"))
end end
GR.restorestate() GR.restorestate()
end end
@ -648,7 +648,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
# TODO: can we remove? # TODO: can we remove?
gr_set_font(xaxis[:tickfont]) gr_set_font(xaxis[:tickfont])
GR.setcolormap(1000 + GR.COLORMAP_COOLWARM) # GR.setcolormap(1000 + GR.COLORMAP_COOLWARM)
for (idx, series) in enumerate(series_list(sp)) for (idx, series) in enumerate(series_list(sp))
st = series[:seriestype] st = series[:seriestype]
@ -805,15 +805,15 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
a2 = round(Int, a1 + (slices[i] / total) * 360.0) a2 = round(Int, a1 + (slices[i] / total) * 360.0)
GR.setfillcolorind(980 + (i-1) % 20) GR.setfillcolorind(980 + (i-1) % 20)
GR.fillarc(xmin, xmax, ymin, ymax, a1, a2) GR.fillarc(xmin, xmax, ymin, ymax, a1, a2)
alpha = 0.5 * (a1 + a2) α = 0.5 * (a1 + a2)
cosf = r * cos(alpha * pi / 180) cosf = r * cos(α * pi / 180)
sinf = r * sin(alpha * pi / 180) sinf = r * sin(α * pi / 180)
x[1] = xcenter + cosf x[1] = xcenter + cosf
y[1] = ycenter + sinf y[1] = ycenter + sinf
x[2] = x[1] + 0.1 * cosf x[2] = x[1] + 0.1 * cosf
y[2] = y[1] + 0.1 * sinf y[2] = y[1] + 0.1 * sinf
y[3] = y[2] y[3] = y[2]
if 90 <= alpha < 270 if 90 <= α < 270
x[3] = x[2] - 0.05 x[3] = x[2] - 0.05
GR.settextalign(GR.TEXT_HALIGN_RIGHT, GR.TEXT_VALIGN_HALF) GR.settextalign(GR.TEXT_HALIGN_RIGHT, GR.TEXT_VALIGN_HALF)
gr_text(x[3] - 0.01, y[3], string(labels[i])) gr_text(x[3] - 0.01, y[3], string(labels[i]))
@ -849,15 +849,15 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
elseif st == :image elseif st == :image
img = series[:z].surf img = series[:z].surf
w, h = size(img) h, w = size(img)
if eltype(img) <: Colors.AbstractGray if eltype(z) <: Colors.AbstractGray
grey = round(UInt8, float(img) * 255) grey = round(UInt8, float(z) * 255)
rgba = map(c -> UInt32( 0xff000000 + Int(c)<<16 + Int(c)<<8 + Int(c) ), grey) rgba = map(c -> UInt32( 0xff000000 + Int(c)<<16 + Int(c)<<8 + Int(c) ), grey)
else else
rgba = map(c -> UInt32( round(Int, alpha(c) * 255) << 24 + rgba = map(c -> UInt32( round(Int, alpha(c) * 255) << 24 +
round(Int, blue(c) * 255) << 16 + round(Int, blue(c) * 255) << 16 +
round(Int, green(c) * 255) << 8 + round(Int, green(c) * 255) << 8 +
round(Int, red(c) * 255) ), img) round(Int, red(c) * 255) ), z)
end end
GR.drawimage(xmin, xmax, ymax, ymin, w, h, rgba) GR.drawimage(xmin, xmax, ymax, ymin, w, h, rgba)
end end

View File

@ -445,7 +445,8 @@ end
# for example: PyPlot sends rows to y, so transpose_on_match should be true # for example: PyPlot sends rows to y, so transpose_on_match should be true
function transpose_z(d, z, transpose_on_match::Bool = true) function transpose_z(d, z, transpose_on_match::Bool = true)
if d[:match_dimensions] == transpose_on_match if d[:match_dimensions] == transpose_on_match
z' # z'
permutedims(z, [2,1])
else else
z z
end end

View File

@ -30,7 +30,7 @@ facts("GR") do
@fact gr() --> Plots.GRBackend() @fact gr() --> Plots.GRBackend()
@fact backend() --> Plots.GRBackend() @fact backend() --> Plots.GRBackend()
# @linux_only image_comparison_facts(:gr, skip=[], eps=img_eps) # @static is_linux() && image_comparison_facts(:gr, skip=[], eps=img_eps)
end end
facts("Plotly") do facts("Plotly") do
@ -38,7 +38,7 @@ facts("Plotly") do
@fact backend() --> Plots.PlotlyBackend() @fact backend() --> Plots.PlotlyBackend()
# # until png generation is reliable on OSX, just test on linux # # until png generation is reliable on OSX, just test on linux
# @linux_only image_comparison_facts(:plotly, only=[1,3,4,7,8,9,10,11,12,14,15,20,22,23,27], eps=img_eps) # @static is_linux() && image_comparison_facts(:plotly, only=[1,3,4,7,8,9,10,11,12,14,15,20,22,23,27], eps=img_eps)
end end