Skip to content

Commit

Permalink
update flow_diagram coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
cecoeco committed Sep 21, 2024
1 parent 20cae63 commit 5555425
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PRISMA"
uuid = "7b67a8d2-c4f5-4933-b91c-0fc427024db5"
authors = ["Ceco Elijah Maples <[email protected]>", "PRISMA.jl Contributors"]
version = "0.0.7"
version = "0.0.8"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,16 @@
create, plot, and save a flow diagram:

```julia
using PRISMA: FlowDiagram, flow_diagram, flow_diagram_save
using PRISMA: flow_diagram, flow_diagram_save

fd::FlowDiagram = flow_diagram()

display(fd)

flow_diagram_save("flow_diagram.svg", fd)
flow_diagram_save("example-01.svg", flow_diagram())
```

output:

![flow diagram](docs/src/assets/flow_diagram.svg)

**Citing:** please consider citing PRISMA.jl and giving the GitHub repository a star, if possible.
**Citing:** please consider citing `PRISMA.jl` and giving the GitHub repository a star, if possible.

The citation information may be found in the [`CITATION.bib`](CITATION.bib) file within the repository

Expand Down
14 changes: 4 additions & 10 deletions src/PRISMA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,14 @@ import Base.Multimedia.display, Base.show
export
# re-exports
DataFrame, display, show,

# checklist.jl
checklist_df, checklist_template,
checklist_read, checklist,
Checklist, checklist_save,

checklist_df, checklist_template, checklist_read, checklist, Checklist, checklist_save,
# flow_diagram.jl
flow_diagram_df, flow_diagram_template,
flow_diagram_read, flow_diagram,
FlowDiagram, flow_diagram_save
flow_diagram_df, flow_diagram_template, flow_diagram_read, flow_diagram, FlowDiagram, flow_diagram_save

include("checklist_docstrings.jl")
include("checklist.jl")
include("flow_diagram_docstrings.jl")
include("flow_diagram.jl")

display(flow_diagram())

end # module
2 changes: 2 additions & 0 deletions src/checklist.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include("checklist_docstrings.jl")

"""
$docstring_checklist_df
"""
Expand Down
41 changes: 30 additions & 11 deletions src/flow_diagram.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include("flow_diagram_docstrings.jl")

"""
$docstring_flow_diagram_df
"""
Expand Down Expand Up @@ -91,13 +93,29 @@ function group_labels(df::DataFrame)::DataFrame
labels::Vector{String} = String[]

for row in Base.eachrow(g)
text::String = row.box_num in TOP_BOXES || row.box_num in SIDE_BOXES ? "<b>$(row.box_text)</b>" : row.box_text
text::String = if row.box_num in TOP_BOXES || row.box_num in SIDE_BOXES
"<b>$(row.box_text)</b>"
else
row.box_text
end

result::String = Base.ismissing(row.result) ? "" : "(<i>n</i>&nbsp;=&nbsp;$(row.result))"

wrapped_text::String = row.box_num in TOP_BOXES || row.box_num in SIDE_BOXES ? text : wrap_text(text)
wrapped_text::String = if row.box_num in TOP_BOXES || row.box_num in SIDE_BOXES
text
else
wrap_text(text)
end

wrapped_result::String = wrap_text(result)

label::String = Base.ismissing(row.result) ? wrapped_text : Base.string(wrapped_text, "<br/>", wrapped_result)
label::String = if Base.ismissing(row.result)
wrapped_text
elseif row.box_num in [7, 9, 10, 11, 12, 13, 14, 16, 17, 19, 20, 21]
Base.string(wrapped_text, "<br/>", wrapped_result)
else
Base.string(wrapped_text, "&nbsp;", wrapped_result)
end

Base.push!(labels, label)
end
Expand All @@ -110,20 +128,20 @@ function group_labels(df::DataFrame)::DataFrame
return grouped_labels
end

FLOW_DIAGRAM_TOP_MARGIN::Number = 1.4
FLOW_DIAGRAM_TOP_MARGIN::Number = 1

