plotjs 0.0.7__tar.gz → 0.0.9__tar.gz
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-0.0.7 → plotjs-0.0.9}/.github/workflows/tests-python.yaml +2 -0
- plotjs-0.0.7/AGENTS.md → plotjs-0.0.9/AGENT.md +16 -10
- {plotjs-0.0.7 → plotjs-0.0.9}/LICENSE +1 -1
- {plotjs-0.0.7 → plotjs-0.0.9}/PKG-INFO +1 -3
- {plotjs-0.0.7 → plotjs-0.0.9}/README.md +0 -2
- plotjs-0.0.9/docs/developers/svg-parser-reference.md +164 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/guides/css/index.md +7 -7
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/guides/javascript/index.md +14 -14
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/guides/javascript/javascript.py +1 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/iframes/CSS-2.html +277 -70
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/iframes/CSS.html +277 -70
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/iframes/area-natural-disasters.html +277 -70
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/iframes/bug.html +277 -70
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/iframes/javascript.html +278 -71
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/iframes/javascript2.html +277 -70
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/iframes/quickstart.html +277 -70
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/iframes/quickstart10.html +277 -70
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/iframes/quickstart11.html +277 -70
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/iframes/quickstart2.html +277 -70
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/iframes/quickstart3.html +277 -70
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/iframes/quickstart4.html +277 -70
- plotjs-0.0.9/docs/iframes/quickstart5.html +1758 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/iframes/quickstart6.html +277 -70
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/iframes/quickstart7.html +277 -70
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/iframes/quickstart8.html +277 -70
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/iframes/quickstart9.html +277 -70
- plotjs-0.0.9/docs/iframes/random-walk-1.html +39624 -0
- plotjs-0.0.9/docs/reference/javascript.md +9 -0
- plotjs-0.0.9/docs/reference/plotjs.md +1 -0
- plotjs-0.0.9/justfile +44 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/mkdocs.yaml +19 -1
- plotjs-0.0.9/plotjs/__init__.py +4 -0
- plotjs-0.0.7/plotjs/main.py → plotjs-0.0.9/plotjs/plotjs.py +116 -11
- {plotjs-0.0.7 → plotjs-0.0.9}/plotjs/static/plotparser.js +1 -3
- {plotjs-0.0.7 → plotjs-0.0.9}/plotjs/static/template.html +31 -17
- {plotjs-0.0.7 → plotjs-0.0.9}/plotjs.egg-info/PKG-INFO +1 -3
- {plotjs-0.0.7 → plotjs-0.0.9}/plotjs.egg-info/SOURCES.txt +4 -5
- {plotjs-0.0.7 → plotjs-0.0.9}/pyproject.toml +1 -1
- {plotjs-0.0.7 → plotjs-0.0.9}/tests/test-browser/conftest.py +0 -2
- {plotjs-0.0.7 → plotjs-0.0.9}/tests/test-browser/test_interactions.py +134 -2
- {plotjs-0.0.7 → plotjs-0.0.9}/tests/test-browser/test_rendering.py +0 -2
- plotjs-0.0.9/tests/test-javascript/EdgeCases.test.js +394 -0
- plotjs-0.0.9/tests/test-javascript/ParserSelectors.test.js +430 -0
- plotjs-0.0.9/tests/test-javascript/ParserSetHover.test.js +576 -0
- plotjs-0.0.9/tests/test-javascript/Selection.test.js +219 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/tests/test-python/test_js.py +8 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/tests/test-python/test_main.py +1 -1
- plotjs-0.0.9/tests/test-python/test_plotjs.py +358 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/uv.lock +1 -1
- plotjs-0.0.7/.coverage +0 -0
- plotjs-0.0.7/coverage-badge.svg +0 -1
- plotjs-0.0.7/docs/developers/svg-parser-reference.md +0 -123
- plotjs-0.0.7/docs/iframes/quickstart5.html +0 -1595
- plotjs-0.0.7/docs/iframes/random-walk-1.html +0 -39128
- plotjs-0.0.7/docs/reference/javascript.md +0 -5
- plotjs-0.0.7/docs/reference/plotjs.md +0 -1
- plotjs-0.0.7/justfile +0 -34
- plotjs-0.0.7/plotjs/__init__.py +0 -6
- plotjs-0.0.7/tests/test-browser/README.md +0 -120
- plotjs-0.0.7/tests/test-javascript/ParserSelectors.test.js +0 -50
- plotjs-0.0.7/tests/test-javascript/ParserSetHover.test.js +0 -48
- plotjs-0.0.7/tests/test-python/test_plotjs.py +0 -145
- {plotjs-0.0.7 → plotjs-0.0.9}/.gitattributes +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/.github/workflows/doc.yaml +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/.github/workflows/lint.yaml +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/.github/workflows/pypi.yaml +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/.github/workflows/tests-browser.yaml +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/.github/workflows/tests-js.yaml +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/.github/workflows/type.yaml +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/.gitignore +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/.pre-commit-config.yaml +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/bun.lock +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/developers/contributing.md +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/developers/overview.md +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/developers/parsing-matplotlib-svg.md +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/gallery/index.md +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/gallery/index.qmd +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/guides/advanced/advanced.py +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/guides/advanced/index.md +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/guides/css/CSS.py +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/guides/embed-graphs/index.md +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/guides/troubleshooting/index.md +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/img/how-it-works-1.png +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/img/how-it-works-2.png +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/img/overview.png +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/index.md +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/index.qmd +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/index_files/figure-commonmark/cell-3-output-1.png +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/reference/css.md +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/reference/datasets.md +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/static/style.css +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/docs/stylesheets/style.css +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/overrides/partials/footer.html +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/package.json +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/plotjs/css.py +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/plotjs/data/__init__.py +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/plotjs/data/datasets.py +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/plotjs/data/iris.csv +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/plotjs/data/mtcars.csv +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/plotjs/data/titanic.csv +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/plotjs/javascript.py +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/plotjs/static/default.css +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/plotjs/utils.py +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/plotjs.egg-info/dependency_links.txt +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/plotjs.egg-info/requires.txt +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/plotjs.egg-info/top_level.txt +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/pytest.ini +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/setup.cfg +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/tests/test-browser/__init__.py +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/tests/test-python/__init__.py +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/tests/test-python/static/script.js +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/tests/test-python/static/script2.js +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/tests/test-python/static/style-invalid.css +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/tests/test-python/static/style.css +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/tests/test-python/test_css.py +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/tests/test-python/test_data.py +0 -0
- {plotjs-0.0.7 → plotjs-0.0.9}/tests/test-python/test_other_utils.py +0 -0
|
@@ -12,17 +12,23 @@ PlotJS is a Python package that transforms static matplotlib charts into interac
|
|
|
12
12
|
Matplotlib Figure → SVG Export (Python) → HTML Template (Jinja2) → Interactive Browser
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
### Workflow:
|
|
16
|
-
|
|
17
15
|
1. **Python (PlotJS class):** Captures matplotlib figure as SVG string, collects tooltip/styling metadata
|
|
18
16
|
2. **Jinja2 Template:** Injects SVG + CSS + JavaScript parser + configuration into HTML
|
|
19
17
|
3. **Browser (PlotSVGParser):** Parses SVG structure to identify plot elements, attaches hover interactivity
|
|
20
18
|
|
|
19
|
+
## How to run command
|
|
20
|
+
|
|
21
|
+
Always use `uv` and/or `just` for running commands:
|
|
22
|
+
|
|
23
|
+
- `uv run pytest tests/test-python`
|
|
24
|
+
- `uv run pytest tests/test-python`
|
|
25
|
+
- `uv run python -c "import matplotlib"`
|
|
26
|
+
|
|
21
27
|
## Key Components
|
|
22
28
|
|
|
23
29
|
### Python Module (`/plotjs/`)
|
|
24
30
|
|
|
25
|
-
**`
|
|
31
|
+
**`plotjs.py`** - Core `PlotJS` class with method chaining
|
|
26
32
|
|
|
27
33
|
- `__init__(fig, **savefig_kws)` - Converts matplotlib figure to SVG
|
|
28
34
|
- `add_tooltip(labels, groups, hover_nearest, ax)` - Configure hover tooltips
|
|
@@ -125,17 +131,17 @@ Optional `seed` parameter ensures deterministic UUID generation for consistent o
|
|
|
125
131
|
```
|
|
126
132
|
plotjs/
|
|
127
133
|
├── __init__.py # Package exports
|
|
128
|
-
├──
|
|
129
|
-
├── css.py # CSS utilities
|
|
130
|
-
├── javascript.py # JavaScript utilities
|
|
131
|
-
├── utils.py # Internal helpers
|
|
134
|
+
├── plotjs.py # Core PlotJS class
|
|
135
|
+
├── css.py # CSS utilities
|
|
136
|
+
├── javascript.py # JavaScript utilities
|
|
137
|
+
├── utils.py # Internal helpers
|
|
132
138
|
├── data/
|
|
133
139
|
│ ├── datasets.py # Sample datasets with Narwhals
|
|
134
140
|
│ └── *.csv # Data files
|
|
135
141
|
└── static/
|
|
136
|
-
├── template.html # Jinja2 HTML template
|
|
137
|
-
├── plotparser.js # SVG parser class
|
|
138
|
-
└── default.css # Default styles
|
|
142
|
+
├── template.html # Jinja2 HTML template
|
|
143
|
+
├── plotparser.js # SVG parser class
|
|
144
|
+
└── default.css # Default styles
|
|
139
145
|
|
|
140
146
|
tests/
|
|
141
147
|
├── test-python/ # Python unit tests
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: plotjs
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.9
|
|
4
4
|
Summary: Turn static matplotlib charts into interactive web visualizations
|
|
5
5
|
Author-email: Joseph Barbier <joseph.barbierdarnal@mail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -20,8 +20,6 @@ Requires-Dist: matplotlib>=3.10.0
|
|
|
20
20
|
Requires-Dist: narwhals>=2.0.0
|
|
21
21
|
Dynamic: license-file
|
|
22
22
|
|
|
23
|
-

