Skip to content

Commit 7751626

Browse files
authored
Merge branch 'master' into issues/454-fix-redundant-labels
2 parents 8a1e02f + 5fd2908 commit 7751626

50 files changed

Lines changed: 4084 additions & 43866 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ module.exports = {
1111
browser: true,
1212
es6: true,
1313
},
14+
globals: {
15+
BUNDLE_LEAFLET: "readonly",
16+
},
1417
};

.github/workflows/ci.yml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ jobs:
1818
with:
1919
ref: ${{ github.event.pull_request.head.sha }}
2020

21+
- name: Set up Node.js
22+
uses: actions/setup-node@v6
23+
with:
24+
node-version-file: ".nvmrc"
25+
2126
- name: Get yarn cache directory path
2227
id: yarn-cache-dir-path
2328
run: echo "::set-output name=dir::$(yarn cache dir)"
@@ -44,12 +49,21 @@ jobs:
4449
run: ./run-qa-checks
4550

4651
build:
47-
name: Tests and Coverage
52+
name: Tests and Coverage (${{ matrix.build-type }})
4853
runs-on: ubuntu-latest
54+
strategy:
55+
fail-fast: false
56+
matrix:
57+
build-type: [dev, prod, echarts-only]
4958

5059
steps:
5160
- uses: actions/checkout@v6
5261

62+
- name: Set up Node.js
63+
uses: actions/setup-node@v6
64+
with:
65+
node-version-file: ".nvmrc"
66+
5367
- name: Get yarn cache directory path
5468
id: yarn-cache-dir-path
5569
run: echo "::set-output name=dir::$(yarn cache dir)"
@@ -66,9 +80,22 @@ jobs:
6680
run: |
6781
yarn install
6882
69-
- name: Running Server
83+
- name: Build (Prod Full)
84+
if: matrix.build-type == 'prod'
85+
run: yarn build:full
86+
87+
- name: Build (Echarts Only)
88+
if: matrix.build-type == 'echarts-only'
89+
run: yarn build:echarts-only
90+
91+
- name: Running Server (Dev)
92+
if: matrix.build-type == 'dev'
7093
run: yarn start &
7194

95+
- name: Running Server (Dist)
96+
if: matrix.build-type == 'prod' || matrix.build-type == 'echarts-only'
97+
run: npx --yes http-server dist -p 8080 &
98+
7299
- name: Wait for server to be ready
73100
run: npx wait-on http://localhost:8080
74101

@@ -86,13 +113,15 @@ jobs:
86113
which chromedriver
87114
88115
- name: Unit tests
116+
if: matrix.build-type == 'dev'
89117
run: yarn coverage --testPathIgnorePatterns=test/netjsongraph.browser.test.js
90118

91119
- name: Browser tests
92120
# Test timeout set to 30 seconds in CI since it runs slower
93121
run: yarn test --runInBand --testTimeout=30000 test/netjsongraph.browser.test.js
94122

95123
- name: Coveralls
124+
if: matrix.build-type == 'dev'
96125
uses: coverallsapp/github-action@master
97126
with:
98127
github-token: ${{ secrets.GITHUB_TOKEN }}

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18
1+
lts/krypton

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ Visualize a NetJSON NetworkGraph with pan/zoom, labels and tooltips.
2525

2626
Plot nodes by geographic coordinates on a Leaflet basemap; pan/zoom with markers.
2727

