-
Notifications
You must be signed in to change notification settings - Fork 248
Expand file tree
/
Copy pathpoint.jl
More file actions
94 lines (82 loc) · 3.96 KB
/
Copy pathpoint.jl
File metadata and controls
94 lines (82 loc) · 3.96 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Geometry which displays points at given (x, y) positions.
struct PointGeometry <: Gadfly.GeometryElement
tag::Symbol
end
PointGeometry(; tag=empty_tag) = PointGeometry(tag)
"""
Geom.point
Draw scatter plots of the `x` and `y` aesthetics.
# Optional Aesthetics
- `color`: Categorical data will choose maximally distinguishable colors from
the LCHab color space. Continuous data will map onto LCHab as well. Colors
can also be specified explicitly for each data point with a vector of colors of
length(x). A vector of length one specifies the color to use for all points.
Default is `Theme.default_color`.
- `shape`: Categorical data will cycle through `Theme.point_shapes`. Shapes
can also be specified explicitly for each data point with a vector of shapes of
length(x). A vector of length one specifies the shape to use for all points.
Default is `Theme.point_shapes[1]`.
- `size`: Categorical data and vectors of `Ints` will interpolate between
`Theme.point_size_{min,max}`. A continuous vector of `AbstractFloats` or
`Measures` of length(x) specifies the size of each data point explicitly. A
vector of length one specifies the size to use for all points. Default is
`Theme.point_size`.
- `alpha`: Categorical data will use the alpha palette in `Theme.alphas`.
Continuous data will remap from 0-1. Default is `Theme.alphas[1]`.
"""
const point = PointGeometry
element_aesthetics(::PointGeometry) = [:x, :y, :size, :color, :shape, :alpha]
# 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)
Gadfly.assert_aesthetics_defined("Geom.point", aes, :x, :y)
Gadfly.assert_aesthetics_equal_length("Geom.point", aes, :x, :y)
default_aes = Gadfly.Aesthetics()
default_aes.shape = Function[theme.point_shapes[1]]
default_aes.color = discretize_make_ia(RGBA{Float32}[theme.default_color])
default_aes.size = Measure[theme.point_size]
default_aes.alpha = [theme.alphas[1]]
aes = inherit(aes, default_aes)
# This remains to preserve the behaviour of Scale.size_discrete (to be replaced)
aes_size = if eltype(aes.size) <: Int
size_min, size_max = extrema(aes.size)
size_range = size_max - size_min
point_size_range = theme.point_size_max - theme.point_size_min
theme.point_size_min .+ ((aes.size .- size_min) ./ size_range .* point_size_range)
else
aes.size
end
aes_alpha = eltype(aes.alpha) <: Int ? theme.alphas[aes.alpha] : aes.alpha
ctx = context()
for (i, (x, y, color, size, shape, alpha)) in
enumerate(Compose.cyclezip(aes.x, aes.y, aes.color, aes_size, aes.shape, aes_alpha))
shapefun = typeof(shape) <: Function ? shape : theme.point_shapes[shape]
strokecolor = aes.color_key_continuous != nothing && aes.color_key_continuous ?
theme.continuous_highlight_color(color) :
theme.discrete_highlight_color(color)
label = aes.color_label([color])[1]
class = svg_color_class_from_label(label)
compose!(ctx, (context(),
(context(), shapefun([x], [y], [size]), svgclass("marker"),
fill(color), stroke(strokecolor), fillopacity(alpha)),
(context(order=2), Shape.datatip([x], [y]),
svgclass("datatip"),
svgattribute("ilabel", string(i,label)),
fillopacity(0.0),
jscall("""
data(\"ilabel\", \"$(string(i,label))\")
.mouseenter(Gadfly.datatip_visible)
.mouseleave(Gadfly.datatip_hidden)
""")),
svgclass(class)))
end
return compose!(context(order=4), ctx, linewidth(theme.highlight_width), svgclass("geometry"))
end