fixes in plotly/plotlyjs; smooth primary false

This commit is contained in:
Thomas Breloff 2016-06-07 01:42:33 -04:00
parent 990314cefc
commit 05fa4a92de
4 changed files with 48 additions and 42 deletions

View File

@ -253,6 +253,7 @@ const _suppress_warnings = Set{Symbol}([
:link, :link,
:plot_object, :plot_object,
:primary, :primary,
:smooth,
]) ])
# add defaults for the letter versions # add defaults for the letter versions

View File

@ -148,7 +148,7 @@ use_axis_field(ticks) = !(ticks in (nothing, :none))
# this method gets the start/end in percentage of the canvas for this axis direction # this method gets the start/end in percentage of the canvas for this axis direction
function plotly_domain(sp::Subplot, letter) function plotly_domain(sp::Subplot, letter)
figw, figh = sp.plt.attr[:size] figw, figh = sp.plt[:size]
pcts = bbox_to_pcts(sp.plotarea, figw*px, figh*px) pcts = bbox_to_pcts(sp.plotarea, figw*px, figh*px)
i1,i2 = (letter == :x ? (1,3) : (2,4)) i1,i2 = (letter == :x ? (1,3) : (2,4))
[pcts[i1], pcts[i1]+pcts[i2]] [pcts[i1], pcts[i1]+pcts[i2]]
@ -157,17 +157,17 @@ end
function plotly_axis(axis::Axis, sp::Subplot) function plotly_axis(axis::Axis, sp::Subplot)
letter = axis[:letter] letter = axis[:letter]
d = axis.d # d = axis.d
ax = KW( ax = KW(
:title => d[:guide], :title => axis[:guide],
:showgrid => sp.attr[:grid], :showgrid => sp[:grid],
:zeroline => false, :zeroline => false,
) )
# fgcolor = webcolor(d[:foreground_color]) # fgcolor = webcolor(axis[:foreground_color])
# tsym = tickssym(letter) # tsym = tickssym(letter)
# spidx = sp.attr[:subplot_index] # spidx = sp[:subplot_index]
# d_out[:xaxis] = "x$spidx" # d_out[:xaxis] = "x$spidx"
# d_out[:yaxis] = "y$spidx" # d_out[:yaxis] = "y$spidx"
if letter in (:x,:y) if letter in (:x,:y)
@ -175,31 +175,31 @@ function plotly_axis(axis::Axis, sp::Subplot)
ax[:anchor] = "$(letter==:x ? :y : :x)$(plotly_subplot_index(sp))" ax[:anchor] = "$(letter==:x ? :y : :x)$(plotly_subplot_index(sp))"
end end
rot = d[:rotation] rot = axis[:rotation]
if rot != 0 if rot != 0
ax[:tickangle] = rot ax[:tickangle] = rot
end end
if use_axis_field(d[:ticks]) if use_axis_field(axis[:ticks])
ax[:titlefont] = plotlyfont(d[:guidefont], webcolor(d[:foreground_color_guide])) ax[:titlefont] = plotlyfont(axis[:guidefont], webcolor(axis[:foreground_color_guide]))
ax[:type] = plotlyscale(d[:scale]) ax[:type] = plotlyscale(axis[:scale])
ax[:tickfont] = plotlyfont(d[:tickfont], webcolor(d[:foreground_color_text])) ax[:tickfont] = plotlyfont(axis[:tickfont], webcolor(axis[:foreground_color_text]))
ax[:tickcolor] = webcolor(d[:foreground_color_border]) ax[:tickcolor] = webcolor(axis[:foreground_color_border])
ax[:linecolor] = webcolor(d[:foreground_color_border]) ax[:linecolor] = webcolor(axis[:foreground_color_border])
# lims # lims
lims = d[:lims] lims = axis[:lims]
if lims != :auto && limsType(lims) == :limits if lims != :auto && limsType(lims) == :limits
ax[:range] = lims ax[:range] = lims
end end
# flip # flip
if d[:flip] if axis[:flip]
ax[:autorange] = "reversed" ax[:autorange] = "reversed"
end end
# ticks # ticks
ticks = d[:ticks] ticks = axis[:ticks]
if ticks != :auto if ticks != :auto
ttype = ticksType(ticks) ttype = ticksType(ticks)
if ttype == :ticks if ttype == :ticks
@ -219,7 +219,7 @@ function plotly_axis(axis::Axis, sp::Subplot)
end end
# function plotly_layout_json(plt::Plot{PlotlyBackend}) # function plotly_layout_json(plt::Plot{PlotlyBackend})
# d = plt.attr # d = plt
# function plotly_layout(d::KW, seriesargs::AVec{KW}) # function plotly_layout(d::KW, seriesargs::AVec{KW})
function plotly_layout(plt::Plot) function plotly_layout(plt::Plot)
d_out = KW() d_out = KW()
@ -230,49 +230,49 @@ function plotly_layout(plt::Plot)
# end # end
# sp = plt.subplots[1] # sp = plt.subplots[1]
d_out[:width], d_out[:height] = plt.attr[:size] d_out[:width], d_out[:height] = plt[:size]
d_out[:paper_bgcolor] = webcolor(plt.attr[:background_color_outside]) d_out[:paper_bgcolor] = webcolor(plt[:background_color_outside])
for sp in plt.subplots for sp in plt.subplots
sp_out = KW() sp_out = KW()
spidx = plotly_subplot_index(sp) spidx = plotly_subplot_index(sp)
# set the fields for the plot # set the fields for the plot
d_out[:title] = sp.attr[:title] d_out[:title] = sp[:title]
d_out[:titlefont] = plotlyfont(sp.attr[:titlefont], webcolor(sp.attr[:foreground_color_title])) d_out[:titlefont] = plotlyfont(sp[:titlefont], webcolor(sp[:foreground_color_title]))
# # TODO: use subplot positioning logic # # TODO: use subplot positioning logic
# d_out[:margin] = KW(:l=>35, :b=>30, :r=>8, :t=>20) # d_out[:margin] = KW(:l=>35, :b=>30, :r=>8, :t=>20)
d_out[:margin] = KW(:l=>0, :b=>0, :r=>0, :t=>30) d_out[:margin] = KW(:l=>0, :b=>0, :r=>0, :t=>30)
d_out[:plot_bgcolor] = webcolor(sp.attr[:background_color_inside]) d_out[:plot_bgcolor] = webcolor(sp[:background_color_inside])
# TODO: x/y axis tick values/labels # TODO: x/y axis tick values/labels
# if any(is3d, seriesargs) # if any(is3d, seriesargs)
if is3d(sp) if is3d(sp)
d_out[:scene] = KW( d_out[:scene] = KW(
Symbol("xaxis$spidx") => plotly_axis(sp.attr[:xaxis], sp), Symbol("xaxis$spidx") => plotly_axis(sp[:xaxis], sp),
Symbol("yaxis$spidx") => plotly_axis(sp.attr[:yaxis], sp), Symbol("yaxis$spidx") => plotly_axis(sp[:yaxis], sp),
Symbol("zaxis$spidx") => plotly_axis(sp.attr[:zaxis], sp), Symbol("zaxis$spidx") => plotly_axis(sp[:zaxis], sp),
) )
else else
d_out[Symbol("xaxis$spidx")] = plotly_axis(sp.attr[:xaxis], sp) d_out[Symbol("xaxis$spidx")] = plotly_axis(sp[:xaxis], sp)
d_out[Symbol("yaxis$spidx")] = plotly_axis(sp.attr[:yaxis], sp) d_out[Symbol("yaxis$spidx")] = plotly_axis(sp[:yaxis], sp)
end end
# legend # legend
d_out[:showlegend] = sp.attr[:legend] != :none d_out[:showlegend] = sp[:legend] != :none
if sp.attr[:legend] != :none if sp[:legend] != :none
d_out[:legend] = KW( d_out[:legend] = KW(
:bgcolor => webcolor(sp.attr[:background_color_legend]), :bgcolor => webcolor(sp[:background_color_legend]),
:bordercolor => webcolor(sp.attr[:foreground_color_legend]), :bordercolor => webcolor(sp[:foreground_color_legend]),
:font => plotlyfont(sp.attr[:legendfont]), :font => plotlyfont(sp[:legendfont]),
) )
end end
# annotations # annotations
anns = get(sp.attr, :annotations, []) anns = sp[:annotations]
d_out[:annotations] = if isempty(anns) d_out[:annotations] = if isempty(anns)
KW[] KW[]
else else
@ -322,7 +322,7 @@ const _plotly_markers = KW(
) )
function plotly_subplot_index(sp::Subplot) function plotly_subplot_index(sp::Subplot)
spidx = sp.attr[:subplot_index] spidx = sp[:subplot_index]
spidx == 1 ? "" : spidx spidx == 1 ? "" : spidx
end end
@ -375,6 +375,7 @@ function plotly_series(plt::Plot, series::Series)
end end
d_out[:nbinsx] = xbins d_out[:nbinsx] = xbins
d_out[:nbinsy] = ybins d_out[:nbinsy] = ybins
d_out[:colorscale] = plotly_colorscale(d[:fillcolor], d[:fillalpha])
elseif st in (:histogram, :density) elseif st in (:histogram, :density)
d_out[:type] = "histogram" d_out[:type] = "histogram"
@ -387,14 +388,16 @@ function plotly_series(plt::Plot, series::Series)
elseif st == :heatmap elseif st == :heatmap
d_out[:type] = "heatmap" d_out[:type] = "heatmap"
d_out[:x], d_out[:y] = x, y # d_out[:x], d_out[:y] = x, y
d_out[:z] = d[:z].surf # d_out[:z] = d[:z].surf
d_out[:x], d_out[:y], d_out[:z] = d[:x], d[:y], transpose_z(d, d[:z].surf, false)
d_out[:colorscale] = plotly_colorscale(d[:fillcolor], d[:fillalpha]) d_out[:colorscale] = plotly_colorscale(d[:fillcolor], d[:fillalpha])
elseif st == :contour elseif st == :contour
d_out[:type] = "contour" d_out[:type] = "contour"
d_out[:x], d_out[:y] = x, y # d_out[:x], d_out[:y] = x, y
d_out[:z] = d[:z].surf # d_out[:z] = d[:z].surf
d_out[:x], d_out[:y], d_out[:z] = d[:x], d[:y], transpose_z(d, d[:z].surf, false)
# d_out[:showscale] = d[:colorbar] != :none # d_out[:showscale] = d[:colorbar] != :none
d_out[:ncontours] = d[:levels] d_out[:ncontours] = d[:levels]
d_out[:contours] = KW(:coloring => d[:fillrange] != nothing ? "fill" : "lines") d_out[:contours] = KW(:coloring => d[:fillrange] != nothing ? "fill" : "lines")
@ -402,8 +405,9 @@ function plotly_series(plt::Plot, series::Series)
elseif st in (:surface, :wireframe) elseif st in (:surface, :wireframe)
d_out[:type] = "surface" d_out[:type] = "surface"
d_out[:x], d_out[:y] = x, y # d_out[:x], d_out[:y] = x, y
d_out[:z] = d[:z].surf # d_out[:z] = d[:z].surf
d_out[:x], d_out[:y], d_out[:z] = d[:x], d[:y], transpose_z(d, d[:z].surf, false)
d_out[:colorscale] = plotly_colorscale(d[:fillcolor], d[:fillalpha]) d_out[:colorscale] = plotly_colorscale(d[:fillcolor], d[:fillalpha])
elseif st == :pie elseif st == :pie
@ -490,7 +494,7 @@ end
function html_body(plt::Plot{PlotlyBackend}, style = nothing) function html_body(plt::Plot{PlotlyBackend}, style = nothing)
if style == nothing if style == nothing
w, h = plt.attr[:size] w, h = plt[:size]
style = "width:$(w)px;height:$(h)px;" style = "width:$(w)px;height:$(h)px;"
end end
uuid = Base.Random.uuid4() uuid = Base.Random.uuid4()

View File

@ -137,7 +137,7 @@ end
function _update_plot_object(plt::Plot{PlotlyJSBackend}) function _update_plot_object(plt::Plot{PlotlyJSBackend})
pdict = plotly_layout(plt) pdict = plotly_layout(plt)
syncplot = plt.o syncplot = plt.o
w,h = plt.attr[:size] w,h = plt[:size]
# DD(pdict) # DD(pdict)
PlotlyJS.relayout!(syncplot, pdict, width = w, height = h) PlotlyJS.relayout!(syncplot, pdict, width = w, height = h)
end end

View File

@ -290,6 +290,7 @@ function _plot!(plt::Plot, d::KW, args...)
:y => sy, :y => sy,
:fillrange => nothing, :fillrange => nothing,
:label => "", :label => "",
:primary => false,
))) )))
# don't allow something else to handle it # don't allow something else to handle it