Skip to content

Commit

Permalink
added make_gradient
Browse files Browse the repository at this point in the history
  • Loading branch information
emmaccode authored May 10, 2024
1 parent 2401ecb commit 4ce6318
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
17 changes: 14 additions & 3 deletions src/Contexts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,18 @@ Animates the layer `layer` with the animation `animation`.
```
"""
function animate!(con::AbstractContext, layer::String, animation::ToolipsSVG.KeyFrames)
function style!(con::AbstractContext, layer::String, a::ToolipsSVG.ToolipsServables.AbstractAnimation)
layer::Component{<:Any} = con.window[:children][layer]
if length(layer[:children]) > 1
[style!(child, a) for child in layer[:children]]
end
style!(layer, a)
if ~(a.name in con.window[:extras])
push!(con.window[:extras], a)
end
end

function animate!(f::Function, con::AbstractContext, layer::String)

end

Expand Down Expand Up @@ -553,14 +564,14 @@ end
"""
```julia
set_gradient!(ecomp::Pair{Int64, <:ToolipsSVG.ToolipsServables.Servable},
vec::Vector{<:Number}, colors::Vector{String} = ["#DC1C13", "#EA4C46", "#F07470", "#F1959B", "#F6BDC0"]) -> ::Nothing
vec::Vector{<:Number}, colors::Vector{String} = make_gradient((1, 100, 120), 10, 30, 10, -10)) -> ::Nothing
```
`set_gradient!` is used to display new values with a gradient between different colors with `open_layer!`.
```example
```
"""
function set_gradient!(ecomp::Pair{Int64, <:ToolipsSVG.ToolipsServables.Servable}, vec::Vector{<:Number}, colors::Vector{String} = ["#DC1C13", "#EA4C46", "#F07470", "#F1959B", "#F6BDC0"])
function set_gradient!(ecomp::Pair{Int64, <:ToolipsSVG.ToolipsServables.Servable}, vec::Vector{<:Number}, colors::Vector{String} = make_gradient((1, 100, 120), 10, 30, 10, -10))
maxval::Number = maximum(vec)
divisions = length(colors)
div_amount = floor(maxval / divisions)
Expand Down
21 changes: 18 additions & 3 deletions src/Gattino.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ end
```
`Gattino`
- For more information on creating and editing visualizations, use `?context`.
###### export list
###### names
- **colors** (not exported)
```julia
randcolor
make_gradient
```
- **visualizations** (exported)
```julia
# plot | context plotting equivalent
Expand Down Expand Up @@ -73,7 +78,7 @@ module Gattino
using ToolipsSVG
import Base: getindex, setindex!, show, display, vcat, push!, hcat, size, reshape, string
import ToolipsSVG: position, set_position!, set_size!, style!, set_shape, SVGShape
import ToolipsSVG.ToolipsServables: Servable, Component, AbstractComponent, br, gen_ref
import ToolipsSVG.ToolipsServables: Servable, Component, AbstractComponent, br, gen_ref, rgba

include("context_plotting.jl")

Expand Down Expand Up @@ -101,6 +106,16 @@ function randcolor()
colors[rand(1:length(colors))]::String
end

make_gradient(base_color::Tuple, len::Int64, scaler::Int64 ...) = begin
base = [base_color ...]
scaler = [scaler ...]
n = length(scaler)
[begin
[base[e] += scaler[e] for e in 1:n]
rgba(base ...)
end for e in 1:len]
end

"""
```julia
scatter_plot!(con::AbstractContext, x::Vector{<:Number}, y::Vector{<:Number}, features::Pair{String, <:AbstractVector} ...;
Expand Down Expand Up @@ -552,7 +567,7 @@ function hist(features::Any, x::Any = names(features)[1], y::Any = names(feature
hist(string(x), string(y), features, args ...; keyargs ...)
end

export Group, group!, style!, px, pt, group, layers, context, move_layer!, seconds, percent, Context, Animation
export Group, group!, style!, px, pt, group, layers, context, move_layer!, seconds, percent, Context, Animation, rgba, s, ms
export compose, delete_layer!, open_layer!, merge!, set!, set_gradient!, set_shape!
export hist, scatter, line
end # module

0 comments on commit 4ce6318

Please sign in to comment.