Skip to content

Commit e3b1b0a

Browse files
committed
Merge remote-tracking branch 'origin/dev' into feat/offline
2 parents 2ed4c59 + bb1ec26 commit e3b1b0a

6 files changed

Lines changed: 72 additions & 57 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Allow to log scale axes
1313
- Offline mode
1414

15+
### Fix
16+
- Add reference_path to all Primitive / Elementary drawing Objects
17+
- Remove data attr from class Arc in Python
18+
- Light improvement of class Arc in Python
19+
- Html stream method
20+
1521
## [0.21.0]
1622
### Add
1723
- Tests of typescript app

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': 19,
38+
'too-many-arguments': 20,
3939
'too-few-public-methods': 5,
4040
'unnecessary-comprehension': 5,
4141
'no-value-for-parameter': 2,

plot_data/core.py

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ def _to_html(self, local: bool = False, canvas_id: str = 'canvas', version: str
134134

135135
def to_html_stream(self, stream, local: bool = False, canvas_id: str = 'canvas', version: str = None):
136136
""" Export current Figure to its equivalent html stream file. """
137-
html = self._to_html(local=local, canvas_id=canvas_id, version=version)
138-
stream.write(html.encode('utf-8'))
137+
html = self._to_html(debug_mode=debug_mode, canvas_id=canvas_id, version=version)
138+
stream.write(html)
139139

140140
def to_html(self, filepath: str = None, local: bool = False, canvas_id: str = 'canvas', version: str = None):
141141
""" Export current Figure to an HTML file given by the filepath. """
142142
filepath = make_filepath(filepath=filepath)
143-
with open(filepath, 'wb') as file:
144-
self.to_html_stream(file, local=local, canvas_id=canvas_id, version=version)
143+
with open(filepath, 'w', encoding="utf-8") as file:
144+
self.to_html_stream(file, debug_mode=debug_mode, canvas_id=canvas_id, version=version)
145145
return filepath
146146

147147
def plot_data(self, **kwargs):
@@ -152,13 +152,21 @@ def plot(self, filepath: str = None, **kwargs):
152152
webbrowser.open('file://' + os.path.realpath(filepath))
153153

154154

155-
class Sample(PlotDataObject):
155+
class ReferencedObject(PlotDataObject):
156+
""" PlotData object with reference_path. """
157+
158+
def __init__(self, type_: str, reference_path: str = "#", name: str = ""):
159+
self.reference_path = reference_path
160+
super().__init__(type_=type_, name=name)
161+
162+
163+
class Sample(ReferencedObject):
156164
""" Graph Point. """
157165

158166
def __init__(self, values, reference_path: str = "#", name: str = ""):
159167
self.values = values
160168
self.reference_path = reference_path
161-
super().__init__(type_="sample", name=name)
169+
super().__init__(type_="sample", reference_path=reference_path, name=name)
162170

163171
def to_dict(self, use_pointers: bool = True, memo=None, path: str = '#', id_method=True,
164172
id_memo=None) -> JsonSerializable:
@@ -419,7 +427,7 @@ def __init__(self, point_color: str, point_index: List[int], name: str = ''):
419427
PlotDataObject.__init__(self, type_=None, name=name)
420428

421429

422-
class Text(PlotDataObject):
430+
class Text(ReferencedObject):
423431
"""
424432
A class for displaying texts on canvas. Text is a primitive and can be instantiated by PrimitiveGroup.
425433
@@ -443,7 +451,7 @@ class Text(PlotDataObject):
443451

444452
def __init__(self, comment: str, position_x: float, position_y: float, text_style: TextStyle = None,
445453
text_scaling: bool = None, max_width: float = None, height: float = None, multi_lines: bool = True,
446-
name: str = ''):
454+
reference_path: str = "#", name: str = ''):
447455
self.comment = comment
448456
self.text_style = text_style
449457
self.position_x = position_x
@@ -452,7 +460,7 @@ def __init__(self, comment: str, position_x: float, position_y: float, text_styl
452460
self.max_width = max_width
453461
self.height = height
454462
self.multi_lines = multi_lines
455-
PlotDataObject.__init__(self, type_='text', name=name)
463+
super().__init__(type_='text', reference_path=reference_path, name=name)
456464

457465
def mpl_plot(self, ax=None, color='k', alpha=1., **kwargs):
458466
""" Plots using Matplotlib. """
@@ -462,7 +470,7 @@ def mpl_plot(self, ax=None, color='k', alpha=1., **kwargs):
462470
return ax
463471

464472

465-
class Line2D(PlotDataObject):
473+
class Line2D(ReferencedObject):
466474
"""
467475
An infinite line. Line2D is a primitive and can be instantiated by PrimitiveGroups.
468476
@@ -474,12 +482,13 @@ class Line2D(PlotDataObject):
474482
:type edge_style: EdgeStyle
475483
"""
476484

477-
def __init__(self, point1: List[float], point2: List[float], edge_style: EdgeStyle = None, name: str = ''):
485+
def __init__(self, point1: List[float], point2: List[float], edge_style: EdgeStyle = None,
486+
reference_path: str = "#", name: str = ''):
478487
self.data = point1 + point2 # Retrocompatibility
479488
self.point1 = point1
480489
self.point2 = point2
481490
self.edge_style = edge_style
482-
PlotDataObject.__init__(self, type_='line2d', name=name)
491+
super().__init__(type_='line2d', reference_path=reference_path, name=name)
483492

484493
def mpl_plot(self, ax=None, edge_style=None, **kwargs):
485494
""" Plots using matplotlib. """
@@ -497,7 +506,7 @@ def mpl_plot(self, ax=None, edge_style=None, **kwargs):
497506
return ax
498507

499508

500-
class LineSegment2D(PlotDataObject):
509+
class LineSegment2D(ReferencedObject):
501510
"""
502511
A line segment. This is a primitive that can be called by PrimitiveGroup.
503512
@@ -509,7 +518,8 @@ class LineSegment2D(PlotDataObject):
509518
:type edge_style: EdgeStyle
510519
"""
511520

512-
def __init__(self, point1: List[float], point2: List[float], edge_style: EdgeStyle = None, name: str = ''):
521+
def __init__(self, point1: List[float], point2: List[float], edge_style: EdgeStyle = None,
522+
reference_path: str = "#", name: str = ''):
513523
# Data is used in typescript
514524
self.data = point1 + point2
515525
self.point1 = point1
@@ -519,7 +529,7 @@ def __init__(self, point1: List[float], point2: List[float], edge_style: EdgeSty
519529
self.edge_style = EdgeStyle()
520530
else:
521531
self.edge_style = edge_style
522-
PlotDataObject.__init__(self, type_='linesegment2d', name=name)
532+
super().__init__(type_='linesegment2d', reference_path=reference_path, name=name)
523533

524534
def bounding_box(self):
525535
""" Get 2D bounding box of current LineSegment2D. """
@@ -547,7 +557,7 @@ def mpl_plot(self, ax=None, edge_style=None, **kwargs):
547557
return ax
548558

549559

550-
class Wire(PlotDataObject):
560+
class Wire(ReferencedObject):
551561
"""
552562
A set of connected lines. It also provides highlighting feature.
553563
@@ -560,11 +570,11 @@ class Wire(PlotDataObject):
560570
"""
561571

562572
def __init__(self, lines: List[Tuple[float, float]], edge_style: EdgeStyle = None, tooltip: str = None,
563-
name: str = ""):
573+
reference_path: str = "#", name: str = ""):
564574
self.lines = lines
565575
self.edge_style = edge_style
566576
self.tooltip = tooltip
567-
PlotDataObject.__init__(self, type_="wire", name=name)
577+
super().__init__(type_="wire", reference_path=reference_path, name=name)
568578

569579
def mpl_plot(self, ax=None, **kwargs):
570580
""" Plots using matplotlib. """
@@ -579,7 +589,7 @@ def mpl_plot(self, ax=None, **kwargs):
579589
return ax
580590

581591

582-
class Circle2D(PlotDataObject):
592+
class Circle2D(ReferencedObject):
583593
"""
584594
A circle. It is a primitive and can be instantiated by PrimitiveGroup.
585595
@@ -598,14 +608,14 @@ class Circle2D(PlotDataObject):
598608
"""
599609

600610
def __init__(self, cx: float, cy: float, r: float, edge_style: EdgeStyle = None,
601-
surface_style: SurfaceStyle = None, tooltip: str = None, name: str = ''):
611+
surface_style: SurfaceStyle = None, tooltip: str = None, reference_path: str = "#", name: str = ''):
602612
self.edge_style = edge_style
603613
self.surface_style = surface_style
604614
self.r = r
605615
self.cx = cx
606616
self.cy = cy
607617
self.tooltip = tooltip
608-
PlotDataObject.__init__(self, type_='circle', name=name)
618+
super().__init__(type_='circle', reference_path=reference_path, name=name)
609619

610620
def bounding_box(self):
611621
""" Get 2D bounding box of current Circle2D. """
@@ -635,19 +645,19 @@ def mpl_plot(self, ax=None, **kwargs):
635645
return ax
636646

637647

638-
class Rectangle(PlotDataObject):
648+
class Rectangle(ReferencedObject):
639649
""" Class to draw a rectangle. """
640650

641651
def __init__(self, x_coord: float, y_coord: float, width: float, height: float, edge_style: EdgeStyle = None,
642-
surface_style: SurfaceStyle = None, tooltip: str = None, name: str = ''):
652+
surface_style: SurfaceStyle = None, tooltip: str = None, reference_path: str = "#", name: str = ''):
643653
self.x_coord = x_coord
644654
self.y_coord = y_coord
645655
self.width = width
646656
self.height = height
647657
self.surface_style = surface_style
648658
self.edge_style = edge_style
649659
self.tooltip = tooltip
650-
PlotDataObject.__init__(self, type_='rectangle', name=name)
660+
super().__init__(type_='rectangle', reference_path=reference_path, name=name)
651661

652662
def bounding_box(self):
653663
""" Get 2D bounding box of current Circle2D. """
@@ -681,13 +691,15 @@ class RoundRectangle(Rectangle):
681691
""" Class to draw a round rectangle. """
682692

683693
def __init__(self, x_coord: float, y_coord: float, width: float, height: float, radius: float = 2,
684-
edge_style: EdgeStyle = None, surface_style: SurfaceStyle = None, tooltip: str = None, name: str = ''):
685-
super().__init__(x_coord, y_coord, width, height, edge_style, surface_style, tooltip, name=name)
694+
edge_style: EdgeStyle = None, surface_style: SurfaceStyle = None, tooltip: str = None,
695+
reference_path: str = "#", name: str = ''):
696+
super().__init__(x_coord, y_coord, width, height, edge_style, surface_style, tooltip,
697+
reference_path=reference_path, name=name)
686698
self.type_ = "roundrectangle"
687699
self.radius = radius
688700

689701

690-
class Point2D(PlotDataObject):
702+
class Point2D(ReferencedObject):
691703
"""
692704
A class for instantiating a point.
693705
@@ -699,11 +711,11 @@ class Point2D(PlotDataObject):
699711
:type point_style: PointStyle
700712
"""
701713

702-
def __init__(self, cx: float, cy: float, point_style: PointStyle = None, name: str = ''):
714+
def __init__(self, cx: float, cy: float, point_style: PointStyle = None, reference_path: str = "#", name: str = ''):
703715
self.cx = cx
704716
self.cy = cy
705717
self.point_style = point_style
706-
PlotDataObject.__init__(self, type_='point', name=name)
718+
super().__init__(type_='point', reference_path=reference_path, name=name)
707719

708720
def bounding_box(self):
709721
""" Get 2D bounding box of current Circle2D. """
@@ -1103,7 +1115,7 @@ def _build_multiplot(self):
11031115
for row in sample_attributes for col in sample_attributes]
11041116

11051117

1106-
class Arc2D(PlotDataObject):
1118+
class Arc2D(ReferencedObject):
11071119
"""
11081120
A class for drawing arcs. Arc2D is a primitive and can be instantiated by PrimitiveGroup. By default,
11091121
the arc is drawn anticlockwise.
@@ -1122,25 +1134,22 @@ class Arc2D(PlotDataObject):
11221134
BSPline method. This argument is useless unless the arc2D is part of\
11231135
a Contour2D. In such case, the arc must be instantiated by volmdlr.
11241136
:type data: List[dict]
1125-
:param anticlockwise: True if you want the arc the be drawn \
1126-
anticlockwise, False otherwise
1127-
:type anticlockwise: bool
1137+
:param clockwise: True if you want the arc the be drawn clockwise, False otherwise
1138+
:type clockwise: bool
11281139
:param edge_style: for customization
11291140
:type edge_style: EdgeStyle
11301141
"""
11311142

1132-
def __init__(self, cx: float, cy: float, r: float, start_angle: float, end_angle: float, data=None,
1133-
clockwise: bool = None, edge_style: EdgeStyle = None, name: str = ''):
1143+
def __init__(self, cx: float, cy: float, r: float, start_angle: float, end_angle: float, clockwise: bool = None,
1144+
edge_style: EdgeStyle = None, reference_path: str = "#", name: str = ''):
11341145
self.cx = cx
11351146
self.cy = cy
11361147
self.r = r
11371148
self.start_angle = start_angle
11381149
self.end_angle = end_angle
1139-
self.data = data
1140-
self.anticlockwise = not clockwise
11411150
self.clockwise = clockwise
11421151
self.edge_style = edge_style
1143-
PlotDataObject.__init__(self, type_='arc', name=name)
1152+
super().__init__(type_='arc', reference_path=reference_path, name=name)
11441153

11451154
def bounding_box(self):
11461155
""" Get 2D bounding box of current Circle2D. """
@@ -1174,7 +1183,7 @@ def mpl_plot(self, ax=None, **kwargs):
11741183
return ax
11751184

11761185

1177-
class Contour2D(PlotDataObject):
1186+
class Contour2D(ReferencedObject):
11781187
"""
11791188
A Contour2D is a closed polygon that is formed by multiple primitives.
11801189
@@ -1190,13 +1199,13 @@ class Contour2D(PlotDataObject):
11901199
"""
11911200

11921201
def __init__(self, plot_data_primitives: List[Union[Arc2D, LineSegment2D]], edge_style: EdgeStyle = None,
1193-
surface_style: SurfaceStyle = None, tooltip: str = None, name: str = ''):
1202+
surface_style: SurfaceStyle = None, tooltip: str = None, reference_path: str = "#", name: str = ''):
11941203
self.plot_data_primitives = plot_data_primitives
11951204
self.edge_style = edge_style
11961205
self.surface_style = surface_style
11971206
self.tooltip = tooltip
11981207
self.is_filled = surface_style is not None
1199-
PlotDataObject.__init__(self, type_='contour', name=name)
1208+
super().__init__(type_='contour', reference_path=reference_path, name=name)
12001209

12011210
def bounding_box(self):
12021211
""" Get 2D bounding box of current Contour2D. """

script/histogram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'color': random_color
1919
})
2020

21-
plot_data_object = plot_data.Histogram(x_variable='mass', elements=elements, graduation_nb = 20,
21+
plot_data_object = plot_data.Histogram(x_variable='mass', elements=elements, graduation_nb=20,
2222
surface_style=plot_data.SurfaceStyle("rgb(50, 50, 220)"),
2323
edge_style=plot_data.EdgeStyle(1, "rgb(0, 255, 0)", [5, 3]))
2424

script/minimal_dataviz.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717

1818
for i in range(100):
1919

20-
elements.append({'mass': 52+ 47*random.random(),
21-
'cost': 231 + 89*random.random(),
22-
'wiring_length': 8.9 + 3.1*random.random()})
20+
elements.append({'mass': 52 + 47 * random.random(),
21+
'cost': 231 + 89 * random.random(),
22+
'wiring_length': 8.9 + 3.1 * random.random()})
2323

2424

2525
parallel_plot = plot_data.ParallelPlot(disposition='vertical',
26-
axes=axes)
26+
axes=axes)
2727

2828
# Scatter
2929

script/plot_scatter.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
'shape': random_shape,
1919
'color': random_color})
2020

21-
points_sets = [plot_data.PointFamily(plot_data.colors.RED, [0,1,2,3,4,5,6,7,8,9]),
22-
plot_data.PointFamily(plot_data.colors.YELLOW, [10,11,12,13,14,15,16,17,18,19]),
23-
plot_data.PointFamily(plot_data.colors.GREEN, [20,21,22,23,24,25,26,27,28,29]),
24-
plot_data.PointFamily(plot_data.colors.PINK, [30,31,32,33,34,35,36,37,38,39])]
21+
points_sets = [plot_data.PointFamily(plot_data.colors.RED, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
22+
plot_data.PointFamily(plot_data.colors.YELLOW, [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]),
23+
plot_data.PointFamily(plot_data.colors.GREEN, [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]),
24+
plot_data.PointFamily(plot_data.colors.PINK, [30, 31, 32, 33, 34, 35, 36, 37, 38, 39])]
2525

2626
plot_data_object = plot_data.Scatter(elements=elements, points_sets=points_sets,
2727
x_variable='mass', y_variable='length')
@@ -66,12 +66,12 @@
6666

6767
# Now, here is the new scatterplot
6868
plot_data_object = plot_data.Scatter(x_variable='mass', y_variable='length',
69-
point_style=point_style,
70-
elements=elements,
71-
points_sets=points_sets,
72-
axis=axis,
73-
tooltip=tooltip,
74-
heatmap=heatmap)
69+
point_style=point_style,
70+
elements=elements,
71+
points_sets=points_sets,
72+
axis=axis,
73+
tooltip=tooltip,
74+
heatmap=heatmap)
7575

7676
# if local is True, set it to False
7777
plot_data.plot_canvas(plot_data_object=plot_data_object, local=True)

0 commit comments

Comments
 (0)