28+
### Geographic map with nodes moving in real-time
29+
30+
[![Geographic map with nodes moving in real-time](docs/gifs/movingnode.gif)](https://openwisp.github.io/netjsongraph.js/examples/netjsonmap-moving-node.html)
31+
32+
This example demonstrates how to update a node’s coordinates to simulate a moving vehicle.
33+
2834
### Indoor map
2935

3036
[![Indoor map](docs/gifs/netjsonmap-indoormap.gif)](https://openwisp.github.io/netjsongraph.js/examples/netjsonmap-indoormap.html)
@@ -141,6 +147,61 @@ yarn install
141147
yarn start
142148
```
143149

150+
## Building the library
151+
152+
The netjsongraph.js library provides **two build variants** to optimize bundle size for different use cases.
153+
154+
By default, `yarn build` executes the full bundle.
155+
156+
### 1. Full Bundle (Recommended for standalone usage)
157+
158+
Build the complete library with all dependencies included:
159+
160+
```bash
161+
yarn build:full
162+
```
163+
164+
Analyze the build with [Webpack Bundle Analyzer](https://github.com/webpack/webpack-bundle-analyzer):
165+
166+
```bash
167+
yarn build:full:stats
168+
```
169+
170+
**Output**:
171+
172+
- `dist/netjsongraph.min.js` - Complete library with ECharts and Leaflet
173+
- Compressed versions (`.gz` and `.br`) for optimized delivery
174+
- Deletes/overwrites previous builds
175+
176+
**Use when**: You want a standalone library with all dependencies bundled.
177+
178+
### 2. ECharts-Only Bundle (Optimized for projects with existing Leaflet)
179+
180+
Build the library without Leaflet, expecting it to be provided externally:
181+
182+
```bash
183+
yarn build:echarts-only
184+
```
185+
186+
Analyze the build with [Webpack Bundle Analyzer](https://github.com/webpack/webpack-bundle-analyzer):
187+
188+
```bash
189+
yarn build:echarts-only:stats
190+
```
191+
192+
**Output**:
193+
194+
- `dist/netjsongraph.echarts.min.js` - Library with ECharts only
195+
- Compressed versions (`.gz` and `.br`)
196+
- Deletes/overwrites previous builds
197+
198+
**Use when**: Your project already includes Leaflet (e.g., via django-leaflet in OpenWISP projects). This reduces bundle size by ~144 KiB.
199+
200+
**Requirements**: Leaflet must be loaded before NetJSONGraph (available as global `L` object).
201+
202+
**Note**: The echarts-only build dynamically loads Leaflet from CDN for map examples.
203+
For production use, ensure Leaflet is available locally or from a trusted CDN.
204+
144205
### Run Tests
145206

146207
The test suite includes browser tests, so **ensure that ChromeDriver is installed** before running them.
@@ -924,6 +985,22 @@ yarn start
924985
</html>
925986
```
926987

988+
### Geographic map nodes moving in realtime
989+
990+
You can move a node programmatically on the map at runtime using the `moveNodeInRealTime` helper in utils.
991+
992+
This is useful to animate devices, show mobile nodes, or reflect position updates coming from a realtime source (sockets, polling, etc.).
993+
994+
You can see this feature in action in the following example: [Geographic map nodes moving in realtime](https://openwisp.github.io/netjsongraph.js/examples/netjsonmap-moving-node.html).
995+
996+
```JS
997+
// .util.moveNodeInRealTime(nodeId, location)
998+
moveNodeInRealTime(id, location)
999+
```
1000+
1001+
- `id` - the node id (string) to move.
1002+
- `location` - `{lat: number, lng: number}`
1003+
9271004
### Upgrading from 0.1.x versions to 0.2.x
9281005

9291006
We advise all users of netjsongraph.js who are using the 0.1.x version to

docs/gifs/movingnode.gif

1.61 MB
Loading

examples/load_data_geo_extent/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<title>Load data using geo extent</title>
Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,58 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
3-
<head>
3+
<head>
44
<title>Live update example</title>
5-
<meta charset="utf-8">
5+
<meta charset="utf-8" />
66
<!-- theme can be easily customized via css -->
7-
<link href="/netjsongraph.css" rel="stylesheet">
8-
<link href="/netjsongraph-theme.css" rel="stylesheet">
9-
</head>
10-
<body>
11-
<script src="https://cdn.socket.io/4.5.0/socket.io.min.js" integrity="sha384-7EyYLQZgWBi67fBtVxw60/OWl1kjsfrPFcaU0pp0nAh+i8FD068QogUvg85Ewy1k" crossorigin="anonymous"></script>
7+
<link href="/netjsongraph.css" rel="stylesheet" />
8+
<link href="/netjsongraph-theme.css" rel="stylesheet" />
9+
</head>
10+
<body>
11+
<script
12+
src="https://cdn.socket.io/4.5.0/socket.io.min.js"
13+
integrity="sha384-7EyYLQZgWBi67fBtVxw60/OWl1kjsfrPFcaU0pp0nAh+i8FD068QogUvg85Ewy1k"
14+
crossorigin="anonymous"
15+
></script>
1216
<script type="text/javascript" src="/netjsongraph.min.js"></script>
1317
<script type="text/javascript">
14-
/*
18+
/*
1519
The demo is used to show how to use the `JSONDataUpdate` function to update data.
1620
In this example we use socket.io to listen for server messages.
1721
Adopted the default parameters of function --
1822
overrride old data and deal with the new data with the processing function set in config.
1923
See other examples:
2024
*/
21-
// `graph` render by default.
22-
const graph = new NetJSONGraph("/netjsonmap.json",{
23-
echartsOption: {
24-
legend: {
25-
show: false,
26-
},
27-
title:{
28-
text:'Live update example',
29-
textStyle:{
30-
color:'#fff',
31-
fontSize:24,
32-
},
33-
left:'center',
34-
top:20,
35-
}
25+
// `graph` render by default.
26+
const graph = new NetJSONGraph("/netjsonmap.json", {
27+
echartsOption: {
28+
legend: {
29+
show: false,
30+
},
31+
title: {
32+
text: "Live update example",
33+
textStyle: {
34+
color: "#fff",
35+
fontSize: 24,
3636
},
37-
});
37+
left: "center",
38+
top: 20,
39+
},
40+
},
41+
});
3842

39-
graph.render();
43+
graph.render();
4044

41-
const socket = io("http://localhost:3000/",{ transports : ['websocket'] });
45+
const socket = io("http://localhost:3000/", {transports: ["websocket"]});
4246

43-
socket.on("connect", function() {
44-
console.log("client connected");
45-
});
46-
socket.on("disconnect", function() {
47-
console.log("client disconnected");
48-
});
47+
socket.on("connect", function () {
48+
console.log("client connected");
49+
});
50+
socket.on("disconnect", function () {
51+
console.log("client disconnected");
52+
});
4953

50-
// Update view when the data changes. override old data by default.
51-
socket.on("netjsonChange", graph.utils.JSONDataUpdate.bind(graph));
54+
// Update view when the data changes. override old data by default.
55+
socket.on("netjsonChange", graph.utils.JSONDataUpdate.bind(graph));
5256
</script>
53-
</html>
57+
</body>
58+
</html>

0 commit comments

Comments
 (0)