0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 11:41:49 +02:00

fix(plot_base): font size is set with setScale which is scaling the whole legend window

This commit is contained in:
2024-06-19 11:43:44 +02:00
committed by wyzula_j
parent 140ad83380
commit 5d6672069e
2 changed files with 10 additions and 17 deletions

View File

@ -139,16 +139,10 @@ class BECPlotBase(BECConnector, pg.GraphicsLayout):
if self.config.axis.legend_label_size or size: if self.config.axis.legend_label_size or size:
if size: if size:
self.config.axis.legend_label_size = size self.config.axis.legend_label_size = size
style = { scale = (
"color": self.get_text_color(), size / 9
"size": f"{self.config.axis.legend_label_size}pt", ) # 9 is the default font size of the legend, so we always scale it against 9
} self.plot_item.legend.setScale(scale)
else:
style = {}
for item in self.plot_item.legend.items:
for single_item in item:
if isinstance(single_item, pg.graphicsItems.LabelItem.LabelItem):
single_item.setText(single_item.text, **style)
def get_text_color(self): def get_text_color(self):
return "#FFF" if self.figure.config.theme == "dark" else "#000" return "#FFF" if self.figure.config.theme == "dark" else "#000"

View File

@ -201,13 +201,12 @@ def test_change_legend_font_size(bec_figure):
plot = bec_figure.add_plot() plot = bec_figure.add_plot()
w1 = plot.add_curve_scan(x_name="samx", y_name="bpm4i") w1 = plot.add_curve_scan(x_name="samx", y_name="bpm4i")
my_func = plot.plot_item.legend.items[0][1] my_func = plot.plot_item.legend
with mock.patch.object(my_func, "setText") as mock_set_text: with mock.patch.object(my_func, "setScale") as mock_set_scale:
plot.set_legend_label_size(16) plot.set_legend_label_size(18)
assert plot.config.axis.legend_label_size == 16 assert plot.config.axis.legend_label_size == 18
assert mock_set_text.call_count == 1 assert mock_set_scale.call_count == 1
style = {"color": plot.get_text_color(), "size": "16pt"} assert mock_set_scale.call_args == mock.call(2)
assert mock_set_text.call_args == mock.call(my_func.text, **style)
def test_remove_curve(bec_figure): def test_remove_curve(bec_figure):