Skip to content

Commit

Permalink
Fade stdlib (close #47)
Browse files Browse the repository at this point in the history
jll is still left as is; but that's fine
  • Loading branch information
tfiers committed Jan 14, 2023
1 parent c7b98e7 commit 2b9e134
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
35 changes: 25 additions & 10 deletions src/modules/DotString.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@

module DotString

using ..DepGraph: vertices, is_in_stdlib, depgraph

export to_dot_str,
default_style

docstr_file = joinpath(@__DIR__, "to_dot_string.md")
include_dependency(docstr_file)
@doc readchomp(docstr_file)
docstr = joinpath(@__DIR__, "to_dot_string.md")
include_dependency(docstr)

@doc readchomp(docstr)
function to_dot_str(
edges;
dark = false,
bg = "transparent",
style = default_style(),
indent = 4,
emptymsg = nothing,
dark = false,
bg = "transparent",
style = default_style(),
indent = 4,
emptymsg = nothing,
fade_stdlib = true,
)
lines = ["digraph {"] # DIrected graph
tab = " "^indent
Expand All @@ -22,8 +26,19 @@ function to_dot_str(
for line in [bgcolor; colourscheme; style]
push!(lines, tab * line)
end
for (m, n) in edges
push!(lines, tab * "$m -> $n")
for (pkg, dep) in edges
if fade_stdlib && any(is_in_stdlib, [pkg, dep])
push!(lines, tab * "$pkg -> $dep [color=gray]")
else
push!(lines, tab * "$pkg -> $dep")
end
end
if fade_stdlib
for pkg in vertices(edges)
if is_in_stdlib(pkg)
push!(lines, tab * "$pkg [color=gray fontcolor=gray]")
end
end
end
if !isnothing(emptymsg) && isempty(edges)
push!(lines, tab * single_node(emptymsg))
Expand Down
16 changes: 11 additions & 5 deletions src/modules/to_dot_string.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
```julia
to_dot_str(
edges;
dark = false,
bg = "transparent",
style = default_style(),
indent = 4,
emptymsg = nothing,
dark = false,
bg = "transparent",
style = default_style(),
indent = 4,
emptymsg = nothing,
fade_stdlib = true,
)
```

Expand Down Expand Up @@ -43,6 +44,11 @@ If there are no `edges`, a single node with `emptymsg` is created. If
`emptymsg` is `nothing` (default), no nodes are created, and the image
rendered from the DOT-string will be empty.

### `fade_stdlib`
Whether to draw packages in the Julia standard library in gray. Note
that they can be excluded entirely by setting `stdlib = false` in
[`depgraph`](@ref)

## Example:

```jldoctest
Expand Down

0 comments on commit 2b9e134

Please sign in to comment.