Skip to content

Commit 8a3af2a

Browse files
committed
rework modules
1 parent 9f697ba commit 8a3af2a

File tree

13 files changed

+2805
-2837
lines changed

13 files changed

+2805
-2837
lines changed

PlotsBase/src/Annotations.jl

Lines changed: 246 additions & 249 deletions
Large diffs are not rendered by default.

PlotsBase/src/Arrows.jl

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,65 @@
11
module Arrows
22

3-
export Arrow, arrow, add_arrows
3+
export Arrow, arrow, add_arrows
44

5-
using ..PlotsBase.Commons
5+
using ..PlotsBase.Commons
66

7-
# style is :open or :closed (for now)
8-
struct Arrow
9-
style::Symbol
10-
side::Symbol # :head (default), :tail, or :both
11-
headlength::Float64
12-
headwidth::Float64
13-
end
7+
# style is :open or :closed (for now)
8+
struct Arrow
9+
style::Symbol
10+
side::Symbol # :head (default), :tail, or :both
11+
headlength::Float64
12+
headwidth::Float64
13+
end
1414

15-
"""
16-
arrow(args...)
15+
"""
16+
arrow(args...)
1717
18-
Define arrowheads to apply to lines - args are `style` (`:open` or `:closed`),
19-
`side` (`:head`, `:tail` or `:both`), `headlength` and `headwidth`
20-
"""
21-
function arrow(args...)
22-
style, side = :simple, :head
23-
headlength = headwidth = 1
24-
setlength = false
25-
for arg in args
26-
T = typeof(arg)
27-
if T == Symbol
28-
if arg in (:head, :tail, :both)
29-
side = arg
30-
else
31-
style = arg
32-
end
33-
elseif T <: Number
34-
# first we apply to both, but if there's more, then only change width after the first number
35-
headwidth = Float64(arg)
36-
if !setlength
37-
headlength = headwidth
38-
end
39-
setlength = true
40-
elseif T <: Tuple && length(arg) == 2
41-
headlength, headwidth = Float64(arg[1]), Float64(arg[2])
18+
Define arrowheads to apply to lines - args are `style` (`:open` or `:closed`),
19+
`side` (`:head`, `:tail` or `:both`), `headlength` and `headwidth`
20+
"""
21+
function arrow(args...)
22+
style, side = :simple, :head
23+
headlength = headwidth = 1
24+
setlength = false
25+
for arg in args
26+
T = typeof(arg)
27+
if T == Symbol
28+
if arg in (:head, :tail, :both)
29+
side = arg
4230
else
43-
@warn "Skipped arrow arg $arg"
31+
style = arg
32+
end
33+
elseif T <: Number
34+
# first we apply to both, but if there's more, then only change width after the first number
35+
headwidth = Float64(arg)
36+
if !setlength
37+
headlength = headwidth
4438
end
39+
setlength = true
40+
elseif T <: Tuple && length(arg) == 2
41+
headlength, headwidth = Float64(arg[1]), Float64(arg[2])
42+
else
43+
@warn "Skipped arrow arg $arg"
4544
end
46-
return Arrow(style, side, headlength, headwidth)
4745
end
46+
return Arrow(style, side, headlength, headwidth)
47+
end
4848

49-
# allow for do-block notation which gets called on every valid start/end pair which
50-
# we need to draw an arrow
51-
function add_arrows(func::Function, x::AVec, y::AVec)
52-
for i in 2:length(x)
53-
xyprev = (x[i - 1], y[i - 1])
54-
xy = (x[i], y[i])
55-
if ok(xyprev) && ok(xy)
56-
if i == length(x) || !ok(x[i + 1], y[i + 1])
57-
# add the arrow from xyprev to xy
58-
func(xyprev, xy)
59-
end
49+
# allow for do-block notation which gets called on every valid start/end pair which
50+
# we need to draw an arrow
51+
function add_arrows(func::Function, x::AVec, y::AVec)
52+
for i in 2:length(x)
53+
xyprev = (x[i - 1], y[i - 1])
54+
xy = (x[i], y[i])
55+
if ok(xyprev) && ok(xy)
56+
if i == length(x) || !ok(x[i + 1], y[i + 1])
57+
# add the arrow from xyprev to xy
58+
func(xyprev, xy)
6059
end
6160
end
62-
return
6361
end
62+
return
63+
end
6464

6565
end # module
66-
67-
# -----------------------------------------------------------------------------
68-
69-
using .Arrows

PlotsBase/src/Axes.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Axes
44
export sort_3d_axes, axes_letters, process_axis_arg!, has_ticks, get_axis, get_guide
55

66
import ..PlotsBase
7-
import ..PlotsBase: Subplot, DefaultsDict, attr!
7+
import ..PlotsBase: Subplot, DefaultsDict
88

99
using ..RecipesPipeline
1010
using ..Commons
@@ -56,7 +56,7 @@ module Axes
5656
attr = DefaultsDict(explicit, Commons._axis_defaults_byletter[letter])
5757

5858
# update the defaults
59-
return attr!(Axis([sp], attr), args...; kw...)
59+
return PlotsBase.attr!(Axis([sp], attr), args...; kw...)
6060
end
6161

6262
"properly retrieve from axis.attr, passing `:match` to the correct key"

PlotsBase/src/BezierCurves.jl

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
module BezierCurves
22

3-
import ..PlotsBase
3+
import ..PlotsBase
44

5-
"create a BezierCurve for plotting"
6-
mutable struct BezierCurve{T <: Tuple}
7-
control_points::Vector{T}
8-
end
5+
"create a BezierCurve for plotting"
6+
mutable struct BezierCurve{T <: Tuple}
7+
control_points::Vector{T}
8+
end
99

10-
function (bc::BezierCurve)(t::Real)
11-
p = (0.0, 0.0)
12-
n = length(bc.control_points) - 1
13-
for i in 0:n
14-
p = p .+ bc.control_points[i + 1] .* binomial(n, i) .* (1 - t)^(n - i) .* t^i
15-
end
16-
return p
10+
function (bc::BezierCurve)(t::Real)
11+
p = (0.0, 0.0)
12+
n = length(bc.control_points) - 1
13+
for i in 0:n
14+
p = p .+ bc.control_points[i + 1] .* binomial(n, i) .* (1 - t)^(n - i) .* t^i
1715
end
16+
return p
17+
end
1818

19-
PlotsBase.coords(curve::BezierCurve, n::Integer = 30; range = [0, 1]) =
20-
map(curve, Base.range(first(range), stop = last(range), length = n))
19+
PlotsBase.coords(curve::BezierCurve, n::Integer = 30; range = [0, 1]) =
20+
map(curve, Base.range(first(range), stop = last(range), length = n))
2121

2222
end # module
23-
24-
# -----------------------------------------------------------------------------
25-
26-
using .BezierCurves

0 commit comments

Comments
 (0)