-
Notifications
You must be signed in to change notification settings - Fork 99
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
Adding a 'list of polygons' capability #207
Open
SDiot
wants to merge
8
commits into
enthought:main
Choose a base branch
from
SDiot:feature/list_of_polygons
base: main
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.
+34
−12
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d663bd2
Update better_selecting_zoom.py
SDiot 8911a22
Merge remote-tracking branch 'upstream/master'
SDiot 8171fb8
Add list of polygon capability
SDiot 9e187ad
Update polygon_plot.py
SDiot c0d4b89
Update polygon_plot.py
SDiot e4e5461
Update better_selecting_zoom.py
SDiot 8fba87e
Update polygon_plot.py
SDiot 8905c0e
Update polygon_plot.py
SDiot 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,15 +51,15 @@ class PolygonPlot(BaseXYPlot): | |
|
||
# Override the hittest_type trait inherited from BaseXYPlot | ||
hittest_type = Enum("poly", "point", "line") | ||
|
||
# The RGBA tuple for rendering edges. It is always a tuple of length 4. | ||
# It has the same RGB values as edge_color_, and its alpha value is the | ||
# alpha value of self.edge_color multiplied by self.alpha. | ||
# alpha value of self.edge_color multiplied by self.alpha. | ||
effective_edge_color = Property(Tuple, depends_on=['edge_color', 'alpha']) | ||
|
||
# The RGBA tuple for rendering the face. It is always a tuple of length 4. | ||
# It has the same RGB values as face_color_, and its alpha value is the | ||
# alpha value of self.face_color multiplied by self.alpha. | ||
# alpha value of self.face_color multiplied by self.alpha. | ||
effective_face_color = Property(Tuple, depends_on=['face_color', 'alpha']) | ||
|
||
#---------------------------------------------------------------------- | ||
|
@@ -100,9 +100,19 @@ def _render(self, gc, points): | |
gc.set_line_dash(self.edge_style_) | ||
gc.set_fill_color(self.effective_face_color) | ||
|
||
gc.lines(points) | ||
gc.close_path() | ||
gc.draw_path() | ||
# bnds is True where polygons are separated + ensures last is True | ||
# indx contains the list of indices that separates the polygons | ||
# lines contains a list of lines that represents all polygons | ||
bnds = [np.isnan(point[0]) for point in points] | ||
if not bnds[-1]: | ||
bnds.append(True) | ||
indx = [-1] + [n for n, b in enumerate(bnds) if b] | ||
lines = [points[i+1:j] for i, j in zip(indx[:-1],indx[1:])] | ||
|
||
for line in lines: | ||
gc.lines(line) | ||
gc.close_path() | ||
gc.draw_path() | ||
|
||
|
||
def _render_icon(self, gc, x, y, width, height): | ||
|
@@ -134,11 +144,23 @@ def hittest(self, screen_pt, threshold=7.0, return_distance=False): | |
data_pt = self.map_data(screen_pt, all_values=True) | ||
index = self.index.get_data() | ||
value = self.value.get_data() | ||
poly = np.vstack((index,value)).T | ||
if points_in_polygon([data_pt], poly)[0] == 1: | ||
return True | ||
else: | ||
return False | ||
points = zip(index,value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using |
||
|
||
# bnds is True where polygons are separated + ensures last is True | ||
# indx contains the list of indices that separates the polygons | ||
# lines contains a list of lines that represents all polygons | ||
bnds = [np.isnan(point[0]) for point in points] | ||
if not bnds[-1]: | ||
bnds.append(True) | ||
indx = [-1] + [n for n, b in enumerate(bnds) if b] | ||
lines = [points[i+1:j] for i, j in zip(indx[:-1],indx[1:])] | ||
|
||
for line in lines: | ||
poly = np.vstack(line).T | ||
if points_in_polygon([data_pt], poly)[0] == 1: | ||
return True | ||
|
||
return False | ||
|
||
#------------------------------------------------------------------------ | ||
# Event handlers | ||
|
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.
This is likely to be slow: see https://github.com/enthought/chaco/blob/master/chaco/lineplot.py#L266 for comparison to get an idea of how the line plot finds the runs of non-nan values.
Also this code, and the equivalent code below in
hittest
should probably go into thegather_points
function so that it can be cached and we can avoid re-computation of the polygons on every draw.