Skip to content

Commit

Permalink
Added line style customization (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 authored Jun 9, 2023
1 parent ab05d80 commit 118ab95
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/GraphTikZ.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using InfiniteArrays
using LaTeXStrings
using Statistics

export tikz
export tikz, rotate

to_function(x::Function) = x
to_function(x) = Returns(x)
Expand Down Expand Up @@ -37,6 +37,7 @@ default_shape(v) = default_shape()
default_shapes(v) = Fill(default_shape())
default_line_color() = "black"
default_line_color(v) = default_line_color()
default_line_style() = "solid"

default_edge_shape(e) = Line

Expand Down Expand Up @@ -210,10 +211,11 @@ tikz(s::PointMeta; kwargs...) = tikz(metafree(s); kwargs..., meta(s)...)
function tikz(
s::Line{2};
line_thickness=default_line_thickness(),
line_style=default_line_style(),
line_color=default_line_color(),
kwargs...,
)
draw_args = "[draw=$(line_color),line width=$(line_thickness)pt]"
draw_args = "[draw=$(line_color),$(line_style),line width=$(line_thickness)pt]"
return L"\draw%$(draw_args) %$(string(Tuple(s[1]))) -- %$(string(Tuple((s[2]))));"
end
tikz(s::Line{1}; kwargs...) = tikz(line2(s); kwargs...)
Expand All @@ -224,11 +226,12 @@ tikz_shape(::Circle) = "circle"
function tikz(
s::Circle;
line_thickness=default_line_thickness(),
line_style=default_line_style(),
line_color=default_line_color(),
fill_color=default_fill_color(),
kwargs...,
)
filldraw_args = "[draw=$(line_color),line width=$(line_thickness)pt,fill=$(fill_color)!40]"
filldraw_args = "[draw=$(line_color),$(line_style),line width=$(line_thickness)pt,fill=$(fill_color)!40]"
tikz_str = L"\filldraw%$(filldraw_args) %$(string(Tuple(s.center))) %$(tikz_shape(s)) (%$(s.r)) node {};"
return tikz_str
end
Expand All @@ -243,14 +246,15 @@ lines(s::LineString) = decompose(Line, s)
function tikz(
s::LineString;
line_thickness=default_line_thickness(),
line_style=default_line_style(),
line_color=default_line_color(),
fill_color=default_fill_color(),
corner_roundness=default_corner_roundness(),
kwargs...,
)
# Convert to Vector of length `length(coordinates(s))` if it is just a number
corner_roundness = to_fill(corner_roundness, length(coordinates(s)))
draw_args = "[draw=$(line_color),line width=$(line_thickness)pt]"
draw_args = "[draw=$(line_color),$(line_style),line width=$(line_thickness)pt]"
tikz_str = "\\draw$(draw_args) $(string(Tuple(coordinates(s)[1]))) "
for i in 2:(length(coordinates(s)) - 1)
tikz_str *= "{[rounded corners=$(corner_roundness[i - 1])pt] -- $(string(Tuple(coordinates(s)[i])))} "
Expand All @@ -265,14 +269,15 @@ tikz(s::LineStringMeta; kwargs...) = tikz(metafree(s); kwargs..., meta(s)...)
function tikz(
s::Polygon;
line_thickness=default_line_thickness(),
line_style=default_line_style(),
line_color=default_line_color(),
fill_color=default_fill_color(),
corner_roundness=default_corner_roundness(),
kwargs...,
)
# Convert to Vector of length `length(coordinates(s))` if it is just a number
corner_roundness = to_fill(corner_roundness, length(coordinates(s)))
filldraw_args = "[draw=$(line_color),line width=$(line_thickness)pt,fill=$(fill_color)!40]"
filldraw_args = "[draw=$(line_color),$(line_style),line width=$(line_thickness)pt,fill=$(fill_color)!40]"
tikz_str = "\\filldraw$(filldraw_args) $(string(Tuple(coordinates(s)[1]))) "
for i in 2:length(coordinates(s))
tikz_str *= "{[rounded corners=$(corner_roundness[i])pt] -- $(string(Tuple(coordinates(s)[i])))} "
Expand Down

0 comments on commit 118ab95

Please sign in to comment.