Skip to content
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

Fix drawing issues with wrong origin in line plot related compositors. Fixes #1223. #1235

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 36 additions & 26 deletions nion/swift/LineGraphCanvasItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ def convert_coordinate_to_pixel(canvas_size: Geometry.IntSize, c: float, data_sc
index = region.index
level = canvas_size.height - canvas_size.height * 0.8 + index * 8
with drawing_context.saver():
drawing_context.translate(canvas_bounds.left, canvas_bounds.top)
drawing_context.clip_rect(0, 0, canvas_size.width, canvas_size.height)
drawing_context.begin_path()

Expand Down Expand Up @@ -1013,6 +1014,7 @@ def _repaint(self, drawing_context: DrawingContext.DrawingContext, canvas_bounds
x_ticks = axes.calculate_x_ticks(plot_width)
# draw the tick marks
with drawing_context.saver():
drawing_context.translate(canvas_bounds.left, canvas_bounds.top)
for x, _ in x_ticks:
drawing_context.begin_path()
drawing_context.move_to(x, 0)
Expand Down Expand Up @@ -1055,6 +1057,7 @@ def _repaint(self, drawing_context: DrawingContext.DrawingContext, canvas_bounds
x_ticks = axes.calculate_x_ticks(canvas_size.width - 1)
# draw the tick marks
with drawing_context.saver():
drawing_context.translate(canvas_bounds.left, canvas_bounds.top)
drawing_context.font = "{0:d}px".format(self.__font_size)
for x, label in x_ticks:
drawing_context.text_align = "center"
Expand Down Expand Up @@ -1096,6 +1099,7 @@ def _repaint(self, drawing_context: DrawingContext.DrawingContext, canvas_bounds
if axes.x_calibration and axes.x_calibration.units:
plot_width = canvas_size.width - 1
with drawing_context.saver():
drawing_context.translate(canvas_bounds.left, canvas_bounds.top)
drawing_context.text_align = "center"
drawing_context.text_baseline = "middle"
drawing_context.fill_style = "#000"
Expand Down Expand Up @@ -1150,6 +1154,7 @@ def _repaint(self, drawing_context: DrawingContext.DrawingContext, canvas_bounds
y_ticks = axes.calculate_y_ticks(canvas_size.height - 1)
# draw the y_ticks and labels
with drawing_context.saver():
drawing_context.translate(canvas_bounds.left, canvas_bounds.top)
for y, _, _ in y_ticks:
drawing_context.begin_path()
drawing_context.move_to(canvas_size.width, y)
Expand Down Expand Up @@ -1265,6 +1270,7 @@ def _repaint(self, drawing_context: DrawingContext.DrawingContext, canvas_bounds

# draw the y_ticks and labels
with drawing_context.saver():
drawing_context.translate(canvas_bounds.left, canvas_bounds.top)
drawing_context.text_baseline = "middle"
drawing_context.font = "{0:d}px".format(self.__font_size)
for y, label, is_minor in y_ticks:
Expand Down Expand Up @@ -1333,6 +1339,7 @@ def _repaint(self, drawing_context: DrawingContext.DrawingContext, canvas_bounds
if axes:
if axes.y_calibration and axes.y_calibration.units:
with drawing_context.saver():
drawing_context.translate(canvas_bounds.left, canvas_bounds.top)
drawing_context.font = "{0:d}px".format(self.__font_size)
drawing_context.text_align = "center"
drawing_context.text_baseline = "middle"
Expand Down Expand Up @@ -1443,41 +1450,44 @@ def _repaint(self, drawing_context: DrawingContext.DrawingContext, canvas_bounds
legend_height = len(effective_entries_and_foreign) * line_height

with drawing_context.saver():
drawing_context.begin_path()
drawing_context.rect(0,
0,
legend_width + border * 2 + line_height,
legend_height + border * 2)
drawing_context.fill_style = "rgba(192, 192, 192, 0.5)"
drawing_context.fill()
drawing_context.translate(canvas_bounds.left, canvas_bounds.top)

if mouse_pressed_for_dragging or foreign_legend_entry is not None:
with drawing_context.saver():
drawing_context.begin_path()
entry_to_insert = entry_to_insert or 0 # for type checking
drawing_context.rect(0,
entry_to_insert * line_height + border,
0,
legend_width + border * 2 + line_height,
line_height)
legend_height + border * 2)
drawing_context.fill_style = "rgba(192, 192, 192, 0.5)"
drawing_context.fill()

for index, legend_entry in enumerate(effective_entries_and_foreign):
with drawing_context.saver():
drawing_context.font = font
drawing_context.text_align = "right"
drawing_context.text_baseline = "bottom"
drawing_context.fill_style = "#000"
drawing_context.fill_text(legend_entry.label, legend_width + border, line_height * (index + 1) - 4 + border)

drawing_context.begin_path()
drawing_context.rect(legend_width + border + 3, line_height * index + 3 + border, line_height - 6, line_height - 6)
if legend_entry.fill_color:
drawing_context.fill_style = legend_entry.fill_color
if mouse_pressed_for_dragging or foreign_legend_entry is not None:
with drawing_context.saver():
drawing_context.begin_path()
entry_to_insert = entry_to_insert or 0 # for type checking
drawing_context.rect(0,
entry_to_insert * line_height + border,
legend_width + border * 2 + line_height,
line_height)
drawing_context.fill_style = "rgba(192, 192, 192, 0.5)"
drawing_context.fill()
if legend_entry.stroke_color:
drawing_context.stroke_style = legend_entry.stroke_color
drawing_context.stroke()

for index, legend_entry in enumerate(effective_entries_and_foreign):
with drawing_context.saver():
drawing_context.font = font
drawing_context.text_align = "right"
drawing_context.text_baseline = "bottom"
drawing_context.fill_style = "#000"
drawing_context.fill_text(legend_entry.label, legend_width + border, line_height * (index + 1) - 4 + border)

drawing_context.begin_path()
drawing_context.rect(legend_width + border + 3, line_height * index + 3 + border, line_height - 6, line_height - 6)
if legend_entry.fill_color:
drawing_context.fill_style = legend_entry.fill_color
drawing_context.fill()
if legend_entry.stroke_color:
drawing_context.stroke_style = legend_entry.stroke_color
drawing_context.stroke()


class LineGraphLegendCanvasItem(CanvasItem.AbstractCanvasItem):
Expand Down
1 change: 0 additions & 1 deletion nion/swift/LinePlotCanvasItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from nion.swift.model import DisplayItem
from nion.swift.model import Graphics
from nion.swift.model import UISettings
from nion.swift.model import Utility
from nion.ui import CanvasItem
from nion.utils import Color
from nion.utils import Geometry
Expand Down