FLOW_DIAGRAM_ROW_01::Number = 15.5
FLOW_DIAGRAM_ROW_02::Number = FLOW_DIAGRAM_ROW_01 - 1
FLOW_DIAGRAM_ROW_02::Number = FLOW_DIAGRAM_ROW_01 - 0.75
FLOW_DIAGRAM_ROW_03::Number = FLOW_DIAGRAM_ROW_02 - FLOW_DIAGRAM_TOP_MARGIN
FLOW_DIAGRAM_ROW_04::Number = FLOW_DIAGRAM_ROW_03 - FLOW_DIAGRAM_TOP_MARGIN
FLOW_DIAGRAM_ROW_05::Number = FLOW_DIAGRAM_ROW_04 - FLOW_DIAGRAM_TOP_MARGIN
FLOW_DIAGRAM_ROW_06::Number = FLOW_DIAGRAM_ROW_05 - FLOW_DIAGRAM_TOP_MARGIN
FLOW_DIAGRAM_ROW_07::Number = FLOW_DIAGRAM_ROW_06 - FLOW_DIAGRAM_TOP_MARGIN

FLOW_DIAGRAM_LEFT_MARGIN::Number = 2.65
FLOW_DIAGRAM_LEFT_MARGIN::Number = 2.5

FLOW_DIAGRAM_COL_01::Number = 01
FLOW_DIAGRAM_COL_02::Number = FLOW_DIAGRAM_COL_01 + FLOW_DIAGRAM_LEFT_MARGIN
FLOW_DIAGRAM_COL_02::Number = FLOW_DIAGRAM_COL_01 + 1.25
FLOW_DIAGRAM_COL_03::Number = FLOW_DIAGRAM_COL_02 + FLOW_DIAGRAM_LEFT_MARGIN
FLOW_DIAGRAM_COL_04::Number = FLOW_DIAGRAM_COL_03 + FLOW_DIAGRAM_LEFT_MARGIN
FLOW_DIAGRAM_COL_05::Number = FLOW_DIAGRAM_COL_04 + FLOW_DIAGRAM_LEFT_MARGIN
Expand Down Expand Up @@ -234,6 +252,7 @@ $docstring_flow_diagram
function flow_diagram(
data::DataFrame=flow_diagram_df();
background_color::AbstractString="white",
boxes_color::AbstractString="white",
grayboxes::Bool=true,
grayboxes_color::AbstractString="#f0f0f0",
top_boxes::Bool=true,
Expand All @@ -250,7 +269,7 @@ function flow_diagram(
border_color::AbstractString="black",
font::AbstractString="Helvetica",
font_color::AbstractString="black",
font_size::Union{AbstractString,Number}=10,
font_size::Union{AbstractString,Number}=8,
arrow_head::AbstractString="normal",
arrow_size::Union{AbstractString,Number}=1,
arrow_color::AbstractString="black",
Expand Down Expand Up @@ -288,7 +307,7 @@ function flow_diagram(
"""

for row in eachrow(group_labels(data))
box_color = "white"
box_color = boxes_color
box_border_width = border_width

if top_boxes && row.box_num in TOP_BOXES
Expand Down Expand Up @@ -325,8 +344,8 @@ function flow_diagram(
fontcolor="$font_color",
fontsize="$font_size",
pos="$(pos.x),$(pos.y)!",
width=2
height=0
width=$(row.box_num in SIDE_BOXES ? 1 : row.box_num in [2, 3] ? 4.5 : 2),
height=$(row.box_num in [4, 6] ? 1.5 : row.box_num in [5] ? 2 : 0),
];
"""
end
Expand Down
2 changes: 2 additions & 0 deletions src/flow_diagram_docstrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const docstring_flow_diagram::String =
PRISMA.flow_diagram(
data::DataFrame=flow_diagram_df(),
background_color::AbstractString="white",
boxes_color::AbstractString="white",
grayboxes::Bool=true,
grayboxes_color::AbstractString="#f0f0f0",
top_boxes::Bool=true,
Expand Down Expand Up @@ -45,6 +46,7 @@ generates the flow diagram figure from the flow diagram dataframe.
## Keyword Arguments
- `background_color::String`: The background color of the flow diagram. Default is `white`.
- `boxes_color::String`: The color of the boxes. Default is `white`.
- `grayboxes::Bool`: Whether to show gray boxes. Default is `true`.
- `grayboxes_color::String`: The color of the gray boxes. Default is `#f0f0f0`.
- `top_boxes::Bool`: Whether to show top boxes. Default is `true`.
Expand Down

0 comments on commit 5555425

Please sign in to comment.