Skip to content

Commit

Permalink
Work
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaranOMara committed May 10, 2019
1 parent beee870 commit dc3805c
Showing 1 changed file with 68 additions and 34 deletions.
102 changes: 68 additions & 34 deletions src/geom/rect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,45 +37,74 @@ element_aesthetics(::RectangularGeometry) =
#
function render(geom::RectangularGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics)

Gadfly.assert_aesthetics_defined("RectangularGeometry", aes, :xmin, :xmax, :ymin, :ymax)
Gadfly.assert_aesthetics_equal_length("RectangularGeometry", aes, :xmin, :xmax, :ymin, :ymax)

n = length(aes.xmin)

default_aes = Gadfly.Aesthetics()
default_aes.color = discretize_make_ia(RGBA{Float32}[theme.default_color])
# default_aes.alpha = fill(1, length(aes.x))
default_aes.alpha = Float64[theme.alphas[1]]
# default_aes.alpha = [theme.alphas[1]]
# default_aes.color = discretize_make_ia(RGBA{Float32}[theme.default_color])
# default_aes.color = fill(theme.default_color, length(aes.x))
default_aes.color = RGBA{Float32}[theme.default_color]
default_aes.group = IndirectArray(fill(1,length(aes.x)))
default_aes.linestyle = fill(1, length(aes.x))
aes = inherit(aes, default_aes)

Gadfly.assert_aesthetics_defined("RectangularGeometry", aes, :xmin, :xmax, :ymin, :ymax)
Gadfly.assert_aesthetics_equal_length("RectangularGeometry", aes, :xmin, :xmax, :ymin, :ymax)

aes_alpha = eltype(aes.alpha) <: Int ? theme.alphas[aes.alpha] : aes.alpha

strokef = aes.color_key_continuous != nothing && aes.color_key_continuous ?
theme.continuous_highlight_color : theme.discrete_highlight_color

CT, AT = eltype(aes.color), eltype(aes_alpha)
groups = collect(Tuple{CT, AT}, Compose.cyclezip(aes.color, aes_alpha))
ug = unique(groups)


for (k,g) in enumerate(ug)
i = groups.==[g]
polys[k] = polygon_points(aes_x[i], aes_y[i], geom.preserve_order)
colors[k] = first(aes_color[i])
line_styles[k] = mod1(first(aes_linestyle[i]), linestyle_palette_length)
alphas[k] = first(alpha_discrete ? theme.alphas[aes_alpha[i]] : aes_alpha[i])
end

xmin = aes.xmin
xmax = aes.xmax
ymin = aes.ymin
ymax = aes.ymax

n = length(xmin)

if length(aes.color) == n
cs = aes.color
else
cs = Vector{RGBA{Float32}}(undef, n)
for i in 1:n
cs[i] = aes.color[((i - 1) % length(aes.color)) + 1]
end
end

allvisible = true
for c in cs
if c == nothing
allvisible = false
break
end
end

if !allvisible
visibility = cs .!= nothing
cs = cs[visibility]
xmin = xmin[visibility]
xmax = xmax[visibility]
ymin = ymin[visibility]
ymax = ymax[visibility]
end
# @info(aes.color)
#
# if length(aes.color) == n
# colors = aes.color
# else #Note: at least RGBA{Float32}[default colour] was inherited.
# colors = Vector{RGBA{Float32}}(undef, n)
# for i in 1:n
# cs[i] = aes.color[((i - 1) % length(aes.color)) + 1]
# end
# end
#
# allvisible = true
# for c in cs
# if c == nothing
# allvisible = false
# break
# end
# end
#
# if !allvisible
# visibility = colors .!= nothing
# colors = colors[visibility]
# xmin = xmin[visibility]
# xmax = xmax[visibility]
# ymin = ymin[visibility]
# ymax = ymax[visibility]
# end

polys = Vector{Vector{Tuple{Measure, Measure}}}(undef, length(xmin))
for i in 1:length(xmin)
Expand All @@ -86,14 +115,19 @@ function render(geom::RectangularGeometry, theme::Gadfly.Theme, aes::Gadfly.Aest
polys[i] = Tuple{Measure, Measure}[(x0, y0), (x0, y1), (x1, y1), (x1, y0)]
end

linestyles = Gadfly.get_stroke_vector.(theme.line_style[line_styles])

properties = (
stroke(nothing), #TODO: Apply theme attributes.
svgclass("geometry"),
svgattribute("shape-rendering", "crispEdges"))
fill(colors),
fillopacity(alphas),
stroke(theme.discrete_highlight_color.(colors)),
strokedash(linestyles),
linewidth(theme.highlight_width),
svgclass("geometry"))

return compose!(
context(),
context(order = geom.order),
Compose.polygon(polys, geom.tag),
fill(cs),
properties...)

end

0 comments on commit dc3805c

Please sign in to comment.