From 8b4edae35858a12533332719ce568aab4693f7f9 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 24 Sep 2017 20:52:02 +0200 Subject: [PATCH 1/5] implement line_z for GR --- src/backends/gr.jl | 10 +++++++--- src/utils.jl | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index ebd35f20..a3d86d9c 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -22,7 +22,7 @@ const _gr_attr = merge_with_base_supported([ :tickfont, :guidefont, :legendfont, :grid, :gridalpha, :gridstyle, :gridlinewidth, :legend, :legendtitle, :colorbar, - :marker_z, :levels, + :line_z, :marker_z, :levels, :ribbon, :quiver, :orientation, :overwrite_figure, @@ -896,6 +896,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) gr_set_gradient(series[:fillcolor]) #, series[:fillalpha]) elseif series[:marker_z] != nothing series[:markercolor] = gr_set_gradient(series[:markercolor]) + elseif series[:line_z] != nothing + series[:linecolor] = gr_set_gradient(series[:linecolor]) end GR.savestate() @@ -947,9 +949,11 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # draw the line(s) if st == :path - gr_set_line(series[:linewidth], series[:linestyle], series[:linecolor]) #, series[:linealpha]) + gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series)) #, series[:linealpha]) arrowside = isa(series[:arrow], Arrow) ? series[:arrow].side : :none gr_polyline(x, y; arrowside = arrowside) + gr_set_line(1, :solid, yaxis[:foreground_color_axis]) + cmap && gr_colorbar(sp, clims) end end @@ -1169,7 +1173,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) for series in series_list(sp) should_add_to_legend(series) || continue st = series[:seriestype] - gr_set_line(series[:linewidth], series[:linestyle], series[:linecolor]) #, series[:linealpha]) + gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series)) #, series[:linealpha]) if (st == :shape || series[:fillrange] != nothing) && series[:ribbon] == nothing gr_set_fill(series[:fillcolor]) #, series[:fillalpha]) diff --git a/src/utils.jl b/src/utils.jl index bc13d191..38bb2b5a 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -587,6 +587,17 @@ function hascolorbar(sp::Subplot) hascbar end +function get_linecolor(sp::Subplot, series::Series) + lc = series[:linecolor] + if series[:line_z] == nothing + lc + else + cmin, cmax = get_clims(sp) + grad = isa(lc, ColorGradient) ? lc : cgrad() + grad[clamp((series[:line_z] - cmin) / (cmax -cmin), 0, 1)] + end +end + # --------------------------------------------------------------- makekw(; kw...) = KW(kw) From 337a107168b6739d3e4bd0c35d201f63f6346110 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 25 Sep 2017 17:22:13 +0200 Subject: [PATCH 2/5] different colors for different line segments in GR --- src/backends/gr.jl | 10 ++++++---- src/utils.jl | 9 +++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index a3d86d9c..60fdba5b 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -949,9 +949,11 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # draw the line(s) if st == :path - gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series)) #, series[:linealpha]) - arrowside = isa(series[:arrow], Arrow) ? series[:arrow].side : :none - gr_polyline(x, y; arrowside = arrowside) + for (i,rng) in enumerate(iter_segments(series[:x], series[:y])) + gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series, i)) #, series[:linealpha]) + arrowside = isa(series[:arrow], Arrow) ? series[:arrow].side : :none + gr_polyline(series[:x][rng], series[:y][rng]; arrowside = arrowside) + end gr_set_line(1, :solid, yaxis[:foreground_color_axis]) cmap && gr_colorbar(sp, clims) end @@ -1173,7 +1175,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) for series in series_list(sp) should_add_to_legend(series) || continue st = series[:seriestype] - gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series)) #, series[:linealpha]) + gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series, 1)) #, series[:linealpha]) if (st == :shape || series[:fillrange] != nothing) && series[:ribbon] == nothing gr_set_fill(series[:fillcolor]) #, series[:fillalpha]) diff --git a/src/utils.jl b/src/utils.jl index 38bb2b5a..f9a6cb0c 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -587,14 +587,15 @@ function hascolorbar(sp::Subplot) hascbar end -function get_linecolor(sp::Subplot, series::Series) +function get_linecolor(sp::Subplot, series::Series, i::Int) lc = series[:linecolor] - if series[:line_z] == nothing - lc + lz = series[:line_z] + if lz == nothing + _cycle(lc, i) else cmin, cmax = get_clims(sp) grad = isa(lc, ColorGradient) ? lc : cgrad() - grad[clamp((series[:line_z] - cmin) / (cmax -cmin), 0, 1)] + grad[clamp((_cycle(lz, i) - cmin) / (cmax -cmin), 0, 1)] end end From 5f8486536561746b73823065ac033896ed220082 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Tue, 26 Sep 2017 16:58:46 +0200 Subject: [PATCH 3/5] implement fill_z and line_z for GR --- src/args.jl | 5 +++- src/backends/gr.jl | 60 ++++++++++++++++++++++++++++------------------ src/utils.jl | 27 +++++++++++++++++---- 3 files changed, 63 insertions(+), 29 deletions(-) diff --git a/src/args.jl b/src/args.jl index caa2f7b7..0e9f4569 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1371,13 +1371,16 @@ function _add_defaults!(d::KW, plt::Plot, sp::Subplot, commandIndex::Int) getSeriesRGBColor(d[:markerstrokecolor], d[:markerstrokealpha], sp, plotIndex) end - # if marker_z or line_z are set, ensure we have a gradient + # if marker_z, fill_z or line_z are set, ensure we have a gradient if d[:marker_z] != nothing ensure_gradient!(d, :markercolor, :markeralpha) end if d[:line_z] != nothing ensure_gradient!(d, :linecolor, :linealpha) end + if d[:fill_z] != nothing + ensure_gradient!(d, :fillcolor, :fillalpha) + end # scatter plots don't have a line, but must have a shape if d[:seriestype] in (:scatter, :scatterbins, :scatterhist, :scatter3d) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 60fdba5b..e6c68b41 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -22,7 +22,7 @@ const _gr_attr = merge_with_base_supported([ :tickfont, :guidefont, :legendfont, :grid, :gridalpha, :gridstyle, :gridlinewidth, :legend, :legendtitle, :colorbar, - :line_z, :marker_z, :levels, + :fill_z, :line_z, :marker_z, :levels, :ribbon, :quiver, :orientation, :overwrite_figure, @@ -898,6 +898,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) series[:markercolor] = gr_set_gradient(series[:markercolor]) elseif series[:line_z] != nothing series[:linecolor] = gr_set_gradient(series[:linecolor]) + elseif series[:fill_z] != nothing + series[:fillcolor] = gr_set_gradient(series[:fillcolor]) end GR.savestate() @@ -936,23 +938,26 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) if frng != nothing GR.setfillintstyle(GR.INTSTYLE_SOLID) fr_from, fr_to = (is_2tuple(frng) ? frng : (y, frng)) - for (i,rng) in enumerate(iter_segments(series[:x], series[:y])) - if length(rng) > 1 - gr_set_fillcolor(_cycle(series[:fillcolor], i)) - fx = _cycle(x, vcat(rng, reverse(rng))) - fy = vcat(_cycle(fr_from,rng), _cycle(fr_to,reverse(rng))) - # @show i rng fx fy - GR.fillarea(fx, fy) - end + for i in 1:length(x) - 1 + gr_set_fillcolor(get_fillcolor(sp, series, i)) + xseg = _cycle(x, [i, i+1, i+1, i]) + yseg = [_cycle(fr_from, [i, i+1]); _cycle(fr_to, [i+1, i])] + GR.settransparency(series[:fillalpha]) + GR.fillarea(xseg, yseg) end + gr_set_line(1, :solid, yaxis[:foreground_color_axis]) + GR.settransparency(1) + cmap && gr_colorbar(sp, clims) end # draw the line(s) if st == :path - for (i,rng) in enumerate(iter_segments(series[:x], series[:y])) + for i in 1:length(x) - 1 + xseg = x[i:(i + 1)] + yseg = y[i:(i + 1)] gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series, i)) #, series[:linealpha]) - arrowside = isa(series[:arrow], Arrow) ? series[:arrow].side : :none - gr_polyline(series[:x][rng], series[:y][rng]; arrowside = arrowside) + arrowside = (i == length(y) - 1) && isa(series[:arrow], Arrow) ? series[:arrow].side : :none + gr_polyline(xseg, yseg; arrowside = arrowside) end gr_set_line(1, :solid, yaxis[:foreground_color_axis]) cmap && gr_colorbar(sp, clims) @@ -1022,10 +1027,15 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) elseif st in (:path3d, :scatter3d) # draw path if st == :path3d - if length(x) > 1 - gr_set_line(series[:linewidth], series[:linestyle], series[:linecolor]) #, series[:linealpha]) - GR.polyline3d(x, y, z) + for i in 1:length(x) - 1 + xseg = x[i:(i + 1)] + yseg = y[i:(i + 1)] + zseg = z[i:(i + 1)] + gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series, i)) #, series[:linealpha]) + GR.polyline3d(xseg, yseg, zseg) end + gr_set_line(1, :solid, yaxis[:foreground_color_axis]) + cmap && gr_colorbar(sp, clims) end # draw markers @@ -1083,22 +1093,26 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) GR.selntran(1) elseif st == :shape - for (i,rng) in enumerate(iter_segments(series[:x], series[:y])) + for (i,rng) in enumerate(iter_segments(x, y)) if length(rng) > 1 # connect to the beginning rng = vcat(rng, rng[1]) # get the segments - x, y = series[:x][rng], series[:y][rng] + xseg, yseg = x[rng], y[rng] + @show xseg + @show yseg # draw the interior - gr_set_fill(_cycle(series[:fillcolor], i)) - GR.fillarea(x, y) + gr_set_fill(get_fillcolor(sp, series, i)) + GR.fillarea(xseg, yseg) # draw the shapes - gr_set_line(series[:linewidth], :solid, _cycle(series[:linecolor], i)) - GR.polyline(x, y) + gr_set_line(series[:linewidth], :solid, get_linecolor(sp, series, i)) + GR.polyline(xseg, yseg) end + gr_set_line(1, :solid, yaxis[:foreground_color_axis]) + cmap && gr_colorbar(sp, clims) end @@ -1175,10 +1189,10 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) for series in series_list(sp) should_add_to_legend(series) || continue st = series[:seriestype] - gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series, 1)) #, series[:linealpha]) + gr_set_line(series[:linewidth], series[:linestyle], get_linecolor(sp, series)) #, series[:linealpha]) if (st == :shape || series[:fillrange] != nothing) && series[:ribbon] == nothing - gr_set_fill(series[:fillcolor]) #, series[:fillalpha]) + gr_set_fill(get_fillcolor(sp, series)) #, series[:fillalpha]) l, r = xpos-0.07, xpos-0.01 b, t = ypos-0.4dy, ypos+0.4dy x = [l, r, r, l, l] diff --git a/src/utils.jl b/src/utils.jl index f9a6cb0c..65142bfc 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -543,7 +543,7 @@ zlims(sp_idx::Int = 1) = zlims(current(), sp_idx) function get_clims(sp::Subplot) zmin, zmax = Inf, -Inf for series in series_list(sp) - for vals in (series[:z], series[:line_z], series[:marker_z]) + for vals in (series[:z], series[:line_z], series[:marker_z], series[:fill_z]) if (typeof(vals) <: AbstractSurface) && (eltype(vals.surf) <: Real) zmin, zmax = _update_clims(zmin, zmax, ignorenan_extrema(vals.surf)...) elseif (vals != nothing) && (eltype(vals) <: Real) @@ -564,7 +564,7 @@ _update_clims(zmin, zmax, emin, emax) = min(zmin, emin), max(zmax, emax) function hascolorbar(series::Series) st = series[:seriestype] hascbar = st in (:heatmap, :contour) - if series[:marker_z] != nothing || series[:line_z] != nothing + if series[:marker_z] != nothing || series[:line_z] != nothing || series[:fill_z] != nothing hascbar = true end # no colorbar if we are creating a surface LightSource @@ -587,15 +587,32 @@ function hascolorbar(sp::Subplot) hascbar end -function get_linecolor(sp::Subplot, series::Series, i::Int) +function get_linecolor(sp::Subplot, series::Series, i::Int = 1) lc = series[:linecolor] lz = series[:line_z] if lz == nothing - _cycle(lc, i) + isa(lc, ColorGradient) ? lc : _cycle(lc, i) else cmin, cmax = get_clims(sp) grad = isa(lc, ColorGradient) ? lc : cgrad() - grad[clamp((_cycle(lz, i) - cmin) / (cmax -cmin), 0, 1)] + grad[clamp((_cycle(lz, i) - cmin) / (cmax - cmin), 0, 1)] + end +end + +function get_fillcolor(sp::Subplot, series::Series, i::Int = 1) + fc = series[:fillcolor] + fz = series[:fill_z] + lz = series[:line_z] + if fz == nothing && lz == nothing + isa(fc, ColorGradient) ? fc : _cycle(fc, i) + else + cmin, cmax = get_clims(sp) + grad = isa(fc, ColorGradient) ? fc : cgrad() + if fz != nothing + grad[clamp((_cycle(fz, i) - cmin) / (cmax - cmin), 0, 1)] + elseif lz != nothing + grad[clamp((_cycle(lz, i) - cmin) / (cmax - cmin), 0, 1)] + end end end From ea6ab46a13bd1068dc2b0692bd76eedb7b449b6c Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Tue, 26 Sep 2017 17:18:35 +0200 Subject: [PATCH 4/5] fix fill_z for shapes (draw colorbar once) --- src/backends/gr.jl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index e6c68b41..e2054a90 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1100,8 +1100,6 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # get the segments xseg, yseg = x[rng], y[rng] - @show xseg - @show yseg # draw the interior gr_set_fill(get_fillcolor(sp, series, i)) @@ -1111,9 +1109,9 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) gr_set_line(series[:linewidth], :solid, get_linecolor(sp, series, i)) GR.polyline(xseg, yseg) end - gr_set_line(1, :solid, yaxis[:foreground_color_axis]) - cmap && gr_colorbar(sp, clims) end + gr_set_line(1, :solid, yaxis[:foreground_color_axis]) + cmap && gr_colorbar(sp, clims) elseif st == :image From 9eac6a1db00b66fa03c254107e61eccc32f42f1b Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Tue, 26 Sep 2017 17:40:54 +0200 Subject: [PATCH 5/5] fix fillalpha --- src/backends/gr.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index e2054a90..09fb7270 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -942,7 +942,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) gr_set_fillcolor(get_fillcolor(sp, series, i)) xseg = _cycle(x, [i, i+1, i+1, i]) yseg = [_cycle(fr_from, [i, i+1]); _cycle(fr_to, [i+1, i])] - GR.settransparency(series[:fillalpha]) + series[:fillalpha] != nothing && GR.settransparency(series[:fillalpha]) GR.fillarea(xseg, yseg) end gr_set_line(1, :solid, yaxis[:foreground_color_axis])