Skip to content

Commit 0788c36

Browse files
Merge pull request #31 from ConnectedSystems/makie-migration
Separate out plotting into extension packages
2 parents 4ef9042 + b93e291 commit 0788c36

File tree

20 files changed

+1061
-112
lines changed

20 files changed

+1061
-112
lines changed

Project.toml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
1717
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
1818
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
1919
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
20-
GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"
21-
GR_jll = "d2c73de3-f751-5644-a686-071e5b155ba9"
22-
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
2320
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
2421
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
2522
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
@@ -29,19 +26,29 @@ ModelParameters = "4744a3fa-6c31-4707-899e-a3298e4618ad"
2926
OnlineStats = "a15396b6-48d5-5d58-9928-6d29437db91e"
3027
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
3128
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
32-
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
3329
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
3430
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
3531
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
3632
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
3733
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
3834
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
39-
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
4035
Tar = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
4136
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4237
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
4338
ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"
4439

40+
[weakdeps]
41+
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
42+
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
43+
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
44+
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
45+
46+
[extensions]
47+
GraphMakieExt = ["Makie", "GraphMakie"]
48+
MakieExt = "Makie"
49+
GraphPlotExt = ["StatsPlots", "GraphPlot"]
50+
PlotsExt = "StatsPlots"
51+
4552
[compat]
4653
BlackBoxOptim = "0.5, 0.6"
4754
Bootstrap = "2"
@@ -54,9 +61,6 @@ DataFrames = "1.6"
5461
DataStructures = "0.18.10"
5562
Dates = "1.11.0"
5663
Distributions = "0.25.100"
57-
GR = "0.72.9, 0.73"
58-
GR_jll = "0.73"
59-
GraphPlot = "0.5, 0.6"
6064
Graphs = "1.9"
6165
JSON = "0.20.1, 0.21"
6266
LaTeXStrings = "1.3"
@@ -66,13 +70,13 @@ ModelParameters = "0.4.4"
6670
OnlineStats = "1.6"
6771
OrderedCollections = "1.6"
6872
Parameters = "0.12"
69-
Plots = "1.39"
7073
PrettyTables = "2.3"
7174
Setfield = "1"
7275
Statistics = "1.10, 1.11.1"
7376
StatsBase = "0.34"
7477
StatsFuns = "1.3"
75-
StatsPlots = "0.15"
7678
YAML = "0.4"
7779
ZipFile = "0.10"
7880
julia = "1"
81+
StatsPlots = "0.15"
82+
GraphPlot = "0.6"

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,17 @@ The examples below are run from the [examples](https://github.com/ConnectedSyste
8989
```julia
9090
using Statistics
9191
using CSV, DataFrames, YAML
92-
using Plots
92+
using StatsPlots
9393
using Streamfall
9494

95+
example_data_dir = joinpath(dirname(dirname(pathof(Streamfall))), "test/data")
96+
9597
# Load data file which holds observed streamflow, precipitation and PET data
96-
obs_data = CSV.read("../test/data/cotter/climate/CAMELS-AUS_410730.csv", DataFrame; comment="#")
98+
obs_data = CSV.read(
99+
joinpath(example_data_dir, "cotter/climate/CAMELS-AUS_410730.csv"),
100+
DataFrame;
101+
comment="#"
102+
)
97103
# 18808×8 DataFrame
98104
# Row │ year month day Date 410730_P 410730_PET 410730_max_T 410730_Q
99105
# │ Int64 Int64 Int64 Date Float64 Float64 Float64 Float64
@@ -213,17 +219,18 @@ model.
213219

214220
```julia
215221
using CSV, DataFrames, YAML
216-
using Plots
222+
using StatsPlots
217223
using Streamfall
218224

219225

220226
# Load a network from a file, providing a name for the network and the file path.
221227
# Creates a graph representation of the stream with associated metadata.
222-
sn = load_network("Example Network", "../test/data/campaspe/campaspe_network.yml")
228+
example_data_dir = joinpath(dirname(dirname(pathof(Streamfall))), "test/data")
229+
sn = load_network("Example Network", joinpath(example_data_dir, "campaspe/campaspe_network.yml"))
223230

224231
# Load climate data, in this case from a CSV file with data for all nodes.
225232
# Indicate which columns are precipitation and evaporation data based on partial identifiers
226-
climate = Climate("../test/data/campaspe/climate/climate.csv", "_rain", "_evap")
233+
climate = Climate(joinpath(example_data_dir, "campaspe/climate/climate.csv"), "_rain", "_evap")
227234

228235
# This runs an entire stream network
229236
@info "Running an example stream..."

docs/src/examples/calibration.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ using Statistics
1616
using CSV, DataFrames, YAML
1717
using Streamfall
1818

19-
using Plots
19+
# Import visualization packages to compile extensions
20+
using Plots, GraphPlot
2021

2122

2223
sn = load_network("Example Network", "../test/data/campaspe/campaspe_network.yml")

docs/src/examples/network_loading.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Loading a pre-defined network from a YAML file.
44

55
```julia
66
using YAML
7+
using Plots, GraphPlot
78
using Streamfall
89

910

examples/run_nodes.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using GLMakie, GraphMakie
12
using YAML, DataFrames, CSV, Plots
23
using Statistics
34
using Streamfall

ext/GraphMakieExt/GraphMakieExt.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module GraphMakieExt
2+
3+
using Streamfall
4+
import Streamfall: StreamfallNetwork
5+
6+
using Makie
7+
8+
using Graphs
9+
using GraphMakie
10+
11+
12+
"""
13+
plot_network(sn::StreamfallNetwork)
14+
15+
Simple plot of stream network.
16+
"""
17+
function Streamfall.NetworkViz.plot_network(sn::StreamfallNetwork)
18+
node_labels = ["$(sn[i].name)\n"*string(nameof(typeof(sn[i]))) for i in vertices(sn.mg)]
19+
f, ax, sp = graphplot(
20+
sn.mg;
21+
nlabels=node_labels,
22+
nlabels_align=(:center, :bottom),
23+
node_size=16,
24+
node_color=:blue
25+
)
26+
# f.scene.padding = (50, 50, 50, 50) # (left, right, bottom, top)
27+
28+
# Turn off grid lines
29+
ax.xgridvisible = false
30+
ax.ygridvisible = false
31+
32+
# Hide ticks and labels
33+
hidedecorations!(ax)
34+
35+
reset_limits!(ax)
36+
37+
return f
38+
end
39+
40+
end

ext/GraphPlotExt/GraphPlotExt.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module GraphPlotExt
2+
3+
using StatsPlots, GraphPlot
4+
using Streamfall
5+
import Streamfall: vertices
6+
import Streamfall: StreamfallNetwork
7+
8+
"""
9+
plot_network(sn::StreamfallNetwork)
10+
11+
Simple plot of stream network.
12+
"""
13+
function Streamfall.NetworkViz.plot_network(sn::StreamfallNetwork; as_html::Bool=false)
14+
node_labels = ["$(sn[i].name)\n" * string(nameof(typeof(sn[i]))) for i in vertices(sn.mg)]
15+
16+
if as_html
17+
plot_func = gplothtml
18+
else
19+
plot_func = gplot
20+
end
21+
22+
plot_func(sn.mg, nodelabel=node_labels)
23+
end
24+
25+
"""
26+
save_figure(sn::StreamfallNetwork, fn::String)
27+
28+
Save a figure of the network in SVG format.
29+
"""
30+
function Streamfall.NetworkViz.save_figure(sn::StreamfallNetwork, fn::String)
31+
draw(SVG(fn, 16cm, 16cm), plot_network(sn))
32+
end
33+
34+
end

0 commit comments

Comments
 (0)