Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moving plots to extensions #146

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Compose = "a81c6b42-2e10-5240-aca2-a61377ecd94b"
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LinearMaps = "7a12625a-238d-50fd-b39a-03d52299707e"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Expand All @@ -21,11 +20,13 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
AlgebraicPetri = "4f99eebe-17bf-4e98-b6a1-2c4f205a959b"
DelayDiffEq = "bcd4f6db-9728-5f36-b5f7-82caef46ccdb"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"

[extensions]
AlgebraicDynamicsAlgebraicPetriExt = "AlgebraicPetri"
AlgebraicDynamicsDelayDiffEqExt = "DelayDiffEq"
AlgebraicDynamicsOrdinaryDiffEqExt = "OrdinaryDiffEq"
AlgebraicDynamicsPlotsExt = "Plots"

[compat]
AlgebraicPetri = "0.9"
Expand Down
25 changes: 25 additions & 0 deletions ext/AlgebraicDynamicsPlotsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module AlgebraicDynamicsPlotsExt

using AlgebraicDynamics

using Plots

### Plotting backend
@recipe function f(sol, m::AbstractMachine, p=nothing)
labels = (String ∘ Symbol).(output_ports(m))
label --> reshape(labels, 1, length(labels))
vars --> map(1:noutputs(m)) do i
((t, args...) -> (t, readout(m)(collect(args), p, t)[i]), 0:nstates(m)...)
end
sol
end

### Plotting backend
@recipe function f(sol, r::AbstractResourceSharer)
labels = (String ∘ Symbol).(collect(view(ports(r), portmap(r))))
label --> reshape(labels, 1, length(labels))
vars --> portmap(r)
sol
end

end
11 changes: 1 addition & 10 deletions src/dwd_dynam.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Catlab.WiringDiagrams: oapply, input_ports, output_ports

import ..UWDDynam: AbstractInterface, nstates, eval_dynamics, euler_approx, trajectory

using Plots

export AbstractMachine, ContinuousMachine, DiscreteMachine, DelayMachine,
InstantaneousContinuousMachine, InstantaneousDiscreteMachine, InstantaneousDelayMachine,
Expand Down Expand Up @@ -378,15 +377,7 @@ euler_approx(fs::AbstractDict{S, M}, args...) where {S, M<:ContinuousMachine} =



### Plotting backend
@recipe function f(sol, m::AbstractMachine, p=nothing)
labels = (String ∘ Symbol).(output_ports(m))
label --> reshape(labels, 1, length(labels))
vars --> map(1:noutputs(m)) do i
((t, args...) -> (t, readout(m)(collect(args), p, t)[i]), 0:nstates(m)...)
end
sol
end



""" oapply(d::WiringDiagram, ms::Vector{M}) where {M<:AbstractMachine}
Expand Down
9 changes: 0 additions & 9 deletions src/uwd_dynam.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ using Catlab
using Catlab.WiringDiagrams.UndirectedWiringDiagrams: AbstractUWD
import Catlab.WiringDiagrams: oapply, ports

using Plots

export AbstractResourceSharer, ContinuousResourceSharer, DelayResourceSharer, DiscreteResourceSharer,
euler_approx, nstates, nports, portmap, portfunction, trajectory,
eval_dynamics, eval_dynamics!, exposed_states, fills, induced_states
Expand Down Expand Up @@ -217,13 +215,6 @@ euler_approx(fs::AbstractDict{S, R}, args...) where {S, T, R<:ContinuousResource
# Trajectories
function trajectory() end

### Plotting backend
@recipe function f(sol, r::ResourceSharer)
labels = (String ∘ Symbol).(collect(view(ports(r), portmap(r))))
label --> reshape(labels, 1, length(labels))
vars --> portmap(r)
sol
end

""" fills(r::AbstractResourceSharer, d::AbstractUWD, b::Int)

Expand Down
Loading