Skip to content

Commit

Permalink
Merge pull request #579 from piever/pull-request/bdce27dd
Browse files Browse the repository at this point in the history
Implemented legend position in plotly
  • Loading branch information
tbreloff authored Nov 21, 2016
2 parents 436ab89 + bdce27d commit e9ccdef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/args.jl
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ function convertLegendValue(val::Symbol)
end
convertLegendValue(val::Bool) = val ? :best : :none
convertLegendValue(val::Void) = :none
convertLegendValue{S<:Real, T<:Real}(v::Tuple{S,T}) = v
convertLegendValue(v::AbstractArray) = map(convertLegendValue, v)

# -----------------------------------------------------------------------------
Expand Down
18 changes: 18 additions & 0 deletions src/backends/plotly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ end

# ----------------------------------------------------------------

const _plotly_legend_pos = KW(
:right => [1., 0.5],
:left => [0., 0.5],
:top => [0.5, 1.],
:bottom => [0.5, 0.],
:bottomleft => [0., 0.],
:bottomright => [1., 0.],
:topright => [1., 1.],
:topleft => [0., 1.]
)

plotly_legend_pos(pos::Symbol) = get(_plotly_legend_pos, pos, [1.,1.])
plotly_legend_pos{S<:Real, T<:Real}(v::Tuple{S,T}) = v

function plotly_font(font::Font, color = font.color)
KW(
:family => font.family,
Expand All @@ -101,6 +115,7 @@ function plotly_font(font::Font, color = font.color)
)
end


function plotly_annotation_dict(x, y, val; xref="paper", yref="paper")
KW(
:text => val,
Expand Down Expand Up @@ -293,11 +308,14 @@ function plotly_layout(plt::Plot)

# legend
d_out[:showlegend] = sp[:legend] != :none
xpos,ypos = plotly_legend_pos(sp[:legend])
if sp[:legend] != :none
d_out[:legend] = KW(
:bgcolor => rgba_string(sp[:background_color_legend]),
:bordercolor => rgba_string(sp[:foreground_color_legend]),
:font => plotly_font(sp[:legendfont], sp[:foreground_color_legend]),
:x => xpos,
:y => ypos
)
end

Expand Down

0 comments on commit e9ccdef

Please sign in to comment.