Skip to content

Commit 1c74911

Browse files
authored
Merge pull request #364 from Dessia-tech/chore/patch0-22
Chore/patch0 22
2 parents f10c6d9 + f2ddea8 commit 1c74911

6 files changed

Lines changed: 64 additions & 54 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
### Refactor
1818
- Implements InteractiveObject for handling all mouse objects in one class
1919

20+
## [0.22.2]
21+
### Fix
22+
- Local import
23+
- Add tooltip on any shape with Python with Shape object
24+
2025
## [0.22.0]
2126
### Add
2227
- Integer axes only show integer ticks

code_pylint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
'trailing-whitespace': 11,
3636
'empty-docstring': 7,
3737
'missing-module-docstring': 4,
38-
'too-many-arguments': 20,
38+
'too-many-arguments': 23,
3939
'too-few-public-methods': 5,
4040
'unnecessary-comprehension': 5,
4141
'no-value-for-parameter': 2,

plot_data/core.py

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ def __init__(self, type_: str, reference_path: str = "#", name: str = ""):
160160
super().__init__(type_=type_, name=name)
161161

162162

163+
class Shape(ReferencedObject):
164+
""" Shape object. """
165+
166+
def __init__(self, type_: str, reference_path: str = "#", tooltip: str = None, name: str = ""):
167+
self.tooltip = tooltip
168+
super().__init__(type_=type_, reference_path=reference_path, name=name)
169+
170+
163171
class Sample(ReferencedObject):
164172
""" Graph Point. """
165173

@@ -426,7 +434,7 @@ def __init__(self, point_color: str, point_index: List[int], name: str = ''):
426434
PlotDataObject.__init__(self, type_=None, name=name)
427435

428436

429-
class Text(ReferencedObject):
437+
class Text(Shape):
430438
"""
431439
A class for displaying texts on canvas. Text is a primitive and can be instantiated by PrimitiveGroup.
432440
@@ -450,7 +458,7 @@ class Text(ReferencedObject):
450458

451459
def __init__(self, comment: str, position_x: float, position_y: float, text_style: TextStyle = None,
452460
text_scaling: bool = None, max_width: float = None, height: float = None, multi_lines: bool = True,
453-
reference_path: str = "#", name: str = ''):
461+
reference_path: str = "#", tooltip: str = None, name: str = ''):
454462
self.comment = comment
455463
self.text_style = text_style
456464
self.position_x = position_x
@@ -459,7 +467,7 @@ def __init__(self, comment: str, position_x: float, position_y: float, text_styl
459467
self.max_width = max_width
460468
self.height = height
461469
self.multi_lines = multi_lines
462-
super().__init__(type_='text', reference_path=reference_path, name=name)
470+
super().__init__(type_='text', reference_path=reference_path, tooltip=tooltip, name=name)
463471

464472
def mpl_plot(self, ax=None, color='k', alpha=1., **kwargs):
465473
""" Plots using Matplotlib. """
@@ -469,7 +477,7 @@ def mpl_plot(self, ax=None, color='k', alpha=1., **kwargs):
469477
return ax
470478

471479

472-
class Line2D(ReferencedObject):
480+
class Line2D(Shape):
473481
"""
474482
An infinite line. Line2D is a primitive and can be instantiated by PrimitiveGroups.
475483
@@ -482,12 +490,12 @@ class Line2D(ReferencedObject):
482490
"""
483491

484492
def __init__(self, point1: List[float], point2: List[float], edge_style: EdgeStyle = None,
485-
reference_path: str = "#", name: str = ''):
493+
reference_path: str = "#", tooltip: str = None, name: str = ''):
486494
self.data = point1 + point2 # Retrocompatibility
487495
self.point1 = point1
488496
self.point2 = point2
489497
self.edge_style = edge_style
490-
super().__init__(type_='line2d', reference_path=reference_path, name=name)
498+
super().__init__(type_='line2d', reference_path=reference_path, tooltip=tooltip, name=name)
491499

492500
def mpl_plot(self, ax=None, edge_style=None, **kwargs):
493501
""" Plots using matplotlib. """
@@ -505,7 +513,7 @@ def mpl_plot(self, ax=None, edge_style=None, **kwargs):
505513
return ax
506514

507515

508-
class LineSegment2D(ReferencedObject):
516+
class LineSegment2D(Shape):
509517
"""
510518
A line segment. This is a primitive that can be called by PrimitiveGroup.
511519
@@ -518,7 +526,7 @@ class LineSegment2D(ReferencedObject):
518526
"""
519527

520528
def __init__(self, point1: List[float], point2: List[float], edge_style: EdgeStyle = None,
521-
reference_path: str = "#", name: str = ''):
529+
reference_path: str = "#", tooltip: str = None, name: str = ''):
522530
# Data is used in typescript
523531
self.data = point1 + point2
524532
self.point1 = point1
@@ -528,7 +536,7 @@ def __init__(self, point1: List[float], point2: List[float], edge_style: EdgeSty
528536
self.edge_style = EdgeStyle()
529537
else:
530538
self.edge_style = edge_style
531-
super().__init__(type_='linesegment2d', reference_path=reference_path, name=name)
539+
super().__init__(type_='linesegment2d', reference_path=reference_path, tooltip=tooltip, name=name)
532540

533541
def bounding_box(self):
534542
""" Get 2D bounding box of current LineSegment2D. """
@@ -556,7 +564,7 @@ def mpl_plot(self, ax=None, edge_style=None, **kwargs):
556564
return ax
557565

558566

559-
class Wire(ReferencedObject):
567+
class Wire(Shape):
560568
"""
561569
A set of connected lines. It also provides highlighting feature.
562570
@@ -572,8 +580,7 @@ def __init__(self, lines: List[Tuple[float, float]], edge_style: EdgeStyle = Non
572580
reference_path: str = "#", name: str = ""):
573581
self.lines = lines
574582
self.edge_style = edge_style
575-
self.tooltip = tooltip
576-
super().__init__(type_="wire", reference_path=reference_path, name=name)
583+
super().__init__(type_="wire", reference_path=reference_path, tooltip=tooltip, name=name)
577584

