Skip to content

Commit

Permalink
new legend preview binding
Browse files Browse the repository at this point in the history
  • Loading branch information
emmaccode authored May 10, 2024
1 parent b35aed2 commit ce11220
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/Gattino.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ end
`Gattino`
- For more information on creating and editing visualizations, use `?context`.
###### export list
- **visualizations**
- **visualizations** (exported)
```julia
# plot | context plotting equivalent
scatter #| scatter_plot!
line #| line_plot!
hist #| hist_plot!
```
- **contexts**
- **contexts** (exported)
```julia
AbstractContext
compose
Expand All @@ -50,7 +50,7 @@ set!
set_gradient!
style!(ecomp::Pair{Int64, <:ToolipsSVG.ToolipsServables.AbstractComponent}, vec::Vector{<:Number}, stylep::Pair{String, Int64} ...)
```
- **context plotting**
- **context plotting** (not exported)
```julia
text!
line!
Expand All @@ -66,6 +66,7 @@ v_bars!
v_barlabels!
legend!
append_legend!
make_legend_preview
```
"""
module Gattino
Expand Down Expand Up @@ -313,7 +314,7 @@ function line_plot!(con::AbstractContext, x::Vector{<:Number}, y::Vector{<:Numbe
end
lbls = [begin
group!(plotgroup, feature[1]) do g::Group
line!(g, x, feature[2], "fill" => colors[e], xmax = xmax, ymax = ymax, xmin = xmin, ymin = ymin)
line!(g, x, feature[2], "stroke" => colors[e], "stroke-width" => 3px, "fill" => "none", xmax = xmax, ymax = ymax, xmin = xmin, ymin = ymin)
end
string(feature[1])::String
end for (e, feature) in enumerate(features)]
Expand Down
22 changes: 16 additions & 6 deletions src/context_plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function line!(con::AbstractContext, x::Vector{<:AbstractString}, y::Vector{<:Nu
scaled_y::Int64 = con.dim[2] - round(con.dim[2] * yper) + con.margin[2]
"$(scaled_x)&#32;$(scaled_y),"
end for (xper, yper) in zip(percvec_x, percvec_y)])
line_comp = ToolipsSVG.polyline("newline", points = line_data)
line_comp = ToolipsSVG.polyline("newline", points = line_data[1:length(line_data) - 1])
style!(line_comp, styles ...)
draw!(con, [line_comp])
nothing::Nothing
Expand All @@ -100,7 +100,7 @@ function line!(con::AbstractContext, x::Vector{<:Number}, y::Vector{<:Number},
scaled_y::Int64 = con.dim[2] - round(con.dim[2] * yper) + con.margin[2]
"$(scaled_x)&#32;$(scaled_y),"
end for (xper, yper) in zip(percvec_x, percvec_y)])
line_comp = ToolipsSVG.polyline("newline", points = line_data)
line_comp = ToolipsSVG.polyline("newline", points = line_data[1:length(line_data) - 1])
style!(line_comp, styles ...)
draw!(con, [line_comp])
end
Expand Down Expand Up @@ -560,9 +560,9 @@ function legend!(con::AbstractContext, names::Vector{String}, styles::Pair{Strin
style!(legbox, styles ...)
push!(legg, legbox)
[begin
samp = con.window[:children][name][:children][1]
samp = make_legend_preview(copy(con.window[:children][name][:children][1]),
positionx + sample_margin, positiony + sample_margin * e)
samp.name = "$(name)-preview"
set_position!(samp, positionx + sample_margin, positiony + sample_margin * e)
samplabel = ToolipsSVG.text("$(name)-label", x = positionx + (sample_margin * 2), y = positiony + (sample_margin * e * 1.15),
text = name)
style!(samplabel, "stroke" => "darkgray", "font-size" => 9pt)
Expand Down Expand Up @@ -593,9 +593,8 @@ function append_legend!(con::AbstractContext, name::String; sample_width::Number
n_features::Int64 = length(legend[:children]) - 1
box::Component{:rect} = legend[:children]["legendbg"]
positionx, positiony = box[:x], box[:y]
samp = con.window[:children][name][:children][1]
samp = make_legend_preview(copy(con.window[:children][name][:children][1]), positionx + sample_margin, positiony + sample_margin * (n_features))
box[:height] += 20
set_position!(samp, positionx + sample_margin, positiony + sample_margin * (n_features))
samplabel = ToolipsSVG.text("$(name)-label", x = positionx + (sample_margin * 2), y = positiony + (sample_margin * (n_features) * 1.15),
text = name)
style!(samplabel, "stroke" => "darkgray", "font-size" => 9pt)
Expand Down Expand Up @@ -648,4 +647,15 @@ function remove_legend!(con::AbstractContext, name::String)
pos = findfirst(comp -> comp.name == name, legendcs)
deleteat!(legendcs, pos); deleteat!(legendcs, pos + 1)
nothing::Nothing
end

function make_legend_preview(comp::Component{<:Any}, x::Number, y::Number)
set_position!(comp, x, y)
comp::Component{<:Any}
end


function make_legend_preview(comp::Component{:polyline}, x::Number, y::Number)
comp.properties[:points] = "$(x - 5)&#32;$(y),$(x + 10)&#32;$(y),"
comp::Component{:polyline}
end

0 comments on commit ce11220

Please sign in to comment.