Skip to content

Commit

Permalink
revised existing functions to fit margins
Browse files Browse the repository at this point in the history
  • Loading branch information
emmaccode authored Feb 20, 2023
1 parent 7212b3e commit 04de4c9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
6 changes: 6 additions & 0 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ git-tree-sha1 = "79f5dc8a1b0b678260865acdc2c002aab4a53101"
uuid = "a47e2ad8-fcf7-417c-9746-32b9bdf220bd"
version = "0.2.3"

[[deps.ToolipsDefaults]]
deps = ["Toolips", "ToolipsSession"]
git-tree-sha1 = "513c9d3bfc7268dc820ac77dffdd85877b070ddf"
uuid = "1710be6b-e895-498d-ba35-e3ff0dac7995"
version = "0.1.0"

[[deps.ToolipsMarkdown]]
deps = ["Markdown", "Toolips"]
git-tree-sha1 = "9248ccc0d0114e73a0169b2687a6d27199fb722d"
Expand Down
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ version = "0.1.0"

[deps]
Toolips = "a47e2ad8-fcf7-417c-9746-32b9bdf220bd"
ToolipsDefaults = "1710be6b-e895-498d-ba35-e3ff0dac7995"
ToolipsMarkdown = "33f7ff50-f2f2-41f0-8a96-482dce5c1514"
ToolipsSVG = "8ae86ec9-919d-4ece-9a6d-09b7d28dae11"
39 changes: 22 additions & 17 deletions src/context_plotting.jl
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
function grid!(con::Context, n::Int64 = 4, styles::Pair{String, <:Any} ...)
function grid!(con::AbstractContext, n::Int64 = 4, styles::Pair{String, <:Any} ...)
if length(styles) == 0
styles = ("fill" => "none", "stroke" => "lightblue", "stroke-width" => "1", "opacity" => 80percent)
end
division_amountx::Int64 = round(con.dim[1] / n)
division_amounty::Int64 = round(con.dim[2] / n)
[begin
line!(con, xcoord => 0, xcoord => con.dim[2], styles ...)
line!(con, 0 => ycoord, con.dim[1] => ycoord, styles ...)
mx = con.margin[1]
my = con.margin[2]
division_amountx::Int64 = round((con.dim[1]) / n)
division_amounty::Int64 = round((con.dim[2]) / n)
(begin
line!(con, xcoord + mx => 0 + my, xcoord + mx => con.dim[2] + mx, styles ...)
line!(con, 0 + mx => ycoord + my, con.dim[1] + mx => ycoord + my, styles ...)
end for (xcoord, ycoord) in zip(
range(1 + con.margin[1], con.dim[1],
step = division_amountx), range(1 + con.margin[2], con.dim[2], step = division_amounty))]
range(1, con.dim[1],
step = division_amountx), range(1, con.dim[2], step = division_amounty)))
end

function points!(con::Context, x::Vector{<:Number}, y::Vector{<:Number},
function points!(con::AbstractContext, x::Vector{<:Number}, y::Vector{<:Number},
styles::Pair{String, <:Any} ...)
if length(styles) == 0
styles = ("fill" => "orange", "stroke" => "lightblue", "stroke-width" => "0")
end
xmax::Number, ymax::Number = maximum(x), maximum(y)
percvec_x = map(n::Number -> n / xmax, x)
percvec_y = map(n::Number -> n / ymax, y)
[begin
c = circle(randstring(), cx = string(pointx * con.dim[1]), cy = string(pointy * con.dim[2]), r = "5")
percvec_x::Vector{Float64} = map(n::Number -> n / xmax, x)
percvec_y::Vector{Float64} = map(n::Number -> n / ymax, y)
(begin
c = circle(randstring(), cx = string(pointx * con.dim[1] + con.margin[1]),
cy = string(pointy * con.dim[2] + con.margin[2]), r = "5")
style!(c, styles ...)
draw!(con, [c])
end for (pointx, pointy) in zip(percvec_x, percvec_y)]
end for (pointx, pointy) in zip(percvec_x, percvec_y))
end

function axes!(con::AbstractContext, styles::Pair{String, <:Any} ...)
if length(styles) == 0
styles = ("fill" => "none", "stroke" => "black", "stroke-width" => "4")
end
line!(con, 0 => con.dim[2], con.dim[1] => con.dim[2], styles ...)
println(con.window[:children])
line!(con, 0 => 0, 0 => con.dim[2], styles ...)
line!(con, con.margin[1] => con.dim[2] + con.margin[2],
con.dim[1] + con.margin[1] => con.dim[2] + con.margin[2], styles ...)
line!(con, con.margin[1] => con.margin[2],
con.margin[1] => con.dim[2] + con.margin[2], styles ...)
end

function trendline!(context::Context, styles::Pair{String, String} ...)
Expand Down

0 comments on commit 04de4c9

Please sign in to comment.