13
13
from magpylib ._src .defaults .defaults_utility import validate_property_class
14
14
from magpylib ._src .defaults .defaults_utility import validate_style_keys
15
15
16
+ ALLOWED_SIZEMODES = ("scaled" , "absolute" )
17
+
16
18
17
19
def get_families (obj ):
18
20
"""get obj families"""
@@ -1493,6 +1495,10 @@ class SensorProperties:
1493
1495
size: float, default=None
1494
1496
Positive float for ratio of sensor to canvas size.
1495
1497
1498
+ sizemode: {'scaled', 'absolute'}, default='scaled'
1499
+ Defines the scale reference for the sensor size. If 'absolute', the `size` parameters
1500
+ becomes the sensor size in millimeters.
1501
+
1496
1502
pixel: dict, Pixel, default=None
1497
1503
`Pixel` object or dict with equivalent key/value pairs (e.g. `color`, `size`).
1498
1504
@@ -1513,6 +1519,19 @@ def size(self, val):
1513
1519
)
1514
1520
self ._size = val
1515
1521
1522
+ @property
1523
+ def sizemode (self ):
1524
+ """Sizemode of the sensor."""
1525
+ return self ._sizemode
1526
+
1527
+ @sizemode .setter
1528
+ def sizemode (self , val ):
1529
+ assert val is None or val in ALLOWED_SIZEMODES , (
1530
+ f"The `sizemode` property of { type (self ).__name__ } must be a one of "
1531
+ f"{ ALLOWED_SIZEMODES } ,\n but received { repr (val )} instead."
1532
+ )
1533
+ self ._sizemode = val
1534
+
1516
1535
@property
1517
1536
def pixel (self ):
1518
1537
"""`Pixel` object or dict with equivalent key/value pairs (e.g. `color`, `size`)."""
@@ -1540,15 +1559,32 @@ class DefaultSensor(MagicProperties, SensorProperties):
1540
1559
size: float, default=None
1541
1560
Positive float for ratio of sensor to canvas size.
1542
1561
1562
+ sizemode: {'scaled', 'absolute'}, default='scaled'
1563
+ Defines the scale reference for the sensor size. If 'absolute', the `size` parameters
1564
+ becomes the sensor size in millimeters.
1565
+
1543
1566
pixel: dict, Pixel, default=None
1544
1567
`Pixel` object or dict with equivalent key/value pairs (e.g. `color`, `size`).
1545
1568
1546
1569
arrows: dict, ArrowCS, default=None
1547
1570
`ArrowCS` object or dict with equivalent key/value pairs (e.g. `color`, `size`).
1548
1571
"""
1549
1572
1550
- def __init__ (self , size = None , pixel = None , arrows = None , ** kwargs ):
1551
- super ().__init__ (size = size , pixel = pixel , arrows = arrows , ** kwargs )
1573
+ def __init__ (
1574
+ self ,
1575
+ size = None ,
1576
+ sizemode = None ,
1577
+ pixel = None ,
1578
+ arrows = None ,
1579
+ ** kwargs ,
1580
+ ):
1581
+ super ().__init__ (
1582
+ size = size ,
1583
+ sizemode = sizemode ,
1584
+ pixel = pixel ,
1585
+ arrows = arrows ,
1586
+ ** kwargs ,
1587
+ )
1552
1588
1553
1589
1554
1590
class SensorStyle (BaseStyle , SensorProperties ):
@@ -1602,6 +1638,10 @@ class Pixel(MagicProperties):
1602
1638
- matplotlib backend: Pixel size is the marker size.
1603
1639
- plotly backend: Relative distance to nearest neighbor pixel.
1604
1640
1641
+ sizemode: {'scaled', 'absolute'}, default='scaled'
1642
+ Defines the scale reference for the pixel size. If 'absolute', the `size` parameters
1643
+ becomes the pixel size in millimeters.
1644
+
1605
1645
color: str, default=None
1606
1646
Defines the pixel color@property.
1607
1647
@@ -1610,8 +1650,14 @@ class Pixel(MagicProperties):
1610
1650
Only applies for matplotlib plotting backend.
1611
1651
"""
1612
1652
1613
- def __init__ (self , size = 1 , color = None , symbol = None , ** kwargs ):
1614
- super ().__init__ (size = size , color = color , symbol = symbol , ** kwargs )
1653
+ def __init__ (self , size = 1 , sizemode = None , color = None , symbol = None , ** kwargs ):
1654
+ super ().__init__ (
1655
+ size = size ,
1656
+ sizemode = sizemode ,
1657
+ color = color ,
1658
+ symbol = symbol ,
1659
+ ** kwargs ,
1660
+ )
1615
1661
1616
1662
@property
1617
1663
def size (self ):
@@ -1628,6 +1674,19 @@ def size(self, val):
1628
1674
)
1629
1675
self ._size = val
1630
1676
1677
+ @property
1678
+ def sizemode (self ):
1679
+ """Sizemode of the pixel."""
1680
+ return self ._sizemode
1681
+
1682
+ @sizemode .setter
1683
+ def sizemode (self , val ):
1684
+ assert val is None or val in ALLOWED_SIZEMODES , (
1685
+ f"The `sizemode` property of { type (self ).__name__ } must be a one of "
1686
+ f"{ ALLOWED_SIZEMODES } ,\n but received { repr (val )} instead."
1687
+ )
1688
+ self ._sizemode = val
1689
+
1631
1690
@property
1632
1691
def color (self ):
1633
1692
"""Pixel color."""
@@ -1763,8 +1822,6 @@ class Arrow(Line):
1763
1822
Positive number that defines the line width.
1764
1823
"""
1765
1824
1766
- _allowed_sizemodes = ("scaled" , "absolute" )
1767
-
1768
1825
def __init__ (self , show = None , size = None , ** kwargs ):
1769
1826
super ().__init__ (show = show , size = size , ** kwargs )
1770
1827
@@ -1796,14 +1853,14 @@ def size(self, val):
1796
1853
1797
1854
@property
1798
1855
def sizemode (self ):
1799
- """Positive number defining the sizemode of the arrows."""
1856
+ """Sizemode of the arrows."""
1800
1857
return self ._sizemode
1801
1858
1802
1859
@sizemode .setter
1803
1860
def sizemode (self , val ):
1804
- assert val is None or val in self . _allowed_sizemodes , (
1861
+ assert val is None or val in ALLOWED_SIZEMODES , (
1805
1862
f"The `sizemode` property of { type (self ).__name__ } must be a one of "
1806
- f"{ self . _allowed_sizemodes } ,\n but received { repr (val )} instead."
1863
+ f"{ ALLOWED_SIZEMODES } ,\n but received { repr (val )} instead."
1807
1864
)
1808
1865
self ._sizemode = val
1809
1866
@@ -1941,6 +1998,10 @@ class DipoleProperties:
1941
1998
size: float
1942
1999
Positive value for ratio of dipole size to canvas size.
1943
2000
2001
+ sizemode: {'scaled', 'absolute'}, default='scaled'
2002
+ Defines the scale reference for the dipole size. If 'absolute', the `size` parameters
2003
+ becomes the dipole size in millimeters.
2004
+
1944
2005
pivot: str
1945
2006
The part of the arrow that is anchored to the X, Y grid.
1946
2007
The arrow rotates about this point. Can be one of `['tail', 'middle', 'tip']`.
@@ -1961,6 +2022,19 @@ def size(self, val):
1961
2022
)
1962
2023
self ._size = val
1963
2024
2025
+ @property
2026
+ def sizemode (self ):
2027
+ """Sizemode of the dipole."""
2028
+ return self ._sizemode
2029
+
2030
+ @sizemode .setter
2031
+ def sizemode (self , val ):
2032
+ assert val is None or val in ALLOWED_SIZEMODES , (
2033
+ f"The `sizemode` property of { type (self ).__name__ } must be a one of "
2034
+ f"{ ALLOWED_SIZEMODES } ,\n but received { repr (val )} instead."
2035
+ )
2036
+ self ._sizemode = val
2037
+
1964
2038
@property
1965
2039
def pivot (self ):
1966
2040
"""The part of the arrow that is anchored to the X, Y grid.
@@ -1987,13 +2061,17 @@ class DefaultDipole(MagicProperties, DipoleProperties):
1987
2061
size: float, default=None
1988
2062
Positive float for ratio of dipole size to canvas size.
1989
2063
2064
+ sizemode: {'scaled', 'absolute'}, default='scaled'
2065
+ Defines the scale reference for the dipole size. If 'absolute', the `size` parameters
2066
+ becomes the dipole size in millimeters.
2067
+
1990
2068
pivot: str, default=None
1991
2069
The part of the arrow that is anchored to the X, Y grid.
1992
2070
The arrow rotates about this point. Can be one of `['tail', 'middle', 'tip']`.
1993
2071
"""
1994
2072
1995
- def __init__ (self , size = None , pivot = None , ** kwargs ):
1996
- super ().__init__ (size = size , pivot = pivot , ** kwargs )
2073
+ def __init__ (self , size = None , sizemode = None , pivot = None , ** kwargs ):
2074
+ super ().__init__ (size = size , sizemode = sizemode , pivot = pivot , ** kwargs )
1997
2075
1998
2076
1999
2077
class DipoleStyle (BaseStyle , DipoleProperties ):
0 commit comments