-
Notifications
You must be signed in to change notification settings - Fork 0
Created fix for handling large jumps in plotted data. Reworked patch … #5
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
base: main
Are you sure you want to change the base?
Changes from 8 commits
5074f94
011ded9
991eb37
0e030ad
13e2a19
28f843d
eea2b0d
f973c50
1fcd5e2
0660a7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,13 +138,10 @@ def _clip_mpl(self, gc, vertices, obj): | |
| elif obj == "line2d": | ||
| cliprect = Polygon(cliprect) | ||
| line = LineString(vertices) | ||
| try: | ||
| intersection = line.intersection(cliprect) | ||
| except: | ||
| intersection = Polygon() | ||
| intersection = line.intersection(cliprect) | ||
|
|
||
| # Check if intersection is a multi-part geometry | ||
| if intersection.is_empty: | ||
| # if intersection is empty, return empty list of vertices | ||
| vertices = [] # No intersection | ||
| elif ( | ||
| "Multi" in intersection.geom_type | ||
|
|
@@ -168,34 +165,53 @@ def _draw_mpl_lwpoly(self, gc, path, transform, obj): | |
| dxfattribs = self._get_polyline_attribs(gc) | ||
| vertices = path.transformed(transform).vertices | ||
|
|
||
| # clip the polygon if clip rectangle present | ||
|
|
||
| if isinstance(vertices[0][0], float or np.float64): | ||
| vertices = self._clip_mpl(gc, vertices, obj=obj) | ||
| # Check if vertices hold NaN values | ||
| if np.isnan(vertices).any(): | ||
| nan_rows = np.isnan(vertices).all(axis=1) | ||
| split_indices = np.where(nan_rows)[0] | ||
|
|
||
| else: | ||
| vertices = [self._clip_mpl(gc, points, obj=obj) for points in vertices] | ||
| # Split the array at NaN indices | ||
| list_of_split_vertices = np.split(vertices, split_indices) | ||
|
|
||
| # if vertices. | ||
| if len(vertices) == 0: | ||
| entity = None | ||
| # Remove NaN values from sub-arrays | ||
| list_of_split_vertices = [ | ||
| arr[~np.isnan(arr).any(axis=1)] for arr in list_of_split_vertices | ||
| ] | ||
|
|
||
| for split_vertices in list_of_split_vertices: | ||
| self._clip_and_add_mpl_lwpoly(gc, dxfattribs, split_vertices, obj) | ||
| else: | ||
| self._clip_and_add_mpl_lwpoly(gc, dxfattribs, vertices, obj) | ||
|
|
||
| def _clip_and_add_mpl_lwpoly(self, gc, dxfattribs, vertices, obj): | ||
| # clip the polygon if clip rectangle present | ||
| if len(vertices) > 0: | ||
| if isinstance(vertices[0][0], float or np.float64): | ||
| if vertices[0][0] != 0: | ||
| entity = self.modelspace.add_lwpolyline( | ||
| points=vertices, close=False, dxfattribs=dxfattribs | ||
| ) # set close to false because it broke some arrows | ||
| else: | ||
| entity = None | ||
| vertices = self._clip_mpl(gc, vertices, obj=obj) | ||
|
|
||
| else: | ||
| entity = [ | ||
| self.modelspace.add_lwpolyline( | ||
| points=points, close=False, dxfattribs=dxfattribs | ||
| ) | ||
| for points in vertices | ||
| ] # set close to false because it broke some arrows | ||
| vertices = [self._clip_mpl(gc, points, obj=obj) for points in vertices] | ||
|
|
||
| # if vertices. | ||
| if len(vertices) == 0: | ||
| entity = None | ||
|
|
||
| else: | ||
| if isinstance(vertices[0][0], float or np.float64): | ||
| if vertices[0][0] != 0: | ||
| entity = self.modelspace.add_lwpolyline( | ||
| points=vertices, close=False, dxfattribs=dxfattribs | ||
| ) # set close to false because it broke some arrows | ||
| else: | ||
| entity = None | ||
|
|
||
| else: | ||
| entity = [ | ||
| self.modelspace.add_lwpolyline( | ||
| points=points, close=False, dxfattribs=dxfattribs | ||
| ) | ||
| for points in vertices | ||
| ] # set close to false because it broke some arrows | ||
| return entity | ||
|
|
||
| def _draw_mpl_line2d(self, gc, path, transform): | ||
|
|
@@ -323,17 +339,15 @@ def draw_path_collection( | |
| urls, | ||
| offset_position, | ||
| ): | ||
| if self._groupd[-1] == "PolyCollection": | ||
| # Behandle PolyCollection som en samling av 'patch'-objekter | ||
| for path in paths: | ||
| # Kombiner master_transform med path_transform for hver path | ||
| for i, path in enumerate(paths): | ||
|
Collaborator
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. Has this been reverted to an old version of the code?
Collaborator
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. What's the reason for this change?
Collaborator
Author
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. When I tried to figure out where the failure happend, I tried some different approaches and that we didnt handle all_transforms was one thing I was looking into.
Collaborator
Author
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. Sorry, I figured out it actually fixed a bug as well! |
||
| if len(all_transforms): | ||
| combined_transform = master_transform + all_transforms[i] | ||
| else: | ||
| combined_transform = master_transform | ||
| # Her kan du velge å bruke eller tilpasse rgbFace basert på facecolors, hvis det er relevant | ||
| if facecolors.size: | ||
| rgbFace = facecolors[0] if facecolors is not None else None | ||
| else: | ||
| rgbFace = None | ||
| self._draw_mpl_patch(gc, path, combined_transform, rgbFace) | ||
| facecolor = facecolors[i] if i < len(facecolors) else None | ||
| edgecolor = edgecolors[i] if i < len(edgecolors) else None | ||
| # Draw each path as a filled patch | ||
| self._draw_mpl_patch(gc, path, combined_transform, rgbFace=facecolor) | ||
|
|
||
| def draw_path(self, gc, path, transform, rgbFace=None): | ||
| # print('\nEntered ###DRAW_PATH###') | ||
|
|
@@ -352,7 +366,6 @@ def draw_path(self, gc, path, transform, rgbFace=None): | |
| elif self._groupd[-1] == "line2d": | ||
| line = self._draw_mpl_line2d(gc, path, transform) | ||
|
|
||
| # Note if this is used then tick marks and lines with markers go through this function | ||
| def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None): | ||
| # print('\nEntered ###DRAW_MARKERS###') | ||
| # print('\t', self._groupd) | ||
|
|
@@ -479,6 +492,21 @@ def new_gc(self): | |
| def points_to_pixels(self, points): | ||
| return points / 72.0 * self.dpi | ||
|
|
||
| def draw_quad_mesh( | ||
|
Collaborator
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. What's the reason for this change? Do we need it?
Collaborator
Author
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. When I tried to figure out where the failure happend, I tried some different approaches and figured out that we didnt handle quad mesh, so I set up some of the entities we didnt handle to see what wass passed to them. |
||
| self, | ||
| gc, | ||
| master_transform, | ||
| meshWidth, | ||
| meshHeight, | ||
| coordinates, | ||
| offsets, | ||
| offsetTrans, | ||
| facecolors, | ||
| antialiased, | ||
| edgecolors, | ||
| ): | ||
| pass | ||
|
|
||
|
|
||
| class FigureCanvasDxf(FigureCanvasBase): | ||
| """ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.