plotjs 0.0.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- plotjs/__init__.py +6 -0
- plotjs/css.py +100 -0
- plotjs/data/__init__.py +3 -0
- plotjs/data/datasets.py +138 -0
- plotjs/data/iris.csv +151 -0
- plotjs/data/mtcars.csv +33 -0
- plotjs/data/titanic.csv +892 -0
- plotjs/javascript.py +23 -0
- plotjs/main.py +359 -0
- plotjs/static/default.css +40 -0
- plotjs/static/plotparser.js +229 -0
- plotjs/static/template.html +103 -0
- plotjs/utils.py +43 -0
- plotjs-0.0.6.dist-info/METADATA +54 -0
- plotjs-0.0.6.dist-info/RECORD +18 -0
- plotjs-0.0.6.dist-info/WHEEL +5 -0
- plotjs-0.0.6.dist-info/licenses/LICENSE +21 -0
- plotjs-0.0.6.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<title>{{ document_title | safe }}</title>
|
|
6
|
+
<link rel="icon" href="{{ favicon_path | safe }}" type="image/x-icon" />
|
|
7
|
+
<style>
|
|
8
|
+
{{ default_css | safe }}
|
|
9
|
+
{{ additional_css | safe }}
|
|
10
|
+
</style>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
{% set chart_id = "plot-container-" + uuid %}
|
|
14
|
+
|
|
15
|
+
<div id="{{ chart_id }}">
|
|
16
|
+
{{ svg | safe }}
|
|
17
|
+
<div class="tooltip" id="tooltip-{{ uuid }}"></div>
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/7.9.0/d3.min.js"></script>
|
|
21
|
+
<script type="module">
|
|
22
|
+
(function () {
|
|
23
|
+
// prettier-ignore
|
|
24
|
+
{{ js_parser | safe }}
|
|
25
|
+
|
|
26
|
+
const container = document.getElementById("{{ chart_id }}");
|
|
27
|
+
|
|
28
|
+
const tooltip = d3.select("#tooltip-{{ uuid }}");
|
|
29
|
+
const svg = d3.select(container).select("svg");
|
|
30
|
+
|
|
31
|
+
const plot_data = JSON.parse(`{{ plot_data_json | tojson | safe }}`);
|
|
32
|
+
const tooltip_x_shift = plot_data["tooltip_x_shift"];
|
|
33
|
+
const tooltip_y_shift = -plot_data["tooltip_y_shift"];
|
|
34
|
+
const axes = plot_data["axes"];
|
|
35
|
+
|
|
36
|
+
const plotParser = new PlotSVGParser(
|
|
37
|
+
svg,
|
|
38
|
+
tooltip,
|
|
39
|
+
tooltip_x_shift,
|
|
40
|
+
tooltip_y_shift
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
// Process each axes that has tooltip configuration
|
|
44
|
+
for (const axes_class in axes) {
|
|
45
|
+
if (axes.hasOwnProperty(axes_class)) {
|
|
46
|
+
const axe_data = axes[axes_class];
|
|
47
|
+
const tooltip_labels = axe_data["tooltip_labels"];
|
|
48
|
+
const tooltip_groups = axe_data["tooltip_groups"];
|
|
49
|
+
const hover_nearest = axe_data["hover_nearest"] === "true";
|
|
50
|
+
const show_tooltip = tooltip_labels.length === 0 ? "none" : "block";
|
|
51
|
+
|
|
52
|
+
const lines = plotParser.findLines(svg, axes_class);
|
|
53
|
+
const bars = plotParser.findBars(svg, axes_class);
|
|
54
|
+
const points = plotParser.findPoints(
|
|
55
|
+
svg,
|
|
56
|
+
axes_class,
|
|
57
|
+
tooltip_groups
|
|
58
|
+
);
|
|
59
|
+
const areas = plotParser.findAreas(svg, axes_class);
|
|
60
|
+
|
|
61
|
+
plotParser.setHoverEffect(
|
|
62
|
+
points,
|
|
63
|
+
axes_class,
|
|
64
|
+
tooltip_labels,
|
|
65
|
+
tooltip_groups,
|
|
66
|
+
show_tooltip,
|
|
67
|
+
hover_nearest
|
|
68
|
+
);
|
|
69
|
+
plotParser.setHoverEffect(
|
|
70
|
+
lines,
|
|
71
|
+
axes_class,
|
|
72
|
+
tooltip_labels,
|
|
73
|
+
tooltip_groups,
|
|
74
|
+
show_tooltip,
|
|
75
|
+
hover_nearest
|
|
76
|
+
);
|
|
77
|
+
plotParser.setHoverEffect(
|
|
78
|
+
bars,
|
|
79
|
+
axes_class,
|
|
80
|
+
tooltip_labels,
|
|
81
|
+
tooltip_groups,
|
|
82
|
+
show_tooltip,
|
|
83
|
+
hover_nearest
|
|
84
|
+
);
|
|
85
|
+
plotParser.setHoverEffect(
|
|
86
|
+
areas,
|
|
87
|
+
axes_class,
|
|
88
|
+
tooltip_labels,
|
|
89
|
+
tooltip_groups,
|
|
90
|
+
show_tooltip,
|
|
91
|
+
hover_nearest
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
})();
|
|
96
|
+
</script>
|
|
97
|
+
|
|
98
|
+
<script type="module">
|
|
99
|
+
// prettier-ignore
|
|
100
|
+
{{ additional_javascript | safe }}
|
|
101
|
+
</script>
|
|
102
|
+
</body>
|
|
103
|
+
</html>
|
plotjs/utils.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import narwhals.stable.v2 as nw
|
|
2
|
+
from narwhals.stable.v2.dependencies import is_numpy_array, is_into_series
|
|
3
|
+
|
|
4
|
+
import re
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _vector_to_list(vector, name="labels and groups") -> list:
|
|
8
|
+
"""
|
|
9
|
+
Function used to easily convert various kind of iterables to
|
|
10
|
+
lists in order to have standardised objects passed to javascript.
|
|
11
|
+
|
|
12
|
+
It accepts all backend series from narwhals and common objects
|
|
13
|
+
such as numpy arrays.
|
|
14
|
+
|
|
15
|
+
Todo: test this extensively to make sure it behaves as expected.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
vector: A valid iterable.
|
|
19
|
+
name: The name passed to the error message when type is
|
|
20
|
+
invalid.
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
A list
|
|
24
|
+
"""
|
|
25
|
+
if isinstance(vector, (list, tuple)) or is_numpy_array(vector):
|
|
26
|
+
return list(vector)
|
|
27
|
+
elif is_into_series(vector):
|
|
28
|
+
return nw.from_native(vector, allow_series=True).to_list()
|
|
29
|
+
else:
|
|
30
|
+
raise ValueError(
|
|
31
|
+
f"{name} must be a Series or a valid iterable (list, tuple, ndarray...)."
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _get_and_sanitize_js(file_path, after_pattern):
|
|
36
|
+
with open(file_path) as f:
|
|
37
|
+
content = f.read()
|
|
38
|
+
|
|
39
|
+
match = re.search(after_pattern, content, re.DOTALL)
|
|
40
|
+
if match:
|
|
41
|
+
return match.group(0)
|
|
42
|
+
else:
|
|
43
|
+
raise ValueError(f"Could not find '{after_pattern}' in the file")
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: plotjs
|
|
3
|
+
Version: 0.0.6
|
|
4
|
+
Summary: Turn static matplotlib charts into interactive web visualizations
|
|
5
|
+
Author-email: Joseph Barbier <joseph.barbierdarnal@mail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://y-sunflower.github.io/plotjs/
|
|
8
|
+
Project-URL: Issues, https://github.com/y-sunflower/plotjs/issues
|
|
9
|
+
Project-URL: Documentation, https://y-sunflower.github.io/plotjs/
|
|
10
|
+
Project-URL: Repository, https://github.com/y-sunflower/plotjs
|
|
11
|
+
Keywords: matplotlib,interactive,javascript,web,css,d3,mpld3,plotnine
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: jinja2>=3.0.0
|
|
19
|
+
Requires-Dist: matplotlib>=3.10.0
|
|
20
|
+
Requires-Dist: narwhals>=2.0.0
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+

|
|
24
|
+
|
|
25
|
+
# `plotjs`: Turn static matplotlib charts into interactive web visualizations
|
|
26
|
+
|
|
27
|
+
<img src="https://github.com/JosephBARBIERDARNAL/static/blob/main/python-libs/plotjs/image.png?raw=true" alt="plotjs logo" align="right" width="150px"/>
|
|
28
|
+
|
|
29
|
+
`plotjs` is a Python package that transform matplotlib plots into interactive charts with minimum user inputs. You can:
|
|
30
|
+
|
|
31
|
+
- control tooltip labels and grouping
|
|
32
|
+
- add CSS
|
|
33
|
+
- add JavaScript
|
|
34
|
+
- and many more
|
|
35
|
+
|
|
36
|
+
> Consider that the project is still **very unstable**.
|
|
37
|
+
|
|
38
|
+
[Online demo](https://y-sunflower.github.io/plotjs/)
|
|
39
|
+
|
|
40
|
+
<br><br>
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
From PyPI (recommended):
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
pip install plotjs
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Latest dev version:
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
pip install git+https://github.com/y-sunflower/plotjs.git
|
|
54
|
+
```
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
plotjs/__init__.py,sha256=PBTZcmQtjp9ATylrqeYfZwi74tWHWsm-LwJr2C933nk,87
|
|
2
|
+
plotjs/css.py,sha256=9X2-cjS0CttPxQC7msPe1WNPxvBeGNAq2EuYHpRhuPA,2424
|
|
3
|
+
plotjs/javascript.py,sha256=oO16m0yUUl4JAsG7swk2TRA2k-qr8yKBuzpcENV4yXo,489
|
|
4
|
+
plotjs/main.py,sha256=ChzWn1UhiqVPVVnIK11F2RrPe6ojjOq3Zf6_VW7tnxY,11642
|
|
5
|
+
plotjs/utils.py,sha256=Ckt1orIismrR8dsiOt_3xsM2Z-WZKOj4pSsKlLTm9OA,1283
|
|
6
|
+
plotjs/data/__init__.py,sha256=zyH9-p1G2B-6KQSQpsQLYpyzfrUa3phUc97a71FGGkM,152
|
|
7
|
+
plotjs/data/datasets.py,sha256=RtdRtrk-fAf3HpcVmc6MsuwR6ucyQU7hE7uvCgnmNpw,3448
|
|
8
|
+
plotjs/data/iris.csv,sha256=xSdC5QMVqZ-Vajg_rt91dVUmdfZAnvD5pHB23QhHmTA,3858
|
|
9
|
+
plotjs/data/mtcars.csv,sha256=t9kUtdR8c7PqWquOcpiIbXDG_fhzCH3w1KOCOT-BBls,1700
|
|
10
|
+
plotjs/data/titanic.csv,sha256=SkN_3gX-UmThcBpzh6xvt1OTdyuji7LJxWZAWvWvS9c,60302
|
|
11
|
+
plotjs/static/default.css,sha256=eSaoCCCwJKSSN4eU4WwAPHzvXX_hIGKM-TCIxENhTVI,729
|
|
12
|
+
plotjs/static/plotparser.js,sha256=V5wXY4MrmYFFVmFGTnFWJet_MURyvlgZC_bJ5Pwok6A,8054
|
|
13
|
+
plotjs/static/template.html,sha256=F8RAM7C7aBLYs7U9GUhw3uNP0wsB1VgkZ-Ue3jNGm_c,3097
|
|
14
|
+
plotjs-0.0.6.dist-info/licenses/LICENSE,sha256=0tiC65L_9U5H0FD8LV6N8t8kI1iLDPVDLCK2qenV9w4,1071
|
|
15
|
+
plotjs-0.0.6.dist-info/METADATA,sha256=98qasu-97LUuI344wlmi8MPYz0-S2lZERfoYdFjMV8I,1620
|
|
16
|
+
plotjs-0.0.6.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
17
|
+
plotjs-0.0.6.dist-info/top_level.txt,sha256=kDec-84OOKAI1HbXjkuHx3mOw0P2JDxW_tAbwuYscAc,7
|
|
18
|
+
plotjs-0.0.6.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Joseph Barbier
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
plotjs
|