Skip to content

Commit

Permalink
Merge pull request #673 from Sjoerd1993/Enhance-canvas-performance
Browse files Browse the repository at this point in the history
Only draw minor ticks if spine visible
  • Loading branch information
cmkohnen authored Dec 31, 2023
2 parents 7a8389d + 12f824f commit aaaae69
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ def _on_pan_gesture(self, event_controller, x, y):
Determines what to do when a panning gesture is detected, pans the
canvas in the gesture direction.
"""
if self.get_application().get_shift():
x, y = y, x
if event_controller.get_unit() == Gdk.ScrollUnit.WHEEL:
x *= 10
y *= 10
if self.get_application().get_ctrl() is False:
if self.get_application().get_shift():
x, y = y, x
if event_controller.get_unit() == Gdk.ScrollUnit.WHEEL:
x *= 10
y *= 10
for ax in self.axes:
xmin, xmax, ymin, ymax = \
self._calculate_pan_values(ax, x, y)
Expand Down Expand Up @@ -295,11 +295,12 @@ def _redraw(self, *_args):
visible_axes[2 + yposition] = True
used_axes[xposition + 2 * yposition] = True
axes_directions = (
("bottom", "left"), # axis
("left", "bottom"), # axis
("top", "left"), # top_left_axis
("bottom", "right"), # right_axis
("top", "right"), # top_right_axis
("right", "top"), # top_right_axis
)
axes_ticks = ("ytick.left", "xtick.top", "xtick.bottom", "ytick.right")

if not any(visible_axes):
visible_axes = (True, False, True, False) # Left and bottom
Expand All @@ -310,18 +311,19 @@ def _redraw(self, *_args):
draw_frame = params["axes.spines.bottom"]
ticks = "both" if params["xtick.minor.visible"] else "major"
possible_directions = ("bottom", "top", "left", "right")
for directions, axis, used \
in zip(axes_directions, self.axes, used_axes):
for directions, axis, used, axis_ticks \
in zip(axes_directions, self.axes, used_axes, axes_ticks):
axis.get_xaxis().set_visible(False)
axis.get_yaxis().set_visible(False)
# Set tick where requested, as long as that axis is not occupied
# and visible
axis.tick_params(which=ticks, **{
direction: (draw_frame and not visible_axes[i]
or direction in directions)
and params[f"{'x' if i < 2 else 'y'}tick.{direction}"]
for i, direction in enumerate(possible_directions)
})
if params[axis_ticks]:
axis.tick_params(which=ticks, **{
direction: (draw_frame and not visible_axes[i]
or direction in directions)
and params[f"{'x' if i < 2 else 'y'}tick.{direction}"]
for i, direction in enumerate(possible_directions)
})
for handle in axis.lines + axis.texts:
handle.remove()
axis_legend = axis.get_legend()
Expand Down

0 comments on commit aaaae69

Please sign in to comment.