UnicodePlots: support :annotations (#3804)
This commit is contained in:
parent
0a9d30f7ac
commit
6cf01229bb
@ -910,6 +910,7 @@ const _gaston_scale = [:identity, :ln, :log2, :log10]
|
|||||||
# unicodeplots
|
# unicodeplots
|
||||||
|
|
||||||
const _unicodeplots_attr = merge_with_base_supported([
|
const _unicodeplots_attr = merge_with_base_supported([
|
||||||
|
:annotations,
|
||||||
:label,
|
:label,
|
||||||
:legend,
|
:legend,
|
||||||
:seriescolor,
|
:seriescolor,
|
||||||
|
|||||||
@ -57,10 +57,30 @@ function unicodeplots_rebuild(plt::Plot{UnicodePlotsBackend})
|
|||||||
o = addUnicodeSeries!(sp, o, series, sp[:legend] != :none, xlim, ylim)
|
o = addUnicodeSeries!(sp, o, series, sp[:legend] != :none, xlim, ylim)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for ann in sp[:annotations]
|
||||||
|
x, y, val = locate_annotation(sp, ann...)
|
||||||
|
o = UnicodePlots.annotate!(
|
||||||
|
o, x, y, val.str;
|
||||||
|
color = up_color(val.font.color), halign = val.font.halign, valign = val.font.valign
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
push!(plt.o, o) # save the object
|
push!(plt.o, o) # save the object
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function up_color(col)
|
||||||
|
if typeof(col) <: UnicodePlots.UserColorType
|
||||||
|
color = col
|
||||||
|
elseif typeof(col) <: RGBA
|
||||||
|
col = convert(ARGB32, col)
|
||||||
|
color = map(Int, (red(col).i, green(col).i, blue(col).i))
|
||||||
|
else
|
||||||
|
color = :auto
|
||||||
|
end
|
||||||
|
color
|
||||||
|
end
|
||||||
|
|
||||||
# add a single series
|
# add a single series
|
||||||
function addUnicodeSeries!(
|
function addUnicodeSeries!(
|
||||||
sp::Subplot{UnicodePlotsBackend},
|
sp::Subplot{UnicodePlotsBackend},
|
||||||
@ -111,17 +131,16 @@ function addUnicodeSeries!(
|
|||||||
for (n, segment) in enumerate(series_segments(series, st; check = true))
|
for (n, segment) in enumerate(series_segments(series, st; check = true))
|
||||||
i, rng = segment.attr_index, segment.range
|
i, rng = segment.attr_index, segment.range
|
||||||
lc = get_linecolor(series, i)
|
lc = get_linecolor(series, i)
|
||||||
if typeof(lc) <: UnicodePlots.UserColorType
|
up = func(up, x[rng], y[rng]; color = up_color(lc), name = n == 1 ? label : "")
|
||||||
color = lc
|
|
||||||
elseif typeof(lc) <: RGBA
|
|
||||||
lc = convert(ARGB32, lc)
|
|
||||||
color = map(Int, (red(lc).i, green(lc).i, blue(lc).i))
|
|
||||||
else
|
|
||||||
color = :auto
|
|
||||||
end
|
|
||||||
|
|
||||||
up = func(up, x[rng], y[rng]; color = color, name = n == 1 ? label : "")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for (xi, yi, str, fnt) in EachAnn(series[:series_annotations], x, y)
|
||||||
|
up = UnicodePlots.annotate!(
|
||||||
|
up, xi, yi, str;
|
||||||
|
color = up_color(fnt.color), halign = fnt.halign, valign = fnt.valign
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
return up
|
return up
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user