UnicodePlots: fix NaN segments plot (#3794)
This commit is contained in:
parent
0d2bc3f227
commit
748104c807
@ -19,7 +19,7 @@ _canvas_map() = (
|
|||||||
# do all the magic here... build it all at once, since we need to know about all the series at the very beginning
|
# do all the magic here... build it all at once, since we need to know about all the series at the very beginning
|
||||||
function unicodeplots_rebuild(plt::Plot{UnicodePlotsBackend})
|
function unicodeplots_rebuild(plt::Plot{UnicodePlotsBackend})
|
||||||
plt.o = UnicodePlots.Plot[]
|
plt.o = UnicodePlots.Plot[]
|
||||||
|
canvas_map = _canvas_map()
|
||||||
for sp in plt.subplots
|
for sp in plt.subplots
|
||||||
xaxis = sp[:xaxis]
|
xaxis = sp[:xaxis]
|
||||||
yaxis = sp[:yaxis]
|
yaxis = sp[:yaxis]
|
||||||
@ -36,17 +36,16 @@ function unicodeplots_rebuild(plt::Plot{UnicodePlotsBackend})
|
|||||||
y = Float64[ylim[1]]
|
y = Float64[ylim[1]]
|
||||||
|
|
||||||
# create a plot window with xlim/ylim set, but the X/Y vectors are outside the bounds
|
# create a plot window with xlim/ylim set, but the X/Y vectors are outside the bounds
|
||||||
ct = _canvas_type[]
|
canvas_type = if (ct = _canvas_type[]) == :auto
|
||||||
canvas_type = if ct == :auto
|
isijulia() ? :ascii : :braille
|
||||||
isijulia() ? UnicodePlots.AsciiCanvas : UnicodePlots.BrailleCanvas
|
|
||||||
else
|
else
|
||||||
_canvas_map()[ct]
|
ct
|
||||||
end
|
end
|
||||||
|
|
||||||
o = UnicodePlots.Plot(
|
o = UnicodePlots.Plot(
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
canvas_type;
|
canvas_map[canvas_type];
|
||||||
title = sp[:title],
|
title = sp[:title],
|
||||||
xlim = xlim,
|
xlim = xlim,
|
||||||
ylim = ylim,
|
ylim = ylim,
|
||||||
@ -54,7 +53,6 @@ function unicodeplots_rebuild(plt::Plot{UnicodePlotsBackend})
|
|||||||
ylabel = yaxis[:guide],
|
ylabel = yaxis[:guide],
|
||||||
border = isijulia() ? :ascii : :solid,
|
border = isijulia() ? :ascii : :solid,
|
||||||
)
|
)
|
||||||
|
|
||||||
for series in series_list(sp)
|
for series in series_list(sp)
|
||||||
o = addUnicodeSeries!(sp, o, series, sp[:legend] != :none, xlim, ylim)
|
o = addUnicodeSeries!(sp, o, series, sp[:legend] != :none, xlim, ylim)
|
||||||
end
|
end
|
||||||
@ -66,18 +64,26 @@ end
|
|||||||
# add a single series
|
# add a single series
|
||||||
function addUnicodeSeries!(
|
function addUnicodeSeries!(
|
||||||
sp::Subplot{UnicodePlotsBackend},
|
sp::Subplot{UnicodePlotsBackend},
|
||||||
o,
|
up::UnicodePlots.Plot,
|
||||||
series,
|
series,
|
||||||
addlegend::Bool,
|
addlegend::Bool,
|
||||||
xlim,
|
xlim,
|
||||||
ylim,
|
ylim,
|
||||||
)
|
)
|
||||||
attrs = series.plotattributes
|
st = series[:seriestype]
|
||||||
st = attrs[:seriestype]
|
|
||||||
|
|
||||||
# special handling
|
# get the series data and label
|
||||||
|
x, y = if st == :straightline
|
||||||
|
straightline_data(series)
|
||||||
|
elseif st == :shape
|
||||||
|
shape_data(series)
|
||||||
|
else
|
||||||
|
float(series[:x]), float(series[:y])
|
||||||
|
end
|
||||||
|
|
||||||
|
# special handling (src/interface)
|
||||||
if st == :histogram2d
|
if st == :histogram2d
|
||||||
return UnicodePlots.densityplot!(o, attrs[:x], attrs[:y])
|
return UnicodePlots.densityplot(x, y)
|
||||||
elseif st == :heatmap
|
elseif st == :heatmap
|
||||||
rng = range(0, 1, length = length(UnicodePlots.COLOR_MAP_DATA[:viridis]))
|
rng = range(0, 1, length = length(UnicodePlots.COLOR_MAP_DATA[:viridis]))
|
||||||
cmap = [(red(c), green(c), blue(c)) for c in get(get_colorgradient(series), rng)]
|
cmap = [(red(c), green(c), blue(c)) for c in get(get_colorgradient(series), rng)]
|
||||||
@ -92,29 +98,19 @@ function addUnicodeSeries!(
|
|||||||
end
|
end
|
||||||
|
|
||||||
# now use the ! functions to add to the plot
|
# now use the ! functions to add to the plot
|
||||||
if st in (:path, :straightline)
|
if st in (:path, :straightline, :shape)
|
||||||
func = UnicodePlots.lineplot!
|
func = UnicodePlots.lineplot!
|
||||||
elseif st == :scatter || attrs[:markershape] != :none
|
elseif st == :scatter || series[:markershape] != :none
|
||||||
func = UnicodePlots.scatterplot!
|
func = UnicodePlots.scatterplot!
|
||||||
# elseif st == :bar
|
|
||||||
# func = UnicodePlots.barplot!
|
|
||||||
elseif st == :shape
|
|
||||||
func = UnicodePlots.lineplot!
|
|
||||||
else
|
else
|
||||||
error("Series type $st not supported by UnicodePlots")
|
error("Series type $st not supported by UnicodePlots")
|
||||||
end
|
end
|
||||||
|
|
||||||
# get the series data and label
|
label = addlegend ? series[:label] : ""
|
||||||
x, y = if st == :straightline
|
|
||||||
straightline_data(attrs)
|
|
||||||
elseif st == :shape
|
|
||||||
shape_data(attrs)
|
|
||||||
else
|
|
||||||
[collect(float(attrs[s])) for s in (:x, :y)]
|
|
||||||
end
|
|
||||||
label = addlegend ? attrs[:label] : ""
|
|
||||||
|
|
||||||
lc = attrs[:linecolor]
|
for (n, segment) in enumerate(series_segments(series, st; check = true))
|
||||||
|
i, rng = segment.attr_index, segment.range
|
||||||
|
lc = get_linecolor(series, i)
|
||||||
if typeof(lc) <: UnicodePlots.UserColorType
|
if typeof(lc) <: UnicodePlots.UserColorType
|
||||||
color = lc
|
color = lc
|
||||||
elseif typeof(lc) <: RGBA
|
elseif typeof(lc) <: RGBA
|
||||||
@ -124,7 +120,9 @@ function addUnicodeSeries!(
|
|||||||
color = :auto
|
color = :auto
|
||||||
end
|
end
|
||||||
|
|
||||||
func(o, x, y; color = color, name = label)
|
up = func(up, x[rng], y[rng]; color = color, name = n == 1 ? label : "")
|
||||||
|
end
|
||||||
|
return up
|
||||||
end
|
end
|
||||||
|
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
|
|||||||
@ -1250,8 +1250,8 @@ _backend_skips = Dict(
|
|||||||
],
|
],
|
||||||
:inspectdr => [4, 6, 10, 22, 24, 28, 30, 38, 43, 45, 47, 48, 49, 50, 51, 55],
|
:inspectdr => [4, 6, 10, 22, 24, 28, 30, 38, 43, 45, 47, 48, 49, 50, 51, 55],
|
||||||
:unicodeplots => [
|
:unicodeplots => [
|
||||||
|
5, # log scales unsupported
|
||||||
6, # embedded images unsupported
|
6, # embedded images unsupported
|
||||||
10, # histogram2d
|
|
||||||
13, # markers unsupported
|
13, # markers unsupported
|
||||||
16, # nested layout unsupported
|
16, # nested layout unsupported
|
||||||
20, # annotations unsupported
|
20, # annotations unsupported
|
||||||
@ -1263,7 +1263,6 @@ _backend_skips = Dict(
|
|||||||
33, # grid lines unsupported
|
33, # grid lines unsupported
|
||||||
34, # framestyle unsupported
|
34, # framestyle unsupported
|
||||||
37, # ribbons / filled unsupported
|
37, # ribbons / filled unsupported
|
||||||
38, # histogram2D
|
|
||||||
43, # heatmap with DateTime
|
43, # heatmap with DateTime
|
||||||
45, # error bars
|
45, # error bars
|
||||||
47, # mesh3D unsupported
|
47, # mesh3D unsupported
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user