From 33a7e12ae84a00c596ee71c63771c144b395c06f Mon Sep 17 00:00:00 2001 From: Andy Nowacki Date: Tue, 24 Aug 2021 16:12:13 +0100 Subject: [PATCH] Plotly: Remove argument checking for `levels` Checking of the `levels` keyword argument will be moved out of individual backends' code, so we can assume that `levels` if present in `plotattributes` is either an `AbstractVector` or `Integer`. --- src/backends/plotly.jl | 10 +++++----- test/test_plotly.jl | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 83ef2d00..adc9baa5 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -621,8 +621,9 @@ function plotly_series(plt::Plot, series::Series) :coloring => filled ? "fill" : "lines", :showlabels => series[:contour_labels] == true, ) - # Plotly does not support arbitrary sets of contours: - # https://github.com/plotly/plotly.js/issues/4503 + # Plotly does not support arbitrary sets of contours + # (https://github.com/plotly/plotly.js/issues/4503) + # so we distinguish AbstractRanges and AbstractVectors let levels = series[:levels] if levels isa AbstractRange plotattributes_out[:contours][:start] = first(levels) @@ -638,10 +639,9 @@ function plotly_series(plt::Plot, series::Series) "setting arbitrary contour levels with Plotly backend is not supported; " * "use a range to set equally-spaced contours or an integer to set the " * "approximate number of contours with the keyword `levels`. " * - "Using levels $(levels_range)" + "Setting levels to $(levels_range)" ) - elseif isinteger(levels) - # Assume this is a number of levels + elseif levels isa Integer plotattributes_out[:ncontours] = levels + 2 end end diff --git a/test/test_plotly.jl b/test/test_plotly.jl index 85cc6f9f..0758c410 100644 --- a/test/test_plotly.jl +++ b/test/test_plotly.jl @@ -46,7 +46,7 @@ using Plots, Test "setting arbitrary contour levels with Plotly backend " * "is not supported; use a range to set equally-spaced contours or an " * "integer to set the approximate number of contours with the keyword " * - "`levels`. Using levels -1.0:0.5:1.0", + "`levels`. Setting levels to -1.0:0.5:1.0", ) Plots.plotly_series(p) @test series_dict[1][:contours][:start] == first(levels_range) @test series_dict[1][:contours][:end] == last(levels_range)