From 00fd916595a0e31a2717a6f12e57f8d151f1ec6a Mon Sep 17 00:00:00 2001 From: Lukas Hauertmann Date: Mon, 4 Nov 2019 21:30:11 +0100 Subject: [PATCH] Remove code duplication Use the function `heatmap_edges` again --- src/backends/gr.jl | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index ef05550b..6fa33080 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -921,7 +921,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) for ax in (sp[:xaxis], sp[:yaxis]) v = series[ax[:letter]] end - fx, fy = scalefunc(sp[:xaxis][:scale]), scalefunc(sp[:yaxis][:scale]) nx, ny = length(series[:x]), length(series[:y]) z = series[:z] use_midpoints = size(z) == (ny, nx) @@ -931,15 +930,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) Must be either `size(z) == (length(y), length(x))` (x & y define midpoints) or `size(z) == (length(y)+1, length(x)+1))` (x & y define edges).""") end - x, y = if use_midpoints - x_diff, y_diff = diff(series[:x]) ./ 2, diff(series[:y]) ./ 2 - x = [ series[:x][1] - x_diff[1], (series[:x][1:end-1] .+ x_diff)..., series[:x][end] + x_diff[end] ] - y = [ series[:y][1] - y_diff[1], (series[:y][1:end-1] .+ y_diff)..., series[:y][end] + y_diff[end] ] - x, y - else - series[:x], series[:y] - end - x, y = map(fx, series[:x]), map(fy, series[:y]) + x, y = heatmap_edges(series[:x], sp[:xaxis][:scale]; isedges = use_edges), + heatmap_edges(series[:y], sp[:yaxis][:scale]; isedges = use_edges) xy_lims = x[1], x[end], y[1], y[end] expand_extrema!(sp[:xaxis], x) expand_extrema!(sp[:yaxis], y) @@ -1335,14 +1327,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) use_midpoints = length(z) == ny * nx if !ispolar(sp) GR.setspace(zmin, zmax, 0, 90) - x, y = if use_midpoints - x_diff, y_diff = diff(series[:x]) ./ 2, diff(series[:y]) ./ 2 - x = [ series[:x][1] - x_diff[1], (series[:x][1:end-1] .+ x_diff)..., series[:x][end] + x_diff[end] ] - y = [ series[:y][1] - y_diff[1], (series[:y][1:end-1] .+ y_diff)..., series[:y][end] + y_diff[end] ] - x, y - else - series[:x], series[:y] - end + x, y = heatmap_edges(series[:x], sp[:xaxis][:scale]; isedges = !use_midpoints), + heatmap_edges(series[:y], sp[:yaxis][:scale]; isedges = !use_midpoints) w, h = length(x) - 1, length(y) - 1 z_normalized = map(x -> GR.jlgr.normalize_color(x, zmin, zmax), z) colors = Int32[round(Int32, 1000 + _i * 255) for _i in z_normalized]