578585
def mpl_plot(self, ax=None, **kwargs):
579586
""" Plots using matplotlib. """
@@ -588,7 +595,7 @@ def mpl_plot(self, ax=None, **kwargs):
588595
return ax
589596

590597

591-
class Circle2D(ReferencedObject):
598+
class Circle2D(Shape):
592599
"""
593600
A circle. It is a primitive and can be instantiated by PrimitiveGroup.
594601
@@ -613,8 +620,7 @@ def __init__(self, cx: float, cy: float, r: float, edge_style: EdgeStyle = None,
613620
self.r = r
614621
self.cx = cx
615622
self.cy = cy
616-
self.tooltip = tooltip
617-
super().__init__(type_='circle', reference_path=reference_path, name=name)
623+
super().__init__(type_='circle', reference_path=reference_path, tooltip=tooltip, name=name)
618624

619625
def bounding_box(self):
620626
""" Get 2D bounding box of current Circle2D. """
@@ -644,7 +650,7 @@ def mpl_plot(self, ax=None, **kwargs):
644650
return ax
645651

646652

647-
class Rectangle(ReferencedObject):
653+
class Rectangle(Shape):
648654
""" Class to draw a rectangle. """
649655

650656
def __init__(self, x_coord: float, y_coord: float, width: float, height: float, edge_style: EdgeStyle = None,
@@ -655,8 +661,7 @@ def __init__(self, x_coord: float, y_coord: float, width: float, height: float,
655661
self.height = height
656662
self.surface_style = surface_style
657663
self.edge_style = edge_style
658-
self.tooltip = tooltip
659-
super().__init__(type_='rectangle', reference_path=reference_path, name=name)
664+
super().__init__(type_='rectangle', reference_path=reference_path, tooltip=tooltip, name=name)
660665

661666
def bounding_box(self):
662667
""" Get 2D bounding box of current Circle2D. """
@@ -698,7 +703,7 @@ def __init__(self, x_coord: float, y_coord: float, width: float, height: float,
698703
self.radius = radius
699704

700705

701-
class Point2D(ReferencedObject):
706+
class Point2D(Shape):
702707
"""
703708
A class for instantiating a point.
704709
@@ -710,11 +715,12 @@ class Point2D(ReferencedObject):
710715
:type point_style: PointStyle
711716
"""
712717

713-
def __init__(self, cx: float, cy: float, point_style: PointStyle = None, reference_path: str = "#", name: str = ''):
718+
def __init__(self, cx: float, cy: float, point_style: PointStyle = None, reference_path: str = "#",
719+
tooltip: str = None, name: str = ''):
714720
self.cx = cx
715721
self.cy = cy
716722
self.point_style = point_style
717-
super().__init__(type_='point', reference_path=reference_path, name=name)
723+
super().__init__(type_='point', reference_path=reference_path, tooltip=tooltip, name=name)
718724

719725
def bounding_box(self):
720726
""" Get 2D bounding box of current Circle2D. """
@@ -1114,7 +1120,7 @@ def _build_multiplot(self):
11141120
for row in sample_attributes for col in sample_attributes]
11151121

11161122

1117-
class Arc2D(ReferencedObject):
1123+
class Arc2D(Shape):
11181124
"""
11191125
A class for drawing arcs. Arc2D is a primitive and can be instantiated by PrimitiveGroup. By default,
11201126
the arc is drawn anticlockwise.
@@ -1140,15 +1146,15 @@ class Arc2D(ReferencedObject):
11401146
"""
11411147

11421148
def __init__(self, cx: float, cy: float, r: float, start_angle: float, end_angle: float, clockwise: bool = None,
1143-
edge_style: EdgeStyle = None, reference_path: str = "#", name: str = ''):
1149+
edge_style: EdgeStyle = None, reference_path: str = "#", tooltip: str = None, name: str = ''):
11441150
self.cx = cx
11451151
self.cy = cy
11461152
self.r = r
11471153
self.start_angle = start_angle
11481154
self.end_angle = end_angle
11491155
self.clockwise = clockwise
11501156
self.edge_style = edge_style
1151-
super().__init__(type_='arc', reference_path=reference_path, name=name)
1157+
super().__init__(type_='arc', reference_path=reference_path, tooltip=tooltip, name=name)
11521158

11531159
def bounding_box(self):
11541160
""" Get 2D bounding box of current Circle2D. """
@@ -1182,7 +1188,7 @@ def mpl_plot(self, ax=None, **kwargs):
11821188
return ax
11831189

11841190

1185-
class Contour2D(ReferencedObject):
1191+
class Contour2D(Shape):
11861192
"""
11871193
A Contour2D is a closed polygon that is formed by multiple primitives.
11881194
@@ -1202,9 +1208,8 @@ def __init__(self, plot_data_primitives: List[Union[Arc2D, LineSegment2D]], edge
12021208
self.plot_data_primitives = plot_data_primitives
12031209
self.edge_style = edge_style
12041210
self.surface_style = surface_style
1205-
self.tooltip = tooltip
12061211
self.is_filled = surface_style is not None
1207-
super().__init__(type_='contour', reference_path=reference_path, name=name)
1212+
super().__init__(type_='contour', reference_path=reference_path, tooltip=tooltip, name=name)
12081213

12091214
def bounding_box(self):
12101215
""" Get 2D bounding box of current Contour2D. """
@@ -1508,7 +1513,7 @@ def plot_data_path(local: bool = False, version: str = None):
15081513
""" Get path of plot_data package to write it in html file of Figure to draw. """
15091514
version, folder, filename = get_current_link(version=version)
15101515
if local:
1511-
core_path = os.sep.join(os.getcwd().split(os.sep)[:-1] + [folder, filename])
1516+
core_path = os.sep.join(__file__.split(os.sep)[:-2] + [folder, filename])
15121517
if os.path.isfile(core_path):
15131518
return core_path.replace(" ", "%20")
15141519
print(f'Local compiled {core_path} not found, fall back to CDN')

script/test_objects/primitive_group_test.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,28 @@
2626
# Symmetric shapes
2727
points_text = plot_data.Text(comment="Points: ", text_scaling=True, position_x=0, position_y=21.2, text_style=title_style)
2828
round_rect = plot_data.RoundRectangle(0, 0, 21, 21, 1, edge_style=edge_style_dashed, surface_style=surface_style_empty)
29-
cross = plot_data.Point2D(3, 3, plot_data.PointStyle(color_stroke=colors.ORANGE, stroke_width=5, shape="cross", size = 20))
30-
circle = plot_data.Point2D(8, 3, plot_data.PointStyle(color_fill=colors.ORANGE, color_stroke=colors.BLACK, stroke_width=2, shape="circle", size = 20))
31-
square = plot_data.Point2D(13, 3, plot_data.PointStyle(color_fill=colors.PINK, color_stroke=colors.PURPLE, stroke_width=3, shape="square", size = 20))
32-
mark = plot_data.Point2D(18, 3, plot_data.PointStyle(color_stroke=colors.BLUE, stroke_width=3, shape="mark", size = 20))
29+
cross = plot_data.Point2D(3, 3, plot_data.PointStyle(color_stroke=colors.ORANGE, stroke_width=5, shape="cross", size = 20), tooltip="cross")
30+
circle = plot_data.Point2D(8, 3, plot_data.PointStyle(color_fill=colors.ORANGE, color_stroke=colors.BLACK, stroke_width=2, shape="circle", size = 20), tooltip="circle")
31+
square = plot_data.Point2D(13, 3, plot_data.PointStyle(color_fill=colors.PINK, color_stroke=colors.PURPLE, stroke_width=3, shape="square", size = 20), tooltip="square")
32+
mark = plot_data.Point2D(18, 3, plot_data.PointStyle(color_stroke=colors.BLUE, stroke_width=3, shape="mark", size = 20), tooltip="mark")
3333

3434
## Triangles
35-
up_triangle = plot_data.Point2D(3, 8, plot_data.PointStyle(color_fill=colors.RED, color_stroke=colors.DARK_PURPLE, stroke_width=4, shape="triangle", orientation="up", size = 20))
36-
down_triangle = plot_data.Point2D(8, 8, plot_data.PointStyle(color_fill=colors.YELLOW, color_stroke=colors.EMPIRE_YELLOW, stroke_width=4, shape="triangle", orientation="down", size = 20))
37-
left_triangle = plot_data.Point2D(13, 8, plot_data.PointStyle(color_fill=colors.GREEN, color_stroke=colors.EMERALD, stroke_width=4, shape="triangle", orientation="left", size = 20))
38-
right_triangle = plot_data.Point2D(18, 8, plot_data.PointStyle(color_fill=colors.BLUE, color_stroke=colors.DARK_BLUE, stroke_width=4, shape="triangle", orientation="right", size = 20))
35+
up_triangle = plot_data.Point2D(3, 8, plot_data.PointStyle(color_fill=colors.RED, color_stroke=colors.DARK_PURPLE, stroke_width=4, shape="triangle", orientation="up", size = 20), tooltip="triangle_up")
36+
down_triangle = plot_data.Point2D(8, 8, plot_data.PointStyle(color_fill=colors.YELLOW, color_stroke=colors.EMPIRE_YELLOW, stroke_width=4, shape="triangle", orientation="down", size = 20), tooltip="triangle_down")
37+
left_triangle = plot_data.Point2D(13, 8, plot_data.PointStyle(color_fill=colors.GREEN, color_stroke=colors.EMERALD, stroke_width=4, shape="triangle", orientation="left", size = 20), tooltip="triangle_left")
38+
right_triangle = plot_data.Point2D(18, 8, plot_data.PointStyle(color_fill=colors.BLUE, color_stroke=colors.DARK_BLUE, stroke_width=4, shape="triangle", orientation="right", size = 20), tooltip="triangle_right")
3939

4040
## Half Lines
41-
up_halfline = plot_data.Point2D(3, 13, plot_data.PointStyle(color_stroke=colors.PINK, stroke_width=4, shape="halfline", orientation="up", size = 20))
42-
down_halfline = plot_data.Point2D(8, 13, plot_data.PointStyle(color_stroke=colors.PURPLE, stroke_width=4, shape="halfline", orientation="down", size = 20))
43-
left_halfline = plot_data.Point2D(13, 13, plot_data.PointStyle(color_stroke=colors.ORANGE, stroke_width=4, shape="halfline", orientation="left", size = 20))
44-
right_halfline = plot_data.Point2D(18, 13, plot_data.PointStyle(color_stroke=colors.BLACK, stroke_width=4, shape="halfline", orientation="right", size = 20))
41+
up_halfline = plot_data.Point2D(3, 13, plot_data.PointStyle(color_stroke=colors.PINK, stroke_width=4, shape="halfline", orientation="up", size = 20), tooltip="halfline_up")
42+
down_halfline = plot_data.Point2D(8, 13, plot_data.PointStyle(color_stroke=colors.PURPLE, stroke_width=4, shape="halfline", orientation="down", size = 20), tooltip="halfline_down")
43+
left_halfline = plot_data.Point2D(13, 13, plot_data.PointStyle(color_stroke=colors.ORANGE, stroke_width=4, shape="halfline", orientation="left", size = 20), tooltip="halfline_left")
44+
right_halfline = plot_data.Point2D(18, 13, plot_data.PointStyle(color_stroke=colors.BLACK, stroke_width=4, shape="halfline", orientation="right", size = 20), tooltip="halfline_right")
4545

4646
## Lines
47-
vline = plot_data.Point2D(3, 18, plot_data.PointStyle(color_stroke=colors.LIGHTBLUE, stroke_width=2, shape="line", orientation="vertical", size = 20))
48-
hline = plot_data.Point2D(8, 18, plot_data.PointStyle(color_stroke=colors.LIGHTPURPLE, stroke_width=2, shape="line", orientation="horizontal", size = 20))
49-
slash = plot_data.Point2D(13, 18, plot_data.PointStyle(color_stroke=colors.ANGEL_BLUE, stroke_width=2, shape="line", orientation="slash", size = 20))
50-
backslash = plot_data.Point2D(18, 18, plot_data.PointStyle(color_stroke=colors.BRIGHT_LIME_GREEN, stroke_width=2, shape="line", orientation="backslash", size = 20))
47+
vline = plot_data.Point2D(3, 18, plot_data.PointStyle(color_stroke=colors.LIGHTBLUE, stroke_width=2, shape="line", orientation="vertical", size = 20), tooltip="vertical")
48+
hline = plot_data.Point2D(8, 18, plot_data.PointStyle(color_stroke=colors.LIGHTPURPLE, stroke_width=2, shape="line", orientation="horizontal", size = 20), tooltip="horizontal")
49+
slash = plot_data.Point2D(13, 18, plot_data.PointStyle(color_stroke=colors.ANGEL_BLUE, stroke_width=2, shape="line", orientation="slash", size = 20), tooltip="slash")
50+
backslash = plot_data.Point2D(18, 18, plot_data.PointStyle(color_stroke=colors.BRIGHT_LIME_GREEN, stroke_width=2, shape="line", orientation="backslash", size = 20), tooltip="backslash")
5151

5252
points = [cross, circle, square, mark,
5353
up_triangle, down_triangle, left_triangle, right_triangle,
@@ -56,17 +56,17 @@
5656

5757
# ============================================= SHAPES =================================================================
5858
# Lines
59-
line_2d = plot_data.Line2D(point1=[-10, 24.5], point2=[22, 24.5], edge_style=edge_style_purple)
60-
round_rect_shapes = plot_data.RoundRectangle(24, 0, 60, 37, 1, edge_style=edge_style_dashed, surface_style=surface_style_empty)
59+
line_2d = plot_data.Line2D(point1=[-10, 24.5], point2=[22, 24.5], edge_style=edge_style_purple, tooltip="line2d")
60+
round_rect_shapes = plot_data.RoundRectangle(24, 0, 60, 37, 1, edge_style=edge_style_dashed, surface_style=surface_style_empty, tooltip="round_rect")
6161
points_text_shapes = plot_data.Text(comment="Shapes: ", text_scaling=True, position_x=24, position_y=37.2, text_style=title_style)
6262

6363
# Arcs
6464
circle = plot_data.Circle2D(cx=31, cy=10.5, r=5, edge_style=edge_style_red, surface_style=surface_style_yellow, tooltip="It's a circle")
65-
arc = plot_data.Arc2D(cx=43, cy=10.5, r=5, start_angle=math.pi/4, end_angle=2*math.pi/3, edge_style=edge_style_red, clockwise=True)
66-
arc_anti = plot_data.Arc2D(cx=43, cy=10.5, r=5, start_angle=math.pi/4, end_angle=2*math.pi/3, edge_style=edge_style_blue, clockwise=False)
67-
line_segment_1 = plot_data.LineSegment2D(point1=[50, 1], point2=[53, 20], edge_style=edge_style_black)
68-
line_segment_2 = plot_data.LineSegment2D(point1=[75, 20], point2=[78, 1], edge_style=edge_style_black)
69-
rectangle = plot_data.Rectangle(57, 26, 25, 9, surface_style=surface_style_green, edge_style=edge_style_red)
65+
arc = plot_data.Arc2D(cx=43, cy=10.5, r=5, start_angle=math.pi/4, end_angle=2*math.pi/3, edge_style=edge_style_red, clockwise=True, tooltip="arc2d")
66+
arc_anti = plot_data.Arc2D(cx=43, cy=10.5, r=5, start_angle=math.pi/4, end_angle=2*math.pi/3, edge_style=edge_style_blue, clockwise=False, tooltip="arc2d_anticlockwise")
67+
line_segment_1 = plot_data.LineSegment2D(point1=[50, 1], point2=[53, 20], edge_style=edge_style_black, tooltip="linesegment")
68+
line_segment_2 = plot_data.LineSegment2D(point1=[75, 20], point2=[78, 1], edge_style=edge_style_black, tooltip="linesegment")
69+
rectangle = plot_data.Rectangle(57, 26, 25, 9, surface_style=surface_style_green, edge_style=edge_style_red, tooltip="rectangle")
7070

7171
# Contours
7272
star_lines_closed = [plot_data.LineSegment2D([57, 1.5], [60, 8.5]),

src/primitives.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,6 @@ export class Point extends Shape {
650650
return marker
651651
}
652652

653-
protected updateTooltipOrigin(matrix: DOMMatrix): void { this.tooltipOrigin = this.center.copy() }
654-
655653
get markerOrientation(): string { return this._markerOrientation };
656654

657655
set markerOrientation(value: string) { this._markerOrientation = value };

src/shapes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,8 @@ export class ScatterPoint extends Point {
749749
this.update();
750750
}
751751

752+
protected updateTooltipOrigin(matrix: DOMMatrix): void { this.tooltipOrigin = this.center.copy() }
753+
752754
public updateTooltipMap() { this._tooltipMap = new Map<string, any>([["Number", this.values.length], ["X mean", this.mean.x], ["Y mean", this.mean.y],]) };
753755

754756
private monoValueTooltip(tooltipAttributes: string[], features: Map<string, number[]>): void {

0 commit comments

Comments
 (0)