Skip to content

Commit

Permalink
added plots kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
co1emi11er2 committed Oct 12, 2024
1 parent c8d1043 commit b53d66d
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 39 deletions.
35 changes: 18 additions & 17 deletions Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.10.5"
julia_version = "1.11.0"
manifest_format = "2.0"
project_hash = "a3759a91696dfa3539a50ebd4ff309f54681c810"
project_hash = "eb43398618790c77903dbed97f32bac722c5ce53"

[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
version = "1.11.0"

[[deps.CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
Expand All @@ -15,51 +16,51 @@ version = "1.1.1+0"
[[deps.Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
version = "1.11.0"

[[deps.Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
version = "1.11.0"

[[deps.LinearAlgebra]]
deps = ["Libdl", "OpenBLAS_jll", "libblastrampoline_jll"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
version = "1.11.0"

[[deps.OpenBLAS_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
version = "0.3.23+4"
version = "0.3.27+1"

[[deps.Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
version = "1.11.0"

[[deps.Random]]
deps = ["SHA"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
version = "1.11.0"

[[deps.SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
version = "0.7.0"

[[deps.Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[deps.SparseArrays]]
deps = ["Libdl", "LinearAlgebra", "Random", "Serialization", "SuiteSparse_jll"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
version = "1.10.0"

[[deps.Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
deps = ["LinearAlgebra"]
git-tree-sha1 = "ae3bb1eb3bba077cd276bc5cfc337cc65c3075c0"
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
version = "1.10.0"
version = "1.11.1"

[deps.Statistics.extensions]
SparseArraysExt = ["SparseArrays"]

[[deps.SuiteSparse_jll]]
deps = ["Artifacts", "Libdl", "libblastrampoline_jll"]
uuid = "bea87d4a-7f5b-5778-9afe-8cc45184846c"
version = "7.2.1+1"
[deps.Statistics.weakdeps]
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[deps.Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
version = "1.11.0"

[[deps.Unitful]]
deps = ["Dates", "LinearAlgebra", "Random"]
Expand Down
10 changes: 5 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[weakdeps]
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"

[extensions]
MakieDimExt = "Makie"
PlotsDimExt = "RecipesBase"
PlotsDimExt = "Plots"

[compat]
julia = "1.10"
Makie = "0.21"
Plots = "1.40"
Statistics = "1.10"
Unitful = "1.21"
Makie = "0.21"
RecipesBase = "1.3"
julia = "1.10"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
7 changes: 6 additions & 1 deletion ext/PlotsDimExt/BottomDimensions.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@recipe function f(dims::BottomDimensions; with_mask=true, dim_color=:black)
@recipe function f(dims::BottomDimensions; with_mask=true, dim_color=:black, font_size = 5, align_text=:bottom, text_rotation=0)

legend := false

Expand Down Expand Up @@ -33,6 +33,11 @@

# plot labels
@series begin
with_mask --> with_mask
font_color --> dim_color
font_size --> font_size
align_text --> align_text
text_rotation --> text_rotation
dims.labels
end
end
22 changes: 13 additions & 9 deletions ext/PlotsDimExt/Labels.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
function labels_for_plots(
labels::Labels,
with_mask::Bool=true,
font_size = 5,
font_color = :black,
font = "Courier",)
with_mask::Bool,
font_size,
font_color,
font,
align_text,
text_rotation)

x_lbls = labels.xs
y_lbls = labels.ys
annos = labels.lbls

align = with_mask ? :center : align_text
annotations = []
for (x, y, txt) in zip(x_lbls, y_lbls, annos)
push!(annotations, (x, y, (txt, font_color, font_size)))
push!(annotations, (x, y, Plots.text(txt, font_size, font_color, font, align, rotation=text_rotation)))
end

if with_mask
n = length.(annos)
blanks = vcat("".^n #=.* "█"=#)
blank_mask = lowercase(font) == "courier" ? "".^n .* "" : "".^n # courier is monospaced (add extra blank)
blanks = vcat(blank_mask)

# annotations = Vector{Tuple{Float64, Float64, String, Tuple}}(undef, length(x_lbls))
blank_annotations = []
for (x, y, txt) in zip(x_lbls, y_lbls, blanks)
push!(blank_annotations, (x, y, (txt, font_size, :white)))
push!(blank_annotations, (x, y, Plots.text(txt, font_size, :white, font, rotation=text_rotation)))
end

annotations = vcat(blank_annotations, annotations)
Expand All @@ -32,12 +36,12 @@ function labels_for_plots(
x_lbls, y_lbls, annotations
end

@recipe function f(lbls::Labels; with_mask=true, font_color=:black, font_size=5)
@recipe function f(lbls::Labels; with_mask=true, font_color=:black, font_size=5, font = "sans-serif", align_text = :bottom, text_rotation=0)

legend := false

# points for labels
x_lbls, y_lbls, annos = labels_for_plots(lbls, with_mask, font_size, font_color)
x_lbls, y_lbls, annos = labels_for_plots(lbls, with_mask, font_size, font_color, font, align_text, text_rotation)

# plot labels
@series begin
Expand Down
7 changes: 6 additions & 1 deletion ext/PlotsDimExt/LeftDimensions.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@recipe function f(dims::LeftDimensions; with_mask=true, dim_color=:black)
@recipe function f(dims::LeftDimensions; with_mask=true, dim_color=:black, font_size = 5, align_text=:bottom, text_rotation=90)

legend := false

Expand Down Expand Up @@ -33,6 +33,11 @@

# plot labels
@series begin
with_mask --> with_mask
font_color --> dim_color
font_size --> font_size
align_text --> align_text
text_rotation --> text_rotation
dims.labels
end
end
2 changes: 1 addition & 1 deletion ext/PlotsDimExt/PlotsDimExt.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module PlotsDimExt

using TapeMeasure
using RecipesBase
using Plots

include("Labels.jl")
include("TopDimensions.jl")
Expand Down
7 changes: 6 additions & 1 deletion ext/PlotsDimExt/RightDimensions.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@recipe function f(dims::RightDimensions; with_mask=true, dim_color=:black)
@recipe function f(dims::RightDimensions; with_mask=true, dim_color=:black, font_size = 5, align_text=:bottom, text_rotation=90)

legend := false

Expand Down Expand Up @@ -33,6 +33,11 @@

# plot labels
@series begin
with_mask --> with_mask
font_color --> dim_color
font_size --> font_size
align_text --> align_text
text_rotation --> text_rotation
dims.labels
end
end
7 changes: 6 additions & 1 deletion ext/PlotsDimExt/TopDimensions.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@recipe function f(dims::TopDimensions; with_mask=true, dim_color=:black)
@recipe function f(dims::TopDimensions; with_mask=true, dim_color=:black, font_size = 5, align_text=:bottom, text_rotation=0)

legend := false

Expand Down Expand Up @@ -33,6 +33,11 @@

# plot labels
@series begin
with_mask --> with_mask
font_color --> dim_color
font_size --> font_size
align_text --> align_text
text_rotation --> text_rotation
dims.labels
end
end
6 changes: 3 additions & 3 deletions src/dim_pluto.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### A Pluto.jl notebook ###
# v0.19.46
# v0.19.47

using Markdown
using InteractiveUtils
Expand Down Expand Up @@ -36,7 +36,7 @@ y = [
]

# ╔═╡ 8b54cbee-419e-4498-be73-d0c03ef2f5c9
td = h_dimension(x, y)
td = h_dimension(x, y, offset=-3ft)

# ╔═╡ fa68b90c-4b93-4d32-be72-32f96318f34f
begin
Expand Down Expand Up @@ -86,7 +86,7 @@ vd = v_dimension(yy, xx, offset=-5)
# ╔═╡ 9c23f4c3-609c-4178-bf85-512c4d0ecfcf
begin
plot(yy, xx, seriestype=:shape, color=:lightgrey, legend=false, aspectratio=1)
plot!(vd)
plot!(vd, with_mask=false)
end

# ╔═╡ 64c3d889-3da7-4a42-87cb-c796b259cafb
Expand Down

0 comments on commit b53d66d

Please sign in to comment.