Skip to content

Commit 63d0f02

Browse files
committed
2 parents eaa3505 + 5e83184 commit 63d0f02

File tree

8 files changed

+150
-177
lines changed

8 files changed

+150
-177
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules/**
2+
lib/**

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"block-scoped-var": 0,
4848
// Temporarily disabled for test/* until babel/babel-eslint#33 is resolved
4949
"padded-blocks": 0,
50-
50+
"no-param-reassign": 0
5151
},
5252
"plugins": [
5353
"react",

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 0.2.4 Release
2+
- List eslint as an explicit devDependency
3+
- upgrade the eslint related packages
4+
- fix linting errors using current config
5+
- Add notes about maintaining absence of lint errors and warnings in Contributing guide
6+
- This should make it easier to ensure code quality as others contribute in the open
7+
- Also, drop unused jest and enzyme deps
8+
19
# 0.2.3 Release
210
- Missed Transpilation
311

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Before submitting a Pull Request please ensure you have completed the following
5656
2. Make sure your copy is up to date: `git pull upstream master`
5757
3. Run `npm run compile`, to compile your changes to the exported `/lib` code.
5858
4. Bump the version in `package.json` as appropriate, see `Versioning` in the section below.
59+
4. Run `npm run lint` to verify code style, all pull requests should have zero lint errors and warnings
5960
4. Commit your changes
6061
5. Push your changes to your fork: `your-username/react-leaflet-heatmap-layer`
6162
6. Open a pull request from your fork to the `upstream` fork (`OpenGov/react-leaflet-heatmap-layer`)

example/index.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { render } from 'react-dom';
3-
import { Map, Marker, Popup, TileLayer } from 'react-leaflet';
3+
import { Map, TileLayer } from 'react-leaflet';
44
import HeatmapLayer from '../src/HeatmapLayer';
55
import { addressPoints } from './realworld.10000.js';
66

@@ -9,7 +9,7 @@ class MapExample extends React.Component {
99
state = {
1010
mapHidden: false,
1111
layerHidden: false,
12-
addressPoints: addressPoints
12+
addressPoints
1313
};
1414

1515
componentDidMount() {
@@ -25,38 +25,46 @@ class MapExample extends React.Component {
2525
<input
2626
type="button"
2727
value="Toggle Map"
28-
onClick={() => this.setState({ mapHidden: !this.state.mapHidden })} />
28+
onClick={() => this.setState({ mapHidden: !this.state.mapHidden })}
29+
/>
2930
</div>
3031
);
3132
}
32-
const gradient = { '0.1': '#89BDE0', '0.2': '#96E3E6', '0.4': '#82CEB6', '0.6': '#FAF3A5', '0.8': '#F5D98B', '1.0': '#DE9A96'};
33+
34+
const gradient = {
35+
0.1: '#89BDE0', 0.2: '#96E3E6', 0.4: '#82CEB6',
36+
0.6: '#FAF3A5', 0.8: '#F5D98B', '1.0': '#DE9A96'
37+
};
3338

3439
return (
3540
<div>
36-
<Map center={[0,0]} zoom={13}>
41+
<Map center={[0, 0]} zoom={13}>
3742
{!this.state.layerHidden &&
3843
<HeatmapLayer
39-
fitBoundsOnLoad
40-
fitBoundsOnUpdate
41-
points={this.state.addressPoints}
42-
longitudeExtractor={m => m[1]}
43-
latitudeExtractor={m => m[0]}
44-
gradient={gradient}
45-
intensityExtractor={m => parseFloat(m[2])} />
44+
fitBoundsOnLoad
45+
fitBoundsOnUpdate
46+
points={this.state.addressPoints}
47+
longitudeExtractor={m => m[1]}
48+
latitudeExtractor={m => m[0]}
49+
gradient={gradient}
50+
intensityExtractor={m => parseFloat(m[2])}
51+
/>
4652
}
4753
<TileLayer
48-
url='http://{s}.tile.osm.org/{z}/{x}/{y}.png'
54+
url="http://{s}.tile.osm.org/{z}/{x}/{y}.png"
4955
attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
5056
/>
5157
</Map>
5258
<input
5359
type="button"
5460
value="Toggle Map"
55-
onClick={() => this.setState({ mapHidden: !this.state.mapHidden })} />
61+
onClick={() => this.setState({ mapHidden: !this.state.mapHidden })}
62+
/>
5663
<input
5764
type="button"
5865
value="Toggle Layer"
59-
onClick={() => this.setState({ layerHidden: !this.state.layerHidden })} />
66+
onClick={() => this.setState({ layerHidden: !this.state.layerHidden })}
67+
/>
6068
</div>
6169
);
6270
}

lib/HeatmapLayer.js

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,22 @@ var _lodash3 = require('lodash.reduce');
1818

1919
var _lodash4 = _interopRequireDefault(_lodash3);
2020

21-
var _lodash5 = require('lodash.foreach');
21+
var _lodash5 = require('lodash.filter');
2222

2323
var _lodash6 = _interopRequireDefault(_lodash5);
2424

25-
var _lodash7 = require('lodash.pluck');
25+
var _lodash7 = require('lodash.min');
2626

2727
var _lodash8 = _interopRequireDefault(_lodash7);
2828

29-
var _lodash9 = require('lodash.filter');
29+
var _lodash9 = require('lodash.max');
3030

3131
var _lodash10 = _interopRequireDefault(_lodash9);
3232

33-
var _lodash11 = require('lodash.min');
33+
var _lodash11 = require('lodash.isnumber');
3434

3535
var _lodash12 = _interopRequireDefault(_lodash11);
3636

37-
var _lodash13 = require('lodash.max');
38-
39-
var _lodash14 = _interopRequireDefault(_lodash13);
40-
41-
var _lodash15 = require('lodash.isnumber');
42-
43-
var _lodash16 = _interopRequireDefault(_lodash15);
44-
4537
var _leaflet = require('leaflet');
4638

4739
var _leaflet2 = _interopRequireDefault(_leaflet);
@@ -60,20 +52,20 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
6052

6153
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
6254

63-
function isValidLatLngArray(arr) {
64-
return (0, _lodash10.default)(arr, isValid).length === arr.length;
55+
function isInvalid(num) {
56+
return !(0, _lodash12.default)(num) && !num;
6557
}
6658

67-
function isInvalidLatLngArray(arr) {
68-
return !isValidLatLngArray(arr);
59+
function isValid(num) {
60+
return !isInvalid(num);
6961
}
7062

71-
function isInvalid(num) {
72-
return !(0, _lodash16.default)(num) && !num;
63+
function isValidLatLngArray(arr) {
64+
return (0, _lodash6.default)(arr, isValid).length === arr.length;
7365
}
7466

75-
function isValid(num) {
76-
return !isInvalid(num);
67+
function isInvalidLatLngArray(arr) {
68+
return !isValidLatLngArray(arr);
7769
}
7870

7971
function safeRemoveLayer(map, el) {
@@ -207,8 +199,8 @@ var HeatmapLayer = function (_MapLayer) {
207199
var points = this.props.points;
208200
var lngs = (0, _lodash2.default)(points, this.props.longitudeExtractor);
209201
var lats = (0, _lodash2.default)(points, this.props.latitudeExtractor);
210-
var ne = { lng: (0, _lodash14.default)(lngs), lat: (0, _lodash14.default)(lats) };
211-
var sw = { lng: (0, _lodash12.default)(lngs), lat: (0, _lodash12.default)(lats) };
202+
var ne = { lng: (0, _lodash10.default)(lngs), lat: (0, _lodash10.default)(lats) };
203+
var sw = { lng: (0, _lodash8.default)(lngs), lat: (0, _lodash8.default)(lats) };
212204

213205
if (shouldIgnoreLocation(ne) || shouldIgnoreLocation(sw)) {
214206
return;
@@ -232,15 +224,15 @@ var HeatmapLayer = function (_MapLayer) {
232224
HeatmapLayer.prototype.attachEvents = function attachEvents() {
233225
var _this2 = this;
234226

235-
var map = this.context.map;
236-
map.on('viewreset', function () {
227+
var leafletMap = this.props.map;
228+
leafletMap.on('viewreset', function () {
237229
return _this2.reset();
238230
});
239-
map.on('moveend', function () {
231+
leafletMap.on('moveend', function () {
240232
return _this2.reset();
241233
});
242-
if (map.options.zoomAnimation && _leaflet2.default.Browser.any3d) {
243-
map.on('zoomanim', this._animateZoom, this);
234+
if (leafletMap.options.zoomAnimation && _leaflet2.default.Browser.any3d) {
235+
leafletMap.on('zoomanim', this._animateZoom, this);
244236
}
245237
};
246238

@@ -249,9 +241,9 @@ var HeatmapLayer = function (_MapLayer) {
249241
var offset = this.context.map._getCenterOffset(e.center)._multiplyBy(-scale).subtract(this.context.map._getMapPanePos());
250242

251243
if (_leaflet2.default.DomUtil.setTransform) {
252-
_leaflet2.default.DomUtil.setTransform(this._el, offset, scale);
244+
_leaflet2.default.DomUtil.setTransform(this.refs.container, offset, scale);
253245
} else {
254-
this._el.style[_leaflet2.default.DomUtil.TRANSFORM] = _leaflet2.default.DomUtil.getTranslateString(offset) + ' scale(' + scale + ')';
246+
this.refs.container.style[_leaflet2.default.DomUtil.TRANSFORM] = _leaflet2.default.DomUtil.getTranslateString(offset) + ' scale(' + scale + ')';
255247
}
256248
};
257249

@@ -262,13 +254,13 @@ var HeatmapLayer = function (_MapLayer) {
262254
var size = this.context.map.getSize();
263255

264256
if (this._heatmap._width !== size.x) {
265-
this._el.width = this._heatmap._width = size.x;
257+
this.refs.container.width = this._heatmap._width = size.x;
266258
}
267259
if (this._heatmap._height !== size.y) {
268-
this._el.height = this._heatmap._height = size.y;
260+
this.refs.container.height = this._heatmap._height = size.y;
269261
}
270262

271-
if (this._heatmap && !this._frame && !this.context.map._animating) {
263+
if (this._heatmap && !this._frame && !this.props.map._animating) {
272264
this._frame = _leaflet2.default.Util.requestAnimFrame(this.redraw, this);
273265
}
274266

@@ -286,8 +278,7 @@ var HeatmapLayer = function (_MapLayer) {
286278
var v = 1 / Math.pow(2, Math.max(0, Math.min(maxZoom - this.context.map.getZoom(), 12)));
287279

288280
var cellSize = r / 2;
289-
var grid = [];
290-
var panePos = this.context.map._getMapPanePos();
281+
var panePos = this.props.map._getMapPanePos();
291282
var offsetX = panePos.x % cellSize;
292283
var offsetY = panePos.y % cellSize;
293284
var getLat = this.props.latitudeExtractor;
@@ -298,15 +289,15 @@ var HeatmapLayer = function (_MapLayer) {
298289
return bounds.contains(p);
299290
};
300291

301-
var filterUndefined = function filterUndefined(r) {
302-
return (0, _lodash10.default)(r, function (c) {
292+
var filterUndefined = function filterUndefined(row) {
293+
return (0, _lodash6.default)(row, function (c) {
303294
return c !== undefined;
304295
});
305296
};
306297

307298
var roundResults = function roundResults(results) {
308299
return (0, _lodash4.default)(results, function (result, row) {
309-
return (0, _lodash2.default)(filterUndefined(row), function (cell, key, row) {
300+
return (0, _lodash2.default)(filterUndefined(row), function (cell) {
310301
return [Math.round(cell[0]), Math.round(cell[1]), Math.min(cell[2], maxIntensity), cell[3]];
311302
}).concat(result);
312303
}, []);
@@ -348,28 +339,27 @@ var HeatmapLayer = function (_MapLayer) {
348339
}, []);
349340
};
350341

351-
var getBounds = function getBounds(leafletMap) {
342+
var getBounds = function getBounds() {
352343
return new _leaflet2.default.Bounds(_leaflet2.default.point([-r, -r]), size.add([r, r]));
353344
};
354345

355346
var getDataForHeatmap = function getDataForHeatmap(points, leafletMap) {
356347
return roundResults(accumulateInGrid(points, leafletMap, getBounds(leafletMap)));
357348
};
358-
var data = getDataForHeatmap(this.props.points, this.context.map);
349+
350+
var data = getDataForHeatmap(this.props.points, this.props.map);
359351

360352
this._heatmap.clear();
361353
this._heatmap.data(data).draw(this.getMinOpacity(this.props));
362354

363355
this._frame = null;
364356

365357
if (this.props.onStatsUpdate && this.props.points && this.props.points.length > 0) {
366-
var stats = _.reduce(data, function (stats, point) {
358+
this.props.onStatsUpdate((0, _lodash4.default)(data, function (stats, point) {
367359
stats.max = point[3] > stats.max ? point[3] : stats.max;
368360
stats.min = point[3] < stats.min ? point[3] : stats.min;
369361
return stats;
370-
}, { min: Infinity, max: -Infinity });
371-
372-
this.props.onStatsUpdate(stats);
362+
}, { min: Infinity, max: -Infinity }));
373363
}
374364
};
375365

package.json

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"compile": "npm run clean; npm run transpile",
88
"transpile": "./node_modules/.bin/babel src/HeatmapLayer.js --out-file lib/HeatmapLayer.js",
99
"clean": "rm -rf ./lib/*",
10-
"example": "webpack-dev-server --config ./example/webpack.config.js"
10+
"example": "webpack-dev-server --config ./example/webpack.config.js",
11+
"lint": "eslint ./src ./example/index.js"
1112
},
1213
"repository": {
1314
"type": "git",
@@ -36,8 +37,7 @@
3637
"devDependencies": {
3738
"babel-cli": "^6.6.5",
3839
"babel-core": "^6.7.4",
39-
"babel-eslint": "^5.0.0",
40-
"babel-jest": "^9.0.3",
40+
"babel-eslint": "^7.1.1",
4141
"babel-loader": "^6.2.4",
4242
"babel-plugin-object-assign": "^1.2.1",
4343
"babel-plugin-react-transform": "^2.0.0",
@@ -46,43 +46,19 @@
4646
"babel-preset-es2015": "^6.3.13",
4747
"babel-preset-react": "^6.3.13",
4848
"babel-preset-stage-0": "^6.3.13",
49-
"enzyme": "^2.2.0",
49+
"eslint": "^3.15.0",
5050
"eslint-config-airbnb": "^6.2.0",
5151
"eslint-plugin-arrow-function": "^2.0.0",
52+
"eslint-plugin-lean-imports": "^0.3.3",
5253
"eslint-plugin-react": "^4.2.3",
53-
"jest-cli": "^0.9.2",
5454
"leaflet": "^1.0.0",
5555
"react": "^15.4.1",
5656
"react-addons-test-utils": "^0.14.7",
5757
"react-dom": "^15.4.1",
5858
"react-leaflet": "^1.0.0",
5959
"react-transform-hmr": "^1.0.4",
60-
"webpack-dev-server": "^1.14.1",
61-
"webpack": "^1.12.14"
62-
},
63-
"jest": {
64-
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest/src/index.js",
65-
"unmockedModulePathPatterns": [
66-
"react",
67-
"enzyme",
68-
"react-dom",
69-
"react-addons-test-utils",
70-
"fbjs",
71-
"cheerio",
72-
"htmlparser2",
73-
"underscore",
74-
"lodash",
75-
"domhandler",
76-
"object.assign",
77-
"define-properties",
78-
"function-bind",
79-
"object-keys"
80-
],
81-
"moduleFileExtensions": [
82-
"js",
83-
"json",
84-
"jsx"
85-
]
60+
"webpack": "^1.12.14",
61+
"webpack-dev-server": "^1.14.1"
8662
},
8763
"dependencies": {
8864
"lodash.filter": "^4.3.0",
@@ -93,6 +69,6 @@
9369
"lodash.min": "^4.0.0",
9470
"lodash.pluck": "^3.1.2",
9571
"lodash.reduce": "^4.3.0",
96-
"simpleheat": "*"
72+
"simpleheat": "^0.4.0"
9773
}
9874
}

0 commit comments

Comments
 (0)