-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature/rect #1263
Open
CiaranOMara
wants to merge
7
commits into
GiovineItalia:master
Choose a base branch
from
CiaranOMara:feature/rect
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feature/rect #1263
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9266d3d
Develop RectangularGeometry
CiaranOMara a769495
Correct visibility logic
CiaranOMara 3b529ff
Use Compose.polygon
CiaranOMara 134e935
Develop RectangularGeometry return
CiaranOMara 1185c44
Separate Geom.rect and Geom.rectbin gallery examples
CiaranOMara a7fce1f
Remove Geom.rect from Geom.rectbin test
CiaranOMara 8d72b85
Develop rect test to determine overlap
CiaranOMara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,99 @@ | ||
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) | ||
|
||
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 | ||
|
||
polys = Vector{Vector{Tuple{Measure, Measure}}}(undef, length(xmin)) | ||
for i in 1:length(xmin) | ||
x0 = x_measure(xmin[i]) | ||
x1 = x_measure(xmax[i]) | ||
y0 = y_measure(ymin[i]) | ||
y1 = y_measure(ymax[i]) | ||
polys[i] = Tuple{Measure, Measure}[(x0, y0), (x0, y1), (x1, y1), (x1, y0)] | ||
end | ||
|
||
properties = ( | ||
stroke(nothing), #TODO: Apply theme attributes. | ||
svgclass("geometry"), | ||
svgattribute("shape-rendering", "crispEdges")) | ||
|
||
return compose!( | ||
context(), | ||
Compose.polygon(polys, geom.tag), | ||
fill(cs), | ||
properties...) | ||
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,11 @@ | ||
using DataFrames, Gadfly | ||
|
||
set_default_plot_size(21cm, 8cm) | ||
|
||
Da = DataFrame(x1 = [0, 0.5], y1 = [0, 0.5], x2 = [0.5, 1], y2 = [0.5, 1]) | ||
pa = plot(Da, xmin = :x1, ymin = :y1, xmax = :x2, ymax = :y2, Geom.rect) # Shared corner coordinate. | ||
|
||
Db = DataFrame(x1 = [0, 0.5], y1 = [0, 0.5], x2 = [1, 1.5], y2 = [1, 1.5]) | ||
pb = plot(Db, xmin = :x1, ymin = :y1, xmax = :x2, ymax = :y2, Geom.rect) # Overlapping rects. | ||
|
||
hstack(pa,pb) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran into issues using polygons where one axis was a date/datetime type in: GiovineItalia/Compose.jl#338 (comment). You'll need to include tests of that with this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mattriks could you please elaborate on this request for a test?