Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds stem plot trace as wrapper around scatter #86

Merged
merged 1 commit into from
Oct 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/PlotlyJS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ export
# helper methods
plot, fork, vline, hline, attr,

# new trace types
stem,

# frontend methods
init_notebook,

Expand Down
27 changes: 27 additions & 0 deletions src/convenience_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,30 @@ function plot(fs::AbstractVector{Function}, x0::Number, x1::Number,
for f in fs]
plot(traces, l; style=style)
end

"""
$(SIGNATURES)
Creates a "stem" or "lollipop" trace. It is implemented using plotly.js's
`scatter` type, using the error bars to draw the stem.

## Keyword Arguments:
* All properties accepted by `scatter` except `error_y`, which is used to draw
the stems
* stem_color - sets the color of the stems
* stem_thickness - sets the thickness of the stems
"""
function stem(;y=nothing, stem_color="grey", stem_thickness=1, kwargs...)
line_up = -min(y, 0)
line_down = max(y, 0)
trace = scatter(; y=y, text=y, marker_size=10, mode="markers", hoverinfo="text", kwargs...)
trace.fields[:error_y] = Dict(
:type => "data",
:symmetric => false,
:array => line_up,
:arrayminus => line_down,
:visible => true,
:color => stem_color,
:width => 0,
:thickness => stem_thickness)
trace
end