From 948ac37fa4d3a7298f9b52b5a0577b276efe644a Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Mon, 29 May 2017 21:01:59 +0200 Subject: [PATCH 01/20] added image comparison tests for plotlyjs and inspectdr --- test/runtests.jl | 68 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 94f95a1b..cfb43c27 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -19,30 +19,70 @@ img_eps = isinteractive() ? 1e-2 : 10e-2 # image_comparison_facts(:gadfly, skip=[4,6,23,24,27], eps=img_eps) # end -facts("PyPlot") do - @fact pyplot() --> Plots.PyPlotBackend() - @fact backend() --> Plots.PyPlotBackend() - - image_comparison_facts(:pyplot, skip=[6,25,30,31], eps=img_eps) -end +# facts("GR") do +# @fact gr() --> Plots.GRBackend() +# @fact backend() --> Plots.GRBackend() +# +# if is_linux() && isinteractive() +# image_comparison_facts(:gr, eps=img_eps) +# end +# end facts("GR") do @fact gr() --> Plots.GRBackend() @fact backend() --> Plots.GRBackend() - if is_linux() && isinteractive() - image_comparison_facts(:gr, skip=[2,25,30,31], eps=img_eps) - end + image_comparison_facts(:gr, + skip=[ + 13, # :rtriangle not found + ], + eps=img_eps) end -facts("Plotly") do - @fact plotly() --> Plots.PlotlyBackend() - @fact backend() --> Plots.PlotlyBackend() +facts("PyPlot") do + @fact pyplot() --> Plots.PyPlotBackend() + @fact backend() --> Plots.PyPlotBackend() - # # until png generation is reliable on OSX, just test on linux - # @static is_linux() && image_comparison_facts(:plotly, only=[1,3,4,7,8,9,10,11,12,14,15,20,22,23,27], eps=img_eps) + image_comparison_facts(:pyplot, skip=[2,31], eps=img_eps) end +facts("PlotlyJS") do + @fact plotlyjs() --> Plots.PlotlyJSBackend() + @fact backend() --> Plots.PlotlyJSBackend() + + image_comparison_facts(:plotlyjs, + skip=[ + 2, # animation + 10, # match_dimensions not defined + 27, # (polar plots) takes very long / not working + 31, # animation + ], + eps=img_eps) +end + +facts("InspectDR") do + @fact inspectdr() --> Plots.InspectDRBackend() + @fact backend() --> Plots.InspectDRBackend() + + image_comparison_facts(:inspectdr, + skip=[ + 6, # heatmap not defined + 10, # heatmap not defined + 22, # contour not defined + 23, # pie not defined + 28, # heatmap not defined + ], + eps=img_eps) +end + +# facts("Plotly") do +# @fact plotly() --> Plots.PlotlyBackend() +# @fact backend() --> Plots.PlotlyBackend() +# +# # # until png generation is reliable on OSX, just test on linux +# # @static is_linux() && image_comparison_facts(:plotly, only=[1,3,4,7,8,9,10,11,12,14,15,20,22,23,27], eps=img_eps) +# image_comparison_facts(:plotly, eps=img_eps) +# end # facts("Immerse") do # @fact immerse() --> Plots.ImmerseBackend() From e999d67e86b494c193a46c62e3edee462ca94500 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 31 May 2017 18:50:32 +0200 Subject: [PATCH 02/20] added image comparison tests for plotlyjs and inspectdr --- test/runtests.jl | 68 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 94f95a1b..cfb43c27 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -19,30 +19,70 @@ img_eps = isinteractive() ? 1e-2 : 10e-2 # image_comparison_facts(:gadfly, skip=[4,6,23,24,27], eps=img_eps) # end -facts("PyPlot") do - @fact pyplot() --> Plots.PyPlotBackend() - @fact backend() --> Plots.PyPlotBackend() - - image_comparison_facts(:pyplot, skip=[6,25,30,31], eps=img_eps) -end +# facts("GR") do +# @fact gr() --> Plots.GRBackend() +# @fact backend() --> Plots.GRBackend() +# +# if is_linux() && isinteractive() +# image_comparison_facts(:gr, eps=img_eps) +# end +# end facts("GR") do @fact gr() --> Plots.GRBackend() @fact backend() --> Plots.GRBackend() - if is_linux() && isinteractive() - image_comparison_facts(:gr, skip=[2,25,30,31], eps=img_eps) - end + image_comparison_facts(:gr, + skip=[ + 13, # :rtriangle not found + ], + eps=img_eps) end -facts("Plotly") do - @fact plotly() --> Plots.PlotlyBackend() - @fact backend() --> Plots.PlotlyBackend() +facts("PyPlot") do + @fact pyplot() --> Plots.PyPlotBackend() + @fact backend() --> Plots.PyPlotBackend() - # # until png generation is reliable on OSX, just test on linux - # @static is_linux() && image_comparison_facts(:plotly, only=[1,3,4,7,8,9,10,11,12,14,15,20,22,23,27], eps=img_eps) + image_comparison_facts(:pyplot, skip=[2,31], eps=img_eps) end +facts("PlotlyJS") do + @fact plotlyjs() --> Plots.PlotlyJSBackend() + @fact backend() --> Plots.PlotlyJSBackend() + + image_comparison_facts(:plotlyjs, + skip=[ + 2, # animation + 10, # match_dimensions not defined + 27, # (polar plots) takes very long / not working + 31, # animation + ], + eps=img_eps) +end + +facts("InspectDR") do + @fact inspectdr() --> Plots.InspectDRBackend() + @fact backend() --> Plots.InspectDRBackend() + + image_comparison_facts(:inspectdr, + skip=[ + 6, # heatmap not defined + 10, # heatmap not defined + 22, # contour not defined + 23, # pie not defined + 28, # heatmap not defined + ], + eps=img_eps) +end + +# facts("Plotly") do +# @fact plotly() --> Plots.PlotlyBackend() +# @fact backend() --> Plots.PlotlyBackend() +# +# # # until png generation is reliable on OSX, just test on linux +# # @static is_linux() && image_comparison_facts(:plotly, only=[1,3,4,7,8,9,10,11,12,14,15,20,22,23,27], eps=img_eps) +# image_comparison_facts(:plotly, eps=img_eps) +# end # facts("Immerse") do # @fact immerse() --> Plots.ImmerseBackend() From 5b3ce8ab73c309be74fe46ceaed1b5d3b40f284e Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 31 May 2017 19:37:04 +0200 Subject: [PATCH 03/20] restored former version --- test/runtests.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index cfb43c27..476fcd12 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -33,9 +33,9 @@ facts("GR") do @fact backend() --> Plots.GRBackend() image_comparison_facts(:gr, - skip=[ - 13, # :rtriangle not found - ], + # skip=[ + # 13, # :rtriangle not found + # ], eps=img_eps) end From 3c6d8e1ec9246b239544151f55d85ff7382641d6 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 31 May 2017 20:03:52 +0200 Subject: [PATCH 04/20] added packages in test/travis_commands.jl --- test/runtests.jl | 17 +++-------------- test/travis_commands.jl | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 476fcd12..c44ea244 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -19,24 +19,13 @@ img_eps = isinteractive() ? 1e-2 : 10e-2 # image_comparison_facts(:gadfly, skip=[4,6,23,24,27], eps=img_eps) # end -# facts("GR") do -# @fact gr() --> Plots.GRBackend() -# @fact backend() --> Plots.GRBackend() -# -# if is_linux() && isinteractive() -# image_comparison_facts(:gr, eps=img_eps) -# end -# end - facts("GR") do @fact gr() --> Plots.GRBackend() @fact backend() --> Plots.GRBackend() - image_comparison_facts(:gr, - # skip=[ - # 13, # :rtriangle not found - # ], - eps=img_eps) + if is_linux() # && isinteractive() + image_comparison_facts(:gr, eps=img_eps) + end end facts("PyPlot") do diff --git a/test/travis_commands.jl b/test/travis_commands.jl index d0ff84bd..e9e9deed 100644 --- a/test/travis_commands.jl +++ b/test/travis_commands.jl @@ -1,8 +1,8 @@ -# Pkg.clone("ImageMagick") -# Pkg.build("ImageMagick") +Pkg.clone("ImageMagick") +Pkg.build("ImageMagick") -# Pkg.clone("GR") -# Pkg.build("GR") +Pkg.clone("GR") +Pkg.build("GR") Pkg.clone("https://github.com/JuliaPlots/PlotReferenceImages.jl.git") @@ -11,11 +11,12 @@ Pkg.clone("https://github.com/JuliaPlots/PlotReferenceImages.jl.git") Pkg.clone("StatPlots") Pkg.checkout("PlotUtils") -# Pkg.clone("https://github.com/JunoLab/Blink.jl.git") -# Pkg.build("Blink") -# import Blink -# Blink.AtomShell.install() -# Pkg.clone("https://github.com/spencerlyon2/PlotlyJS.jl.git") +Pkg.clone("Blink") +Pkg.build("Blink") +using Blink +Blink.AtomShell.install() +Pkg.add("Rsvg") +Pkg.clone("PlotlyJS") # Pkg.checkout("RecipesBase") # Pkg.clone("VisualRegressionTests") @@ -25,4 +26,6 @@ ENV["PYTHON"] = "" Pkg.add("PyPlot") Pkg.build("PyPlot") +Pkg.add("InspectDR") + Pkg.test("Plots"; coverage=false) From 69e88a519c7cf047ace43484ffe22c3a70c3b6b6 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 31 May 2017 20:16:17 +0200 Subject: [PATCH 05/20] run tests on linux only for plotljs and on all platforms for gr --- test/runtests.jl | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index c44ea244..73ae5f41 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -23,9 +23,7 @@ facts("GR") do @fact gr() --> Plots.GRBackend() @fact backend() --> Plots.GRBackend() - if is_linux() # && isinteractive() - image_comparison_facts(:gr, eps=img_eps) - end + image_comparison_facts(:gr, eps=img_eps) end facts("PyPlot") do @@ -39,14 +37,16 @@ facts("PlotlyJS") do @fact plotlyjs() --> Plots.PlotlyJSBackend() @fact backend() --> Plots.PlotlyJSBackend() - image_comparison_facts(:plotlyjs, - skip=[ - 2, # animation - 10, # match_dimensions not defined - 27, # (polar plots) takes very long / not working - 31, # animation - ], - eps=img_eps) + if is_linux() + image_comparison_facts(:plotlyjs, + skip=[ + 2, # animation + 10, # match_dimensions not defined + 27, # (polar plots) takes very long / not working + 31, # animation + ], + eps=img_eps) + end end facts("InspectDR") do From 09bfa03a2ec1cac93e19ee2d04f6981c2e88b30a Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Tue, 23 May 2017 16:41:18 +0200 Subject: [PATCH 06/20] remove clean up code, switch to renderloop --- src/backends/glvisualize.jl | 42 ++----------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index e97d81fd..c28bfd31 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -98,41 +98,6 @@ end # end const _glplot_deletes = [] -function close_child_signals!(screen) - for child in screen.children - for (k, s) in child.inputs - empty!(s.actions) - end - for (k, cam) in child.cameras - for f in fieldnames(cam) - s = getfield(cam, f) - if isa(s, Signal) - close(s, false) - end - end - end - empty!(child.cameras) - close_child_signals!(child) - end - return -end -function empty_screen!(screen) - if isempty(_glplot_deletes) - close_child_signals!(screen) - empty!(screen) - empty!(screen.cameras) - for (k, s) in screen.inputs - empty!(s.actions) - end - empty!(screen) - else - for del_signal in _glplot_deletes - push!(del_signal, true) # trigger delete - end - empty!(_glplot_deletes) - end - nothing -end function get_plot_screen(list::Vector, name, result = []) for elem in list @@ -158,7 +123,7 @@ function create_window(plt::Plot{GLVisualizeBackend}, visible) resolution = plt[:size], visible = visible ) - @async GLWindow.waiting_renderloop(parent_screen) + @async GLWindow.renderloop(parent_screen) GLVisualize.add_screen(parent_screen) end # now lets get ourselves a permanent Plotting screen @@ -169,9 +134,6 @@ function create_window(plt::Plot{GLVisualizeBackend}, visible) parent, area = map(GLWindow.zeroposition, parent.area), name = name ) - for (k, s) in screen.inputs # copy signals, so we can clean them up better - screen.inputs[k] = map(identity, s) - end screen elseif length(plot_screens) == 1 plot_screens[1] @@ -181,7 +143,7 @@ function create_window(plt::Plot{GLVisualizeBackend}, visible) error("multiple Plot screens. Please don't use any screen with the name $name") end # Since we own this window, we can do deep cleansing - empty_screen!(screen) + empty!(screen) plt.o = screen GLWindow.set_visibility!(screen, visible) resize!(screen, plt[:size]...) From fb0be4ef8982ce9d73924a01c6f03c37429d8154 Mon Sep 17 00:00:00 2001 From: Oliver Schulz Date: Wed, 31 May 2017 23:04:39 +0200 Subject: [PATCH 07/20] Remove remnant debug output about binning --- src/recipes.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/recipes.jl b/src/recipes.jl index 1bc4cad5..d3fe10fa 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -589,7 +589,6 @@ _hist_norm_mode(mode::Symbol) = mode _hist_norm_mode(mode::Bool) = mode ? :pdf : :none function _make_hist{N}(vs::NTuple{N,AbstractVector}, binning; normed = false, weights = nothing) - info("binning = $binning") edges = _hist_edges(vs, binning) h = float( weights == nothing ? StatsBase.fit(StatsBase.Histogram, vs, edges, closed = :left) : From 83d6b5888f6618953ef036939cc2fa24d0b415f3 Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 1 Jun 2017 11:55:43 +0200 Subject: [PATCH 08/20] Change installation message --- src/backends/glvisualize.jl | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index c28bfd31..b1f5663c 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -77,14 +77,9 @@ end function add_backend_string(b::GLVisualizeBackend) """ - For those incredibly brave souls who assume full responsibility for what happens next... - There's an easy way to get what you need for the GLVisualize backend to work (until Pkg3 is usable): - - Pkg.clone("https://github.com/tbreloff/MetaPkg.jl") - using MetaPkg - meta_checkout("MetaGL") - - See the MetaPkg readme for details... + if !Plots.is_installed("GLVisualize") + Pkg.add("PyPlot") + end """ end From eb40120e2a29c7e28122467852f22c0f45f2702a Mon Sep 17 00:00:00 2001 From: Michael Krabbe Borregaard Date: Thu, 1 Jun 2017 17:10:03 +0200 Subject: [PATCH 09/20] Fixed writing error. --- src/backends/glvisualize.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index b1f5663c..f5168e16 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -78,7 +78,7 @@ end function add_backend_string(b::GLVisualizeBackend) """ if !Plots.is_installed("GLVisualize") - Pkg.add("PyPlot") + Pkg.add("GLVisualize") end """ end From 537f1657c9aba523a8f0e5d0fe1382a14ba1c5ef Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 1 Jun 2017 18:42:06 +0200 Subject: [PATCH 10/20] add description why images are skipped --- test/runtests.jl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 73ae5f41..3135e113 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -30,7 +30,12 @@ facts("PyPlot") do @fact pyplot() --> Plots.PyPlotBackend() @fact backend() --> Plots.PyPlotBackend() - image_comparison_facts(:pyplot, skip=[2,31], eps=img_eps) + image_comparison_facts(:pyplot, + skip=[ + 2, # animation (skipped for speed) + 31, # animation (skipped for speed) + ], + eps=img_eps) end facts("PlotlyJS") do @@ -40,10 +45,10 @@ facts("PlotlyJS") do if is_linux() image_comparison_facts(:plotlyjs, skip=[ - 2, # animation + 2, # animation (skipped for speed) 10, # match_dimensions not defined 27, # (polar plots) takes very long / not working - 31, # animation + 31, # animation (skipped for speed) ], eps=img_eps) end From 728acdaa476f16e95d4f4d0f7dfe73349c52672a Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 1 Jun 2017 18:55:38 +0200 Subject: [PATCH 11/20] add images to skip for inspectdr and avoid skipping plotlyjs testimage 10 --- test/runtests.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 3135e113..dbc1cdd7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -46,7 +46,6 @@ facts("PlotlyJS") do image_comparison_facts(:plotlyjs, skip=[ 2, # animation (skipped for speed) - 10, # match_dimensions not defined 27, # (polar plots) takes very long / not working 31, # animation (skipped for speed) ], @@ -60,11 +59,14 @@ facts("InspectDR") do image_comparison_facts(:inspectdr, skip=[ + 2, # animation 6, # heatmap not defined 10, # heatmap not defined 22, # contour not defined 23, # pie not defined + 27, # polar plot not working 28, # heatmap not defined + 31, # animation ], eps=img_eps) end From e530a9f95039c20bf08bfe5b8b3b4559e782663f Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 1 Jun 2017 18:59:20 +0200 Subject: [PATCH 12/20] remove in imgcomp.jl because its reexported by StatPlots --- test/imgcomp.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/imgcomp.jl b/test/imgcomp.jl index 890c374b..1934e6b6 100644 --- a/test/imgcomp.jl +++ b/test/imgcomp.jl @@ -13,7 +13,7 @@ try end -using Plots +# using Plots # reexported by StatPlots using StatPlots using FactCheck using Glob From f65e5dcfb9a90e908d2ca1962cb80296ef5973b4 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 1 Jun 2017 19:04:05 +0200 Subject: [PATCH 13/20] changed wkhtmltox download link --- test/install_wkhtmltoimage.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/install_wkhtmltoimage.sh b/test/install_wkhtmltoimage.sh index b265d183..11fc27e5 100755 --- a/test/install_wkhtmltoimage.sh +++ b/test/install_wkhtmltoimage.sh @@ -6,8 +6,10 @@ sudo apt-get -qq update # sudo apt-get install -y wkhtmltopdf sudo apt-get install -y xfonts-75dpi -wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2/wkhtmltox-0.12.2_linux-trusty-amd64.deb -sudo dpkg -i wkhtmltox-0.12.2_linux-trusty-amd64.deb +wget https://downloads.wkhtmltopdf.org/0.12/0.12.2/wkhtmltox-0.12.2_linux-precise-amd64.deb +sudo dpkg -i wkhtmltox-0.12.2_linux-precise-amd64.deb +# wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2/wkhtmltox-0.12.2_linux-trusty-amd64.deb +# sudo dpkg -i wkhtmltox-0.12.2_linux-trusty-amd64.deb wkhtmltoimage http://www.google.com test.png ls From 0e6479de5ede5ff00ea9ca797ae2e98dff969dfe Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 1 Jun 2017 19:15:13 +0200 Subject: [PATCH 14/20] install xfonts-base --- test/install_wkhtmltoimage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/install_wkhtmltoimage.sh b/test/install_wkhtmltoimage.sh index 11fc27e5..061cf606 100755 --- a/test/install_wkhtmltoimage.sh +++ b/test/install_wkhtmltoimage.sh @@ -5,7 +5,7 @@ set -ex sudo apt-get -qq update # sudo apt-get install -y wkhtmltopdf -sudo apt-get install -y xfonts-75dpi +sudo apt-get install -y xfonts-75dpi xfonts-base wget https://downloads.wkhtmltopdf.org/0.12/0.12.2/wkhtmltox-0.12.2_linux-precise-amd64.deb sudo dpkg -i wkhtmltox-0.12.2_linux-precise-amd64.deb # wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2/wkhtmltox-0.12.2_linux-trusty-amd64.deb From cd1e431a71069f003e714743234f07be799144b1 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 1 Jun 2017 19:35:22 +0200 Subject: [PATCH 15/20] import Blink in travis_commands.jl --- test/travis_commands.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/travis_commands.jl b/test/travis_commands.jl index e9e9deed..423604fa 100644 --- a/test/travis_commands.jl +++ b/test/travis_commands.jl @@ -13,7 +13,7 @@ Pkg.checkout("PlotUtils") Pkg.clone("Blink") Pkg.build("Blink") -using Blink +import Blink Blink.AtomShell.install() Pkg.add("Rsvg") Pkg.clone("PlotlyJS") From 9e3c3f29bff8f71762cd308a558ef26f95734203 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 1 Jun 2017 19:57:06 +0200 Subject: [PATCH 16/20] Pkg.add(PlotlyJS) in travis_commands.jl --- test/travis_commands.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/travis_commands.jl b/test/travis_commands.jl index 423604fa..8340703f 100644 --- a/test/travis_commands.jl +++ b/test/travis_commands.jl @@ -16,7 +16,7 @@ Pkg.build("Blink") import Blink Blink.AtomShell.install() Pkg.add("Rsvg") -Pkg.clone("PlotlyJS") +Pkg.add("PlotlyJS") # Pkg.checkout("RecipesBase") # Pkg.clone("VisualRegressionTests") From 423d0387c5161d611604d8e616904ed87235f089 Mon Sep 17 00:00:00 2001 From: Michael Krabbe Borregaard Date: Thu, 1 Jun 2017 19:17:28 +0200 Subject: [PATCH 17/20] RFC: Ignore NaNs on 0.6 (like on 0.5): fixes #796 (#876) Replaces min, max, minimum, mean, maximum and extrema with NaNMath versions in places where NaNs can occur. To avoid returning NaN when there are NaNs in the Vector * Also add maximum and minimum * define _-prefaced versions of mean, maximum, minimum, extrema * variable arg numbers for Base methods * Different implementation of the override * remove underscore from 2-arg versions of maximum * some forgotten extrema -> _extrema * Fix bug in _extrema definition * edit comment * replace min and max with _min and _max * Base NaN-compliant functions on NaNMath replace _min and _max with NaNMath versions * Use NaNMath explicitly everywhere * remove unneccesary NaNMath calls * Ensure ceil does not error on NaN * Added one more maximum in gr --- REQUIRE | 1 + src/Plots.jl | 1 + src/axes.jl | 22 +++++++++++----------- src/backends/glvisualize.jl | 20 ++++++++++---------- src/backends/gr.jl | 8 ++++---- src/backends/inspectdr.jl | 2 +- src/backends/plotly.jl | 2 +- src/backends/pyplot.jl | 12 ++++++------ src/components.jl | 8 ++++---- src/layouts.jl | 2 +- src/pipeline.jl | 2 +- src/recipes.jl | 22 +++++++++++----------- src/utils.jl | 28 ++++++++++++++-------------- test/runtests.jl | 4 ++-- 14 files changed, 68 insertions(+), 66 deletions(-) diff --git a/REQUIRE b/REQUIRE index 22f785ac..2f70e7f9 100644 --- a/REQUIRE +++ b/REQUIRE @@ -9,3 +9,4 @@ Measures Showoff StatsBase 0.14.0 JSON +NaNMath diff --git a/src/Plots.jl b/src/Plots.jl index 7e630ad7..4842a039 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -10,6 +10,7 @@ using Base.Meta @reexport using PlotThemes import Showoff import StatsBase +import NaNMath # define functions that ignores NaNs. To overcome the destructive effects of https://github.com/JuliaLang/julia/pull/12563 export grid, diff --git a/src/axes.jl b/src/axes.jl index a5882d9a..0d855190 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -118,7 +118,7 @@ Base.show(io::IO, axis::Axis) = dumpdict(axis.d, "Axis", true) # Base.getindex(axis::Axis, k::Symbol) = getindex(axis.d, k) Base.setindex!(axis::Axis, v, ks::Symbol...) = setindex!(axis.d, v, ks...) Base.haskey(axis::Axis, k::Symbol) = haskey(axis.d, k) -Base.extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax)) +NaNMath.extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax)) const _scale_funcs = Dict{Symbol,Function}( @@ -260,8 +260,8 @@ end function expand_extrema!(ex::Extrema, v::Number) - ex.emin = min(v, ex.emin) - ex.emax = max(v, ex.emax) + ex.emin = NaNMath.min(v, ex.emin) + ex.emax = NaNMath.max(v, ex.emax) ex end @@ -276,8 +276,8 @@ expand_extrema!(axis::Axis, ::Bool) = axis[:extrema] function expand_extrema!{MIN<:Number,MAX<:Number}(axis::Axis, v::Tuple{MIN,MAX}) ex = axis[:extrema] - ex.emin = min(v[1], ex.emin) - ex.emax = max(v[2], ex.emax) + ex.emin = NaNMath.min(v[1], ex.emin) + ex.emax = NaNMath.max(v[2], ex.emax) ex end function expand_extrema!{N<:Number}(axis::Axis, v::AVec{N}) @@ -349,11 +349,11 @@ function expand_extrema!(sp::Subplot, d::KW) bw = d[:bar_width] if bw == nothing - bw = d[:bar_width] = mean(diff(data)) + bw = d[:bar_width] = NaNMath.mean(diff(data)) end axis = sp.attr[Symbol(dsym, :axis)] - expand_extrema!(axis, maximum(data) + 0.5maximum(bw)) - expand_extrema!(axis, minimum(data) - 0.5minimum(bw)) + expand_extrema!(axis, NaNMath.maximum(data) + 0.5maximum(bw)) + expand_extrema!(axis, NaNMath.minimum(data) - 0.5minimum(bw)) end end @@ -368,8 +368,8 @@ end # push the limits out slightly function widen(lmin, lmax) span = lmax - lmin - # eps = max(1e-16, min(1e-2span, 1e-10)) - eps = max(1e-16, 0.03span) + # eps = NaNMath.max(1e-16, min(1e-2span, 1e-10)) + eps = NaNMath.max(1e-16, 0.03span) lmin-eps, lmax+eps end @@ -425,7 +425,7 @@ function discrete_value!(axis::Axis, dv) # @show axis[:discrete_map], axis[:discrete_values], dv if cv_idx == -1 ex = axis[:extrema] - cv = max(0.5, ex.emax + 1.0) + cv = NaNMath.max(0.5, ex.emax + 1.0) expand_extrema!(axis, cv) push!(axis[:discrete_values], dv) push!(axis[:continuous_values], cv) diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index f5168e16..c09fcab0 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -304,7 +304,7 @@ function extract_any_color(d, kw_args) kw_args[:color_norm] = Vec2f0(clims) end elseif clims == :auto - kw_args[:color_norm] = Vec2f0(extrema(d[:y])) + kw_args[:color_norm] = Vec2f0(NaNMath.extrema(d[:y])) end end else @@ -315,7 +315,7 @@ function extract_any_color(d, kw_args) kw_args[:color_norm] = Vec2f0(clims) end elseif clims == :auto - kw_args[:color_norm] = Vec2f0(extrema(d[:y])) + kw_args[:color_norm] = Vec2f0(NaNMath.extrema(d[:y])) else error("Unsupported limits: $clims") end @@ -367,14 +367,14 @@ end dist(a, b) = abs(a-b) -mindist(x, a, b) = min(dist(a, x), dist(b, x)) +mindist(x, a, b) = NaNMath.min(dist(a, x), dist(b, x)) function gappy(x, ps) n = length(ps) x <= first(ps) && return first(ps) - x for j=1:(n-1) p0 = ps[j] - p1 = ps[min(j+1, n)] + p1 = ps[NaNMath.min(j+1, n)] if p0 <= x && p1 >= x return mindist(x, p0, p1) * (isodd(j) ? 1 : -1) end @@ -482,7 +482,7 @@ function hover(to_hover, to_display, window) end function extract_extrema(d, kw_args) - xmin, xmax = extrema(d[:x]); ymin, ymax = extrema(d[:y]) + xmin, xmax = NaNMath.extrema(d[:x]); ymin, ymax = NaNMath.extrema(d[:y]) kw_args[:primitive] = GeometryTypes.SimpleRectangle{Float32}(xmin, ymin, xmax-xmin, ymax-ymin) nothing end @@ -509,7 +509,7 @@ function extract_colornorm(d, kw_args) else d[:y] end - kw_args[:color_norm] = Vec2f0(extrema(z)) + kw_args[:color_norm] = Vec2f0(NaNMath.extrema(z)) kw_args[:intensity] = map(Float32, collect(z)) end end @@ -781,7 +781,7 @@ function gl_bar(d, kw_args) # compute half-width of bars bw = nothing hw = if bw == nothing - mean(diff(x)) + NaNMath.mean(diff(x)) else Float64[cycle(bw,i)*0.5 for i=1:length(x)] end @@ -864,7 +864,7 @@ function gl_boxplot(d, kw_args) end # change q1 and q5 to show outliers # using maximum and minimum values inside the limits - q1, q5 = extrema(inside) + q1, q5 = NaNMath.extrema(inside) end # Box if notch @@ -1318,7 +1318,7 @@ function gl_contour(x, y, z, kw_args) T = eltype(z) levels = Contour.contours(map(T, x), map(T, y), z, h) result = Point2f0[] - zmin, zmax = get(kw_args, :limits, Vec2f0(extrema(z))) + zmin, zmax = get(kw_args, :limits, Vec2f0(NaNMath.extrema(z))) cmap = get(kw_args, :color_map, get(kw_args, :color, RGBA{Float32}(0,0,0,1))) colors = RGBA{Float32}[] for c in levels.contours @@ -1339,7 +1339,7 @@ end function gl_heatmap(x,y,z, kw_args) - get!(kw_args, :color_norm, Vec2f0(extrema(z))) + get!(kw_args, :color_norm, Vec2f0(NaNMath.extrema(z))) get!(kw_args, :color_map, Plots.make_gradient(cgrad())) delete!(kw_args, :intensity) I = GLVisualize.Intensity{1, Float32} diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 9958e0a5..0c34b5d4 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -264,7 +264,7 @@ end normalize_zvals(zv::Void) = zv function normalize_zvals(zv::AVec) - vmin, vmax = extrema(zv) + vmin, vmax = NaNMath.extrema(zv) if vmin == vmax zeros(length(zv)) else @@ -428,7 +428,7 @@ function gr_set_viewport_polar() ymax -= 0.05 * (xmax - xmin) xcenter = 0.5 * (xmin + xmax) ycenter = 0.5 * (ymin + ymax) - r = 0.5 * min(xmax - xmin, ymax - ymin) + r = 0.5 * NaNMath.min(xmax - xmin, ymax - ymin) GR.setviewport(xcenter -r, xcenter + r, ycenter - r, ycenter + r) GR.setwindow(-1, 1, -1, 1) r @@ -639,7 +639,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) elseif ispolar(sp) r = gr_set_viewport_polar() - rmin, rmax = GR.adjustrange(minimum(r), maximum(r)) + rmin, rmax = GR.adjustrange(NaNMath.minimum(r), NaNMath.maximum(r)) # rmin, rmax = axis_limits(sp[:yaxis]) gr_polaraxes(rmin, rmax) @@ -824,7 +824,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # create the colorbar of contour levels if sp[:colorbar] != :none gr_set_viewport_cmap(sp) - l = round(Int32, 1000 + (h - minimum(h)) / (maximum(h) - minimum(h)) * 255) + l = round(Int32, 1000 + (h - NaNMath.minimum(h)) / (NaNMath.maximum(h) - NaNMath.minimum(h)) * 255) GR.setwindow(xmin, xmax, zmin, zmax) GR.cellarray(xmin, xmax, zmax, zmin, 1, length(l), l) ztick = 0.5 * GR.tick(zmin, zmax) diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index c58ef884..18b5b541 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -349,7 +349,7 @@ function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend}) ymin, ymax = axis_limits(yaxis) if ispolar(sp) #Plots.jl appears to give (xmin,xmax) ≜ (Θmin,Θmax) & (ymin,ymax) ≜ (rmin,rmax) - rmax = max(abs(ymin), abs(ymax)) + rmax = NaNMath.max(abs(ymin), abs(ymax)) xmin, xmax = -rmax, rmax ymin, ymax = -rmax, rmax end diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 814e4775..9232fb85 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -546,7 +546,7 @@ function plotly_series(plt::Plot, series::Series) else # grad = ColorGradient(series[:markercolor], alpha=series[:markeralpha]) grad = as_gradient(series[:markercolor], series[:markeralpha]) - zmin, zmax = extrema(series[:marker_z]) + zmin, zmax = NaNMath.extrema(series[:marker_z]) zrange = zmax == zmin ? 1 : zmax - zmin # if all marker_z values are the same, plot all markers same color (avoids division by zero in next line) [rgba_string(grad[(zi - zmin) / zrange]) for zi in series[:marker_z]] end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 69fbe426..49760a75 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -705,11 +705,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) # contours on the axis planes if series[:contours] for (zdir,mat) in (("x",x), ("y",y), ("z",z)) - offset = (zdir == "y" ? maximum : minimum)(mat) + offset = (zdir == "y" ? NaNMath.maximum : NaNMath.minimum)(mat) handle = ax[:contourf](x, y, z, levelargs...; zdir = zdir, cmap = py_fillcolormap(series), - offset = (zdir == "y" ? maximum : minimum)(mat) # where to draw the contour plane + offset = (zdir == "y" ? NaNMath.maximum : NaNMath.minimum)(mat) # where to draw the contour plane ) push!(handles, handle) needs_colorbar = true @@ -778,7 +778,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) end clims = sp[:clims] - zmin, zmax = extrema(z) + zmin, zmax = NaNMath.extrema(z) extrakw[:vmin] = (is_2tuple(clims) && isfinite(clims[1])) ? clims[1] : zmin extrakw[:vmax] = (is_2tuple(clims) && isfinite(clims[2])) ? clims[2] : zmax @@ -926,14 +926,14 @@ function py_compute_axis_minval(axis::Axis) for series in series_list(sp) v = series.d[axis[:letter]] if !isempty(v) - minval = min(minval, minimum(abs(v))) + minval = NaNMath.min(minval, NaNMath.minimum(abs(v))) end end end # now if the axis limits go to a smaller abs value, use that instead vmin, vmax = axis_limits(axis) - minval = min(minval, abs(vmin), abs(vmax)) + minval = NaNMath.min(minval, abs(vmin), abs(vmax)) minval end @@ -954,7 +954,7 @@ function py_set_scale(ax, axis::Axis) elseif scale == :log10 10 end - kw[Symbol(:linthresh,letter)] = max(1e-16, py_compute_axis_minval(axis)) + kw[Symbol(:linthresh,letter)] = NaNMath.max(1e-16, py_compute_axis_minval(axis)) "symlog" end func(arg; kw...) diff --git a/src/components.jl b/src/components.jl index b20eb3d0..4a11bd7e 100644 --- a/src/components.jl +++ b/src/components.jl @@ -501,7 +501,7 @@ immutable ZValues zrange::Tuple{Float64,Float64} end -function zvalues{T<:Real}(values::AVec{T}, zrange::Tuple{T,T} = (minimum(values), maximum(values))) +function zvalues{T<:Real}(values::AVec{T}, zrange::Tuple{T,T} = (NaNMath.minimum(values), NaNMath.maximum(values))) ZValues(collect(float(values)), map(Float64, zrange)) end @@ -645,8 +645,8 @@ function (bc::BezierCurve)(t::Real) p end -Base.mean(x::Real, y::Real) = 0.5*(x+y) -Base.mean{N,T<:Real}(ps::FixedSizeArrays.Vec{N,T}...) = sum(ps) / length(ps) +# mean(x::Real, y::Real) = 0.5*(x+y) #commented out as I cannot see this used anywhere and it overwrites a Base method with different functionality +# mean{N,T<:Real}(ps::FixedSizeArrays.Vec{N,T}...) = sum(ps) / length(ps) # I also could not see this used anywhere, and it's type piracy - implementing a NaNMath version for this would just involve converting to a standard array @deprecate curve_points coords @@ -659,7 +659,7 @@ function directed_curve(args...; kw...) end function extrema_plus_buffer(v, buffmult = 0.2) - vmin,vmax = extrema(v) + vmin,vmax = NaNMath.extrema(v) vdiff = vmax-vmin buffer = vdiff * buffmult vmin - buffer, vmax + buffer diff --git a/src/layouts.jl b/src/layouts.jl index a5814ba1..003c63c1 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -704,7 +704,7 @@ function link_axes!(axes::Axis...) a1 = axes[1] for i=2:length(axes) a2 = axes[i] - expand_extrema!(a1, extrema(a2)) + expand_extrema!(a1, NaNMath.extrema(a2)) for k in (:extrema, :discrete_values, :continuous_values, :discrete_map) a2[k] = a1[k] end diff --git a/src/pipeline.jl b/src/pipeline.jl index 70644055..3a68e4a4 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -153,7 +153,7 @@ function _add_smooth_kw(kw_list::Vector{KW}, kw::KW) if get(kw, :smooth, false) x, y = kw[:x], kw[:y] β, α = convert(Matrix{Float64}, [x ones(length(x))]) \ convert(Vector{Float64}, y) - sx = [minimum(x), maximum(x)] + sx = [NaNMath.minimum(x), NaNMath.maximum(x)] sy = β * sx + α push!(kw_list, merge(copy(kw), KW( :seriestype => :path, diff --git a/src/recipes.jl b/src/recipes.jl index d3fe10fa..68ffd407 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -225,7 +225,7 @@ end fr = if yaxis[:scale] == :identity 0.0 else - min(axis_limits(yaxis)[1], minimum(y)) + NaNMath.min(axis_limits(yaxis)[1], NaNMath.minimum(y)) end end newx, newy = zeros(3n), zeros(3n) @@ -338,7 +338,7 @@ end # compute half-width of bars bw = d[:bar_width] hw = if bw == nothing - 0.5mean(diff(procx)) + 0.5NaNMath.mean(diff(procx)) else Float64[0.5cycle(bw,i) for i=1:length(procx)] end @@ -366,7 +366,7 @@ end end # widen limits out a bit - expand_extrema!(axis, widen(extrema(xseg.pts)...)) + expand_extrema!(axis, widen(NaNMath.extrema(xseg.pts)...)) # switch back if !isvertical(d) @@ -414,8 +414,8 @@ end function _preprocess_binbarlike_weights{T<:AbstractFloat}(::Type{T}, w, wscale::Symbol) w_adj = _scale_adjusted_values(T, w, wscale) - w_min = minimum(w_adj) - w_max = maximum(w_adj) + w_min = NaNMath.minimum(w_adj) + w_max = NaNMath.maximum(w_adj) baseline = _binbarlike_baseline(w_min, wscale) w_adj, baseline end @@ -548,9 +548,9 @@ Plots.@deps stepbins path function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode::Symbol = :auto) - _cl(x) = max(ceil(Int, x), 1) + _cl(x) = ceil(Int, NaNMath.max(x, one(x))) _iqr(v) = quantile(v, 0.75) - quantile(v, 0.25) - _span(v) = maximum(v) - minimum(v) + _span(v) = NaNMath.maximum(v) - NaNMath.minimum(v) n_samples = length(linearindices(first(vs))) # Estimator for number of samples in one row/column of bins along each axis: @@ -919,7 +919,7 @@ end # get the joined vector function get_xy(v::AVec{OHLC}, x = 1:length(v)) - xdiff = 0.3mean(abs(diff(x))) + xdiff = 0.3NaNMath.mean(abs(diff(x))) x_out, y_out = zeros(0), zeros(0) for (i,ohlc) in enumerate(v) ox,oy = get_xy(ohlc, x[i], xdiff) @@ -984,8 +984,8 @@ end yflip := true aspect_ratio := 1 rs, cs, zs = findnz(z.surf) - xlim := extrema(cs) - ylim := extrema(rs) + xlim := NaNMath.extrema(cs) + ylim := NaNMath.extrema(rs) if d[:markershape] == :none markershape := :circle end @@ -1006,7 +1006,7 @@ end "Adds a+bx... straight line over the current plot" function abline!(plt::Plot, a, b; kw...) - plot!(plt, [extrema(plt)...], x -> b + a*x; kw...) + plot!(plt, [NaNMath.extrema(plt)...], x -> b + a*x; kw...) end abline!(args...; kw...) = abline!(current(), args...; kw...) diff --git a/src/utils.jl b/src/utils.jl index f5ae3733..dddfdf19 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -3,7 +3,7 @@ calcMidpoints(edges::AbstractVector) = Float64[0.5 * (edges[i] + edges[i+1]) for "Make histogram-like bins of data" function binData(data, nbins) - lo, hi = extrema(data) + lo, hi = NaNMath.extrema(data) edges = collect(linspace(lo, hi, nbins+1)) midpoints = calcMidpoints(edges) buckets = Int[max(2, min(searchsortedfirst(edges, x), length(edges)))-1 for x in data] @@ -109,7 +109,7 @@ function regressionXY(x, y) β, α = convert(Matrix{Float64}, [x ones(length(x))]) \ convert(Vector{Float64}, y) # make a line segment - regx = [minimum(x), maximum(x)] + regx = [NaNMath.minimum(x), NaNMath.maximum(x)] regy = β * regx + α regx, regy end @@ -283,9 +283,9 @@ unzip{T}(xyuv::FixedSizeArrays.Vec{4,T}) = T[xyuv[1]], T[xyuv[2]], T[xyuv[ # given 2-element lims and a vector of data x, widen lims to account for the extrema of x function _expand_limits(lims, x) try - e1, e2 = extrema(x) - lims[1] = min(lims[1], e1) - lims[2] = max(lims[2], e2) + e1, e2 = NaNMath.extrema(x) + lims[1] = NaNMath.min(lims[1], e1) + lims[2] = NaNMath.max(lims[2], e2) # catch err # warn(err) end @@ -334,17 +334,17 @@ sortedkeys(d::Dict) = sort(collect(keys(d))) "create an (n+1) list of the outsides of heatmap rectangles" function heatmap_edges(v::AVec) - vmin, vmax = extrema(v) + vmin, vmax = NaNMath.extrema(v) extra = 0.5 * (vmax-vmin) / (length(v)-1) vcat(vmin-extra, 0.5 * (v[1:end-1] + v[2:end]), vmax+extra) end function calc_r_extrema(x, y) - xmin, xmax = extrema(x) - ymin, ymax = extrema(y) - r = 0.5 * min(xmax - xmin, ymax - ymin) - extrema(r) + xmin, xmax = NaNMath.extrema(x) + ymin, ymax = NaNMath.extrema(y) + r = 0.5 * NaNMath.min(xmax - xmin, ymax - ymin) + NaNMath.extrema(r) end function convert_to_polar(x, y, r_extrema = calc_r_extrema(x, y)) @@ -645,7 +645,7 @@ end # used in updating an existing series extendSeriesByOne(v::UnitRange{Int}, n::Int = 1) = isempty(v) ? (1:n) : (minimum(v):maximum(v)+n) -extendSeriesByOne(v::AVec, n::Integer = 1) = isempty(v) ? (1:n) : vcat(v, (1:n) + maximum(v)) +extendSeriesByOne(v::AVec, n::Integer = 1) = isempty(v) ? (1:n) : vcat(v, (1:n) + NaNMath.maximum(v)) extendSeriesData{T}(v::Range{T}, z::Real) = extendSeriesData(float(collect(v)), z) extendSeriesData{T}(v::Range{T}, z::AVec) = extendSeriesData(float(collect(v)), z) extendSeriesData{T}(v::AVec{T}, z::Real) = (push!(v, convert(T, z)); v) @@ -871,9 +871,9 @@ mm2px(mm::Real) = float(px / MM_PER_PX) "Smallest x in plot" -xmin(plt::Plot) = minimum([minimum(series.d[:x]) for series in plt.series_list]) +xmin(plt::Plot) = NaNMath.minimum([NaNMath.minimum(series.d[:x]) for series in plt.series_list]) "Largest x in plot" -xmax(plt::Plot) = maximum([maximum(series.d[:x]) for series in plt.series_list]) +xmax(plt::Plot) = NaNMath.maximum([NaNMath.maximum(series.d[:x]) for series in plt.series_list]) "Extrema of x-values in plot" -Base.extrema(plt::Plot) = (xmin(plt), xmax(plt)) +NaNMath.extrema(plt::Plot) = (xmin(plt), xmax(plt)) diff --git a/test/runtests.jl b/test/runtests.jl index dbc1cdd7..2cbbca4a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -114,12 +114,12 @@ facts("Axes") do @fact typeof(axis) --> Plots.Axis @fact Plots.discrete_value!(axis, "HI") --> (0.5, 1) @fact Plots.discrete_value!(axis, :yo) --> (1.5, 2) - @fact extrema(axis) --> (0.5,1.5) + @fact Plots.NaNMath.extrema(axis) --> (0.5,1.5) @fact axis[:discrete_map] --> Dict{Any,Any}(:yo => 2, "HI" => 1) Plots.discrete_value!(axis, ["x$i" for i=1:5]) Plots.discrete_value!(axis, ["x$i" for i=0:2]) - @fact extrema(axis) --> (0.5, 7.5) + @fact Plots.NaNMath.extrema(axis) --> (0.5, 7.5) end From 29ea308da48cc6a349c0c02a6f9d01c1fa7f61ec Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 1 Jun 2017 20:30:55 +0200 Subject: [PATCH 18/20] skip plotlyjs images --- test/runtests.jl | 5 ++++- test/travis_commands.jl | 12 ++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 2cbbca4a..d3241dcb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -38,11 +38,14 @@ facts("PyPlot") do eps=img_eps) end +# The plotlyjs testimages return a connection error on travis: +# connect: connection refused (ECONNREFUSED) + facts("PlotlyJS") do @fact plotlyjs() --> Plots.PlotlyJSBackend() @fact backend() --> Plots.PlotlyJSBackend() - if is_linux() + if is_linux() && isinteractive() image_comparison_facts(:plotlyjs, skip=[ 2, # animation (skipped for speed) diff --git a/test/travis_commands.jl b/test/travis_commands.jl index 8340703f..020770f8 100644 --- a/test/travis_commands.jl +++ b/test/travis_commands.jl @@ -11,12 +11,12 @@ Pkg.clone("https://github.com/JuliaPlots/PlotReferenceImages.jl.git") Pkg.clone("StatPlots") Pkg.checkout("PlotUtils") -Pkg.clone("Blink") -Pkg.build("Blink") -import Blink -Blink.AtomShell.install() -Pkg.add("Rsvg") -Pkg.add("PlotlyJS") +# Pkg.clone("Blink") +# Pkg.build("Blink") +# import Blink +# Blink.AtomShell.install() +# Pkg.add("Rsvg") +# Pkg.add("PlotlyJS") # Pkg.checkout("RecipesBase") # Pkg.clone("VisualRegressionTests") From fe805e2e6d4569e1317578346ff6d08c2d822a36 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Thu, 1 Jun 2017 21:23:08 +0200 Subject: [PATCH 19/20] completely skip plotlys and inspectdr tests --- test/runtests.jl | 64 ++++++++++++++++++++++------------------- test/travis_commands.jl | 2 +- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index d3241dcb..d55d9bf2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -41,38 +41,42 @@ end # The plotlyjs testimages return a connection error on travis: # connect: connection refused (ECONNREFUSED) -facts("PlotlyJS") do - @fact plotlyjs() --> Plots.PlotlyJSBackend() - @fact backend() --> Plots.PlotlyJSBackend() +# facts("PlotlyJS") do +# @fact plotlyjs() --> Plots.PlotlyJSBackend() +# @fact backend() --> Plots.PlotlyJSBackend() +# +# if is_linux() && isinteractive() +# image_comparison_facts(:plotlyjs, +# skip=[ +# 2, # animation (skipped for speed) +# 27, # (polar plots) takes very long / not working +# 31, # animation (skipped for speed) +# ], +# eps=img_eps) +# end +# end - if is_linux() && isinteractive() - image_comparison_facts(:plotlyjs, - skip=[ - 2, # animation (skipped for speed) - 27, # (polar plots) takes very long / not working - 31, # animation (skipped for speed) - ], - eps=img_eps) - end -end +# InspectDR returns that error on travis: +# ERROR: LoadError: InitError: Cannot open display: +# in Gtk.GLib.GError(::Gtk.##229#230) at /home/travis/.julia/v0.5/Gtk/src/GLib/gerror.jl:17 -facts("InspectDR") do - @fact inspectdr() --> Plots.InspectDRBackend() - @fact backend() --> Plots.InspectDRBackend() - - image_comparison_facts(:inspectdr, - skip=[ - 2, # animation - 6, # heatmap not defined - 10, # heatmap not defined - 22, # contour not defined - 23, # pie not defined - 27, # polar plot not working - 28, # heatmap not defined - 31, # animation - ], - eps=img_eps) -end +# facts("InspectDR") do +# @fact inspectdr() --> Plots.InspectDRBackend() +# @fact backend() --> Plots.InspectDRBackend() +# +# image_comparison_facts(:inspectdr, +# skip=[ +# 2, # animation +# 6, # heatmap not defined +# 10, # heatmap not defined +# 22, # contour not defined +# 23, # pie not defined +# 27, # polar plot not working +# 28, # heatmap not defined +# 31, # animation +# ], +# eps=img_eps) +# end # facts("Plotly") do # @fact plotly() --> Plots.PlotlyBackend() diff --git a/test/travis_commands.jl b/test/travis_commands.jl index 020770f8..f3abd0fb 100644 --- a/test/travis_commands.jl +++ b/test/travis_commands.jl @@ -26,6 +26,6 @@ ENV["PYTHON"] = "" Pkg.add("PyPlot") Pkg.build("PyPlot") -Pkg.add("InspectDR") +# Pkg.add("InspectDR") Pkg.test("Plots"; coverage=false) From 90cfdac6ac62bb3f4eff823a0761e4814db9519b Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Thu, 1 Jun 2017 22:19:38 +0200 Subject: [PATCH 20/20] Change NaNMath implementation We needed some functions to forward to Base methods, e.g. when non-`AbstractArray{<:AbstractFloat}` was passed --- src/Plots.jl | 13 ++++++++++++- src/axes.jl | 8 ++++---- src/backends/glvisualize.jl | 16 ++++++++-------- src/backends/gr.jl | 6 +++--- src/backends/plotly.jl | 2 +- src/backends/pyplot.jl | 8 ++++---- src/components.jl | 4 ++-- src/layouts.jl | 2 +- src/pipeline.jl | 2 +- src/recipes.jl | 20 ++++++++++---------- src/utils.jl | 22 +++++++++++----------- test/runtests.jl | 4 ++-- 12 files changed, 59 insertions(+), 48 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index 4842a039..c990e8be 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -10,7 +10,6 @@ using Base.Meta @reexport using PlotThemes import Showoff import StatsBase -import NaNMath # define functions that ignores NaNs. To overcome the destructive effects of https://github.com/JuliaLang/julia/pull/12563 export grid, @@ -107,6 +106,18 @@ export # --------------------------------------------------------- +import NaNMath # define functions that ignores NaNs. To overcome the destructive effects of https://github.com/JuliaLang/julia/pull/12563 +ignoreNaN_minimum{F<:AbstractFloat}(x::AbstractArray{F}) = NaNMath.minimum(x) +ignoreNaN_minimum(x) = Base.minimum(x) +ignoreNaN_maximum{F<:AbstractFloat}(x::AbstractArray{F}) = NaNMath.maximum(x) +ignoreNaN_maximum(x) = Base.maximum(x) +ignoreNaN_mean{F<:AbstractFloat}(x::AbstractArray{F}) = NaNMath.mean(x) +ignoreNaN_mean(x) = Base.mean(x) +ignoreNaN_extrema{F<:AbstractFloat}(x::AbstractArray{F}) = NaNMath.extrema(x) +ignoreNaN_extrema(x) = Base.extrema(x) + +# --------------------------------------------------------- + import Measures import Measures: Length, AbsoluteLength, Measure, BoundingBox, mm, cm, inch, pt, width, height, w, h const BBox = Measures.Absolute2DBox diff --git a/src/axes.jl b/src/axes.jl index 0d855190..f629d22c 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -118,7 +118,7 @@ Base.show(io::IO, axis::Axis) = dumpdict(axis.d, "Axis", true) # Base.getindex(axis::Axis, k::Symbol) = getindex(axis.d, k) Base.setindex!(axis::Axis, v, ks::Symbol...) = setindex!(axis.d, v, ks...) Base.haskey(axis::Axis, k::Symbol) = haskey(axis.d, k) -NaNMath.extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax)) +ignoreNaN_extrema(axis::Axis) = (ex = axis[:extrema]; (ex.emin, ex.emax)) const _scale_funcs = Dict{Symbol,Function}( @@ -349,11 +349,11 @@ function expand_extrema!(sp::Subplot, d::KW) bw = d[:bar_width] if bw == nothing - bw = d[:bar_width] = NaNMath.mean(diff(data)) + bw = d[:bar_width] = ignoreNaN_mean(diff(data)) end axis = sp.attr[Symbol(dsym, :axis)] - expand_extrema!(axis, NaNMath.maximum(data) + 0.5maximum(bw)) - expand_extrema!(axis, NaNMath.minimum(data) - 0.5minimum(bw)) + expand_extrema!(axis, ignoreNaN_maximum(data) + 0.5maximum(bw)) + expand_extrema!(axis, ignoreNaN_minimum(data) - 0.5minimum(bw)) end end diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index c09fcab0..5e78c046 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -304,7 +304,7 @@ function extract_any_color(d, kw_args) kw_args[:color_norm] = Vec2f0(clims) end elseif clims == :auto - kw_args[:color_norm] = Vec2f0(NaNMath.extrema(d[:y])) + kw_args[:color_norm] = Vec2f0(ignoreNaN_extrema(d[:y])) end end else @@ -315,7 +315,7 @@ function extract_any_color(d, kw_args) kw_args[:color_norm] = Vec2f0(clims) end elseif clims == :auto - kw_args[:color_norm] = Vec2f0(NaNMath.extrema(d[:y])) + kw_args[:color_norm] = Vec2f0(ignoreNaN_extrema(d[:y])) else error("Unsupported limits: $clims") end @@ -482,7 +482,7 @@ function hover(to_hover, to_display, window) end function extract_extrema(d, kw_args) - xmin, xmax = NaNMath.extrema(d[:x]); ymin, ymax = NaNMath.extrema(d[:y]) + xmin, xmax = ignoreNaN_extrema(d[:x]); ymin, ymax = ignoreNaN_extrema(d[:y]) kw_args[:primitive] = GeometryTypes.SimpleRectangle{Float32}(xmin, ymin, xmax-xmin, ymax-ymin) nothing end @@ -509,7 +509,7 @@ function extract_colornorm(d, kw_args) else d[:y] end - kw_args[:color_norm] = Vec2f0(NaNMath.extrema(z)) + kw_args[:color_norm] = Vec2f0(ignoreNaN_extrema(z)) kw_args[:intensity] = map(Float32, collect(z)) end end @@ -781,7 +781,7 @@ function gl_bar(d, kw_args) # compute half-width of bars bw = nothing hw = if bw == nothing - NaNMath.mean(diff(x)) + ignoreNaN_mean(diff(x)) else Float64[cycle(bw,i)*0.5 for i=1:length(x)] end @@ -864,7 +864,7 @@ function gl_boxplot(d, kw_args) end # change q1 and q5 to show outliers # using maximum and minimum values inside the limits - q1, q5 = NaNMath.extrema(inside) + q1, q5 = ignoreNaN_extrema(inside) end # Box if notch @@ -1318,7 +1318,7 @@ function gl_contour(x, y, z, kw_args) T = eltype(z) levels = Contour.contours(map(T, x), map(T, y), z, h) result = Point2f0[] - zmin, zmax = get(kw_args, :limits, Vec2f0(NaNMath.extrema(z))) + zmin, zmax = get(kw_args, :limits, Vec2f0(ignoreNaN_extrema(z))) cmap = get(kw_args, :color_map, get(kw_args, :color, RGBA{Float32}(0,0,0,1))) colors = RGBA{Float32}[] for c in levels.contours @@ -1339,7 +1339,7 @@ end function gl_heatmap(x,y,z, kw_args) - get!(kw_args, :color_norm, Vec2f0(NaNMath.extrema(z))) + get!(kw_args, :color_norm, Vec2f0(ignoreNaN_extrema(z))) get!(kw_args, :color_map, Plots.make_gradient(cgrad())) delete!(kw_args, :intensity) I = GLVisualize.Intensity{1, Float32} diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 0c34b5d4..af02902b 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -264,7 +264,7 @@ end normalize_zvals(zv::Void) = zv function normalize_zvals(zv::AVec) - vmin, vmax = NaNMath.extrema(zv) + vmin, vmax = ignoreNaN_extrema(zv) if vmin == vmax zeros(length(zv)) else @@ -639,7 +639,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) elseif ispolar(sp) r = gr_set_viewport_polar() - rmin, rmax = GR.adjustrange(NaNMath.minimum(r), NaNMath.maximum(r)) + rmin, rmax = GR.adjustrange(ignoreNaN_minimum(r), ignoreNaN_maximum(r)) # rmin, rmax = axis_limits(sp[:yaxis]) gr_polaraxes(rmin, rmax) @@ -824,7 +824,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) # create the colorbar of contour levels if sp[:colorbar] != :none gr_set_viewport_cmap(sp) - l = round(Int32, 1000 + (h - NaNMath.minimum(h)) / (NaNMath.maximum(h) - NaNMath.minimum(h)) * 255) + l = round(Int32, 1000 + (h - ignoreNaN_minimum(h)) / (ignoreNaN_maximum(h) - ignoreNaN_minimum(h)) * 255) GR.setwindow(xmin, xmax, zmin, zmax) GR.cellarray(xmin, xmax, zmax, zmin, 1, length(l), l) ztick = 0.5 * GR.tick(zmin, zmax) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 9232fb85..3b681618 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -546,7 +546,7 @@ function plotly_series(plt::Plot, series::Series) else # grad = ColorGradient(series[:markercolor], alpha=series[:markeralpha]) grad = as_gradient(series[:markercolor], series[:markeralpha]) - zmin, zmax = NaNMath.extrema(series[:marker_z]) + zmin, zmax = ignoreNaN_extrema(series[:marker_z]) zrange = zmax == zmin ? 1 : zmax - zmin # if all marker_z values are the same, plot all markers same color (avoids division by zero in next line) [rgba_string(grad[(zi - zmin) / zrange]) for zi in series[:marker_z]] end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 49760a75..82237fbb 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -705,11 +705,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) # contours on the axis planes if series[:contours] for (zdir,mat) in (("x",x), ("y",y), ("z",z)) - offset = (zdir == "y" ? NaNMath.maximum : NaNMath.minimum)(mat) + offset = (zdir == "y" ? ignoreNaN_maximum : ignoreNaN_minimum)(mat) handle = ax[:contourf](x, y, z, levelargs...; zdir = zdir, cmap = py_fillcolormap(series), - offset = (zdir == "y" ? NaNMath.maximum : NaNMath.minimum)(mat) # where to draw the contour plane + offset = (zdir == "y" ? ignoreNaN_maximum : ignoreNaN_minimum)(mat) # where to draw the contour plane ) push!(handles, handle) needs_colorbar = true @@ -778,7 +778,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) end clims = sp[:clims] - zmin, zmax = NaNMath.extrema(z) + zmin, zmax = ignoreNaN_extrema(z) extrakw[:vmin] = (is_2tuple(clims) && isfinite(clims[1])) ? clims[1] : zmin extrakw[:vmax] = (is_2tuple(clims) && isfinite(clims[2])) ? clims[2] : zmax @@ -926,7 +926,7 @@ function py_compute_axis_minval(axis::Axis) for series in series_list(sp) v = series.d[axis[:letter]] if !isempty(v) - minval = NaNMath.min(minval, NaNMath.minimum(abs(v))) + minval = NaNMath.min(minval, ignoreNaN_minimum(abs(v))) end end end diff --git a/src/components.jl b/src/components.jl index 4a11bd7e..6a935c95 100644 --- a/src/components.jl +++ b/src/components.jl @@ -501,7 +501,7 @@ immutable ZValues zrange::Tuple{Float64,Float64} end -function zvalues{T<:Real}(values::AVec{T}, zrange::Tuple{T,T} = (NaNMath.minimum(values), NaNMath.maximum(values))) +function zvalues{T<:Real}(values::AVec{T}, zrange::Tuple{T,T} = (ignoreNaN_minimum(values), ignoreNaN_maximum(values))) ZValues(collect(float(values)), map(Float64, zrange)) end @@ -659,7 +659,7 @@ function directed_curve(args...; kw...) end function extrema_plus_buffer(v, buffmult = 0.2) - vmin,vmax = NaNMath.extrema(v) + vmin,vmax = ignoreNaN_extrema(v) vdiff = vmax-vmin buffer = vdiff * buffmult vmin - buffer, vmax + buffer diff --git a/src/layouts.jl b/src/layouts.jl index 003c63c1..8312d97b 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -704,7 +704,7 @@ function link_axes!(axes::Axis...) a1 = axes[1] for i=2:length(axes) a2 = axes[i] - expand_extrema!(a1, NaNMath.extrema(a2)) + expand_extrema!(a1, ignoreNaN_extrema(a2)) for k in (:extrema, :discrete_values, :continuous_values, :discrete_map) a2[k] = a1[k] end diff --git a/src/pipeline.jl b/src/pipeline.jl index 3a68e4a4..0c111e72 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -153,7 +153,7 @@ function _add_smooth_kw(kw_list::Vector{KW}, kw::KW) if get(kw, :smooth, false) x, y = kw[:x], kw[:y] β, α = convert(Matrix{Float64}, [x ones(length(x))]) \ convert(Vector{Float64}, y) - sx = [NaNMath.minimum(x), NaNMath.maximum(x)] + sx = [ignoreNaN_minimum(x), ignoreNaN_maximum(x)] sy = β * sx + α push!(kw_list, merge(copy(kw), KW( :seriestype => :path, diff --git a/src/recipes.jl b/src/recipes.jl index 68ffd407..9f647f73 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -225,7 +225,7 @@ end fr = if yaxis[:scale] == :identity 0.0 else - NaNMath.min(axis_limits(yaxis)[1], NaNMath.minimum(y)) + NaNMath.min(axis_limits(yaxis)[1], ignoreNaN_minimum(y)) end end newx, newy = zeros(3n), zeros(3n) @@ -338,7 +338,7 @@ end # compute half-width of bars bw = d[:bar_width] hw = if bw == nothing - 0.5NaNMath.mean(diff(procx)) + 0.5ignoreNaN_mean(diff(procx)) else Float64[0.5cycle(bw,i) for i=1:length(procx)] end @@ -366,7 +366,7 @@ end end # widen limits out a bit - expand_extrema!(axis, widen(NaNMath.extrema(xseg.pts)...)) + expand_extrema!(axis, widen(ignoreNaN_extrema(xseg.pts)...)) # switch back if !isvertical(d) @@ -414,8 +414,8 @@ end function _preprocess_binbarlike_weights{T<:AbstractFloat}(::Type{T}, w, wscale::Symbol) w_adj = _scale_adjusted_values(T, w, wscale) - w_min = NaNMath.minimum(w_adj) - w_max = NaNMath.maximum(w_adj) + w_min = ignoreNaN_minimum(w_adj) + w_max = ignoreNaN_maximum(w_adj) baseline = _binbarlike_baseline(w_min, wscale) w_adj, baseline end @@ -550,7 +550,7 @@ Plots.@deps stepbins path function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode::Symbol = :auto) _cl(x) = ceil(Int, NaNMath.max(x, one(x))) _iqr(v) = quantile(v, 0.75) - quantile(v, 0.25) - _span(v) = NaNMath.maximum(v) - NaNMath.minimum(v) + _span(v) = ignoreNaN_maximum(v) - ignoreNaN_minimum(v) n_samples = length(linearindices(first(vs))) # Estimator for number of samples in one row/column of bins along each axis: @@ -919,7 +919,7 @@ end # get the joined vector function get_xy(v::AVec{OHLC}, x = 1:length(v)) - xdiff = 0.3NaNMath.mean(abs(diff(x))) + xdiff = 0.3ignoreNaN_mean(abs(diff(x))) x_out, y_out = zeros(0), zeros(0) for (i,ohlc) in enumerate(v) ox,oy = get_xy(ohlc, x[i], xdiff) @@ -984,8 +984,8 @@ end yflip := true aspect_ratio := 1 rs, cs, zs = findnz(z.surf) - xlim := NaNMath.extrema(cs) - ylim := NaNMath.extrema(rs) + xlim := ignoreNaN_extrema(cs) + ylim := ignoreNaN_extrema(rs) if d[:markershape] == :none markershape := :circle end @@ -1006,7 +1006,7 @@ end "Adds a+bx... straight line over the current plot" function abline!(plt::Plot, a, b; kw...) - plot!(plt, [NaNMath.extrema(plt)...], x -> b + a*x; kw...) + plot!(plt, [ignoreNaN_extrema(plt)...], x -> b + a*x; kw...) end abline!(args...; kw...) = abline!(current(), args...; kw...) diff --git a/src/utils.jl b/src/utils.jl index dddfdf19..bc133c7a 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -3,7 +3,7 @@ calcMidpoints(edges::AbstractVector) = Float64[0.5 * (edges[i] + edges[i+1]) for "Make histogram-like bins of data" function binData(data, nbins) - lo, hi = NaNMath.extrema(data) + lo, hi = ignoreNaN_extrema(data) edges = collect(linspace(lo, hi, nbins+1)) midpoints = calcMidpoints(edges) buckets = Int[max(2, min(searchsortedfirst(edges, x), length(edges)))-1 for x in data] @@ -109,7 +109,7 @@ function regressionXY(x, y) β, α = convert(Matrix{Float64}, [x ones(length(x))]) \ convert(Vector{Float64}, y) # make a line segment - regx = [NaNMath.minimum(x), NaNMath.maximum(x)] + regx = [ignoreNaN_minimum(x), ignoreNaN_maximum(x)] regy = β * regx + α regx, regy end @@ -283,7 +283,7 @@ unzip{T}(xyuv::FixedSizeArrays.Vec{4,T}) = T[xyuv[1]], T[xyuv[2]], T[xyuv[ # given 2-element lims and a vector of data x, widen lims to account for the extrema of x function _expand_limits(lims, x) try - e1, e2 = NaNMath.extrema(x) + e1, e2 = ignoreNaN_extrema(x) lims[1] = NaNMath.min(lims[1], e1) lims[2] = NaNMath.max(lims[2], e2) # catch err @@ -334,17 +334,17 @@ sortedkeys(d::Dict) = sort(collect(keys(d))) "create an (n+1) list of the outsides of heatmap rectangles" function heatmap_edges(v::AVec) - vmin, vmax = NaNMath.extrema(v) + vmin, vmax = ignoreNaN_extrema(v) extra = 0.5 * (vmax-vmin) / (length(v)-1) vcat(vmin-extra, 0.5 * (v[1:end-1] + v[2:end]), vmax+extra) end function calc_r_extrema(x, y) - xmin, xmax = NaNMath.extrema(x) - ymin, ymax = NaNMath.extrema(y) + xmin, xmax = ignoreNaN_extrema(x) + ymin, ymax = ignoreNaN_extrema(y) r = 0.5 * NaNMath.min(xmax - xmin, ymax - ymin) - NaNMath.extrema(r) + ignoreNaN_extrema(r) end function convert_to_polar(x, y, r_extrema = calc_r_extrema(x, y)) @@ -645,7 +645,7 @@ end # used in updating an existing series extendSeriesByOne(v::UnitRange{Int}, n::Int = 1) = isempty(v) ? (1:n) : (minimum(v):maximum(v)+n) -extendSeriesByOne(v::AVec, n::Integer = 1) = isempty(v) ? (1:n) : vcat(v, (1:n) + NaNMath.maximum(v)) +extendSeriesByOne(v::AVec, n::Integer = 1) = isempty(v) ? (1:n) : vcat(v, (1:n) + ignoreNaN_maximum(v)) extendSeriesData{T}(v::Range{T}, z::Real) = extendSeriesData(float(collect(v)), z) extendSeriesData{T}(v::Range{T}, z::AVec) = extendSeriesData(float(collect(v)), z) extendSeriesData{T}(v::AVec{T}, z::Real) = (push!(v, convert(T, z)); v) @@ -871,9 +871,9 @@ mm2px(mm::Real) = float(px / MM_PER_PX) "Smallest x in plot" -xmin(plt::Plot) = NaNMath.minimum([NaNMath.minimum(series.d[:x]) for series in plt.series_list]) +xmin(plt::Plot) = ignoreNaN_minimum([ignoreNaN_minimum(series.d[:x]) for series in plt.series_list]) "Largest x in plot" -xmax(plt::Plot) = NaNMath.maximum([NaNMath.maximum(series.d[:x]) for series in plt.series_list]) +xmax(plt::Plot) = ignoreNaN_maximum([ignoreNaN_maximum(series.d[:x]) for series in plt.series_list]) "Extrema of x-values in plot" -NaNMath.extrema(plt::Plot) = (xmin(plt), xmax(plt)) +ignoreNaN_extrema(plt::Plot) = (xmin(plt), xmax(plt)) diff --git a/test/runtests.jl b/test/runtests.jl index d55d9bf2..bea84472 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -121,12 +121,12 @@ facts("Axes") do @fact typeof(axis) --> Plots.Axis @fact Plots.discrete_value!(axis, "HI") --> (0.5, 1) @fact Plots.discrete_value!(axis, :yo) --> (1.5, 2) - @fact Plots.NaNMath.extrema(axis) --> (0.5,1.5) + @fact Plots.ignoreNaN_extrema(axis) --> (0.5,1.5) @fact axis[:discrete_map] --> Dict{Any,Any}(:yo => 2, "HI" => 1) Plots.discrete_value!(axis, ["x$i" for i=1:5]) Plots.discrete_value!(axis, ["x$i" for i=0:2]) - @fact Plots.NaNMath.extrema(axis) --> (0.5, 7.5) + @fact Plots.ignoreNaN_extrema(axis) --> (0.5, 7.5) end