From bdce27dd7bb9e165bb5c982585dcbf1284cf7116 Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Sun, 20 Nov 2016 15:20:59 +0000 Subject: [PATCH] Implemented legend position in plotly --- src/args.jl | 1 + src/backends/plotly.jl | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/args.jl b/src/args.jl index ab27323b3..119dd1252 100644 --- a/src/args.jl +++ b/src/args.jl @@ -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) # ----------------------------------------------------------------------------- diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 2b3528a0c..c5c8dedfa 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -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, @@ -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, @@ -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