From 4bf8e342dc9491ab80857f4cc55c4a92eb3c76c4 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Wed, 20 Apr 2016 14:44:27 -0400 Subject: [PATCH] plotlyjs travis; plotly/plotlyjs polar --- .travis.yml | 23 +++++++++++++++++------ src/backends/plotly.jl | 16 ++++++++++------ src/backends/plotlyjs.jl | 15 ++++++--------- src/backends/supported.jl | 2 ++ test/runtests.jl | 6 +++--- 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index 75be86ac..4d859aaf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,22 @@ # Documentation: http://docs.travis-ci.com/user/languages/julia/ language: julia -os: - - linux - - osx -julia: - - 0.4 - #- nightly +# os: +# - linux +# - osx +# julia: +# - 0.4 +# #- nightly + +# borrowed from Blink.jl's travis file +matrix: + include: + - os: linux + julia: 0.4 + env: TESTCMD="xvfb-run julia" + - os: osx + julia: 0.4 + env: TESTCMD="julia" + notifications: email: true # uncomment the following lines to override the default test script diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 0486cbc0..30d89f4d 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -245,6 +245,10 @@ function plotly_layout(d::KW) d_out[:annotations] = [get_annotation_dict(ann...) for ann in anns] end + if get(d, :polar, false) + d_out[:direction] = "counterclockwise" + end + d_out end @@ -269,7 +273,7 @@ const _plotly_markers = KW( ) # get a dictionary representing the series params (d is the Plots-dict, d_out is the Plotly-dict) -function plotly_series(d::KW; plot_index = nothing) +function plotly_series(d::KW, plotargs::KW; plot_index = nothing) # dumpdict(d,"series",true) d_out = KW() @@ -406,8 +410,8 @@ function plotly_series(d::KW; plot_index = nothing) end # convert polar plots x/y to theta/radius - if get(d, :polar, false) - d_out[:t] = pop!(d_out, :x) + if get(plotargs, :polar, false) + d_out[:t] = rad2deg(pop!(d_out, :x)) d_out[:r] = pop!(d_out, :y) end @@ -422,14 +426,14 @@ end # get a list of dictionaries, each representing the series params function get_series_json(plt::Plot{PlotlyBackend}) - JSON.json(map(plotly_series, plt.seriesargs)) + JSON.json(map(d -> plotly_series(d, plt.plotargs), plt.seriesargs)) end function get_series_json(subplt::Subplot{PlotlyBackend}) ds = KW[] for (i,plt) in enumerate(subplt.plts) for d in plt.seriesargs - push!(ds, plotly_series(d, plot_index = i)) + push!(ds, plotly_series(d, plt.plotargs, plot_index = i)) end end JSON.json(ds) @@ -454,7 +458,7 @@ function html_body(plt::Plot{PlotlyBackend}, style = nothing) Plotly.plot(PLOT, $(get_series_json(plt)), $(get_plot_json(plt))); """ - # @show html + @show html html end diff --git a/src/backends/plotlyjs.jl b/src/backends/plotlyjs.jl index 4291aa20..9bb16d44 100644 --- a/src/backends/plotlyjs.jl +++ b/src/backends/plotlyjs.jl @@ -37,14 +37,11 @@ function _add_series(::PlotlyJSBackend, plt::Plot; kw...) d = KW(kw) syncplot = plt.o - # dumpdict(d, "addseries", true) - # add to the data array - pdict = plotly_series(d) + pdict = plotly_series(d, plt.plotargs) typ = pop!(pdict, :type) gt = PlotlyJS.GenericTrace(typ; pdict...) PlotlyJS.addtraces!(syncplot, gt) - # PlotlyJS.addtraces!(syncplot.plot, gt) push!(plt.seriesargs, d) plt @@ -70,11 +67,9 @@ end # TODO: override this to update plot items (title, xlabel, etc) after creation function _update_plot(plt::Plot{PlotlyJSBackend}, d::KW) pdict = plotly_layout(d) - # dumpdict(pdict, "pdict updateplot", true) syncplot = plt.o w,h = d[:size] PlotlyJS.relayout!(syncplot, pdict, width = w, height = h) - # PlotlyJS.relayout!(syncplot.plot, pdict, width = w, height = h) end @@ -92,10 +87,12 @@ end function setxy!{X,Y}(plt::Plot{PlotlyJSBackend}, xy::Tuple{X,Y}, i::Integer) d = plt.seriesargs[i] - d[:x], d[:y] = xy + ispolar = get(plt.plotargs, :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, plotly_series(d)) - PlotlyJS.restyle!(plt.o, i, KW(:x=>(d[:x],), :y=>(d[:y],))) + PlotlyJS.restyle!(plt.o, i, KW(xsym=>(d[xsym],), ysym=>(d[ysym],))) plt end diff --git a/src/backends/supported.jl b/src/backends/supported.jl index a5eccb20..e166da34 100644 --- a/src/backends/supported.jl +++ b/src/backends/supported.jl @@ -508,6 +508,7 @@ supportedArgs(::PlotlyBackend) = [ :ribbon, :quiver, :orientation, + :polar, ] supportedAxes(::PlotlyBackend) = [:auto, :left] supportedTypes(::PlotlyBackend) = [:none, :line, :path, :scatter, :steppre, :steppost, @@ -583,6 +584,7 @@ supportedArgs(::PlotlyJSBackend) = [ :ribbon, :quiver, :orientation, + :polar, ] supportedAxes(::PlotlyJSBackend) = [:auto, :left] supportedTypes(::PlotlyJSBackend) = [:none, :line, :path, :scatter, :steppre, :steppost, diff --git a/test/runtests.jl b/test/runtests.jl index c9289a12..a0fe86d7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -16,14 +16,14 @@ facts("Gadfly") do @fact plot(sort(rand(10)), rand(Int, 10, 3)) --> not(nothing) @fact plot!(rand(10,3), rand(10,3)) --> not(nothing) - image_comparison_facts(:gadfly, skip=[4,6,19,23,24], eps=img_eps) + image_comparison_facts(:gadfly, skip=[4,6,19,23,24,27], eps=img_eps) end facts("PyPlot") do @fact pyplot() --> Plots.PyPlotBackend() @fact backend() --> Plots.PyPlotBackend() - image_comparison_facts(:pyplot, skip=[4,10,13,19,21,23], eps=img_eps) + image_comparison_facts(:pyplot, skip=[4,10,13,19,21,23,27], eps=img_eps) end facts("GR") do @@ -37,7 +37,7 @@ facts("PlotlyJS") do @fact plotlyjs() --> Plots.PlotlyJSBackend() @fact backend() --> Plots.PlotlyJSBackend() - image_comparison_facts(:plotlyjs, only=[1,2,3,4,7,8,9,10,11,12,14,15,20,22,23,24], eps=img_eps) + image_comparison_facts(:plotlyjs, only=[1,2,3,4,7,8,9,10,11,12,14,15,20,22,23,24,27], eps=img_eps) end FactCheck.exitstatus()