forked from GiovineItalia/Gadfly.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
point.jl
73 lines (58 loc) · 2 KB
/
point.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Geometry which displays points at given (x, y) positions.
immutable PointGeometry <: Gadfly.GeometryElement
end
const point = PointGeometry
function element_aesthetics(::PointGeometry)
[:x, :y, :size, :color]
end
# Generate a form for a point geometry.
#
# Args:
# geom: point geometry.
# theme: the plot's theme.
# aes: aesthetics.
#
# Returns:
# A compose Form.
#
function render(geom::PointGeometry, theme::Gadfly.Theme,
aes::Gadfly.Aesthetics, data::Gadfly.Data,
scales::Dict{Symbol, ScaleElement})
Gadfly.assert_aesthetics_defined("Geom.point", aes, :x, :y)
Gadfly.assert_aesthetics_equal_length("Geom.point", aes,
element_aesthetics(geom)...)
default_aes = Gadfly.Aesthetics()
default_aes.color = PooledDataArray(RGB{Float32}[theme.default_color])
default_aes.size = Measure[theme.default_point_size]
aes = inherit(aes, default_aes)
lw_hover_scale = 10
lw_ratio = theme.line_width / aes.size[1]
if !all(map(isconcrete, aes.x)) || !all(map(isconcrete, aes.y))
aes_x = Array(eltype(aes.x), 0)
aes_y = Array(eltype(aes.y), 0)
for (x, y) in zip(aes.x, aes.y)
if !isconcrete(x) || !isconcrete(y)
continue
end
push!(aes_x, x)
push!(aes_y, y)
end
else
aes_x, aes_y = aes.x, aes.y
end
ctx = compose!(
context(),
circle(aes.x, aes.y, aes.size),
fill(aes.color),
linewidth(theme.highlight_width))
if aes.color_key_continuous != nothing && aes.color_key_continuous
compose!(ctx,
stroke(map(theme.continuous_highlight_color, aes.color)))
else
compose!(ctx,
stroke(map(theme.discrete_highlight_color, aes.color)),
svgclass([svg_color_class_from_label(escape_id(aes.color_label([c])[1]))
for c in aes.color]))
end
return compose!(context(order=4), svgclass("geometry"), ctx)
end