Skip to content

Commit 89fe07a

Browse files
perf(plot): skip layout update when title and axis styles are unchanged
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9a221b7 commit 89fe07a

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

‎plotpy/plot/base.py‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,10 @@ def set_title(self, title: str) -> None:
886886
Args:
887887
title (str): the title
888888
"""
889+
current = self.title()
890+
if current.text() == title and current.font().key() == self.font_title.key():
891+
# Nothing changed: setting the title would lay out the plot again
892+
return
889893
text = qwt.QwtText(title)
890894
text.setFont(self.font_title)
891895
self.setTitle(text)
@@ -1044,18 +1048,28 @@ def update_axis_style(self, axis_id: int) -> None:
10441048

10451049
title_font = style.title_font.build_font()
10461050
ticks_font = style.ticks_font.build_font()
1047-
self.setAxisFont(axis_id, ticks_font)
1048-
10491051
if style.title and style.unit:
10501052
title = f"{style.title} ({style.unit})"
10511053
elif style.title:
10521054
title = style.title
10531055
else:
10541056
title = style.unit
1057+
color = QG.QColor(style.color)
10551058
axis_text = self.axisTitle(axis_id)
1059+
# Fonts are compared by key: the widget font is resolved against its
1060+
# parent font, so it never compares equal to the built font
1061+
if (
1062+
self.axisFont(axis_id).key() == ticks_font.key()
1063+
and axis_text.text() == title
1064+
and axis_text.font().key() == title_font.key()
1065+
and axis_text.color() == color
1066+
):
1067+
# Nothing changed: setting the axis title would lay out the plot again
1068+
return
1069+
self.setAxisFont(axis_id, ticks_font)
10561070
axis_text.setFont(title_font)
10571071
axis_text.setText(title)
1058-
axis_text.setColor(QG.QColor(style.color))
1072+
axis_text.setColor(color)
10591073
self.setAxisTitle(axis_id, axis_text)
10601074
self.SIG_PLOT_LABELS_CHANGED.emit(self)
10611075

0 commit comments

Comments
 (0)