Skip to content

Commit 7712142

Browse files
authored
Merge pull request #330 from Dessia-tech/feat/offline
[7] Feat/offline
2 parents bb1ec26 + 1da73bb commit 7712142

17 files changed

+293
-32
lines changed

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
node_modules/
2-
lib/
3-
libdev/
4-
51
# CAD files
62
*.fcstd
73
*.fcstd1
@@ -27,6 +23,7 @@ eggs/
2723
.eggs/
2824
lib/
2925
lib64/
26+
node_modules/
3027
parts/
3128
sdist/
3229
var/

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ repos:
66
rev: v3.2.0
77
hooks:
88
- id: trailing-whitespace
9+
exclude: libdev/
910
- id: check-docstring-first
1011
- id: check-json
1112
- id: check-added-large-files
@@ -14,3 +15,4 @@ repos:
1415
- id: requirements-txt-fixer
1516
- id: check-merge-conflict
1617
- id: end-of-file-fixer
18+
exclude: libdev/

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Integer axes only show integer ticks
1111
- Handle date as continuous value on axes
1212
- Allow to log scale axes
13+
- Offline mode
1314

1415
### Fix
1516
- Add reference_path to all Primitive / Elementary drawing Objects

libdev/plot-data.js

Lines changed: 260 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plot_data/core.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,21 @@ def _export_formats(self) -> List[ExportFormat]:
127127
formats.append(ExportFormat(selector="html", extension="html", method_name="to_html_stream", text=False))
128128
return formats
129129

130-
def _to_html(self, debug_mode: bool = False, canvas_id: str = 'canvas', version: str = None):
131-
lib_path = plot_data_path(debug_mode=debug_mode, version=version)
130+
def _to_html(self, local: bool = False, canvas_id: str = 'canvas', version: str = None):
131+
lib_path = plot_data_path(local=local, version=version)
132132
return self.template.substitute(data=json.dumps(self.to_dict()), core_path=lib_path, canvas_id=canvas_id,
133133
width=self.width, height=self.height)
134134

135-
def to_html_stream(self, stream, debug_mode: bool = False, canvas_id: str = 'canvas', version: str = None):
135+
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(debug_mode=debug_mode, canvas_id=canvas_id, version=version)
137+
html = self._to_html(local=local, canvas_id=canvas_id, version=version)
138138
stream.write(html)
139139

140-
def to_html(self, filepath: str = None, debug_mode: bool = False, canvas_id: str = 'canvas', version: str = None):
140+
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)
143143
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)
144+
self.to_html_stream(file, local=local, canvas_id=canvas_id, version=version)
145145
return filepath
146146

147147
def plot_data(self, **kwargs):
@@ -1505,10 +1505,10 @@ def __init__(self, plots: List[PlotDataObject], sizes: List[Window] = None, elem
15051505
super().__init__(width=width, height=height, type_='multiplot', name=name)
15061506

15071507

1508-
def plot_data_path(debug_mode: bool = False, version: str = None):
1508+
def plot_data_path(local: bool = False, version: str = None):
15091509
""" Get path of plot_data package to write it in html file of Figure to draw. """
15101510
version, folder, filename = get_current_link(version=version)
1511-
if debug_mode:
1511+
if local:
15121512
core_path = os.sep.join(os.getcwd().split(os.sep)[:-1] + [folder, filename])
15131513
if os.path.isfile(core_path):
15141514
return core_path.replace(" ", "%20")
@@ -1526,17 +1526,17 @@ def make_filepath(filepath: str = None):
15261526
return filepath
15271527

15281528

1529-
def plot_canvas(plot_data_object: Figure, filepath: str = None, debug_mode: bool = False, canvas_id: str = 'canvas',
1529+
def plot_canvas(plot_data_object: Figure, filepath: str = None, local: bool = False, canvas_id: str = 'canvas',
15301530
force_version: str = None, width: float = None, height: float = None):
15311531
"""
15321532
Creates a html file and plots input data in web browser.
15331533
15341534
:param plot_data_object: a PlotDataObject(ie Scatter, ParallelPlot,\
15351535
MultiplePlots, Graph2D, PrimitiveGroup or PrimitiveGroupContainer)
15361536
:type plot_data_object: PlotDataObject
1537-
:param debug_mode: uses local library if True, uses typescript \
1537+
:param local: uses local library if True, uses typescript \
15381538
library from cdn if False
1539-
:type debug_mode: bool
1539+
:type local: bool
15401540
:param canvas_id: set canvas' id, ie name
15411541
:type canvas_id: str
15421542
:param width: set the canvas' width:
@@ -1550,7 +1550,7 @@ def plot_canvas(plot_data_object: Figure, filepath: str = None, debug_mode: bool
15501550
plot_data_object.width = width
15511551
if height:
15521552
plot_data_object.height = height
1553-
plot_data_object.plot(filepath=filepath, debug_mode=debug_mode, canvas_id=canvas_id, version=force_version)
1553+
plot_data_object.plot(filepath=filepath, local=local, canvas_id=canvas_id, version=force_version)
15541554

15551555

15561556
def write_json_for_tests(plot_data_object: PlotDataObject, json_path: str):

script/graph2D.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# The graph's definition has been moved to test_objects.graph_test.py to
66
# make MultiplePlots.py' imports more convenient
77
plot_data_object = graph2d
8-
plot_data.plot_canvas(plot_data_object=graph2d, canvas_id='canvas', debug_mode=True)
8+
plot_data.plot_canvas(plot_data_object=graph2d, canvas_id='canvas', local=True)

script/histogram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
surface_style=plot_data.SurfaceStyle("rgb(50, 50, 220)"),
2323
edge_style=plot_data.EdgeStyle(1, "rgb(0, 255, 0)", [5, 3]))
2424

25-
plot_data.plot_canvas(plot_data_object=plot_data_object, debug_mode=True)
25+
plot_data.plot_canvas(plot_data_object=plot_data_object, local=True)

script/minimal_dataviz.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88

99
import random
10+
import plot_data
1011

1112
random.seed(7)
1213

@@ -37,4 +38,4 @@
3738
multipleplots = plot_data.MultiplePlots(elements=elements, plots=plots,
3839
initial_view_on=True)
3940

40-
plot_data.plot_canvas(plot_data_object=multipleplots, debug_mode=True)
41+
plot_data.plot_canvas(plot_data_object=multipleplots, local=True)

script/multiplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@
7979
plot_data.PointFamily('rgb(146, 178, 78)', [11,21,31,41,25,26,27])])
8080

8181
# Display
82-
plot_data_object.plot(debug_mode=True, canvas_id='canvas')
83-
# plot_data.plot_canvas(plot_data_object=multiplot, debug_mode=True)
82+
plot_data_object.plot(local=True, canvas_id='canvas')
83+
# plot_data.plot_canvas(plot_data_object=multiplot, local=True)

script/networkx_graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
text_align_x='center',
1919
text_align_y='middle')))
2020

21-
plot_data.plot_canvas(plotdata_nx_graph, debug_mode=True)
21+
plot_data.plot_canvas(plotdata_nx_graph, local=True)

0 commit comments

Comments
 (0)