diff --git a/Project.toml b/Project.toml index c2e0751..fed7253 100644 --- a/Project.toml +++ b/Project.toml @@ -8,17 +8,26 @@ Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c" +[extensions] +TabularFunctionsRecipesBaseExt = "RecipesBase" + +[weakdeps] +RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" + [compat] Adapt = "4" Aqua = "0.8" DocStringExtensions = "0.9" KernelAbstractions = "0.9" +Plots = "1" +RecipesBase = "1" Test = "1" julia = "1" [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" +Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Aqua", "Test"] +test = ["Aqua", "Plots", "Test"] diff --git a/docs/Project.toml b/docs/Project.toml index 665298e..aab09c5 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,3 +1,4 @@ [deps] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" TabularFunctions = "7add9882-6fce-4afb-882d-af036a41bc9c" diff --git a/docs/make.jl b/docs/make.jl index adc8a22..0180439 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,9 +1,11 @@ using Documenter +using Plots using TabularFunctions DocMeta.setdocmeta!(TabularFunctions, :DocTestSetup, :(using TabularFunctions); recursive=true) # meshes_ext = Base.get_extension(Exodus, :ExodusMeshesExt) # unitful_ext = Base.get_extension(Exodus, :ExodusUnitfulExt) +# recipes_ext = Base.get_extension(TabularFunctions, :TabularFunctionsRecipesBaseExt) makedocs(; # modules=[Exodus, meshes_ext, unitful_ext], modules=[TabularFunctions], @@ -18,18 +20,6 @@ makedocs(; size_threshold=nothing ), pages=[ - # "Exodus" => "index.md", - # "Installation" => "installation.md", - # "Opening Files" => "opening_files.md", - # "Reading Data" => "reading_data.md", - # "Writing Data" => "writing_data.md", - # "Use With MPI" => "use_with_mpi.md", - # "Exodus Methods" => "methods.md", - # "Exodus Types" => "types.md", - # "ExodusMeshesExt" => "meshes_ext.md", - # "ExodusUnitfulExt" => "unitful_ext.md", - # "Glossary" => "glossary.md" - # "README" => "../README.md" "TabularFunctions" => "index.md" ], ) diff --git a/docs/src/index.md b/docs/src/index.md index 6e335df..0f4d8c2 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -39,6 +39,7 @@ $$ then we can use the maco ```@piecewise_analytic``` to define the above function as follows ```jldoctest analytic +using Plots using TabularFunctions func = @piecewise_analytic begin 0.0, x -> x @@ -66,6 +67,16 @@ y = func(x) 2.25 ``` +If you have loaded ```Plots.jl``` or any other plotting package that can leverage ```RecipesBase.jl```, then you can readily plot types in ```TabularFunctions.jl``` using the following syntax (```Plots.jl```) +```jldoctest analytic +xs = -5.:0.01:5. |> collect +p = plot(xs, func) +nothing + +# output + +``` + Note that closures are not necessary in the macro definition. The following is also valid syntax for the ```@piecewise_analytic``` macro ```jldoctest; output=false using TabularFunctions diff --git a/ext/TabularFunctionsRecipesBaseExt.jl b/ext/TabularFunctionsRecipesBaseExt.jl new file mode 100644 index 0000000..759773c --- /dev/null +++ b/ext/TabularFunctionsRecipesBaseExt.jl @@ -0,0 +1,16 @@ +module TabularFunctionsRecipesBaseExt + +using RecipesBase +using TabularFunctions + +@recipe function f(x, func::TabularFunctions.AbstractTabularFunction) + xlabel --> "x" + ylabel --> "y" + + @series begin + seriestype := :path + x, func.(x) + end +end + +end # module diff --git a/src/TabularFunctions.jl b/src/TabularFunctions.jl index 43f0bec..80320d2 100644 --- a/src/TabularFunctions.jl +++ b/src/TabularFunctions.jl @@ -22,7 +22,9 @@ function Base.show(io::IO, ::XsNotMonotonicallyIncreasing) end function _monotonic_error() - throw(XsNotMonotonicallyIncreasing()) + exc = XsNotMonotonicallyIncreasing() + @show exc + throw(exc) end # Abstract types