diff --git a/CHANGELOG.md b/CHANGELOG.md index c55e70a..74c525e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## [v0.5.0] - 2022-12-?? +## [v0.5.0] - 2023-01-12 ### Added @@ -8,6 +8,7 @@ - update docs, etc. - arrow widths +- default linewidth calculation fixed (don't use Luxor internals ...) ### Removed diff --git a/docs/src/assets/figures/karnak-social-media-preview.png b/docs/src/assets/figures/karnak-social-media-preview.png index 93a11fa..c4c7763 100644 Binary files a/docs/src/assets/figures/karnak-social-media-preview.png and b/docs/src/assets/figures/karnak-social-media-preview.png differ diff --git a/docs/src/examples.md b/docs/src/examples.md index b001c7b..6d66bfb 100644 --- a/docs/src/examples.md +++ b/docs/src/examples.md @@ -258,7 +258,7 @@ end g, pkgnames = build_depgraph("DataFrames") -d = @svg begin +d = @drawsvg begin background("grey5") sethue("gold") fontsize(10) @@ -283,7 +283,7 @@ d = @svg begin end end, ) -end +end 800 700 nothing # hide ``` diff --git a/examples/karnaksocmedprev.jl b/examples/karnaksocmedprev.jl index 1421d32..8c51569 100644 --- a/examples/karnaksocmedprev.jl +++ b/examples/karnaksocmedprev.jl @@ -11,51 +11,89 @@ function hiero() translate(pos) setline(0.5) bb = BoundingBox(box(O, tiles.tilewidth, tiles.tileheight)) - rule(O + (tiles.tilewidth)/2, π/2) + rule(O + (tiles.tilewidth) / 2, π / 2) R = rand(1:10) - if R == 1 + if R == 1 g = binary_tree(rand(2:4)) dirg = SimpleDiGraph(collect(edges(g))) - drawgraph(dirg, vertexshapesizes = 1, layout = buchheim, edgegaps=0, edgecurvature=1, boundingbox=bb, margin=5) - elseif R == 2 + drawgraph( + dirg, + vertexshapesizes = 1, + layout = buchheim, + edgegaps = 0, + edgecurvature = 1, + boundingbox = bb, + margin = 5, + ) + elseif R == 2 g = star_graph(rand(3:10)) - drawgraph(g, boundingbox=bb, margin=10, layout=stress, vertexstrokeweights=0.25) - elseif R == 3 + drawgraph(g, boundingbox = bb, margin = 10, layout = stress, vertexstrokeweights = 0.25) + elseif R == 3 g = smallgraph(:truncatedcube) - drawgraph(g, boundingbox=bb, margin=10, vertexshapes = :none, layout=stress, vertexstrokeweights=0.3) - elseif R == 4 + drawgraph( + g, + boundingbox = bb, + margin = 10, + vertexshapes = :none, + layout = stress, + vertexstrokeweights = 0.3, + ) + elseif R == 4 g = smallgraph(:tutte) - drawgraph(g, boundingbox=bb, margin=10, vertexshapes = :none, layout=stress, vertexstrokeweights=0.3) - elseif R == 5 + drawgraph( + g, + boundingbox = bb, + margin = 10, + vertexshapes = :none, + layout = stress, + vertexstrokeweights = 0.3, + ) + elseif R == 5 g = smallgraph(:truncatedtetrahedron) - drawgraph(g, boundingbox=bb, margin=10, vertexshapesizes = 2, layout=stress, vertexstrokeweights=0.3) - elseif R == 6 + drawgraph( + g, + boundingbox = bb, + margin = 10, + vertexshapesizes = 2, + layout = stress, + vertexstrokeweights = 0.3, + ) + elseif R == 6 g = smallgraph(:cubical) - drawgraph(g, boundingbox=bb, margin=10, layout = Spring(Ptype=Float64)) - elseif R == 7 + drawgraph(g, boundingbox = bb, margin = 10, layout = Spring(Ptype = Float64)) + elseif R == 7 g = smallgraph(:octahedral) - drawgraph(g, boundingbox=bb, margin=10, layout = Spring(Ptype=Float64)) + drawgraph(g, boundingbox = bb, margin = 10, layout = Spring(Ptype = Float64)) else g = complete_graph(rand(4:12)) - drawgraph(g, boundingbox=bb, margin=10, vertexshapesizes = 1, vertexstrokeweights=0.15, layout = Spring(Ptype=Float64)) + drawgraph( + g, + boundingbox = bb, + margin = 10, + vertexshapesizes = 1, + vertexstrokeweights = 0.15, + layout = Spring(Ptype = Float64), + ) end end end end @png begin - pl = box(BoundingBox()) - mesh1 = mesh(pl, [ - Colors.RGBA(0.0, 0.0, 0.1, 0.99), - Colors.RGBA(0.7, 0.5, 0.0, 0.99), - Colors.RGBA(0.2, 0.1, 0.2, 0.99), - Colors.RGBA(0.0, 0.1, 0.2, 0.99), - ]) + mesh1 = mesh( + pl, + [ + Colors.RGBA(0.0, 0.0, 0.1, 0.99), + Colors.RGBA(0.7, 0.5, 0.0, 0.99), + Colors.RGBA(0.2, 0.1, 0.2, 0.99), + Colors.RGBA(0.0, 0.1, 0.2, 0.99), + ], + ) setmesh(mesh1) paint() - panes = Tiler(1280, 640, 1, 2, margin=0) + panes = Tiler(1280, 640, 1, 2, margin = 0) # left @layer begin @@ -69,10 +107,11 @@ end # right @layer begin - setopacity(0.2) sethue("midnightblue") + setopacity(0.15) box(first(panes[2]), 640, 640, :fill) box(first(panes[2]), 640, 640, :clip) + sethue("gold2") hiero() clipreset() @@ -89,15 +128,15 @@ end @layer begin translate(first(panes[1])) scale(0.9) - placeimage(logo, O, centered=true) + placeimage(logo, O, centered = true) end @layer begin translate(first(panes[2])) fontsize(80) fontface("Goblin") - bx = box(O, panes.tilewidth/1.5, panes.tileheight/1.5) - textoutlines("KARNAK", O + (0, -150), halign=:center, :path) + bx = box(O, panes.tilewidth / 1.5, panes.tileheight / 1.5) + textoutlines("KARNAK", O + (0, -150), halign = :center, :path) @layer begin sethue("gold") fillpreserve() @@ -106,21 +145,18 @@ end strokepath() end - bx = box(O + (0, 100), panes.tilewidth/1.5, panes.tileheight/1.8) + bx = box(O + (0, 100), panes.tilewidth / 1.5, panes.tileheight / 1.8) @layer begin sethue("black") setopacity(0.2) poly(bx, :fill) end - fontsize(25) + fontsize(28) fontface("WorkSans-Bold") sethue("gold") textwrap("Karnak.jl is a small utility package for Luxor.jl -that helps with drawing some graph-style drawings, more for -decorative purposes than anything else. Uses Graphs.jl and -NetworkLayout.jl.", 800, boxtopleft(BoundingBox(bx)) + (20, 0), -leading=get_fontsize() + 20) - + for drawing graphs and networks. It uses Graphs.jl and +NetworkLayout.jl.", 400, boxtopleft(BoundingBox(bx)) + (20, 0), + leading = get_fontsize() + 30) end - end 1280 640 "docs/src/assets/figures/karnak-social-media-preview.png" diff --git a/src/drawgraph.jl b/src/drawgraph.jl index 0cb69ab..5e9b9b8 100644 --- a/src/drawgraph.jl +++ b/src/drawgraph.jl @@ -86,9 +86,9 @@ function _drawedgelines(from, to, edgesrc, edgedest; end # set the stroke weight + currentdrawing().surfacetype == :png ? linewidth = 2 : linewidth = 1 - Luxor.current_surface_type() == :png ? linewidth = 2 : linewidth = 1 - if isnothing(edgestrokeweights) + if isnothing(edgestrokeweights) # by default, do nothing elseif edgestrokeweights isa Array if !isempty(edgestrokeweights) @@ -501,7 +501,7 @@ function _drawvertexshapes(vertex, coordinates::Array{Point,1}; end # set the stroke weight - Luxor.current_surface_type() == :png ? linewidth = 2 : linewidth = 1 + currentdrawing().surfacetype == :png ? linewidth = 2 : linewidth = 1 if isnothing(vertexstrokeweights) # by default, do nothing