Skip to content

Commit

Permalink
Update plot_borefield
Browse files Browse the repository at this point in the history
  • Loading branch information
marcbasquensmunoz committed Oct 22, 2024
1 parent 3e91d2f commit 880b73e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
2 changes: 2 additions & 0 deletions BNSPlots/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ authors = ["Marc Basquens <[email protected]> and contributors"]
version = "1.0.0-DEV"

[deps]
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
WGLMakie = "276b4fcb-3e11-5398-bf8b-a0c2d153d008"

[compat]
Expand Down
1 change: 1 addition & 0 deletions BNSPlots/src/BNSPlots.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module BNSPlots

using WGLMakie
using GraphMakie

include("results.jl")
include("borefield.jl")
Expand Down
46 changes: 18 additions & 28 deletions BNSPlots/src/borefield.jl
Original file line number Diff line number Diff line change
@@ -1,56 +1,46 @@
using Graphs

make_color_range(color_pair, n) = n == 1 ? [color_pair[1]] : range(color_pair[1], stop=color_pair[2], length=n)

"""
plot_borefield(network, positions; distinguished_branches = [], colors = [])
plot_borefield(network, positions; distinguished_boreholes = [])
Makes a plot of the borefield, showing the boreholes numbered and their connections.
# Arguments
- `network`: Network specifying the connections between boreholes.
- `positions`: The positions of each borehole.
# Optional arguments
- `distinguished_branches`: Vector of `Int`. If specified, the branches corresponding to the given values will be highlighted with the colors of `colors`.
- `colors`: Vector of `Tuples` of `Color`. If specified, uses each pair of colors to define a color gradient to color each of the branches of `distinguished_branches`.
- `distinguished_boreholes`: Vector of `Tuple{Int, Color}`. If specified, the boreholes corresponding to the given values will be highlighted with each of the colors provided.
"""
function plot_borefield(network, positions; distinguished_branches = [], colors = [])
function plot_borefield(network, positions; distinguished_boreholes = [])


scene = Figure()
axis = scene[1, 1] = Axis(scene, ylabel = "y [m]", xlabel = "x[m]", aspect = DataAspect())
min_x = minimum(map(x->x[1], positions))
max_x = maximum(map(x->x[1], positions))
min_y = minimum(map(x->x[2], positions))
max_y = maximum(map(x->x[2], positions))

margin = max(max_x-min_x, max_y-min_y) * 0.1

xlims!(axis, min_x-margin, max_x+margin)
ylims!(axis, min_y-margin, max_y+margin)

scatter!(axis, Makie.Point2.(positions), markersize = 15.)

# Draw boreholes
for (i, n_branch) in enumerate(distinguished_branches)
branch = network.branches[n_branch]
branch_colors = make_color_range(colors[i], length(branch))
for (borehole, color) in zip(branch, branch_colors)
point = [ Makie.Point(positions[borehole]) ]
scatter!(axis, point, color = color, markersize = 24)
end
end

# Write labels with borehole numbers
for i in eachindex(1:length(positions))
text!(axis, "$i", fontsize = 9, position = (positions[i] .+ (0.7 , -0.7)) , color = :blue)
end

# Draw lines representing connections
for branch in network.branches
for k in 2:length(branch)
s = Makie.Point.([ positions[branch][k-1], positions[branch][k] ] )
linesegments!(axis, s, color = :red, linewidth = 1.5)
end
N = nv(network.graph)
borefield = SimpleGraph(network.graph)
rem_vertex!(borefield, N)
rem_vertex!(borefield, N - 1)

Nb = nv(borefield)
borehole_colors = [:black for i in 1:Nb]
borehole_sizes = 12 * ones(Int, Nb)
for (bh, color) in distinguished_boreholes
borehole_colors[bh] = color
borehole_sizes[bh] = 16
end
graphplot!(axis, borefield, layout=positions, nlabels=["$i" for i in 1:Nb], node_color = borehole_colors, node_size = borehole_sizes, nlabels_distance = 5.)

hidespines!(axis)

Expand Down

0 comments on commit 880b73e

Please sign in to comment.