diff --git a/src/Contexts.jl b/src/Contexts.jl index fbbc9fb..012782a 100644 --- a/src/Contexts.jl +++ b/src/Contexts.jl @@ -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 @@ -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) diff --git a/src/Gattino.jl b/src/Gattino.jl index bd9dd23..a8cff5e 100644 --- a/src/Gattino.jl +++ b/src/Gattino.jl @@ -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 @@ -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") @@ -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} ...; @@ -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