added hover attribute and desc; fixed plotly title location; already_warned check
This commit is contained in:
parent
e0af4b7925
commit
ed243f4e3e
@ -45,6 +45,7 @@ const _arg_desc = KW(
|
||||
:subplot => "Integer (subplot index) or Subplot object. The subplot that this series belongs to.",
|
||||
:series_annotations => "AbstractVector of String or PlotText. These are annotations which are mapped to data points/positions.",
|
||||
:primary => "Bool. Does this count as a 'real series'? For example, you could have a path (primary), and a scatter (secondary) as 2 separate series, maybe with different data (see sticks recipe for an example). The secondary series will get the same color, etc as the primary.",
|
||||
:hover => "nothing or vector of strings. Text to display when hovering over each data point.",
|
||||
|
||||
# plot args
|
||||
:plot_title => "String. Title for the whole plot (not the subplots) (Note: Not currently implemented)",
|
||||
|
||||
10
src/args.jl
10
src/args.jl
@ -181,6 +181,7 @@ const _series_defaults = KW(
|
||||
:series_annotations => [], # a list of annotations which apply to the coordinates of this series
|
||||
:primary => true, # when true, this "counts" as a series for color selection, etc. the main use is to allow
|
||||
# one logical series to be broken up (path and markers, for example)
|
||||
:hover => nothing, # text to display when hovering over the data points
|
||||
)
|
||||
|
||||
|
||||
@ -725,12 +726,17 @@ end
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
const _already_warned = Set()
|
||||
|
||||
function warnOnUnsupported_args(pkg::AbstractBackend, d::KW)
|
||||
for k in sortedkeys(d)
|
||||
k in supported_args(pkg) && continue
|
||||
k in _suppress_warnings && continue
|
||||
if d[k] != default(k)
|
||||
warn("Keyword argument $k not supported with $pkg. Choose from: $(supported_args(pkg))")
|
||||
if !((pkg, k) in _already_warned)
|
||||
push!(_already_warned, (pkg,k))
|
||||
warn("Keyword argument $k not supported with $pkg. Choose from: $(supported_args(pkg))")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -756,7 +762,7 @@ function warnOnUnsupported_scales(pkg::AbstractBackend, d::KW)
|
||||
v = d[k]
|
||||
v = get(_scaleAliases, v, v)
|
||||
if !(v in supported_scales(pkg))
|
||||
Base.warn_once("scale $(d[k]) is unsupported with $pkg. Choose from: $(supported_scales(pkg))")
|
||||
warn("scale $(d[k]) is unsupported with $pkg. Choose from: $(supported_scales(pkg))")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -216,18 +216,9 @@ function plotly_axis(axis::Axis, sp::Subplot)
|
||||
ax
|
||||
end
|
||||
|
||||
# function plotly_layout_json(plt::Plot{PlotlyBackend})
|
||||
# d = plt
|
||||
# function plotly_layout(d::KW, seriesargs::AVec{KW})
|
||||
function plotly_layout(plt::Plot)
|
||||
d_out = KW()
|
||||
|
||||
# # for now, we only support 1 subplot
|
||||
# if length(plt.subplots) > 1
|
||||
# warn("Subplots not supported yet")
|
||||
# end
|
||||
# sp = plt.subplots[1]
|
||||
|
||||
w, h = plt[:size]
|
||||
d_out[:width], d_out[:height] = w, h
|
||||
d_out[:paper_bgcolor] = webcolor(plt[:background_color_outside])
|
||||
@ -238,9 +229,10 @@ function plotly_layout(plt::Plot)
|
||||
for sp in plt.subplots
|
||||
spidx = plotly_subplot_index(sp)
|
||||
|
||||
# TODO: add an annotation for the title
|
||||
# add an annotation for the title... positioned horizontally relative to plotarea,
|
||||
# but vertically just below the top of the subplot bounding box
|
||||
if sp[:title] != ""
|
||||
bb = bbox(sp)
|
||||
bb = plotarea(sp)
|
||||
tpos = sp[:title_location]
|
||||
xmm = if tpos == :left
|
||||
left(bb)
|
||||
@ -249,7 +241,7 @@ function plotly_layout(plt::Plot)
|
||||
else
|
||||
0.5 * (left(bb) + right(bb))
|
||||
end
|
||||
titlex, titley = xy_mm_to_pcts(xmm, top(bb), w*px, h*px)
|
||||
titlex, titley = xy_mm_to_pcts(xmm, top(bbox(sp)), w*px, h*px)
|
||||
titlefont = font(sp[:titlefont], :top, sp[:foreground_color_title])
|
||||
push!(d_out[:annotations], plotly_annotation_dict(titlex, titley, text(sp[:title], titlefont)))
|
||||
end
|
||||
@ -292,8 +284,6 @@ function plotly_layout(plt::Plot)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# dumpdict(d_out,"",true)
|
||||
# @show d_out[:annotations]
|
||||
|
||||
if ispolar(sp)
|
||||
d_out[:direction] = "counterclockwise"
|
||||
|
||||
@ -16,11 +16,6 @@ function _initialize_backend(::PlotlyJSBackend; kw...)
|
||||
export PlotlyJS
|
||||
end
|
||||
|
||||
# for (mime, fmt) in PlotlyJS._mimeformats
|
||||
# # mime == "image/png" && continue # don't use plotlyjs's writemime for png
|
||||
# @eval Base.writemime(io::IO, m::MIME{Symbol($mime)}, p::Plot{PlotlyJSBackend}) = writemime(io, m, p.o)
|
||||
# end
|
||||
|
||||
# # override IJulia inline display
|
||||
# if isijulia()
|
||||
# IJulia.display_dict(plt::AbstractPlot{PlotlyJSBackend}) = IJulia.display_dict(plt.o)
|
||||
@ -55,7 +50,6 @@ end
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# TODO: override this to update plot items (title, xlabel, etc) after creation
|
||||
function _update_plot_object(plt::Plot{PlotlyJSBackend})
|
||||
pdict = plotly_layout(plt)
|
||||
syncplot = plt.o
|
||||
@ -64,27 +58,6 @@ function _update_plot_object(plt::Plot{PlotlyJSBackend})
|
||||
end
|
||||
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# accessors for x/y data
|
||||
|
||||
# function getxy(plt::Plot{PlotlyJSBackend}, i::Int)
|
||||
# d = plt.seriesargs[i]
|
||||
# d[:x], d[:y]
|
||||
# end
|
||||
|
||||
# function setxy!{X,Y}(plt::Plot{PlotlyJSBackend}, xy::Tuple{X,Y}, i::Integer)
|
||||
# d = plt.seriesargs[i]
|
||||
# ispolar = get(plt.attr, :polar, false)
|
||||
# xsym = ispolar ? :t : :x
|
||||
# ysym = ispolar ? :r : :y
|
||||
# d[xsym], d[ysym] = xy
|
||||
# # TODO: this is likely ineffecient... we should make a call that ONLY changes the plot data
|
||||
# PlotlyJS.restyle!(plt.o, i, KW(xsym=>(d[xsym],), ysym=>(d[ysym],)))
|
||||
# plt
|
||||
# end
|
||||
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
function _writemime(io::IO, ::MIME"image/svg+xml", plt::Plot{PlotlyJSBackend})
|
||||
|
||||
@ -264,7 +264,7 @@ PlotExample("Groups and Subplots",
|
||||
"",
|
||||
[:(begin
|
||||
group = rand(map(i->"group $i",1:4),100)
|
||||
plot(rand(100), layout=@layout([a b;c]), group=group, n=3, linetype=[:bar :scatter :steppre])
|
||||
plot(rand(100), layout=@layout([a b;c]), group=group, linetype=[:bar :scatter :steppre])
|
||||
end)]
|
||||
),
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user