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.
@@ -0,0 +1,66 @@
1
+ name: PR Tests
2
+
3
+ on:
4
+ pull_request:
5
+ branches: [master]
6
+ types: [opened, synchronize, reopened]
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test-unit:
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ include:
17
+ - name: React Leaflet 4
18
+ react: "18.3.1"
19
+ react_dom: "18.3.1"
20
+ react_leaflet: "4.2.1"
21
+ react_leaflet_core: "2.1.0"
22
+ - name: React Leaflet 5
23
+ react: "19.2.3"
24
+ react_dom: "19.2.3"
25
+ react_leaflet: "5.0.0"
26
+ react_leaflet_core: "3.0.0"
27
+ runs-on: ubuntu-latest
28
+ steps:
29
+ - name: Check out repository
30
+ uses: actions/checkout@v4
31
+
32
+ - name: Set up Node.js
33
+ uses: actions/setup-node@v4
34
+ with:
35
+ node-version: 22
36
+ cache: npm
37
+
38
+ - name: Install dependencies
39
+ run: npm ci
40
+
41
+ - name: Install ${{ matrix.name }} compatibility versions
42
+ run: npm install --no-save --package-lock=false --legacy-peer-deps react@${{ matrix.react }} react-dom@${{ matrix.react_dom }} react-leaflet@${{ matrix.react_leaflet }} @react-leaflet/core@${{ matrix.react_leaflet_core }}
43
+
44
+ - name: Run unit tests
45
+ run: npm run test:unit
46
+
47
+ test-e2e:
48
+ runs-on: ubuntu-latest
49
+ steps:
50
+ - name: Check out repository
51
+ uses: actions/checkout@v4
52
+
53
+ - name: Set up Node.js
54
+ uses: actions/setup-node@v4
55
+ with:
56
+ node-version: 22
57
+ cache: npm
58
+
59
+ - name: Install dependencies
60
+ run: npm ci
61
+
62
+ - name: Install Playwright Chromium
63
+ run: npx playwright install --with-deps chromium
64
+
65
+ - name: Run Playwright tests
66
+ run: npm run test:e2e
@@ -0,0 +1,63 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+
7
+ permissions:
8
+ contents: write
9
+ id-token: write
10
+
11
+ jobs:
12
+ release:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - name: Check out pushed commit
16
+ uses: actions/checkout@v4
17
+ with:
18
+ fetch-depth: 0
19
+ persist-credentials: false
20
+
21
+ - name: Set up Node.js
22
+ uses: actions/setup-node@v4
23
+ with:
24
+ node-version: 22
25
+
26
+ - name: Set up npm trusted publishing
27
+ run: npm install --global npm@11.15.0
28
+
29
+ - name: Install dependencies
30
+ run: npm ci
31
+
32
+ - name: Run tests
33
+ run: npm test
34
+
35
+ - name: Build package
36
+ run: npm run build
37
+
38
+ - name: Read version and check release tag
39
+ id: release
40
+ shell: bash
41
+ run: |
42
+ VERSION="$(node -p "require('./package.json').version")"
43
+ TAG="v${VERSION}"
44
+
45
+ if [ -z "$VERSION" ]; then
46
+ echo "::error::package.json does not specify a version."
47
+ exit 1
48
+ fi
49
+
50
+ if git rev-parse --quiet --verify "refs/tags/${TAG}" >/dev/null; then
51
+ echo "::error::Release tag ${TAG} already exists. Bump package.json before merging another release PR."
52
+ exit 1
53
+ fi
54
+
55
+ echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
56
+
57
+ - name: Stage package on npm
58
+ run: npm stage publish --ignore-scripts
59
+
60
+ - name: Create GitHub Release
61
+ run: gh release create "${{ steps.release.outputs.tag }}" --target "$(git rev-parse HEAD)" --title "${{ steps.release.outputs.tag }}" --generate-notes
62
+ env:
63
+ GH_TOKEN: ${{ github.token }}
package/CHANGELOG.md CHANGED
@@ -1,10 +1,20 @@
1
- react-leaflet-d3 Changelog
2
- =========================
3
-
4
-
5
- ## 2.0.0 (2019-01-12)
6
-
7
- * Make compatible with `react-leaflet@2.x`
8
- * Update dependencies
9
- * Update README
10
- * Add example
1
+ react-leaflet-d3 Changelog
2
+ =========================
3
+
4
+ ## 3.0.0
5
+
6
+ * Replace deprecated `@asymmetrik/leaflet-d3` with `@bluehalo/leaflet-d3` 6.x; D3 v7 is required and D3 v5 is no longer supported
7
+ * Migrate PingLayer and HexbinLayer to the React Leaflet v4/v5 hook API
8
+ * Fix layer mounting, LayersControl toggling, and unmount cleanup
9
+ * Fix HexbinLayer data updates and safely handle empty or invalid GeoJSON data
10
+ * Support React 18/19 and Leaflet 1.9+
11
+ * Remove support for React Leaflet 1.x and 2.x
12
+ * Modernize build and test dependencies
13
+ * Remove unused dependencies and address dependency audit findings
14
+
15
+ ## 2.0.0 (2019-01-12)
16
+
17
+ * Make compatible with `react-leaflet@2.x`
18
+ * Update dependencies
19
+ * Update README
20
+ * Add example
package/LICENSE CHANGED
@@ -1,19 +1,19 @@
1
- The MIT License (MIT)
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,184 +1,107 @@
1
- # react-leaflet-d3
2
-
3
- [![travis build](https://img.shields.io/travis/mhasbie/react-leaflet-d3.svg?style=plastic)](https://travis-ci.org/mhasbie/react-leaflet-d3)
4
- [![version](https://img.shields.io/npm/v/react-leaflet-d3.svg?style=plastic)](http://npm.im/react-leaflet-d3)
5
- [![MIT License](https://img.shields.io/npm/l/react-leaflet-d3.svg?style=plastic)](http://opensource.org/licenses/MIT)
6
- [![dependencies](https://img.shields.io/david/mhasbie/react-leaflet-d3.svg?style=plastic)](https://david-dm.org/mhasbie/react-leaflet-d3)
7
- [![peer dependencies](https://img.shields.io/david/peer/mhasbie/react-leaflet-d3.svg?style=plastic)](https://david-dm.org/mhasbie/react-leaflet-d3?type=peer)
8
- [![react-leaflet compatibility](https://img.shields.io/npm/dependency-version/react-leaflet-d3/peer/react-leaflet.svg?style=plastic)](https://github.com/mhasbie/react-leaflet-d3)
9
- [![downloads](https://img.shields.io/npm/dt/react-leaflet-d3.svg?style=plastic)](http://npm-stat.com/charts.html?package=react-leaflet-d3&from=2018-01-01)
10
- [![issues](https://img.shields.io/github/issues/mhasbie/react-leaflet-d3.svg?style=plastic)](https://github.com/mhasbie/react-leaflet-d3/issues)
11
-
12
-
13
- React wrapper of [@asymmetrik/leaflet-d3](https://github.com/Asymmetrik/leaflet-d3)
14
- for [react-leaflet](https://github.com/PaulLeCam/react-leaflet).
15
-
16
- Leaflet D3 Provides a collection of D3.js based visualization plugins for Leaflet.
17
-
18
-
19
- #### Demo
20
-
21
- | Visualization | Demo react-leaflet v1 | Demo react-leaflet v2 |
22
- | --- | --- | --- |
23
- | Hexbins | [`CodePen`](https://codepen.io/m_hasbie/pen/yGQgoV) | [`CodePen`](https://codepen.io/m_hasbie/pen/wRQgpB) |
24
- | Pings | [`CodePen`](https://codepen.io/m_hasbie/pen/oJQBpP) | [`CodePen`](https://codepen.io/m_hasbie/pen/zyMNJR) |
25
-
26
- *Tested with Leaflet 1.3.4 and React-Leaflet 1.9.1, React-Leaflet 2.1.4*
27
-
28
-
29
- ## Installation
30
-
31
- ### Install via NPM
32
-
33
- ```bash
34
- npm install --save react-leaflet-d3
35
- ```
36
-
37
- `react-leaflet-d3` requires `d3` and `d3-hexbin` as [`peerDependency`](https://docs.npmjs.com/files/package.json#peerdependencies)
38
-
39
- (React, PropTypes, Leaflet, react-leaflet also should be installed)
40
- ```bash
41
- npm install --save d3 d3-hexbin
42
- ```
43
-
44
- [Customize css](https://github.com/Asymmetrik/leaflet-d3#styling-1)
45
-
46
-
47
- ## Usage example
48
-
49
- ### HexbinLayer (with react-leaflet v1)
50
-
51
- ```javascript
52
- import { Map, TileLayer } from 'react-leaflet';
53
- import { HexbinLayer } from 'react-leaflet-d3';
54
-
55
- const options = {
56
- colorScaleExtent: [ 1, undefined ],
57
- radiusScaleExtent: [ 1, undefined ],
58
- colorRange: [ '#f7fbff', '#ff0000' ],
59
- radiusRange: [ 5, 12 ],
60
- };
61
-
62
- <Map center={[2.935403, 101.448205]} zoom={10}>
63
- <TileLayer
64
- url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
65
- attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
66
- />
67
-
68
- <HexbinLayer data={geoJsonData} {...options} />
69
- </Map>
70
- ```
71
-
72
- ### HexbinLayer (with react-leaflet v2)
73
-
74
- ```javascript
75
- import { Map, TileLayer, withLeaflet } from 'react-leaflet';
76
- import { HexbinLayer } from 'react-leaflet-d3';
77
- const WrappedHexbinLayer = withLeaflet(HexbinLayer);
78
-
79
- const options = {
80
- colorScaleExtent: [ 1, undefined ],
81
- radiusScaleExtent: [ 1, undefined ],
82
- colorRange: [ '#f7fbff', '#ff0000' ],
83
- radiusRange: [ 5, 12 ],
84
- };
85
-
86
- <Map center={[2.935403, 101.448205]} zoom={10}>
87
- <TileLayer
88
- url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
89
- attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
90
- />
91
-
92
- {/* Use <WrappedHexbinLayer> where you would have used <HexbinLayer>. */}
93
- <WrappedHexbinLayer data={geoJsonData} {...options} />
94
- </Map>
95
- ```
96
-
97
- #### Options [Hexbin options](https://github.com/Asymmetrik/leaflet-d3#options)
98
-
99
- Option | Type | Default | Description
100
- --------------- | --------- | ------- | -------------
101
- `data` | `object` | `{}` | Required. A valid [GeoJSON FeatureCollection object](http://geojson.org/geojson-spec.html). Currently only supports `Point` geometry type.
102
- `radius` | `int` | `12` | Sets the radius on the hexbin layer.
103
- `opacity` | `float` | `0.6` | Sets the opacity on the hexbin layer.
104
- `duration` | `int` | `200` | Sets the transition duration for the hexbin layer.
105
- `colorScaleExtent` | `array` | `[ 1, undefined ]` | Sets the extent of the color scale for the hexbin layer.
106
- `radiusScaleExtent` | `array` | `[ 1, undefined ]` | This is the same exact configuration option as `colorScaleExtent`, only applied to the radius extent.
107
- `colorRange` | `array` | `[ '#f7fbff', '#08306b' ]` | Sets the range of the color scale used to fill the hexbins on the layer.
108
- `radiusRange` | `array` | `[ 4, 12 ]` | Sets the range of the radius scale used to size the hexbins on the layer.
109
- `pointerEvents` | `string` | `all` | This value is passed directly to an element-level css style for `pointer-events`. You should only modify this config option if you want to change the mouse event behavior on hexbins. This will modify when the events are propagated based on the visibility state and/or part of the hexbin being hovered.
110
-
111
-
112
- ### PingLayer (with react-leaflet v1)
113
-
114
- ```javascript
115
- import { Map, TileLayer } from 'react-leaflet';
116
- import { PingLayer } from 'react-leaflet-d3';
117
-
118
- ping() {
119
- this.pingLayer.ping([101.448205, 2.935403], 'myCustomCssClass');
120
- }
121
-
122
- <Map center={[2.935403, 101.448205]} zoom={10}>
123
- <TileLayer
124
- url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
125
- attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
126
- />
127
-
128
- <PingLayer ref={(ref) => { this.pingLayer = ref; }} radiusRange={[3, 50]} />
129
- </Map>
130
- ```
131
-
132
-
133
- ### PingLayer (with react-leaflet v2)
134
-
135
- ```javascript
136
- import { Map, TileLayer, withLeaflet } from 'react-leaflet';
137
- import { PingLayer } from 'react-leaflet-d3';
138
- const WrappedPingLayer = withLeaflet(PingLayer);
139
-
140
- ping() {
141
- this.pingLayer.ping([101.448205, 2.935403], 'myCustomCssClass');
142
- }
143
-
144
- <Map center={[2.935403, 101.448205]} zoom={10}>
145
- <TileLayer
146
- url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
147
- attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
148
- />
149
-
150
- {/* Use <WrappedPingLayer> where you would have used <PingLayer>. */}
151
- <WrappedPingLayer ref={(ref) => { this.pingLayer = ref; }} radiusRange={[3, 50]} />
152
- </Map>
153
- ```
154
-
155
- #### Options [Ping options](https://github.com/Asymmetrik/leaflet-d3#options-1)
156
-
157
- Option | Type | Default | Description
158
- --------------- | --------- | ------- | -------------
159
- `duration` | `int` | `800 ` | Sets the transition duration for the ping layer.
160
- `fps` | `int` | `32` | Sets the target framerate for the ping animation.
161
- `opacityRange` | `array` | `[ 1, 0 ]` | Sets the range of the opacity scale used to fade out the pings as they age.
162
- `radiusRange` | `array` | `[ 3, 15 ]` | Sets the range of the radius scale used to size the pings as they age.
163
-
164
-
165
- #### API
166
-
167
- [Ping API](https://github.com/Asymmetrik/leaflet-d3#lpinglayer)
168
-
169
- ##### pingLayer.ping(coordinates, cssClassName) - [doc](https://github.com/Asymmetrik/leaflet-d3#pinglayerpingvalue-)
170
-
171
- Submit a ping to the layer. The default data schema for the ping layer is:
172
-
173
- `[ [ lng1, lat1 ], [ lng2, lat2 ], [ lng3, lat3 ]... [ lngN, latN ] ]`
174
-
175
- Where the ping radius scale factor is fixed at 1.
176
-
177
-
178
-
179
- # Credits
180
- Credits goes to all the [contributors](https://github.com/Asymmetrik/leaflet-d3/graphs/contributors) for the original work.
181
-
182
- # License
183
-
184
- MIT License
1
+ # react-leaflet-d3
2
+
3
+ [![version](https://img.shields.io/npm/v/react-leaflet-d3.svg?style=plastic)](http://npm.im/react-leaflet-d3)
4
+ [![react-leaflet compatibility](https://img.shields.io/npm/dependency-version/react-leaflet-d3/peer/react-leaflet.svg?style=plastic)](https://github.com/mhasbie/react-leaflet-d3)
5
+ [![issues](https://img.shields.io/github/issues/mhasbie/react-leaflet-d3.svg?style=plastic)](https://github.com/mhasbie/react-leaflet-d3/issues)
6
+ [![downloads](https://img.shields.io/npm/dt/react-leaflet-d3.svg?style=plastic)](http://npm-stat.com/charts.html?package=react-leaflet-d3&from=2018-01-01)
7
+ [![MIT License](https://img.shields.io/npm/l/react-leaflet-d3.svg?style=plastic)](http://opensource.org/licenses/MIT)
8
+
9
+ React wrappers for [@bluehalo/leaflet-d3](https://github.com/bluehalo/leaflet-d3), a collection of D3.js visualizations for Leaflet. This release requires D3 v7.
10
+
11
+ Try the [live demo](https://mhasbie.github.io/react-leaflet-d3/).
12
+
13
+ CodePen demos:
14
+
15
+ - [Hexbin](https://codepen.io/m_hasbie/pen/ramoZmo)
16
+ - [Ping](https://codepen.io/m_hasbie/pen/pvPqOPK)
17
+
18
+ Compatible with React 18 or 19 and React Leaflet 4 or 5.
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ npm install react-leaflet-d3 react react-dom react-leaflet leaflet d3 d3-hexbin
24
+ ```
25
+
26
+ Customize the visualization styles using the [Leaflet D3 CSS guidance](https://github.com/bluehalo/leaflet-d3#styling).
27
+
28
+ ## Usage
29
+
30
+ ```javascript
31
+ import { useRef } from 'react';
32
+ import { MapContainer, TileLayer } from 'react-leaflet';
33
+ import { HexbinLayer, PingLayer } from 'react-leaflet-d3';
34
+
35
+ function Example({ geoJsonData }) {
36
+ const pingRef = useRef(null);
37
+
38
+ function addPing() {
39
+ pingRef.current.ping([101.448205, 2.935403], 'myCustomCssClass');
40
+ }
41
+
42
+ return (
43
+ <>
44
+ <button onClick={addPing}>Ping</button>
45
+ <MapContainer
46
+ center={[2.935403, 101.448205]}
47
+ zoom={10}
48
+ style={{ height: '400px' }}
49
+ >
50
+ <TileLayer
51
+ url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
52
+ attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
53
+ />
54
+ <HexbinLayer
55
+ data={geoJsonData}
56
+ colorRange={['#f7fbff', '#ff0000']}
57
+ radiusRange={[5, 12]}
58
+ />
59
+ <PingLayer ref={pingRef} radiusRange={[3, 50]} />
60
+ </MapContainer>
61
+ </>
62
+ );
63
+ }
64
+ ```
65
+
66
+ `geoJsonData` must be a GeoJSON FeatureCollection. HexbinLayer currently uses Point features only.
67
+
68
+ ## HexbinLayer options
69
+
70
+ See the [Leaflet D3 hexbin API](https://github.com/bluehalo/leaflet-d3/blob/master/docs/API.md#hexbins-api).
71
+
72
+ | Option | Type | Default | Description |
73
+ | --- | --- | --- | --- |
74
+ | `data` | `object` | `{}` | Required GeoJSON FeatureCollection; Point features are used. |
75
+ | `radius` | `int` | `12` | Hexbin radius. |
76
+ | `opacity` | `float` | `0.6` | Layer opacity. |
77
+ | `duration` | `int` | `200` | Transition duration. |
78
+ | `colorScaleExtent` | `array` | `[1, undefined]` | Color scale extent. |
79
+ | `radiusScaleExtent` | `array` | `[1, undefined]` | Radius scale extent. |
80
+ | `colorRange` | `array` | `['#f7fbff', '#08306b']` | Hexbin fill color range. |
81
+ | `radiusRange` | `array` | `[4, 12]` | Hexbin size range. |
82
+ | `pointerEvents` | `string` | `all` | CSS `pointer-events` value for hexbins. |
83
+
84
+ ## PingLayer options and API
85
+
86
+ See the [Leaflet D3 ping API](https://github.com/bluehalo/leaflet-d3/blob/master/docs/API.md#pings-api).
87
+
88
+ | Option | Type | Default | Description |
89
+ | --- | --- | --- | --- |
90
+ | `duration` | `int` | `800` | Ping animation duration. |
91
+ | `fps` | `int` | `32` | Target animation frame rate. |
92
+ | `opacityRange` | `array` | `[1, 0]` | Opacity range as pings age. |
93
+ | `radiusRange` | `array` | `[3, 15]` | Radius range as pings age. |
94
+
95
+ Call `pingRef.current.ping(coordinates, cssClassName)` to add pings. Coordinates use `[longitude, latitude]` pairs.
96
+
97
+ ## Tests
98
+
99
+ Run the unit tests with `npm run test:unit` and the browser tests with `npm run test:e2e`. The Playwright tests require Chromium; install it with `npx playwright install chromium`. Run both suites with `npm run test:all`.
100
+
101
+ ## Releases
102
+
103
+ Merging a pull request into `master` runs the release workflow. Before merging a release PR, update the version in both `package.json` and `package-lock.json`. The workflow uses that version to stage the package on npm and create the GitHub Release tag (`v<version>`), and stops if the tag already exists. The GitHub Release is created when staging succeeds; the npm version is not publicly available until it is approved.
104
+
105
+ ## Credits and license
106
+
107
+ Credit goes to the [Leaflet D3 contributors](https://github.com/bluehalo/leaflet-d3/graphs/contributors). This package is MIT licensed.