different colors for different line segments in GR

This commit is contained in:
Daniel Schwabeneder 2017-09-25 17:22:13 +02:00
parent 8b4edae358
commit 337a107168
2 changed files with 11 additions and 8 deletions

View File

@ -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])

View File

@ -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