react-leaflet-d3 2.0.0 → 3.0.0

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.
package/package.json CHANGED
@@ -1,66 +1,92 @@
1
- {
2
- "name": "react-leaflet-d3",
3
- "version": "2.0.0",
4
- "description": "React wrapper of @asymmetrik/leaflet-d3. Leaflet D3 Provides a collection of D3.js based visualization plugins for Leaflet.",
5
- "main": "dist/react-leaflet-d3.min.js",
6
- "scripts": {
7
- "build": "npm run build:lib && npm run build:dist",
8
- "build:dist": "webpack src/index.js --output dist/react-leaflet-d3.min.js",
9
- "build:lib": "npm run compile:lib",
10
- "clean:lib": "rm -Rf ./lib",
11
- "compile:lib": "babel src --out-dir lib",
12
- "prepublishOnly": "npm run build",
13
- "test": "echo \"Error: no test specified\" && exit 1"
14
- },
15
- "repository": {
16
- "type": "git",
17
- "url": "git+https://github.com/mhasbie/react-leaflet-d3.git"
18
- },
19
- "keywords": [
20
- "react",
21
- "leaflet",
22
- "react-leaflet",
23
- "leaflet-d3",
24
- "d3",
25
- "react-leaflet-d3",
26
- "hexbin",
27
- "ping"
28
- ],
29
- "author": "M. Hasbie",
30
- "license": "MIT",
31
- "peerDependencies": {
32
- "leaflet": "^1.3.4",
33
- "react-leaflet": "^1.9.1 || ^2.1.4",
34
- "d3": "^5",
35
- "d3-hexbin": "^0.2.2"
36
- },
37
- "devDependencies": {
38
- "babel-cli": "^6.26.0",
39
- "babel-core": "^6.26.3",
40
- "babel-eslint": "^10.0.1",
41
- "babel-loader": "^7.1.5",
42
- "babel-plugin-transform-class-properties": "^6.24.1",
43
- "babel-plugin-transform-object-rest-spread": "^6.26.0",
44
- "babel-preset-env": "^1.7.0",
45
- "babel-preset-react": "^6.24.1",
46
- "babel-preset-stage-0": "^6.24.1",
47
- "babel-register": "^6.26.0",
48
- "css-loader": "^2.0.2",
49
- "d3": "^5",
50
- "d3-hexbin": "^0.2.2",
51
- "eslint": "^5.11.0",
52
- "eslint-plugin-react": "^7.11.1",
53
- "leaflet": "^1.3.4",
54
- "prop-types": "^15.5.10",
55
- "react": "^16.5.2",
56
- "react-dom": "^16.5.2",
57
- "react-leaflet": "^2.1.4",
58
- "style-loader": "^0.23.1",
59
- "webpack": "^4.28.2",
60
- "webpack-cli": "^3.1.2",
61
- "webpack-dev-server": "^3.1.14"
62
- },
63
- "dependencies": {
64
- "@asymmetrik/leaflet-d3": "^4.3.2"
65
- }
66
- }
1
+ {
2
+ "name": "react-leaflet-d3",
3
+ "version": "3.0.0",
4
+ "description": "React wrapper of @bluehalo/leaflet-d3. Leaflet D3 Provides a collection of D3.js based visualization plugins for Leaflet.",
5
+ "main": "dist/react-leaflet-d3.min.js",
6
+ "scripts": {
7
+ "build": "npm run build:lib && npm run build:dist",
8
+ "build:dist": "webpack ./src/index.js --mode production --output-path dist --output-filename react-leaflet-d3.min.js",
9
+ "build:lib": "npm run compile:lib",
10
+ "clean:lib": "node -e \"require('fs').rmSync('lib', { recursive: true, force: true })\"",
11
+ "compile:lib": "babel src --out-dir lib",
12
+ "prepublishOnly": "npm run build",
13
+ "test": "jest",
14
+ "test:unit": "jest",
15
+ "test:e2e:build": "webpack --config webpack.e2e.config.js",
16
+ "test:e2e:server": "node tests/e2e/server.js",
17
+ "test:e2e": "playwright test",
18
+ "test:all": "npm run test:unit && npm run test:e2e"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/mhasbie/react-leaflet-d3.git"
23
+ },
24
+ "homepage": "https://mhasbie.github.io/react-leaflet-d3/",
25
+ "keywords": [
26
+ "react",
27
+ "leaflet",
28
+ "react-leaflet",
29
+ "leaflet-d3",
30
+ "d3",
31
+ "react-leaflet-d3",
32
+ "hexbin",
33
+ "ping",
34
+ "react-leaflet-v4",
35
+ "react-leaflet-v5"
36
+ ],
37
+ "author": "M. Hasbie",
38
+ "license": "MIT",
39
+ "peerDependencies": {
40
+ "leaflet": "^1.9.4",
41
+ "react": "^18.0.0 || ^19.0.0",
42
+ "react-dom": "^18.0.0 || ^19.0.0",
43
+ "react-leaflet": "^4.0.0 || ^5.0.0",
44
+ "d3": "^7",
45
+ "d3-hexbin": "^0.2.2"
46
+ },
47
+ "devDependencies": {
48
+ "@babel/cli": "^7.28.3",
49
+ "@babel/core": "^7.28.5",
50
+ "@babel/preset-env": "^7.28.5",
51
+ "@babel/preset-react": "^7.28.5",
52
+ "@playwright/test": "^1.65.1",
53
+ "@testing-library/dom": "^10.4.2",
54
+ "@testing-library/react": "^16.3.0",
55
+ "babel-jest": "^29.7.0",
56
+ "babel-loader": "^10.0.0",
57
+ "css-loader": "^7.1.2",
58
+ "d3": "^7",
59
+ "d3-hexbin": "^0.2.2",
60
+ "identity-obj-proxy": "^3.0.0",
61
+ "jest": "^29.7.0",
62
+ "jest-environment-jsdom": "^29.7.0",
63
+ "leaflet": "^1.9.4",
64
+ "react": "^19.2.3",
65
+ "react-dom": "^19.2.3",
66
+ "react-leaflet": "^5.0.0",
67
+ "style-loader": "^4.0.0",
68
+ "webpack": "^5.102.1",
69
+ "webpack-cli": "^6.0.1"
70
+ },
71
+ "dependencies": {
72
+ "@react-leaflet/core": "^2.1.0 || ^3.0.0",
73
+ "@bluehalo/leaflet-d3": "^6.1.3"
74
+ },
75
+ "jest": {
76
+ "collectCoverage": true,
77
+ "testEnvironment": "jsdom",
78
+ "moduleNameMapper": {
79
+ "^d3$": "<rootDir>/node_modules/d3/dist/d3.min.js",
80
+ "\\.(css|less|scss|sass)$": "identity-obj-proxy"
81
+ },
82
+ "transform": {
83
+ "^.+\\.[jt]sx?$": "babel-jest"
84
+ },
85
+ "testMatch": [
86
+ "**/__tests__/**/?(*.)+(spec|test).[jt]s?(x)"
87
+ ],
88
+ "transformIgnorePatterns": [
89
+ "[/\\\\]node_modules[/\\\\](?!react-leaflet|@react-leaflet|leaflet)[^/\\\\]+[/\\\\]"
90
+ ]
91
+ }
92
+ }
@@ -0,0 +1,17 @@
1
+ const { defineConfig } = require('@playwright/test');
2
+
3
+ module.exports = defineConfig({
4
+ testDir: './tests/e2e',
5
+ testMatch: '**/*.spec.js',
6
+ use: {
7
+ baseURL: 'http://127.0.0.1:4173',
8
+ browserName: 'chromium',
9
+ headless: true
10
+ },
11
+ webServer: {
12
+ command: 'npm run test:e2e:build && npm run test:e2e:server',
13
+ url: 'http://127.0.0.1:4173',
14
+ reuseExistingServer: !process.env.CI,
15
+ timeout: 120000
16
+ }
17
+ });
@@ -0,0 +1,11 @@
1
+ html,
2
+ body,
3
+ #root {
4
+ height: 100%;
5
+ margin: 0;
6
+ }
7
+
8
+ .fixture-map {
9
+ height: 500px;
10
+ width: 700px;
11
+ }
@@ -0,0 +1,102 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { createRoot } from 'react-dom/client';
3
+ import { LayersControl, MapContainer, useMap } from 'react-leaflet';
4
+ import { HexbinLayer, PingLayer } from '../../src';
5
+ import 'leaflet/dist/leaflet.css';
6
+ import './fixture.css';
7
+
8
+ const data = {
9
+ type: 'FeatureCollection',
10
+ features: [
11
+ { type: 'Feature', geometry: { type: 'Point', coordinates: [101, 3] } },
12
+ { type: 'Feature', geometry: { type: 'Point', coordinates: [101.1, 3.1] } },
13
+ { type: 'Feature', geometry: { type: 'Point', coordinates: [100.9, 2.9] } }
14
+ ]
15
+ };
16
+
17
+ function MapProbe({ hexbinRef, secondHexbinRef, pingRef }) {
18
+ const map = useMap();
19
+
20
+ useEffect(() => {
21
+ window.fixture = {
22
+ map,
23
+ hexbinLayer: hexbinRef.current.leafletElement,
24
+ secondHexbinLayer: secondHexbinRef.current.leafletElement,
25
+ pingLayer: pingRef.current.leafletElement
26
+ };
27
+ }, [map, hexbinRef, secondHexbinRef, pingRef]);
28
+
29
+ return null;
30
+ }
31
+
32
+ function Fixture() {
33
+ const [layersMounted, setLayersMounted] = useState(true);
34
+ const hexbinRef = useRef(null);
35
+ const secondHexbinRef = useRef(null);
36
+ const pingRef = useRef(null);
37
+ const layerOptions = {
38
+ radius: 12,
39
+ opacity: 0.5,
40
+ duration: 200,
41
+ colorScaleExtent: [1, undefined],
42
+ radiusScaleExtent: [1, undefined],
43
+ colorRange: ['#f7fbff', '#08306b'],
44
+ radiusRange: [5, 12]
45
+ };
46
+ const pingOptions = {
47
+ duration: 5000,
48
+ fps: 32,
49
+ opacityRange: [1, 0],
50
+ radiusRange: [3, 50]
51
+ };
52
+
53
+ return (
54
+ <>
55
+ <button onClick={() => pingRef.current.ping([101, 3], 'e2e-ping')}>
56
+ Add ping
57
+ </button>
58
+ <button onClick={() => setLayersMounted(false)}>
59
+ Remove layers
60
+ </button>
61
+ <MapContainer
62
+ center={[3, 101]}
63
+ zoom={8}
64
+ minZoom={1}
65
+ maxZoom={12}
66
+ className="fixture-map"
67
+ >
68
+ {layersMounted && (
69
+ <>
70
+ <LayersControl position="topright">
71
+ <LayersControl.Overlay checked name="Hexbin 1">
72
+ <HexbinLayer {...layerOptions} data={data} ref={hexbinRef} />
73
+ </LayersControl.Overlay>
74
+ <LayersControl.Overlay checked={false} name="Hexbin 2">
75
+ <HexbinLayer
76
+ {...layerOptions}
77
+ data={{
78
+ type: 'FeatureCollection',
79
+ features: [
80
+ { type: 'Feature', geometry: { type: 'Point', coordinates: [102, 3] } }
81
+ ]
82
+ }}
83
+ ref={secondHexbinRef}
84
+ />
85
+ </LayersControl.Overlay>
86
+ </LayersControl>
87
+ <PingLayer {...pingOptions} ref={pingRef} />
88
+ </>
89
+ )}
90
+ {layersMounted && (
91
+ <MapProbe
92
+ hexbinRef={hexbinRef}
93
+ secondHexbinRef={secondHexbinRef}
94
+ pingRef={pingRef}
95
+ />
96
+ )}
97
+ </MapContainer>
98
+ </>
99
+ );
100
+ }
101
+
102
+ createRoot(document.getElementById('root')).render(<Fixture />);
@@ -0,0 +1,12 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>react-leaflet-d3 browser test fixture</title>
7
+ </head>
8
+ <body>
9
+ <div id="root"></div>
10
+ <script src="/fixture.js"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,53 @@
1
+ const { test, expect } = require('@playwright/test');
2
+
3
+ test.beforeEach(async ({ page }) => {
4
+ await page.goto('/');
5
+ await expect(page.locator('.leaflet-container')).toBeVisible();
6
+ await expect.poll(() => page.evaluate(() => Boolean(window.fixture))).toBe(true);
7
+ });
8
+
9
+ test('mounts both layers and renders hexbin cells', async ({ page }) => {
10
+ const layersAttached = await page.evaluate(() => {
11
+ const { map, hexbinLayer, secondHexbinLayer, pingLayer } = window.fixture;
12
+ return map.hasLayer(hexbinLayer) &&
13
+ !map.hasLayer(secondHexbinLayer) &&
14
+ map.hasLayer(pingLayer);
15
+ });
16
+
17
+ expect(layersAttached).toBe(true);
18
+ await expect(page.locator('.hexbin-hexagon').first()).toBeVisible();
19
+ });
20
+
21
+ test('forwards a ping with its custom CSS class', async ({ page }) => {
22
+ await page.getByRole('button', { name: 'Add ping' }).click();
23
+
24
+ await expect(page.locator('circle.ping.e2e-ping')).toHaveCount(1);
25
+ });
26
+
27
+ test('removes both Leaflet layers when unmounted', async ({ page }) => {
28
+ await page.getByRole('button', { name: 'Add ping' }).click();
29
+ await expect(page.locator('circle.ping.e2e-ping')).toHaveCount(1);
30
+ await page.getByRole('button', { name: 'Remove layers' }).click();
31
+
32
+ await expect.poll(() => page.evaluate(() => {
33
+ const { map, hexbinLayer, pingLayer } = window.fixture;
34
+ return !map.hasLayer(hexbinLayer) && !map.hasLayer(pingLayer);
35
+ })).toBe(true);
36
+ });
37
+
38
+ test('toggles independent hexbin overlays without leaving stale layers', async ({ page }) => {
39
+ await page.locator('.leaflet-control-layers').hover();
40
+ const selectors = page.locator('.leaflet-control-layers-selector');
41
+ await selectors.nth(0).uncheck();
42
+
43
+ await expect.poll(() => page.evaluate(() => {
44
+ const { map, hexbinLayer } = window.fixture;
45
+ return !map.hasLayer(hexbinLayer);
46
+ })).toBe(true);
47
+
48
+ await selectors.nth(0).check();
49
+ await expect.poll(() => page.evaluate(() => {
50
+ const { map, hexbinLayer } = window.fixture;
51
+ return map.hasLayer(hexbinLayer);
52
+ })).toBe(true);
53
+ });
@@ -0,0 +1,45 @@
1
+ const fs = require('fs');
2
+ const http = require('http');
3
+ const path = require('path');
4
+
5
+ const files = {
6
+ '/': {
7
+ path: path.join(__dirname, 'index.html'),
8
+ contentType: 'text/html; charset=utf-8'
9
+ },
10
+ '/fixture.js': {
11
+ path: path.join(__dirname, 'dist', 'fixture.js'),
12
+ contentType: 'text/javascript; charset=utf-8'
13
+ }
14
+ };
15
+
16
+ const server = http.createServer((request, response) => {
17
+ if (request.method !== 'GET') {
18
+ response.writeHead(405);
19
+ response.end('Method not allowed');
20
+ return;
21
+ }
22
+
23
+ const file = files[request.url];
24
+ if (!file) {
25
+ response.writeHead(404);
26
+ response.end('Not found');
27
+ return;
28
+ }
29
+
30
+ fs.readFile(file.path, (error, content) => {
31
+ if (error) {
32
+ console.error(`Unable to read E2E fixture file: ${file.path}`, error);
33
+ response.writeHead(500);
34
+ response.end('Unable to read E2E fixture');
35
+ return;
36
+ }
37
+
38
+ response.writeHead(200, { 'Content-Type': file.contentType });
39
+ response.end(content);
40
+ });
41
+ });
42
+
43
+ server.listen(4173, '127.0.0.1', () => {
44
+ console.log('E2E fixture server listening on http://127.0.0.1:4173');
45
+ });
@@ -0,0 +1,27 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ mode: 'production',
5
+ entry: path.resolve(__dirname, 'tests/e2e/fixture.jsx'),
6
+ output: {
7
+ path: path.resolve(__dirname, 'tests/e2e/dist'),
8
+ filename: 'fixture.js',
9
+ clean: true
10
+ },
11
+ module: {
12
+ rules: [
13
+ {
14
+ test: /\.(js|jsx)$/,
15
+ exclude: /node_modules/,
16
+ use: 'babel-loader'
17
+ },
18
+ {
19
+ test: /\.css$/,
20
+ use: ['style-loader', 'css-loader']
21
+ }
22
+ ]
23
+ },
24
+ resolve: {
25
+ extensions: ['.js', '.jsx', '.mjs']
26
+ }
27
+ };
@@ -1,27 +0,0 @@
1
- import { MapLayer } from 'react-leaflet';
2
- import L from 'leaflet';
3
- import '@asymmetrik/leaflet-d3';
4
- import './hexbin.css';
5
-
6
- export default class HexbinLayer extends MapLayer {
7
- createLeafletElement(props) {
8
- const { tooltip } = props;
9
- return L.hexbinLayer(props).hoverHandler(L.HexbinHoverHandler.tooltip(tooltip));
10
- }
11
-
12
- componentDidMount() {
13
- const { layerContainer } = this.props.leaflet || this.context;
14
- const { data } = this.props;
15
- const points = data.features.filter(feat => feat.hasOwnProperty('geometry') && feat.geometry && typeof feat.geometry === 'object' && feat.geometry.hasOwnProperty('type') && feat.geometry.type === 'Point');
16
- const coordinates = points.map(feat => feat.geometry.coordinates);
17
- this.leafletElement.addTo(layerContainer);
18
- if (coordinates.length) this.leafletElement.data(coordinates);
19
- }
20
-
21
- componentWillUnmount() {
22
- const { layerContainer, map } = this.props.leaflet || this.context;
23
- this.leafletElement.data(null);
24
- map.removeLayer(this.leafletElement);
25
- layerContainer.removeLayer(this.leafletElement);
26
- }
27
- }
package/lib/PingLayer.js DELETED
@@ -1,18 +0,0 @@
1
- import { MapLayer } from 'react-leaflet';
2
- import L from 'leaflet';
3
- import '@asymmetrik/leaflet-d3';
4
- import './ping.css';
5
-
6
- export default class PingLayer extends MapLayer {
7
- createLeafletElement(props) {
8
- return L.pingLayer(props);
9
- }
10
-
11
- componentDidMount() {
12
- super.componentDidMount();
13
- }
14
-
15
- ping(coordinates, customClass) {
16
- this.leafletElement.ping(coordinates, customClass);
17
- }
18
- }
package/lib/index.js DELETED
@@ -1,4 +0,0 @@
1
- import PingLayer from './PingLayer';
2
- import HexbinLayer from './HexbinLayer';
3
-
4
- export { PingLayer, HexbinLayer };