working on annotations

This commit is contained in:
Thomas Breloff 2015-09-28 10:46:53 -04:00
parent 77d679b63b
commit fd3a4d0a0e
4 changed files with 100 additions and 0 deletions

67
examples/annotate.ipynb Normal file

File diff suppressed because one or more lines are too long

View File

@ -105,6 +105,7 @@ _seriesDefaults[:fillto] = nothing # fills in the area
_seriesDefaults[:reg] = false # regression line?
_seriesDefaults[:group] = nothing
_seriesDefaults[:ribbon] = nothing
_seriesDefaults[:annotation] = nothing
_seriesDefaults[:args] = [] # additional args to pass to the backend
_seriesDefaults[:kwargs] = [] # additional keyword args to pass to the backend
# note: can be Vector{Dict} or Vector{Tuple}
@ -186,6 +187,10 @@ const _keyAliases = Dict(
:area => :fillto,
:g => :group,
:r => :ribbon,
:ann => :annotation,
:anns => :annotation,
:annotate => :annotation,
:annotations => :annotation,
:xlab => :xlabel,
:ylab => :ylabel,
:yrlab => :yrightlabel,

View File

@ -301,6 +301,32 @@ end
# ----------------------------------------------------------------
function createAnnotationObject(x, y, val::AbstractString)
Gadfly.Guide.annotation(Compose.compose(
Compose.context(),
Compose.text(x, y, val)
# Compose.fill(colorant"black"),
# Compose.stroke(colorant"black")
))
end
function addAnnotations(plt::Plot{GadflyPackage}, d::Dict)
if haskey(d, :annotation)
anns = d[:annotation]
if !(isa(anns, AbstractVector) && issubtype(eltype(anns), Tuple))
error("Expecting a vector of tuples for annotations: (x, y, annotation)\n got: $(typeof(anns))")
end
for ann in anns
x, y, val = ann
push!(plt.o.guides, createAnnotationObject(x, y, val))
end
end
end
# ----------------------------------------------------------------
# create the underlying object (each backend will do this differently)
function buildSubplotObject!(subplt::Subplot{GadflyPackage})
subplt.o = nothing

View File

@ -114,6 +114,8 @@ function plot!(plt::Plot, args...; kw...)
end
addAnnotations(plt, d)
# add title, axis labels, ticks, etc
updatePlotItems(plt, d)
currentPlot!(plt)