Bug Description
In originpro/base.py, the add_label() method uses a falsy value check (x if x else ...) to determine whether the
user has provided x or y coordinates. This causes the method to incorrectly ignore x=0 and y=0, treating them as
if no coordinate was provided and defaulting to the layer center instead.
Steps to Reproduce
- Create a graph layer
- Call
gl.add_label("test", x=0, y=0)
- Observe that the label is NOT placed at coordinates (0, 0), but at the center of the layer
import originpro as op
op.set_show()
gp = op.new_graph()
gl = gp[0]
label = gl.add_label("test", x=0, y=0)
- Expected: label at (0, 0)
- Actual: label at the center of the layer (e.g., (5.0, 5.0) or similar)
Root Cause
In originpro/base.py, lines 607-608:
x1 = x if x else (self.get_float('x.from') + self.get_float('x.to')) /2
y1 = y if y else (self.get_float('y.from') + self.get_float('y.to')) /2
Since 0 is a falsy value in Python, x if x else ... evaluates to the else branch when x=0, which is incorrect.
The same applies to y=0.
Suggested Fix
Replace the falsy check with an explicit None check:
x1 = x if x is not None else (self.get_float('x.from') + self.get_float('x.to')) / 2
y1 = y if y is not None else (self.get_float('y.from') + self.get_float('y.to')) / 2
This correctly distinguishes between "the user did not provide a value" (None) and "the user provided zero" (0).
Environment
- OS: Windows 10
- Origin version: Origin 2023
- Python version: 3.9.19
- Originpro version: 1.1.15
Bug Description
In
originpro/base.py, theadd_label()method uses a falsy value check (x if x else ...) to determine whether theuser has provided
xorycoordinates. This causes the method to incorrectly ignorex=0andy=0, treating them asif no coordinate was provided and defaulting to the layer center instead.
Steps to Reproduce
gl.add_label("test", x=0, y=0)Root Cause
In
originpro/base.py, lines 607-608:Since
0is a falsy value in Python,x if x else ...evaluates to theelsebranch whenx=0, which is incorrect.The same applies to
y=0.Suggested Fix
Replace the falsy check with an explicit
Nonecheck:This correctly distinguishes between "the user did not provide a value" (
None) and "the user provided zero" (0).Environment