From 04de4c92d4e6698b5017ad889bd34eb272f08108 Mon Sep 17 00:00:00 2001 From: emmy <52672675+emmettgb@users.noreply.github.com> Date: Sun, 19 Feb 2023 23:28:32 -0600 Subject: [PATCH] revised existing functions to fit margins --- Manifest.toml | 6 ++++++ Project.toml | 1 + src/context_plotting.jl | 39 ++++++++++++++++++++++----------------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index d7f1160..6382098 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -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" diff --git a/Project.toml b/Project.toml index c1f3189..d2204c4 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/context_plotting.jl b/src/context_plotting.jl index b0e5e82..9c055cd 100644 --- a/src/context_plotting.jl +++ b/src/context_plotting.jl @@ -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} ...)