From d663bd206978e262e11468c8c7ce5d1578e37f5a Mon Sep 17 00:00:00 2001 From: Steven Diot Date: Wed, 21 May 2014 08:56:37 -0600 Subject: [PATCH 1/7] Update better_selecting_zoom.py --- chaco/tools/better_selecting_zoom.py | 1 - 1 file changed, 1 deletion(-) diff --git a/chaco/tools/better_selecting_zoom.py b/chaco/tools/better_selecting_zoom.py index 1153d7fee..52871da91 100644 --- a/chaco/tools/better_selecting_zoom.py +++ b/chaco/tools/better_selecting_zoom.py @@ -327,7 +327,6 @@ def _end_select(self, event): """ Ends selection of the zoom region, adds the new zoom range to the zoom stack, and does the zoom. """ - self._screen_end = (event.x, event.y) start = numpy.array(self._screen_start) end = numpy.array(self._screen_end) From 8171fb8ac7c914d14ab389a9020e46f681fa4dde Mon Sep 17 00:00:00 2001 From: Steven Diot Date: Thu, 10 Jul 2014 20:38:45 -0600 Subject: [PATCH 2/7] Add list of polygon capability This mod allows to send a list of polygons separated by bumpy.nan to dramatically speed-up the plots when all the polygons have the same properties (colors, line width). --- chaco/polygon_plot.py | 44 ++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/chaco/polygon_plot.py b/chaco/polygon_plot.py index 864d964c9..c8ed65d95 100644 --- a/chaco/polygon_plot.py +++ b/chaco/polygon_plot.py @@ -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,8 +100,18 @@ 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() + # bnds is True where where polygons are separated, last is also 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() @@ -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) + + # bnds is True where where polygons are separated, last is also 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 From 9e187ad5c12e12a48527b86ed3336661935a3b53 Mon Sep 17 00:00:00 2001 From: Steven Diot Date: Fri, 11 Jul 2014 09:16:46 -0600 Subject: [PATCH 3/7] Update polygon_plot.py --- chaco/polygon_plot.py | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/chaco/polygon_plot.py b/chaco/polygon_plot.py index c8ed65d95..e523f33ad 100644 --- a/chaco/polygon_plot.py +++ b/chaco/polygon_plot.py @@ -100,18 +100,8 @@ def _render(self, gc, points): gc.set_line_dash(self.edge_style_) gc.set_fill_color(self.effective_face_color) - # bnds is True where where polygons are separated, last is also 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.lines(points) + gc.close_path() gc.draw_path() @@ -144,23 +134,11 @@ 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() - points = zip(index,value) - - # bnds is True where where polygons are separated, last is also 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 + poly = np.vstack((index,value)).T + if points_in_polygon([data_pt], poly)[0] == 1: + return True + else: + return False #------------------------------------------------------------------------ # Event handlers From c0d4b89ef80f710d6fa8347a6d7592c8b37894fb Mon Sep 17 00:00:00 2001 From: Steven Diot Date: Fri, 11 Jul 2014 09:32:00 -0600 Subject: [PATCH 4/7] Update polygon_plot.py Add a 'list of polygons' capability. A PR will come soon. --- chaco/polygon_plot.py | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/chaco/polygon_plot.py b/chaco/polygon_plot.py index e523f33ad..c8ed65d95 100644 --- a/chaco/polygon_plot.py +++ b/chaco/polygon_plot.py @@ -100,8 +100,18 @@ 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() + # bnds is True where where polygons are separated, last is also 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() @@ -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) + + # bnds is True where where polygons are separated, last is also 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 From e4e54618704fb5e2d0cb4ac0009a1386e533cbcd Mon Sep 17 00:00:00 2001 From: Steven Diot Date: Fri, 11 Jul 2014 09:36:20 -0600 Subject: [PATCH 5/7] Update better_selecting_zoom.py back to original file so that only polygon_plot.py is modified compared to chaco/Master --- chaco/tools/better_selecting_zoom.py | 1 + 1 file changed, 1 insertion(+) diff --git a/chaco/tools/better_selecting_zoom.py b/chaco/tools/better_selecting_zoom.py index 52871da91..1153d7fee 100644 --- a/chaco/tools/better_selecting_zoom.py +++ b/chaco/tools/better_selecting_zoom.py @@ -327,6 +327,7 @@ def _end_select(self, event): """ Ends selection of the zoom region, adds the new zoom range to the zoom stack, and does the zoom. """ + self._screen_end = (event.x, event.y) start = numpy.array(self._screen_start) end = numpy.array(self._screen_end) From 8fba87e7ae84014f2a93ca50a2902af8712315ff Mon Sep 17 00:00:00 2001 From: Steven Diot Date: Fri, 11 Jul 2014 09:38:15 -0600 Subject: [PATCH 6/7] Update polygon_plot.py --- chaco/polygon_plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaco/polygon_plot.py b/chaco/polygon_plot.py index c8ed65d95..77b54f0f9 100644 --- a/chaco/polygon_plot.py +++ b/chaco/polygon_plot.py @@ -112,7 +112,7 @@ def _render(self, gc, points): for line in lines: gc.lines(line) gc.close_path() - gc.draw_path() + gc.draw_path() def _render_icon(self, gc, x, y, width, height): From 8905c0ed494e9eb9e0794872607ae3e519661c1c Mon Sep 17 00:00:00 2001 From: Steven Diot Date: Fri, 11 Jul 2014 09:40:06 -0600 Subject: [PATCH 7/7] Update polygon_plot.py --- chaco/polygon_plot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chaco/polygon_plot.py b/chaco/polygon_plot.py index 77b54f0f9..59edc7942 100644 --- a/chaco/polygon_plot.py +++ b/chaco/polygon_plot.py @@ -100,7 +100,7 @@ def _render(self, gc, points): gc.set_line_dash(self.edge_style_) gc.set_fill_color(self.effective_face_color) - # bnds is True where where polygons are separated, last is also True + # 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] @@ -146,7 +146,7 @@ def hittest(self, screen_pt, threshold=7.0, return_distance=False): value = self.value.get_data() points = zip(index,value) - # bnds is True where where polygons are separated, last is also True + # 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]