ensure_gradient; plotly fixes
This commit is contained in:
parent
396721568f
commit
e3ccc34a2c
26
src/args.jl
26
src/args.jl
@ -1067,14 +1067,16 @@ end
|
|||||||
|
|
||||||
# converts a symbol or string into a colorant (Colors.RGB), and assigns a color automatically
|
# converts a symbol or string into a colorant (Colors.RGB), and assigns a color automatically
|
||||||
function getSeriesRGBColor(c, α, sp::Subplot, n::Int)
|
function getSeriesRGBColor(c, α, sp::Subplot, n::Int)
|
||||||
|
if c == :auto
|
||||||
|
c = autopick(sp[:color_palette], n)
|
||||||
|
end
|
||||||
|
plot_color(c, α)
|
||||||
|
end
|
||||||
|
|
||||||
if c == :auto
|
function ensure_gradient!(d::KW, csym::Symbol, asym::Symbol)
|
||||||
c = autopick(sp[:color_palette], n)
|
if !isa(d[csym], ColorGradient)
|
||||||
end
|
d[csym] = cgrad(alpha = d[asym])
|
||||||
|
end
|
||||||
# # c should now be a subtype of AbstractPlotColor
|
|
||||||
# colorscheme(c)
|
|
||||||
plot_color(c, α)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -1114,7 +1116,7 @@ function _add_defaults!(d::KW, plt::Plot, sp::Subplot, commandIndex::Int)
|
|||||||
csym, asym = Symbol(s,:color), Symbol(s,:alpha)
|
csym, asym = Symbol(s,:color), Symbol(s,:alpha)
|
||||||
d[csym] = if d[csym] == :match
|
d[csym] = if d[csym] == :match
|
||||||
plot_color(if has_black_border_for_default(d[:seriestype]) && s == :line
|
plot_color(if has_black_border_for_default(d[:seriestype]) && s == :line
|
||||||
:black
|
sp[:foreground_color_subplot]
|
||||||
else
|
else
|
||||||
d[:seriescolor]
|
d[:seriescolor]
|
||||||
end, d[asym])
|
end, d[asym])
|
||||||
@ -1130,6 +1132,14 @@ function _add_defaults!(d::KW, plt::Plot, sp::Subplot, commandIndex::Int)
|
|||||||
getSeriesRGBColor(d[:markerstrokecolor], d[:markerstrokealpha], sp, plotIndex)
|
getSeriesRGBColor(d[:markerstrokecolor], d[:markerstrokealpha], sp, plotIndex)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# if marker_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
|
||||||
|
|
||||||
# scatter plots don't have a line, but must have a shape
|
# scatter plots don't have a line, but must have a shape
|
||||||
if d[:seriestype] in (:scatter, :scatter3d)
|
if d[:seriestype] in (:scatter, :scatter3d)
|
||||||
d[:linewidth] = 0
|
d[:linewidth] = 0
|
||||||
|
|||||||
@ -298,10 +298,11 @@ function plotly_layout_json(plt::Plot)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function plotly_colorscale(grad::ColorGradient, alpha = nothing)
|
function plotly_colorscale(grad::ColorGradient, α)
|
||||||
[[grad.values[i], rgba_string(grad.colors[i], alpha)] for i in 1:length(grad.colors)]
|
[[grad.values[i], rgb_string(grad.colors[i])] for i in 1:length(grad.colors)]
|
||||||
end
|
end
|
||||||
plotly_colorscale(c, alpha = nothing) = plotly_colorscale(cgrad(), alpha)
|
plotly_colorscale(c, α) = plotly_colorscale(cgrad(alpha=α), α)
|
||||||
|
# plotly_colorscale(c, alpha = nothing) = plotly_colorscale(cgrad(), alpha)
|
||||||
|
|
||||||
const _plotly_markers = KW(
|
const _plotly_markers = KW(
|
||||||
:rect => "square",
|
:rect => "square",
|
||||||
@ -374,8 +375,6 @@ function plotly_series(plt::Plot, series::Series)
|
|||||||
d_out[:type] = "scatter"
|
d_out[:type] = "scatter"
|
||||||
d_out[:mode] = "lines"
|
d_out[:mode] = "lines"
|
||||||
d_out[:x], d_out[:y] = plotly_close_shapes(x, y)
|
d_out[:x], d_out[:y] = plotly_close_shapes(x, y)
|
||||||
# @show map(length, (x,y,d_out[:x],d_out[:y]))
|
|
||||||
# @show d_out[:x] d_out[:y]
|
|
||||||
d_out[:fill] = "tozeroy"
|
d_out[:fill] = "tozeroy"
|
||||||
d_out[:fillcolor] = rgba_string(d[:fillcolor])
|
d_out[:fillcolor] = rgba_string(d[:fillcolor])
|
||||||
if d[:markerstrokewidth] > 0
|
if d[:markerstrokewidth] > 0
|
||||||
@ -386,38 +385,15 @@ function plotly_series(plt::Plot, series::Series)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
elseif st == :bar
|
elseif st == :bar
|
||||||
d_out[:type] = "bar"
|
d_out[:type] = "bar"
|
||||||
d_out[:x], d_out[:y] = x, y
|
d_out[:x], d_out[:y] = x, y
|
||||||
d_out[:orientation] = isvertical(d) ? "v" : "h"
|
d_out[:orientation] = isvertical(d) ? "v" : "h"
|
||||||
|
|
||||||
# elseif st == :histogram2d
|
|
||||||
# d_out[:type] = "histogram2d"
|
|
||||||
# d_out[:x], d_out[:y] = x, y
|
|
||||||
# if isa(d[:bins], Tuple)
|
|
||||||
# xbins, ybins = d[:bins]
|
|
||||||
# else
|
|
||||||
# xbins = ybins = d[:bins]
|
|
||||||
# end
|
|
||||||
# d_out[:nbinsx] = xbins
|
|
||||||
# d_out[:nbinsy] = ybins
|
|
||||||
# d_out[:colorscale] = plotly_colorscale(d[:fillcolor])
|
|
||||||
|
|
||||||
# elseif st in (:histogram, :density)
|
|
||||||
# d_out[:type] = "histogram"
|
|
||||||
# isvert = isvertical(d)
|
|
||||||
# d_out[isvert ? :x : :y] = y
|
|
||||||
# d_out[isvert ? :nbinsx : :nbinsy] = d[:bins]
|
|
||||||
# if st == :density
|
|
||||||
# d_out[:histogramnorm] = "probability density"
|
|
||||||
# end
|
|
||||||
|
|
||||||
elseif st == :heatmap
|
elseif st == :heatmap
|
||||||
d_out[:type] = "heatmap"
|
d_out[:type] = "heatmap"
|
||||||
d_out[:x], d_out[:y], d_out[:z] = d[:x], d[:y], transpose_z(d, d[:z].surf, false)
|
d_out[:x], d_out[:y], d_out[:z] = d[:x], d[:y], transpose_z(d, d[:z].surf, false)
|
||||||
d_out[:colorscale] = plotly_colorscale(d[:fillcolor])
|
d_out[:colorscale] = plotly_colorscale(d[:fillcolor], d[:fillalpha])
|
||||||
|
|
||||||
elseif st == :contour
|
elseif st == :contour
|
||||||
d_out[:type] = "contour"
|
d_out[:type] = "contour"
|
||||||
@ -425,12 +401,12 @@ function plotly_series(plt::Plot, series::Series)
|
|||||||
# d_out[:showscale] = d[:colorbar] != :none
|
# d_out[:showscale] = d[:colorbar] != :none
|
||||||
d_out[:ncontours] = d[:levels]
|
d_out[:ncontours] = d[:levels]
|
||||||
d_out[:contours] = KW(:coloring => d[:fillrange] != nothing ? "fill" : "lines")
|
d_out[:contours] = KW(:coloring => d[:fillrange] != nothing ? "fill" : "lines")
|
||||||
d_out[:colorscale] = plotly_colorscale(d[:linecolor])
|
d_out[:colorscale] = plotly_colorscale(d[:linecolor], d[:linealpha])
|
||||||
|
|
||||||
elseif st in (:surface, :wireframe)
|
elseif st in (:surface, :wireframe)
|
||||||
d_out[:type] = "surface"
|
d_out[:type] = "surface"
|
||||||
d_out[:x], d_out[:y], d_out[:z] = d[:x], d[:y], transpose_z(d, d[:z].surf, false)
|
d_out[:x], d_out[:y], d_out[:z] = d[:x], d[:y], transpose_z(d, d[:z].surf, false)
|
||||||
d_out[:colorscale] = plotly_colorscale(d[:fillcolor])
|
d_out[:colorscale] = plotly_colorscale(d[:fillcolor], d[:fillalpha])
|
||||||
|
|
||||||
elseif st == :pie
|
elseif st == :pie
|
||||||
d_out[:type] = "pie"
|
d_out[:type] = "pie"
|
||||||
@ -459,7 +435,7 @@ function plotly_series(plt::Plot, series::Series)
|
|||||||
:symbol => get(_plotly_markers, d[:markershape], string(d[:markershape])),
|
:symbol => get(_plotly_markers, d[:markershape], string(d[:markershape])),
|
||||||
# :opacity => d[:markeralpha],
|
# :opacity => d[:markeralpha],
|
||||||
:size => 2 * d[:markersize],
|
:size => 2 * d[:markersize],
|
||||||
:color => rgba_string(d[:markercolor]),
|
# :color => rgba_string(d[:markercolor]),
|
||||||
:line => KW(
|
:line => KW(
|
||||||
:color => rgba_string(d[:markerstrokecolor]),
|
:color => rgba_string(d[:markerstrokecolor]),
|
||||||
:width => d[:markerstrokewidth],
|
:width => d[:markerstrokewidth],
|
||||||
@ -467,13 +443,13 @@ function plotly_series(plt::Plot, series::Series)
|
|||||||
)
|
)
|
||||||
|
|
||||||
# gotta hack this (for now?) since plotly can't handle rgba values inside the gradient
|
# gotta hack this (for now?) since plotly can't handle rgba values inside the gradient
|
||||||
if d[:marker_z] != nothing
|
d_out[:marker][:color] = if d[:marker_z] == nothing
|
||||||
# d_out[:marker][:color] = d[:marker_z]
|
rgba_string(d[:markercolor])
|
||||||
# d_out[:marker][:colorscale] = plotly_colorscale(d[:markercolor])
|
else
|
||||||
# d_out[:showscale] = true
|
# grad = ColorGradient(d[:markercolor], alpha=d[:markeralpha])
|
||||||
grad = ColorGradient(d[:markercolor], alpha=d[:markeralpha])
|
grad = d[:markercolor]
|
||||||
zmin, zmax = extrema(d[:marker_z])
|
zmin, zmax = extrema(d[:marker_z])
|
||||||
d_out[:marker][:color] = [rgba_string(getColorZ(grad, (zi - zmin) / (zmax - zmin))) for zi in d[:marker_z]]
|
[rgba_string(grad[(zi - zmin) / (zmax - zmin)]) for zi in d[:marker_z]]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user