1919from qwt import QwtPlotItem
2020
2121from plotpy .config import _
22- from plotpy .interfaces import (
23- IBasePlotItem ,
24- ICurveItemType ,
25- ISerializableType ,
26- ITrackableItemType ,
27- )
28- from plotpy .items .curve .base import SELECTED_SYMBOL
29- from plotpy .styles .curve import CurveParam
22+ from plotpy .interfaces import IBasePlotItem , ISerializableType , ITrackableItemType
23+ from plotpy .styles import PolygonMapParam
3024
3125if TYPE_CHECKING : # pragma: no cover
3226 import guidata .dataset .io
4034def simplify_poly (pts , off , scale , bounds ):
4135 """Simplify a polygon by removing points outside the canvas"""
4236 ax , bx , ay , by = scale
43- xm , ym , xM , yM = bounds
4437 a = np .array ([[ax , ay ]])
4538 b = np .array ([[bx , by ]])
4639 _pts = a * pts + b
@@ -57,9 +50,10 @@ def simplify_poly(pts, off, scale, bounds):
5750
5851
5952class PolygonMapItem (QwtPlotItem ):
60- """
61- Construct a curve `plot item` with the parameters *curveparam*
62- (see :py:class:`.styles.CurveParam`)
53+ """Construct a PolygonMapItem object
54+
55+ Args:
56+ param: Polygon parameters
6357 """
6458
6559 __implements__ = (IBasePlotItem , ISerializableType )
@@ -71,20 +65,20 @@ class PolygonMapItem(QwtPlotItem):
7165 _can_move = False
7266 _can_rotate = False
7367
74- def __init__ (self , curveparam = None ):
68+ def __init__ (self , param : PolygonMapParam | None = None ) -> None :
7569 super ().__init__ ()
76- if curveparam is None :
77- self .param = CurveParam (_ ("PolygonMap" ), icon = "curve .png" )
70+ if param is None :
71+ self .param = PolygonMapParam (_ ("PolygonMap" ), icon = "polygonmap .png" )
7872 else :
79- self .param = curveparam
73+ self .param = param
8074 self .selected = False
8175 self .immutable = True # set to false to allow moving points around
8276 self ._pts = None # Array of points Mx2
8377 self ._n = None # Array of polygon offsets/ends Nx1
8478 # (polygon k points are _pts[_n[k-1]:_n[k]])
8579 self ._c = None # Color of polygon Nx2 [border,background] as RGBA uint32
8680 self .update_params ()
87- self .setIcon (get_icon ("curve .png" ))
81+ self .setIcon (get_icon ("polygonmap .png" ))
8882
8983 def types (self ) -> tuple [type [IItemType ], ...]:
9084 """Returns a group or category for this item.
@@ -93,7 +87,7 @@ def types(self) -> tuple[type[IItemType], ...]:
9387 Returns:
9488 tuple: Tuple of class objects inheriting from IItemType
9589 """
96- return (ICurveItemType , ITrackableItemType , ISerializableType )
90+ return (ITrackableItemType , ISerializableType )
9791
9892 def can_select (self ) -> bool :
9993 """
@@ -164,56 +158,6 @@ def set_rotatable(self, state: bool) -> None:
164158 """
165159 self ._can_rotate = state
166160
167- def setPen (self , x ):
168- """
169-
170- :param x:
171- """
172- pass
173-
174- def setBrush (self , x ):
175- """
176-
177- :param x:
178- """
179- pass
180-
181- def setSymbol (self , x ):
182- """
183-
184- :param x:
185- """
186- pass
187-
188- def setCurveAttribute (self , x , y ):
189- """
190-
191- :param x:
192- :param y:
193- """
194- pass
195-
196- def setStyle (self , x ):
197- """
198-
199- :param x:
200- """
201- pass
202-
203- def setCurveType (self , x ):
204- """
205-
206- :param x:
207- """
208- pass
209-
210- def setBaseline (self , x ):
211- """
212-
213- :param x:
214- """
215- pass
216-
217161 def __reduce__ (self ):
218162 state = (self .param , self ._pts , self ._n , self ._c , self .z ())
219163 res = (PolygonMapItem , (), state )
@@ -228,9 +172,11 @@ def __setstate__(self, state):
228172
229173 def serialize (
230174 self ,
231- writer : guidata .dataset .io .HDF5Writer
232- | guidata .dataset .io .INIWriter
233- | guidata .dataset .io .JSONWriter ,
175+ writer : (
176+ guidata .dataset .io .HDF5Writer
177+ | guidata .dataset .io .INIWriter
178+ | guidata .dataset .io .JSONWriter
179+ ),
234180 ) -> None :
235181 """Serialize object to HDF5 writer
236182
@@ -242,13 +188,15 @@ def serialize(
242188 writer .write (self ._c , group_name = "Cdata" )
243189 writer .write (self .z (), group_name = "z" )
244190 self .param .update_param (self )
245- writer .write (self .param , group_name = "curveparam " )
191+ writer .write (self .param , group_name = "param " )
246192
247193 def deserialize (
248194 self ,
249- reader : guidata .dataset .io .HDF5Reader
250- | guidata .dataset .io .INIReader
251- | guidata .dataset .io .JSONReader ,
195+ reader : (
196+ guidata .dataset .io .HDF5Reader
197+ | guidata .dataset .io .INIReader
198+ | guidata .dataset .io .JSONReader
199+ ),
252200 ) -> None :
253201 """Deserialize object from HDF5 reader
254202
@@ -260,8 +208,8 @@ def deserialize(
260208 c = reader .read (group_name = "Cdata" , func = reader .read_array )
261209 self .set_data (pts , n , c )
262210 self .setZ (reader .read ("z" ))
263- self .param = CurveParam (_ ("PolygonMap" ), icon = "curve .png" )
264- reader .read ("curveparam " , instance = self .param )
211+ self .param = PolygonMapParam (_ ("PolygonMap" ), icon = "polygonmap .png" )
212+ reader .read ("param " , instance = self .param )
265213 self .update_params ()
266214
267215 def set_readonly (self , state : bool ) -> None :
@@ -307,19 +255,12 @@ def select(self) -> None:
307255 Select the object and eventually change its appearance to highlight the
308256 fact that it's selected
309257 """
310- self .selected = True
311- self .setSymbol (SELECTED_SYMBOL )
312- self .invalidate_plot ()
313258
314259 def unselect (self ) -> None :
315260 """
316261 Unselect the object and eventually restore its original appearance to
317262 highlight the fact that it's not selected anymore
318263 """
319- self .selected = False
320- # Restoring initial curve parameters:
321- self .param .update_item (self )
322- self .invalidate_plot ()
323264
324265 def get_data (self ):
325266 """Return curve data x, y (NumPy arrays)"""
@@ -451,7 +392,7 @@ def set_item_parameters(self, itemparams: ItemParameters) -> None:
451392 Args:
452393 itemparams: Item parameters
453394 """
454- update_dataset (self .param , itemparams .get ("CurveParam " ), visible_only = True )
395+ update_dataset (self .param , itemparams .get ("PolygonMapParam " ), visible_only = True )
455396 self .update_params ()
456397
457398 def draw (
@@ -469,7 +410,6 @@ def draw(
469410 yMap: Y axis scale map
470411 canvasRect: Canvas rectangle
471412 """
472- # from time import time
473413 p1x = xMap .p1 ()
474414 s1x = xMap .s1 ()
475415 ax = (xMap .p2 () - p1x ) / (xMap .s2 () - s1x )
@@ -481,13 +421,9 @@ def draw(
481421 _n = self ._n
482422 fgcol = QG .QColor ()
483423 bgcol = QG .QColor ()
484- # t0 = time()
485424 polygons = simplify_poly (
486425 self ._pts , _n , (ax , bx , ay , by ), canvasRect .getCoords ()
487426 )
488- # t1 = time()
489- # print len(polygons), t1-t0
490- # t2 = time()
491427 for poly , num in polygons :
492428 points = []
493429 for i in range (poly .shape [0 ]):
@@ -498,7 +434,6 @@ def draw(
498434 painter .setPen (QG .QPen (fgcol ))
499435 painter .setBrush (QG .QBrush (bgcol ))
500436 painter .drawPolygon (pg )
501- # print "poly:", time()-t2
502437
503438 def boundingRect (self ) -> QC .QRectF :
504439 """Return the bounding rectangle of the shape
0 commit comments