2929 ImageItem ,
3030 LabelItem ,
3131 LegendBoxItem ,
32- RangeComputation ,
3332 RangeComputation2d ,
3433 RangeInfo ,
3534 RectangleShape ,
3635 SelectedLegendBoxItem ,
36+ XRangeComputation ,
3737 XRangeSelection ,
38+ YRangeComputation ,
3839 YRangeSelection ,
3940)
4041from plotpy .styles import LabelParam , LabelParamWithContents , LegendParam
@@ -137,13 +138,17 @@ def legend(
137138 return SelectedLegendBoxItem (param , restrict_items )
138139
139140 def info_label (
140- self , anchor : str , comps : list , title : str | None = None
141+ self ,
142+ anchor : str ,
143+ comps : list [XRangeSelection ] | list [YRangeSelection ],
144+ title : str | None = None ,
141145 ) -> DataInfoLabel :
142146 """Make an info label `plot item`
143147
144148 Args:
145149 anchor: anchor position. See :py:class:`.LabelParam` for details
146- comps: list of :py:class:`.label.RangeComputation` objects
150+ comps: list of :py:class:`.label.XRangeComputation` or
151+ :py:class:`.label.YRangeComputation` objects
147152 title: label name. Default is None
148153
149154 Returns:
@@ -203,8 +208,8 @@ def computation(
203208 range : XRangeSelection | YRangeSelection ,
204209 anchor : str ,
205210 label : str ,
206- curve : CurveItem ,
207- function : Callable ,
211+ curve : CurveItem | None = None ,
212+ function : Callable | None = None ,
208213 title : str | None = None ,
209214 ) -> DataInfoLabel :
210215 """Make a computation label `plot item`
@@ -213,7 +218,7 @@ def computation(
213218 range: range selection object
214219 anchor: anchor position. See :py:class:`.LabelParam` for details
215220 label: label name. See :py:class:`.DataInfoLabel` for details
216- curve: curve item
221+ curve: curve item (not used for `YRangeSelection`)
217222 function: function to apply to the range selection object
218223 Default is None (default function is `lambda x, dx: (x, dx)`)
219224
@@ -222,37 +227,59 @@ def computation(
222227 """
223228 if title is None :
224229 title = curve .param .label
225- return self .computations (range , anchor , [(curve , label , function )], title = title )
230+ if isinstance (range , XRangeSelection ):
231+ specs = [(curve , label , function )]
232+ elif isinstance (range , YRangeSelection ):
233+ specs = [(label , function )]
234+ else :
235+ raise TypeError (
236+ "Invalid range selection type: "
237+ f"{ type (range ).__name__ } . "
238+ "Expected XRangeSelection or YRangeSelection."
239+ )
240+ return self .computations (range , anchor , specs , title = title )
226241
227242 def computations (
228243 self ,
229- range : XRangeSelection | YRangeSelection ,
244+ rangeselection : XRangeSelection | YRangeSelection ,
230245 anchor : str ,
231- specs : list ,
246+ specs : list [ tuple [ CurveItem , str , Callable ]] | list [ tuple [ str , Callable ]] ,
232247 title : str | None = None ,
233248 ) -> DataInfoLabel :
234249 """Make computation labels `plot item`
235250
236251 Args:
237- range : range selection object
252+ rangeselection : range selection object
238253 anchor: anchor position. See :py:class:`.LabelParam` for details
239- specs: list of (curve, label, function) tuples
254+ specs: list of (curve, label, function) tuples for `XRangeComputation`,
255+ list of (label, function) tuples for `YRangeComputation`
240256 title: label name. Default is None
241257
242258 Returns:
243259 Data info label object
244260 """
245261 comps = []
246- same_curve = True
247- curve0 = None
248- for curve , label , function in specs :
249- comp = RangeComputation (label , curve , range , function )
250- comps .append (comp )
251- if curve0 is None :
252- curve0 = curve
253- same_curve = same_curve and curve is curve0
254- if title is None and same_curve :
255- title = curve .param .label
262+ if isinstance (rangeselection , XRangeSelection ):
263+ same_curve = True
264+ curve0 = None
265+ for curve , label , function in specs :
266+ comp = XRangeComputation (label , curve , rangeselection , function )
267+ comps .append (comp )
268+ if curve0 is None :
269+ curve0 = curve
270+ same_curve = same_curve and curve is curve0
271+ if title is None and same_curve :
272+ title = curve .param .label
273+ elif isinstance (rangeselection , YRangeSelection ):
274+ for label , function in specs :
275+ comp = YRangeComputation (label , rangeselection , function )
276+ comps .append (comp )
277+ else :
278+ raise TypeError (
279+ "Invalid range selection type: "
280+ f"{ type (rangeselection ).__name__ } . "
281+ "Expected XRangeSelection or YRangeSelection."
282+ )
256283 return self .info_label (anchor , comps , title = title )
257284
258285 def computation2d (
0 commit comments