-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
675a586
commit a2648b1
Showing
5 changed files
with
125 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using Compose: x_measure, y_measure | ||
|
||
struct RectangularGeometry <: Gadfly.GeometryElement | ||
default_statistic::Gadfly.StatisticElement | ||
tag::Symbol | ||
end | ||
|
||
function RectangularGeometry( | ||
default_statistic::Gadfly.StatisticElement=Gadfly.Stat.identity(); | ||
tag=empty_tag) | ||
RectangularGeometry(default_statistic, tag) | ||
end | ||
|
||
""" | ||
Geom.rect | ||
Draw colored rectangles with the corners specified by the | ||
`xmin`, `xmax`, `ymin` and `ymax` aesthetics. Optionally | ||
specify their `color`. | ||
""" | ||
const rect = RectangularGeometry | ||
|
||
default_statistic(geom::RectangularGeometry) = geom.default_statistic | ||
|
||
element_aesthetics(::RectangularGeometry) = | ||
[:xmin, :xmax, :ymin, :ymax, :color] | ||
|
||
# Render rectangle geometry. | ||
# | ||
# Args: | ||
# geom: rect geometry | ||
# theme: the plot's theme | ||
# aes: some aesthetics | ||
# | ||
# Returns | ||
# A compose form. | ||
# | ||
function render(geom::RectangularGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics) | ||
|
||
default_aes = Gadfly.Aesthetics() | ||
default_aes.color = discretize_make_ia(RGBA{Float32}[theme.default_color]) | ||
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) | ||
|
||
nx = length(aes.xmin) | ||
ny = length(aes.ymin) | ||
n = nx | ||
|
||
xmin = aes.xmin | ||
xwidths = [(x1 - x0)*cx | ||
for (x0, x1) in zip(aes.xmin, aes.xmax)] | ||
|
||
ymin = aes.ymin | ||
ywidths = [(y1 - y0)*cy | ||
for (y0, y1) in zip(aes.ymin, aes.ymax)] | ||
|
||
if length(aes.color) == n | ||
cs = aes.color | ||
else | ||
cs = Array{RGBA{Float32}}(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 | ||
|
||
return compose!( | ||
context(), | ||
rectangle(xmin, ymin, xwidths, ywidths, geom.tag), | ||
fill(cs), | ||
stroke(nothing), | ||
svgclass("geometry"), | ||
svgattribute("shape-rendering", "crispEdges")) | ||
|
||
# TODO: determine performance hit of using polygons. | ||
# polys = Vector{Vector{Tuple{Measure, Measure}}}(n) | ||
# for i in 1:n | ||
# x0 = x_measure(aes.xmin[i]) | ||
# x1 = x_measure(aes.xmax[i]) | ||
# y0 = y_measure(aes.ymin[i]) | ||
# y1 = y_measure(aes.ymax[i]) | ||
# polys[i] = Tuple{Measure, Measure}[(x0, y0), (x0, y1), (x1, y1), (x1, y0)] | ||
# end | ||
# | ||
# return compose!( | ||
# context(), | ||
# Compose.polygon(polys), | ||
# fill(color), | ||
# stroke(nothing), | ||
# svgclass("geometry"), | ||
# svgattribute("shape-rendering", "crispEdges")) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using DataFrames, Gadfly | ||
|
||
set_default_plot_size(6inch, 3inch) | ||
|
||
D = DataFrame(x1=[0,0.5], y1=[0,0.5], x2=[1,1.5], y2=[1,1.5]) | ||
pb = plot(D, xmin=:x1, ymin=:y1, xmax=:x2, ymax=:y2, Geom.rect) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters