Skip to content

Commit

Permalink
moving plots to extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
jboubarcelo committed Sep 10, 2024
1 parent fb52920 commit 2c0f926
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
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
21 changes: 21 additions & 0 deletions ext/AlgebraicDynamicsPlotsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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::ResourceSharer)
labels = (String Symbol).(collect(view(ports(r), portmap(r))))
label --> reshape(labels, 1, length(labels))
vars --> portmap(r)
sol
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

0 comments on commit 2c0f926

Please sign in to comment.