Skip to content

Commit f2b1060

Browse files
committed
PlotBuilder/annotated shapes: added more arguments
1 parent a9a37ba commit f2b1060

File tree

2 files changed

+228
-14
lines changed

2 files changed

+228
-14
lines changed

plotpy/builder.py

Lines changed: 222 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,16 +2376,56 @@ def svg(
23762376
shape.set_data(data)
23772377
return shape
23782378

2379-
def __get_annotationparam(self, title: str, subtitle: str) -> AnnotationParam:
2379+
def __get_annotationparam(
2380+
self,
2381+
title: str | None = None,
2382+
subtitle: str | None = None,
2383+
show_label: bool | None = None,
2384+
show_computations: bool | None = None,
2385+
show_subtitle: bool | None = None,
2386+
format: str | None = None,
2387+
uncertainty: float | None = None,
2388+
transform_matrix: np.ndarray | None = None,
2389+
readonly: bool | None = None,
2390+
private: bool | None = None,
2391+
) -> AnnotationParam:
23802392
param = AnnotationParam(_("Annotation"), icon="annotation.png")
23812393
if title is not None:
23822394
param.title = title
23832395
if subtitle is not None:
23842396
param.subtitle = subtitle
2397+
if show_label is not None:
2398+
param.show_label = show_label
2399+
if show_computations is not None:
2400+
param.show_computations = show_computations
2401+
if show_subtitle is not None:
2402+
param.show_subtitle = show_subtitle
2403+
if format is not None:
2404+
param.format = format
2405+
if uncertainty is not None:
2406+
param.uncertainty = uncertainty
2407+
if transform_matrix is not None:
2408+
param.transform_matrix = transform_matrix
2409+
if readonly is not None:
2410+
param.readonly = readonly
2411+
if private is not None:
2412+
param.private = private
23852413
return param
23862414

23872415
def annotated_point(
2388-
self, x: float, y: float, title: str | None = None, subtitle: str | None = None
2416+
self,
2417+
x: float,
2418+
y: float,
2419+
title: str | None = None,
2420+
subtitle: str | None = None,
2421+
show_label: bool | None = None,
2422+
show_computations: bool | None = None,
2423+
show_subtitle: bool | None = None,
2424+
format: str | None = None,
2425+
uncertainty: float | None = None,
2426+
transform_matrix: np.ndarray | None = None,
2427+
readonly: bool | None = None,
2428+
private: bool | None = None,
23892429
) -> AnnotatedPoint:
23902430
"""Make an annotated point `plot item`
23912431
@@ -2394,17 +2434,64 @@ def annotated_point(
23942434
y: point y coordinate
23952435
title: label name. Default is None
23962436
subtitle: label subtitle. Default is None
2437+
show_label: show label. Default is None
2438+
show_computations: show computations. Default is None
2439+
show_subtitle: show subtitle. Default is None
2440+
format: string formatting. Default is None
2441+
uncertainty: measurement relative uncertainty. Default is None
2442+
transform_matrix: transform matrix. Default is None
2443+
readonly: readonly. Default is None
2444+
private: private. Default is None
23972445
23982446
Returns:
23992447
:py:class:`.AnnotatedPoint` object
24002448
"""
2401-
param = self.__get_annotationparam(title, subtitle)
2449+
param = self.__get_annotationparam(
2450+
title=title,
2451+
subtitle=subtitle,
2452+
show_label=show_label,
2453+
show_computations=show_computations,
2454+
show_subtitle=show_subtitle,
2455+
format=format,
2456+
uncertainty=uncertainty,
2457+
transform_matrix=transform_matrix,
2458+
readonly=readonly,
2459+
private=private,
2460+
)
24022461
shape = AnnotatedPoint(x, y, param)
24032462
shape.set_style("plot", "shape/drag")
24042463
return shape
24052464

2406-
def __annotated_shape(self, shapeclass, x0, y0, x1, y1, title, subtitle):
2407-
param = self.__get_annotationparam(title, subtitle)
2465+
def __annotated_shape(
2466+
self,
2467+
shapeclass,
2468+
x0,
2469+
y0,
2470+
x1,
2471+
y1,
2472+
title,
2473+
subtitle,
2474+
show_label,
2475+
show_computations,
2476+
show_subtitle,
2477+
format,
2478+
uncertainty,
2479+
transform_matrix,
2480+
readonly,
2481+
private,
2482+
):
2483+
param = self.__get_annotationparam(
2484+
title=title,
2485+
subtitle=subtitle,
2486+
show_label=show_label,
2487+
show_computations=show_computations,
2488+
show_subtitle=show_subtitle,
2489+
format=format,
2490+
uncertainty=uncertainty,
2491+
transform_matrix=transform_matrix,
2492+
readonly=readonly,
2493+
private=private,
2494+
)
24082495
shape = shapeclass(x0, y0, x1, y1, param)
24092496
shape.set_style("plot", "shape/drag")
24102497
return shape
@@ -2417,6 +2504,14 @@ def annotated_rectangle(
24172504
y1: float,
24182505
title: str | None = None,
24192506
subtitle: str | None = None,
2507+
show_label: bool | None = None,
2508+
show_computations: bool | None = None,
2509+
show_subtitle: bool | None = None,
2510+
format: str | None = None,
2511+
uncertainty: float | None = None,
2512+
transform_matrix: np.ndarray | None = None,
2513+
readonly: bool | None = None,
2514+
private: bool | None = None,
24202515
) -> AnnotatedRectangle:
24212516
"""Make an annotated rectangle `plot item`
24222517
@@ -2427,12 +2522,34 @@ def annotated_rectangle(
24272522
y1: rectangle y1 coordinate
24282523
title: label name. Default is None
24292524
subtitle: label subtitle. Default is None
2525+
show_label: show label. Default is None
2526+
show_computations: show computations. Default is None
2527+
show_subtitle: show subtitle. Default is None
2528+
format: string formatting. Default is None
2529+
uncertainty: measurement relative uncertainty. Default is None
2530+
transform_matrix: transform matrix. Default is None
2531+
readonly: readonly. Default is None
2532+
private: private. Default is None
24302533
24312534
Returns:
24322535
:py:class:`.AnnotatedRectangle` object
24332536
"""
24342537
return self.__annotated_shape(
2435-
AnnotatedRectangle, x0, y0, x1, y1, title, subtitle
2538+
AnnotatedRectangle,
2539+
x0,
2540+
y0,
2541+
x1,
2542+
y1,
2543+
title,
2544+
subtitle,
2545+
show_label,
2546+
show_computations,
2547+
show_subtitle,
2548+
format,
2549+
uncertainty,
2550+
transform_matrix,
2551+
readonly,
2552+
private,
24362553
)
24372554

24382555
def annotated_ellipse(
@@ -2447,6 +2564,14 @@ def annotated_ellipse(
24472564
y3: float = None,
24482565
title: str | None = None,
24492566
subtitle: str | None = None,
2567+
show_label: bool | None = None,
2568+
show_computations: bool | None = None,
2569+
show_subtitle: bool | None = None,
2570+
format: str | None = None,
2571+
uncertainty: float | None = None,
2572+
transform_matrix: np.ndarray | None = None,
2573+
readonly: bool | None = None,
2574+
private: bool | None = None,
24502575
) -> AnnotatedEllipse:
24512576
"""Make an annotated ellipse `plot item`
24522577
@@ -2461,11 +2586,35 @@ def annotated_ellipse(
24612586
y3: ellipse y3 coordinate. Default is None
24622587
title: label name. Default is None
24632588
subtitle: label subtitle. Default is None
2589+
show_label: show label. Default is None
2590+
show_computations: show computations. Default is None
2591+
show_subtitle: show subtitle. Default is None
2592+
format: string formatting. Default is None
2593+
uncertainty: measurement relative uncertainty. Default is None
2594+
transform_matrix: transform matrix. Default is None
2595+
readonly: readonly. Default is None
2596+
private: private. Default is None
24642597
24652598
Returns:
24662599
:py:class:`.AnnotatedEllipse` object
24672600
"""
2468-
item = self.__annotated_shape(AnnotatedEllipse, x0, y0, x1, y1, title, subtitle)
2601+
item = self.__annotated_shape(
2602+
AnnotatedEllipse,
2603+
x0,
2604+
y0,
2605+
x1,
2606+
y1,
2607+
title,
2608+
subtitle,
2609+
show_label,
2610+
show_computations,
2611+
show_subtitle,
2612+
format,
2613+
uncertainty,
2614+
transform_matrix,
2615+
readonly,
2616+
private,
2617+
)
24692618
if x2 is not None and y2 is not None and x3 is not None and y3 is not None:
24702619
item.set_ydiameter(x2, y2, x3, y3)
24712620
return item
@@ -2478,6 +2627,14 @@ def annotated_circle(
24782627
y1: float,
24792628
title: str | None = None,
24802629
subtitle: str | None = None,
2630+
show_label: bool | None = None,
2631+
show_computations: bool | None = None,
2632+
show_subtitle: bool | None = None,
2633+
format: str | None = None,
2634+
uncertainty: float | None = None,
2635+
transform_matrix: np.ndarray | None = None,
2636+
readonly: bool | None = None,
2637+
private: bool | None = None,
24812638
) -> AnnotatedCircle:
24822639
"""Make an annotated circle `plot item`
24832640
@@ -2488,11 +2645,35 @@ def annotated_circle(
24882645
y1: circle y1 coordinate
24892646
title: label name. Default is None
24902647
subtitle: label subtitle. Default is None
2648+
show_label: show label. Default is None
2649+
show_computations: show computations. Default is None
2650+
show_subtitle: show subtitle. Default is None
2651+
format: string formatting. Default is None
2652+
uncertainty: measurement relative uncertainty. Default is None
2653+
transform_matrix: transform matrix. Default is None
2654+
readonly: readonly. Default is None
2655+
private: private. Default is None
24912656
24922657
Returns:
24932658
:py:class:`.AnnotatedCircle` object
24942659
"""
2495-
return self.__annotated_shape(AnnotatedCircle, x0, y0, x1, y1, title, subtitle)
2660+
return self.__annotated_shape(
2661+
AnnotatedCircle,
2662+
x0,
2663+
y0,
2664+
x1,
2665+
y1,
2666+
title,
2667+
subtitle,
2668+
show_label,
2669+
show_computations,
2670+
show_subtitle,
2671+
format,
2672+
uncertainty,
2673+
transform_matrix,
2674+
readonly,
2675+
private,
2676+
)
24962677

24972678
def annotated_segment(
24982679
self,
@@ -2502,6 +2683,14 @@ def annotated_segment(
25022683
y1: float,
25032684
title: str | None = None,
25042685
subtitle: str | None = None,
2686+
show_label: bool | None = None,
2687+
show_computations: bool | None = None,
2688+
show_subtitle: bool | None = None,
2689+
format: str | None = None,
2690+
uncertainty: float | None = None,
2691+
transform_matrix: np.ndarray | None = None,
2692+
readonly: bool | None = None,
2693+
private: bool | None = None,
25052694
) -> AnnotatedSegment:
25062695
"""Make an annotated segment `plot item`
25072696
@@ -2512,11 +2701,35 @@ def annotated_segment(
25122701
y1: segment y1 coordinate
25132702
title: label name. Default is None
25142703
subtitle: label subtitle. Default is None
2704+
show_label: show label. Default is None
2705+
show_computations: show computations. Default is None
2706+
show_subtitle: show subtitle. Default is None
2707+
format: string formatting. Default is None
2708+
uncertainty: measurement relative uncertainty. Default is None
2709+
transform_matrix: transform matrix. Default is None
2710+
readonly: readonly. Default is None
2711+
private: private. Default is None
25152712
25162713
Returns:
25172714
:py:class:`.AnnotatedSegment` object
25182715
"""
2519-
return self.__annotated_shape(AnnotatedSegment, x0, y0, x1, y1, title, subtitle)
2716+
return self.__annotated_shape(
2717+
AnnotatedSegment,
2718+
x0,
2719+
y0,
2720+
x1,
2721+
y1,
2722+
title,
2723+
subtitle,
2724+
show_label,
2725+
show_computations,
2726+
show_subtitle,
2727+
format,
2728+
uncertainty,
2729+
transform_matrix,
2730+
readonly,
2731+
private,
2732+
)
25202733

25212734
def info_label(
25222735
self, anchor: str, comps: list, title: str | None = None

plotpy/tests/gui/test_autoscale_shapes.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,26 @@ def test_autoscale_shapes():
6464
plot.set_antialiasing(False)
6565
win.manager.get_itemlist_panel().show()
6666

67+
incl = "Included in autoscale"
68+
noti = "Excluded from autoscale"
69+
6770
# Add a polygon
6871
x = np.arange(-3.0, 3.0, 0.2)
6972
crv = make.polygon(x, np.sin(x), False, "Polygon")
7073
plot.add_item(crv)
7174

7275
# Add a circle
73-
circle = make.circle(-1, 2, 0, 0, "Circle")
76+
circle = make.annotated_circle(-1, 2, 0, 0, incl, show_computations=False)
7477
plot.add_item(circle)
7578

7679
# Add an annotated rectangle
77-
rect = make.annotated_rectangle(2.5, 1, 4, 1.2, "Annotated rectangle")
80+
rect = make.annotated_rectangle(2.5, 1, 4, 1.2, incl, show_computations=False)
7881
plot.add_item(rect)
7982
plot.add_autoscale_excludes([rect])
8083
plot.remove_autoscale_excludes([rect]) # Just to test the method
8184

8285
# Add an annotated rectangle excluded
83-
rect = make.annotated_rectangle(
84-
1.0, 2.0, 5, 10, "Annotated rectangle excluded from autoscale"
85-
)
86+
rect = make.annotated_rectangle(1.0, 2.0, 5, 10, noti, show_computations=False)
8687
plot.add_item(rect)
8788

8889
plot.add_autoscale_excludes([rect])

0 commit comments

Comments
 (0)