|
|
24
|
-
|
|
25
23
|
# `plotjs`: Turn static matplotlib charts into interactive web visualizations
|
|
26
24
|
|
|
27
25
|
<img src="https://github.com/JosephBARBIERDARNAL/static/blob/main/python-libs/plotjs/image.png?raw=true" alt="plotjs logo" align="right" width="150px"/>
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
## Classes
|
|
2
|
+
|
|
3
|
+
<dl>
|
|
4
|
+
<dt><a href="#Selection">Selection</a></dt>
|
|
5
|
+
<dd><p>Lightweight Selection wrapper that mimics d3-selection's chainable API.
|
|
6
|
+
Provides basic DOM manipulation methods for working with SVG elements.</p>
|
|
7
|
+
</dd>
|
|
8
|
+
</dl>
|
|
9
|
+
|
|
10
|
+
## Functions
|
|
11
|
+
|
|
12
|
+
<dl>
|
|
13
|
+
<dt><a href="#select">select(selector)</a> ⇒ <code><a href="#Selection">Selection</a></code></dt>
|
|
14
|
+
<dd><p>Create a Selection from a DOM element or selector string.</p>
|
|
15
|
+
</dd>
|
|
16
|
+
<dt><a href="#getPointerPosition">getPointerPosition(event, svgElement)</a> ⇒ <code>Array.<number></code></dt>
|
|
17
|
+
<dd><p>Get mouse position relative to an SVG element.</p>
|
|
18
|
+
</dd>
|
|
19
|
+
<dt><a href="#findBars">findBars(svg, axes_class)</a> ⇒ <code><a href="#Selection">Selection</a></code></dt>
|
|
20
|
+
<dd><p>Find bar elements (<code>patch</code> groups with clipping) inside a given axes.</p>
|
|
21
|
+
</dd>
|
|
22
|
+
<dt><a href="#findPoints">findPoints(svg, axes_class, tooltip_groups)</a> ⇒ <code><a href="#Selection">Selection</a></code></dt>
|
|
23
|
+
<dd><p>Find scatter plot points inside a given axes.
|
|
24
|
+
Handles both <code><use></code> and <code><path></code> fallback cases,
|
|
25
|
+
and assigns <code>data-group</code> attributes based on tooltip groups.</p>
|
|
26
|
+
</dd>
|
|
27
|
+
<dt><a href="#findLines">findLines(svg, axes_class)</a> ⇒ <code><a href="#Selection">Selection</a></code></dt>
|
|
28
|
+
<dd><p>Find line elements (<code>line2d</code> paths) inside a given axes,
|
|
29
|
+
excluding axis grid lines.</p>
|
|
30
|
+
</dd>
|
|
31
|
+
<dt><a href="#findAreas">findAreas(svg, axes_class)</a> ⇒ <code><a href="#Selection">Selection</a></code></dt>
|
|
32
|
+
<dd><p>Find filled area elements (<code>FillBetweenPolyCollection</code> paths) inside a given axes.</p>
|
|
33
|
+
</dd>
|
|
34
|
+
<dt><a href="#nearestElementFromMouse">nearestElementFromMouse(mouseX, mouseY, elements)</a> ⇒ <code>Element</code> | <code>null</code></dt>
|
|
35
|
+
<dd><p>Compute the nearest element to the mouse cursor from a set of elements.
|
|
36
|
+
Uses bounding box centers for distance.
|
|
37
|
+
This function is used when the <code>hover_nearest</code> argument is true.</p>
|
|
38
|
+
</dd>
|
|
39
|
+
<dt><a href="#setHoverEffect">setHoverEffect(plot_element, axes_class, tooltip_labels, tooltip_groups, show_tooltip, hover_nearest)</a></dt>
|
|
40
|
+
<dd><p>Attach hover interaction and tooltip display to plot elements.
|
|
41
|
+
Can highlight nearest element (if enabled) or hovered element directly.</p>
|
|
42
|
+
</dd>
|
|
43
|
+
</dl>
|
|
44
|
+
|
|
45
|
+
<a name="Selection"></a>
|
|
46
|
+
|
|
47
|
+
## Selection
|
|
48
|
+
Lightweight Selection wrapper that mimics d3-selection's chainable API.
|
|
49
|
+
Provides basic DOM manipulation methods for working with SVG elements.
|
|
50
|
+
|
|
51
|
+
**Kind**: global class
|
|
52
|
+
<a name="select"></a>
|
|
53
|
+
|
|
54
|
+
## select(selector) ⇒ [<code>Selection</code>](#Selection)
|
|
55
|
+
Create a Selection from a DOM element or selector string.
|
|
56
|
+
|
|
57
|
+
**Kind**: global function
|
|
58
|
+
**Returns**: [<code>Selection</code>](#Selection) - New Selection instance
|
|
59
|
+
|
|
60
|
+
| Param | Type | Description |
|
|
61
|
+
| --- | --- | --- |
|
|
62
|
+
| selector | <code>string</code> \| <code>Element</code> | CSS selector string or DOM element |
|
|
63
|
+
|
|
64
|
+
<a name="getPointerPosition"></a>
|
|
65
|
+
|
|
66
|
+
## getPointerPosition(event, svgElement) ⇒ <code>Array.<number></code>
|
|
67
|
+
Get mouse position relative to an SVG element.
|
|
68
|
+
|
|
69
|
+
**Kind**: global function
|
|
70
|
+
**Returns**: <code>Array.<number></code> - [x, y] coordinates relative to the SVG
|
|
71
|
+
|
|
72
|
+
| Param | Type | Description |
|
|
73
|
+
| --- | --- | --- |
|
|
74
|
+
| event | <code>MouseEvent</code> | The mouse event |
|
|
75
|
+
| svgElement | <code>Element</code> \| [<code>Selection</code>](#Selection) | The SVG element or Selection |
|
|
76
|
+
|
|
77
|
+
<a name="findBars"></a>
|
|
78
|
+
|
|
79
|
+
## findBars(svg, axes_class) ⇒ [<code>Selection</code>](#Selection)
|
|
80
|
+
Find bar elements (`patch` groups with clipping) inside a given axes.
|
|
81
|
+
|
|
82
|
+
**Kind**: global function
|
|
83
|
+
**Returns**: [<code>Selection</code>](#Selection) - Selection of bar elements.
|
|
84
|
+
|
|
85
|
+
| Param | Type | Description |
|
|
86
|
+
| --- | --- | --- |
|
|
87
|
+
| svg | [<code>Selection</code>](#Selection) | Selection of the SVG element. |
|
|
88
|
+
| axes_class | <code>string</code> | ID of the axes group (e.g. "axes_1"). |
|
|
89
|
+
|
|
90
|
+
<a name="findPoints"></a>
|
|
91
|
+
|
|
92
|
+
## findPoints(svg, axes_class, tooltip_groups) ⇒ [<code>Selection</code>](#Selection)
|
|
93
|
+
Find scatter plot points inside a given axes.
|
|
94
|
+
Handles both `<use>` and `<path>` fallback cases,
|
|
95
|
+
and assigns `data-group` attributes based on tooltip groups.
|
|
96
|
+
|
|
97
|
+
**Kind**: global function
|
|
98
|
+
**Returns**: [<code>Selection</code>](#Selection) - Selection of point elements.
|
|
99
|
+
|
|
100
|
+
| Param | Type | Description |
|
|
101
|
+
| --- | --- | --- |
|
|
102
|
+
| svg | [<code>Selection</code>](#Selection) | Selection of the SVG element. |
|
|
103
|
+
| axes_class | <code>string</code> | ID of the axes group (e.g. "axes_1"). |
|
|
104
|
+
| tooltip_groups | <code>Array.<string></code> | Group identifiers for tooltips, parallel to points. |
|
|
105
|
+
|
|
106
|
+
<a name="findLines"></a>
|
|
107
|
+
|
|
108
|
+
## findLines(svg, axes_class) ⇒ [<code>Selection</code>](#Selection)
|
|
109
|
+
Find line elements (`line2d` paths) inside a given axes,
|
|
110
|
+
excluding axis grid lines.
|
|
111
|
+
|
|
112
|
+
**Kind**: global function
|
|
113
|
+
**Returns**: [<code>Selection</code>](#Selection) - Selection of line elements.
|
|
114
|
+
|
|
115
|
+
| Param | Type | Description |
|
|
116
|
+
| --- | --- | --- |
|
|
117
|
+
| svg | [<code>Selection</code>](#Selection) | Selection of the SVG element. |
|
|
118
|
+
| axes_class | <code>string</code> | ID of the axes group. |
|
|
119
|
+
|
|
120
|
+
<a name="findAreas"></a>
|
|
121
|
+
|
|
122
|
+
## findAreas(svg, axes_class) ⇒ [<code>Selection</code>](#Selection)
|
|
123
|
+
Find filled area elements (`FillBetweenPolyCollection` paths) inside a given axes.
|
|
124
|
+
|
|
125
|
+
**Kind**: global function
|
|
126
|
+
**Returns**: [<code>Selection</code>](#Selection) - Selection of area elements.
|
|
127
|
+
|
|
128
|
+
| Param | Type | Description |
|
|
129
|
+
| --- | --- | --- |
|
|
130
|
+
| svg | [<code>Selection</code>](#Selection) | Selection of the SVG element. |
|
|
131
|
+
| axes_class | <code>string</code> | ID of the axes group. |
|
|
132
|
+
|
|
133
|
+
<a name="nearestElementFromMouse"></a>
|
|
134
|
+
|
|
135
|
+
## nearestElementFromMouse(mouseX, mouseY, elements) ⇒ <code>Element</code> \| <code>null</code>
|
|
136
|
+
Compute the nearest element to the mouse cursor from a set of elements.
|
|
137
|
+
Uses bounding box centers for distance.
|
|
138
|
+
This function is used when the `hover_nearest` argument is true.
|
|
139
|
+
|
|
140
|
+
**Kind**: global function
|
|
141
|
+
**Returns**: <code>Element</code> \| <code>null</code> - The nearest DOM element or `null`.
|
|
142
|
+
|
|
143
|
+
| Param | Type | Description |
|
|
144
|
+
| --- | --- | --- |
|
|
145
|
+
| mouseX | <code>number</code> | X coordinate of the mouse relative to SVG. |
|
|
146
|
+
| mouseY | <code>number</code> | Y coordinate of the mouse relative to SVG. |
|
|
147
|
+
| elements | [<code>Selection</code>](#Selection) | Selection of candidate elements. |
|
|
148
|
+
|
|
149
|
+
<a name="setHoverEffect"></a>
|
|
150
|
+
|
|
151
|
+
## setHoverEffect(plot_element, axes_class, tooltip_labels, tooltip_groups, show_tooltip, hover_nearest)
|
|
152
|
+
Attach hover interaction and tooltip display to plot elements.
|
|
153
|
+
Can highlight nearest element (if enabled) or hovered element directly.
|
|
154
|
+
|
|
155
|
+
**Kind**: global function
|
|
156
|
+
|
|
157
|
+
| Param | Type | Description |
|
|
158
|
+
| --- | --- | --- |
|
|
159
|
+
| plot_element | [<code>Selection</code>](#Selection) | Selection of plot elements (points, lines, etc.). |
|
|
160
|
+
| axes_class | <code>string</code> | ID of the axes group. |
|
|
161
|
+
| tooltip_labels | <code>Array.<string></code> | Tooltip labels for each element. |
|
|
162
|
+
| tooltip_groups | <code>Array.<string></code> | Group identifiers for each element. |
|
|
163
|
+
| show_tooltip | <code>"block"</code> \| <code>"none"</code> | Whether to display tooltips. |
|
|
164
|
+
| hover_nearest | <code>boolean</code> | If true, highlight nearest element instead of hovered one. |
|
|
@@ -36,7 +36,7 @@ You can directly apply a CSS string to your plot:
|
|
|
36
36
|
|
|
37
37
|
## Using a Python dictionary
|
|
38
38
|
|
|
39
|
-
For better readability and reusability, you can define CSS as a dictionary
|
|
39
|
+
For better readability and reusability, you can define CSS as a dictionary:
|
|
40
40
|
|
|
41
41
|
```python
|
|
42
42
|
from plotjs import css
|
|
@@ -44,12 +44,12 @@ from plotjs import css
|
|
|
44
44
|
(
|
|
45
45
|
PlotJS()
|
|
46
46
|
.add_tooltip(labels=df["tooltip"])
|
|
47
|
-
.add_css(
|
|
47
|
+
.add_css(from_dict = {
|
|
48
48
|
".tooltip": {
|
|
49
49
|
"background": "red",
|
|
50
50
|
"color": "blue"
|
|
51
51
|
}
|
|
52
|
-
})
|
|
52
|
+
})
|
|
53
53
|
)
|
|
54
54
|
```
|
|
55
55
|
|
|
@@ -59,8 +59,8 @@ Method chaining also works if you want to split styles:
|
|
|
59
59
|
(
|
|
60
60
|
PlotJS()
|
|
61
61
|
.add_tooltip(labels=df["tooltip"])
|
|
62
|
-
.add_css(
|
|
63
|
-
.add_css(
|
|
62
|
+
.add_css(from_dict = {".tooltip": {"color": "blue"}})
|
|
63
|
+
.add_css(from_dict = {".tooltip": {"background": "red"}})
|
|
64
64
|
)
|
|
65
65
|
```
|
|
66
66
|
|
|
@@ -83,7 +83,7 @@ from plotjs import css
|
|
|
83
83
|
(
|
|
84
84
|
PlotJS()
|
|
85
85
|
.add_tooltip(labels=df["tooltip"])
|
|
86
|
-
.add_css(
|
|
86
|
+
.add_css(from_file = "docs/static/style.css")
|
|
87
87
|
)
|
|
88
88
|
```
|
|
89
89
|
|
|
@@ -114,7 +114,7 @@ You can combine with `.hovered` or `.not-hovered`, e.g., `.point.hovered`.
|
|
|
114
114
|
|
|
115
115
|
## Default CSS
|
|
116
116
|
|
|
117
|
-
You can find the default CSS applied by plotjs [here](https://github.com/y-sunflower/plotjs/blob/main/plotjs/static/default.css)
|
|
117
|
+
You can find the default CSS applied by plotjs [here](https://github.com/y-sunflower/plotjs/blob/main/plotjs/static/default.css).
|
|
118
118
|
|
|
119
119
|
## Appendix
|
|
120
120
|
|
|
@@ -23,6 +23,7 @@ ax.scatter(
|
|
|
23
23
|
(
|
|
24
24
|
PlotJS(fig=fig)
|
|
25
25
|
.add_tooltip(labels=df["species"])
|
|
26
|
+
.add_d3js() # import D3.js library
|
|
26
27
|
.add_javascript(
|
|
27
28
|
"""
|
|
28
29
|
d3.selectAll(".point").on("click", () =>
|
|
@@ -39,32 +40,34 @@ Relevant code here is:
|
|
|
39
40
|
|
|
40
41
|
```js
|
|
41
42
|
d3.selectAll(".point").on("click", () =>
|
|
42
|
-
alert("I wish cookies were 0 calories...")
|
|
43
|
+
alert("I wish cookies were 0 calories..."),
|
|
43
44
|
);
|
|
44
45
|
```
|
|
45
46
|
|
|
46
|
-
Here
|
|
47
|
+
Here's what it does:
|
|
47
48
|
|
|
48
49
|
- selects all points (e.g., from the scatter plot)
|
|
49
50
|
- sets that when clicking one of the points
|
|
50
51
|
- it displays a message
|
|
51
52
|
|
|
53
|
+
???+ info
|
|
54
|
+
|
|
55
|
+
We need to call the `add_d3js()` method in order to use the `d3` object here. This method just import D3.js and let us use D3.js functions.
|
|
56
|
+
|
|
52
57
|
## Loading JavaScript from file
|
|
53
58
|
|
|
54
|
-
`plotjs` requires the JavaScript to be in a string, but it's far from being a comfortable way of coding. So there is a convenient
|
|
59
|
+
`plotjs` requires the JavaScript to be in a string, but it's far from being a comfortable way of coding. So there is a convenient argument to load JavaScript from a file:
|
|
55
60
|
|
|
56
61
|
```python
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
PlotJS(fig=fig).add_javascript(
|
|
60
|
-
javascript.from_file("my_script.js"),
|
|
61
|
-
)
|
|
62
|
+
PlotJS(fig=fig).add_javascript(from_file="my_script.js")
|
|
62
63
|
```
|
|
63
64
|
|
|
64
65
|
This allows you to write JavaScript in a separate file so that you can have a code formatter (prettier, etc.), code completion, syntax highlighting, and so on. This is what is recommended to do if you're writing a significant amount of code.
|
|
65
66
|
|
|
66
67
|
## Advanced usage
|
|
67
68
|
|
|
69
|
+
With JavaScript, we can do pretty much anything we want, so be creative! Here, we can force the dots to remain highlighted once we click on them:
|
|
70
|
+
|
|
68
71
|
```python
|
|
69
72
|
import matplotlib.pyplot as plt
|
|
70
73
|
from plotjs import PlotJS, data
|
|
@@ -84,7 +87,7 @@ for specie in df["species"].unique():
|
|
|
84
87
|
)
|
|
85
88
|
ax.legend()
|
|
86
89
|
|
|
87
|
-
custom_js
|
|
90
|
+
custom_js = """
|
|
88
91
|
document.querySelectorAll('.point').forEach(el => {
|
|
89
92
|
el.addEventListener('click', function() {
|
|
90
93
|
const group = this.getAttribute('data-group');
|
|
@@ -108,7 +111,7 @@ el.addEventListener('click', function() {
|
|
|
108
111
|
});
|
|
109
112
|
"""
|
|
110
113
|
|
|
111
|
-
custom_css
|
|
114
|
+
custom_css = """
|
|
112
115
|
.point.dimmed {
|
|
113
116
|
opacity: 0.2;
|
|
114
117
|
}
|
|
@@ -119,10 +122,7 @@ custom_css: str = """
|
|
|
119
122
|
|
|
120
123
|
(
|
|
121
124
|
PlotJS(fig=fig)
|
|
122
|
-
.add_tooltip(
|
|
123
|
-
labels=df["species"],
|
|
124
|
-
groups=df["species"],
|
|
125
|
-
)
|
|
125
|
+
.add_tooltip(labels=df["species"], groups=df["species"])
|
|
126
126
|
.add_css(custom_css)
|
|
127
127
|
.add_javascript(custom_js)
|
|
128
128
|
)
|