mazedesignhq / react-heatmap Goto Github PK
View Code? Open in Web Editor NEWReact component for heatmap.js
React component for heatmap.js
🚨 You need to enable Continuous Integration on all branches of this repository. 🚨
To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.
Since we didn’t receive a CI status on the greenkeeper/initial
branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.
If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/
.
Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial
branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.
I'm developing the web site using React-Heatmap now.
But the react-heatmap is not responsived for defferent device(mobile and desktop).
How can i do it ?
Browserify Error { [Error: Cannot find module 'heatmapjs/build/heatmap.js' from 'F:\react-heatmap\src']
If a try to build the library, I get this error:
# npm run build
> [email protected] build /Users/nono/Desarrollo/react-heatmap
> gulp clean && NODE_ENV=production gulp build
/Users/nono/Desarrollo/react-heatmap/node_modules/require-dir/index.js:93
if (!require.extensions.hasOwnProperty(ext)) {
^
TypeError: require.extensions.hasOwnProperty is not a function
at requireDir (/Users/nono/Desarrollo/react-heatmap/node_modules/require-dir/index.js:93:37)
at Object.<anonymous> (/Users/nono/Desarrollo/react-heatmap/node_modules/gulp-git/index.js:4:18)
at Module._compile (module.js:662:30)
at Object.Module._extensions..js (module.js:673:10)
at Module.load (module.js:575:32)
at tryModuleLoad (module.js:515:12)
at Function.Module._load (module.js:507:3)
at Module.require (module.js:606:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/nono/Desarrollo/react-heatmap/node_modules/react-component-gulp-tasks/tasks/release.js:1:73)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `gulp clean && NODE_ENV=production gulp build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/nono/.npm/_logs/2018-03-22T11_59_34_802Z-debug.log
I have not made any changes to the project.
Is is possible to automatically set the maximum to the highest occurrence of a point? For example:
[{x: 100, y: 100 value: 1}, {x: 150, y: 150, value: 1}, {x: 100, y:100 value: 1}] would set the max to 2 automatically since the highest value (2 occurrences at 100,100 at 1 unit each) is 2.
import React from 'react';
import { reduce, filter, min, max, isNumber, map } from 'lodash';
import L from 'leaflet';
import { MapLayer } from 'react-leaflet';
import simpleheat from 'simpleheat';
export type LngLat = {
lng: number;
lat: number;
}
export type Point = {
x: number;
y: number;
}
export type Bounds = {
contains: (latLng: LngLat) => boolean;
}
export type Pane = {
appendChild: (element: Object) => void;
}
export type Panes = {
overlayPane: Pane;
}
export type Map = {
layerPointToLatLng: (lngLat: Point) => LngLat;
latLngToLayerPoint: (lngLat: LngLat) => Point;
on: (event: string, handler: () => void) => void;
getBounds: () => Bounds;
getPanes: () => Panes;
invalidateSize: () => void;
options: Object;
}
export type LeafletZoomEvent = {
zoom: number;
center: Object;
}
function isValidLatLngArray(arr: Array<number>): boolean {
return filter(arr, isValid).length === arr.length;
}
function isInvalidLatLngArray(arr: Array<number>): boolean {
return !isValidLatLngArray(arr);
}
function isInvalid(num: number): boolean {
return !isNumber(num) && !num;
}
function isValid(num: number): boolean {
return !isInvalid(num);
}
function shouldIgnoreLocation(loc: LngLat): boolean {
return isInvalid(loc.lng) || isInvalid(loc.lat);
}
export default class HeatmapLayer extends MapLayer {
static propTypes = {
points: React.PropTypes.array.isRequired,
longitudeExtractor: React.PropTypes.func.isRequired,
latitudeExtractor: React.PropTypes.func.isRequired,
intensityExtractor: React.PropTypes.func.isRequired,
fitBoundsOnLoad: React.PropTypes.bool,
fitBoundsOnUpdate: React.PropTypes.bool,
onStatsUpdate: React.PropTypes.func,
/* props controlling heatmap generation */
max: React.PropTypes.number,
radius: React.PropTypes.number,
maxZoom: React.PropTypes.number,
minOpacity: React.PropTypes.number,
blur: React.PropTypes.number,
gradient: React.PropTypes.object,
};
componentDidMount(): void {
this.leafletElement = this.container;
this.props.map.getPanes().overlayPane.appendChild(this.leafletElement);
this._heatmap = simpleheat(this.leafletElement);
if (this.props.fitBoundsOnLoad) {
this.fitBounds();
}
this.attachEvents();
this.updateHeatmapProps(this.getHeatmapProps(this.props));
this.reset();
}
getMax(props) { // eslint-disable-line
return props.max || 3.0;
}
getRadius(props) { // eslint-disable-line
return props.radius || 30;
}
getMaxZoom(props) { // eslint-disable-line
return props.maxZoom || 18;
}
getMinOpacity(props) { // eslint-disable-line
return props.minOpacity || 0.01;
}
getBlur(props) { // eslint-disable-line
return props.blur || 15;
}
getHeatmapProps(props) {
return {
minOpacity: this.getMinOpacity(props),
maxZoom: this.getMaxZoom(props),
radius: this.getRadius(props),
blur: this.getBlur(props),
max: this.getMax(props),
gradient: props.gradient,
};
}
componentWillReceiveProps(nextProps: Object): void {
this.updateHeatmapProps(this.getHeatmapProps(nextProps));
}
updateHeatmapProps(nextProps: Object) {
if (nextProps.radius
&& (!this.props || nextProps.radius !== this.props.radius)) {
this._heatmap.radius(nextProps.radius);
}
if (nextProps.gradient) {
this._heatmap.gradient(nextProps.gradient);
}
if (nextProps.max
&& (!this.props || nextProps.max !== this.props.max)) {
this._heatmap.max(nextProps.max);
}
}
createLeafletElement() { // eslint-disable-line
return null;
}
componentWillUnmount(): void {
this.props.map.getPanes().overlayPane.removeChild(this.leafletElement);
}
fitBounds(): void {
const points = this.props.points;
const lngs = map(points, this.props.longitudeExtractor);
const lats = map(points, this.props.latitudeExtractor);
const ne = { lng: max(lngs), lat: max(lats) };
const sw = { lng: min(lngs), lat: min(lats) };
if (shouldIgnoreLocation(ne) || shouldIgnoreLocation(sw)) {
return;
}
this.props.map.fitBounds(L.latLngBounds(L.latLng(sw), L.latLng(ne)));
}
componentDidUpdate(): void {
this.props.map.invalidateSize();
if (this.props.fitBoundsOnUpdate) {
this.fitBounds();
}
this.reset();
}
shouldComponentUpdate(): boolean {
return true;
}
attachEvents(): void {
const maps = (Map = this.props.map);
maps.on('viewreset', () => this.reset());
maps.on('moveend', () => this.reset());
if (maps.options.zoomAnimation && L.Browser.any3d) {
maps.on('zoomanim', this._animateZoom, this);
}
}
_animateZoom(e: LeafletZoomEvent): void {
const scale = this.props.map.getZoomScale(e.zoom);
const offset = this.props.map
._getCenterOffset(e.center)
._multiplyBy(-scale)
.subtract(this.props.map._getMapPanePos());
if (L.DomUtil.setTransform) {
L.DomUtil.setTransform(this.container, offset, scale);
} else {
this.container.style[L.DomUtil.TRANSFORM] =
`${L.DomUtil.getTranslateString(offset)} scale(${scale})`;
}
}
reset(): void {
const topLeft = this.props.map.containerPointToLayerPoint([0, 0]);
L.DomUtil.setPosition(this.container, topLeft);
const size = this.props.map.getSize();
if (this._heatmap._width !== size.x) {
this.container.width = this._heatmap._width = size.x;
}
if (this._heatmap._height !== size.y) {
this.container.height = this._heatmap._height = size.y;
}
if (this._heatmap && !this._frame && !this.props.map._animating) {
this._frame = L.Util.requestAnimFrame(this.redraw, this);
}
this.redraw();
}
redraw(): void {
const r = this._heatmap._r;
const size = this.props.map.getSize();
const maxIntensity = this.props.max === undefined
? 1
: this.getMax(this.props);
const maxZoom = this.props.maxZoom === undefined
? this.props.map.getMaxZoom()
: this.getMaxZoom(this.props);
const v = 1 / Math.max(0, Math.min(maxZoom - this.props.map.getZoom(), 12)) ** 2;
const cellSize = r / 2;
const panePos = this.props.map._getMapPanePos();
const offsetX = panePos.x % cellSize;
const offsetY = panePos.y % cellSize;
const getLat = this.props.latitudeExtractor;
const getLng = this.props.longitudeExtractor;
const getIntensity = this.props.intensityExtractor;
const inBounds = (p, bounds) => bounds.contains(p);
const filterUndefined = rUndefined => filter(rUndefined, c => c !== undefined);
const roundResults = results => reduce(results, (result, row) => map(filterUndefined(row), cell => [
Math.round(cell[0]),
Math.round(cell[1]),
Math.min(cell[2], maxIntensity),
cell[3],
]).concat(result), []);
const accumulateInGrid = (points, leafletMap, bounds) => reduce(points, (grid, point) => {
const latLng = [getLat(point), getLng(point)];
if (isInvalidLatLngArray(latLng)) { // skip invalid points
return grid;
}
const p = leafletMap.latLngToContainerPoint(latLng);
if (!inBounds(p, bounds)) {
return grid;
}
const x = Math.floor((p.x - offsetX) / cellSize) + 2;
const y = Math.floor((p.y - offsetY) / cellSize) + 2;
grid[y] = grid[y] || [];
const cell = grid[y][x];
const alt = getIntensity(point);
const k = alt * v;
if (!cell) {
grid[y][x] = [p.x, p.y, k, 1];
} else {
cell[0] = (cell[0] * cell[2] + p.x * k) / (cell[2] + k); // x
cell[1] = (cell[1] * cell[2] + p.y * k) / (cell[2] + k); // y
cell[2] += k; // accumulated intensity value
cell[3] += 1;
}
return grid;
}, []);
const getBounds = () => new L.Bounds(L.point([-r, -r]), size.add([r, r]));
const getDataForHeatmap = (points, leafletMap) => roundResults(
accumulateInGrid(
points,
leafletMap,
getBounds(leafletMap),
),
);
const data = getDataForHeatmap(this.props.points, this.props.map);
this._heatmap.clear();
this._heatmap.data(data).draw(this.getMinOpacity(this.props));
this._frame = null;
}
render(): React.Element {
const mapSize = this.props.map.getSize();
const transformProp = L.DomUtil.testProp(
['transformOrigin', 'WebkitTransformOrigin', 'msTransformOrigin'],
);
const canAnimate = this.props.map.options.zoomAnimation && L.Browser.any3d;
const zoomClass = `leaflet-zoom-${canAnimate ? 'animated' : 'hide'}`;
const canvasProps = {
className: `leaflet-heatmap-layer leaflet-layer ${zoomClass}`,
style: {
[transformProp]: '50% 50%',
},
width: mapSize.x,
height: mapSize.y,
};
return (
<canvas ref={ref => this.container = ref} {...canvasProps} />
);
}
}
I have this when I try to use react-heatmap 👍
×
TypeError: Cannot read property 'number' of undefined ./node_modules/react-heatmap/lib/ReactHeatmap.js
c:/Users/Covarians/Documents/aex-server/client/node_modules/react-heatmap/lib/ReactHeatmap.js:96
93 | })(_react.Component);
94 |
95 | ReactHeatmap.propTypes = {
96 | max: _react2['default'].PropTypes.number,
97 | data: _react2['default'].PropTypes.array,
98 | unit: _react2['default'].PropTypes.string
99 | };
Note : I commented the lines and it worked. But this is a temporary fix.
Has anyone successfully modified the radius field? I've forked the project and included radius as a config key after container in compDidMount but that seems to make no difference.
Thanks
After I read heatmap.js document, I fund
var nuConfig = {
radius: 10,
maxOpacity: .5,
minOpacity: 0,
blur: .75
};
heatmapInstance.configure(nuConfig);
How we do it on this react version?
also how can we setup lowest value for data points on map, like Min=?
Thx
./node_modules/react-heatmap/lib/ReactHeatmap.js
Line 96 for some reason its not recognizing this property. I am not sure why I am having this issue. I have tried uninstalling, npm cache clean --force, I get the same issues with this component. I used it a few months ago in another project and it worked perfectly. Now I am having issues.
I tried to install react-heatmap with react 16.4, and lower 16. versions, but can t get it to run.
Has anybody had success in using react-heatmap with a react 16.x project?
Please share some insights on how u got it to work.. Thx!
When trying to install, I get the error message, "UNMET PEER DEPENDENCY [email protected]. [email protected] requires a peer of react@^0.14.6 but none was installed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.