Skip to content

Commit 0980fe7

Browse files
committed
change way of MarkerSelector widget size initialization
1 parent b4d064b commit 0980fe7

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

examples/main.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
"marker_selector_widget = MarkerSelectorWidget(\n",
120120
" image_data=plot.data,\n",
121121
" markers_number=plot.markers_number,\n",
122-
" fig_size=15,\n",
122+
" fig_size=10,\n",
123123
")"
124124
]
125125
},

src/scanplot/view/marker_selector_widget.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,25 @@ def __init__(
1919
self._marker_labels: list[str] = [
2020
f"marker{i+1}" for i in range(self.markers_number)
2121
]
22+
23+
# control widget size
2224
self._fig_size = fig_size
25+
self._scaling_factor = fig_size / 10
26+
h_image, w_image = image_data.shape[0], image_data.shape[1]
27+
# add 120 to prevent hiding buttons
28+
self._widget_height_px = int(h_image * self._scaling_factor) + 120
29+
self._widget_width_px = int(w_image * self._scaling_factor)
2330

2431
super().__init__(
2532
hide_buttons=True,
2633
classes=self._marker_labels,
2734
image_bytes=cv.imencode(".png", self.image_data)[1].tobytes(),
2835
layout={
29-
"width": f"{self._fig_size_px}px",
30-
"height": f"{self._fig_size_px}px",
36+
"width": f"{self._widget_width_px}px",
37+
"height": f"{self._widget_height_px}px",
3138
},
3239
)
3340

34-
@property
35-
def _fig_size_px(self) -> int:
36-
return 50 * self._fig_size
37-
3841
def widget(self):
3942
return self
4043

0 commit comments

Comments
 (0)