Skip to content

Commit 5e07fb9

Browse files
Merge pull request #24 from ramosquito5/master
Heat Map!
2 parents ebb2262 + 1604d4c commit 5e07fb9

10 files changed

Lines changed: 178 additions & 18 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
lib
44
dist
55
coverage
6+
.vscode

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ ReactDOM.render(
122122
| map | object | **required** | Describe SVG map to display. See [maps section](#maps) for more details. |
123123
| className | string | `'svg-map'` | CSS class of `<svg>`. |
124124
| role | string | `'none'` | ARIA role of `<svg>`. |
125-
| locationClassName | string | `'svg-map__location'` | CSS class of each `<path>`. |
125+
| locationClassName | string or function | `'svg-map__location'` | CSS class of each `<path>`. |
126126
| locationTabIndex | string or function | `'0'` | Tabindex each `<path>`. |
127127
| locationRole | string | `'none'` | ARIA role of each `<path>`. |
128128
| onLocationMouseOver | function | | Invoked when the user puts the mouse over a location. |
@@ -136,6 +136,7 @@ ReactDOM.render(
136136
| tabIndex | string | `'0'` | **DEPRECATED:** Although this property still works, it has been replaced by `locationTabIndex` and will be removed in next major version. |
137137
| type | string | `'none'` | **DEPRECATED:** Although this property still works, it has been replaced by `locationRole` and will be removed in next major version. |
138138

139+
139140
### CheckboxSVGMap
140141

141142
| Prop | Type | Default | Description |
@@ -326,8 +327,8 @@ You can modify existing maps or create your own.
326327
#### Modify a map
327328

328329
1. Import the map to modify.
329-
1. Create a new object from this map.
330-
1. Pass this new object as `map` prop of `<SVGMap />` component.
330+
2. Create a new object from this map.
331+
3. Pass this new object as `map` prop of `<SVGMap />` component.
331332

332333
```javascript
333334
import React from 'react';

__tests__/__snapshots__/svg-map.test.js.snap

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,6 +2248,34 @@ exports[`SVGMap component Maps displays map of Utah 1`] = `
22482248
</svg>
22492249
`;
22502250

2251+
exports[`SVGMap component Properties displays heat map with custom location css 1`] = `
2252+
<svg
2253+
aria-label="label"
2254+
className="className"
2255+
role="role"
2256+
viewBox="viewBox"
2257+
xmlns="http://www.w3.org/2000/svg"
2258+
>
2259+
<path
2260+
aria-checked="isLocationSelected"
2261+
aria-label="name"
2262+
className="svg-map__location heat0"
2263+
d="path"
2264+
id="id"
2265+
name="name"
2266+
onBlur={[Function]}
2267+
onClick={[Function]}
2268+
onFocus={[Function]}
2269+
onKeyDown={[Function]}
2270+
onMouseMove={[Function]}
2271+
onMouseOut={[Function]}
2272+
onMouseOver={[Function]}
2273+
role="locationRole"
2274+
tabIndex="locationTabIndex"
2275+
/>
2276+
</svg>
2277+
`;
2278+
22512279
exports[`SVGMap component Properties displays map with custom props 1`] = `
22522280
<svg
22532281
aria-label="label"

__tests__/svg-map.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,35 @@ describe('SVGMap component', () => {
4545

4646
expect(tree).toMatchSnapshot();
4747
});
48+
49+
test('displays heat map with custom location css', () => {
50+
const eventHandler = () => 'eventHandler';
51+
const isLocationSelected = () => 'isLocationSelected';
52+
const generateHeat = () => 'svg-map__location heat0';
53+
const component = renderer.create(
54+
<SVGMap map={map}
55+
className="className"
56+
role="role"
57+
locationTabIndex="locationTabIndex"
58+
locationRole="locationRole"
59+
onLocationMouseOver={eventHandler}
60+
onLocationMouseOut={eventHandler}
61+
onLocationMouseMove={eventHandler}
62+
onLocationClick={eventHandler}
63+
onLocationKeyDown={eventHandler}
64+
onLocationFocus={eventHandler}
65+
onLocationBlur={eventHandler}
66+
isLocationSelected={isLocationSelected}
67+
locationClassName={generateHeat}
68+
/>
69+
);
70+
const tree = component.toJSON();
71+
72+
expect(tree).toMatchSnapshot();
73+
});
4874
});
4975

76+
5077
describe('Maps', () => {
5178
test('displays map of Australia', () => {
5279
const component = renderer.create(<SVGMap map={Australia} />);

examples/src/components/examples-app.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import CheckboxMap from './checkbox-map';
33
import RadioMap from './radio-map';
44
import LinkMap from './link-map';
55
import TooltipMap from './tooltip-map';
6+
import HeatMap from './heat-map';
67
import './examples-app.scss';
78

89
class ExamplesApp extends React.Component {
@@ -20,6 +21,7 @@ class ExamplesApp extends React.Component {
2021
<CheckboxMap />
2122
<LinkMap />
2223
<TooltipMap />
24+
<HeatMap />
2325
</section>
2426
);
2527
}

examples/src/components/examples-app.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@
5151

5252
&--usa {
5353
width: 800px; // USA needs more space for tooltip
54+
.svg-map{
55+
&__location {
56+
&.heat1{
57+
opacity:0.8;
58+
}
59+
&.heat2{
60+
opacity:0.6;
61+
}
62+
&.heat3{
63+
opacity:0.4;
64+
}
65+
}
66+
}
5467
}
5568

5669
&__tooltip {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import React from 'react';
2+
import { SVGMap, USA } from '../../../src/';
3+
import { getLocationName } from '../utils';
4+
import '../../../src/svg-map.scss';
5+
6+
class HeatMap extends React.Component {
7+
constructor(props) {
8+
super(props);
9+
10+
this.state = {
11+
pointedLocation: null,
12+
tooltipStyle: {
13+
display: 'none'
14+
}
15+
};
16+
17+
this.handleLocationMouseOver = this.handleLocationMouseOver.bind(this);
18+
this.handleLocationMouseOut = this.handleLocationMouseOut.bind(this);
19+
this.handleLocationMouseMove = this.handleLocationMouseMove.bind(this);
20+
}
21+
22+
handleLocationMouseOver(event) {
23+
const pointedLocation = getLocationName(event);
24+
this.setState({ pointedLocation });
25+
}
26+
27+
handleLocationMouseOut() {
28+
this.setState({ pointedLocation: null, tooltipStyle: { display: 'none' } });
29+
}
30+
31+
handleLocationMouseMove(event) {
32+
const tooltipStyle = {
33+
display: 'block',
34+
top: event.clientY + 10,
35+
left: event.clientX - 100
36+
};
37+
this.setState({ tooltipStyle });
38+
}
39+
40+
generateHeat(location, index) {
41+
return 'svg-map__location heat' + (index % 4);
42+
}
43+
44+
render() {
45+
return (
46+
<article className="examples__block">
47+
<h2 className="examples__block__title">
48+
USA SVG map with tooltips and a heat map
49+
</h2>
50+
<div className="examples__block__map examples__block__map--usa">
51+
<SVGMap
52+
map={USA}
53+
onLocationMouseOver={this.handleLocationMouseOver}
54+
onLocationMouseOut={this.handleLocationMouseOut}
55+
onLocationMouseMove={this.handleLocationMouseMove}
56+
locationClassName={this.generateHeat}
57+
/>
58+
<div className="examples__block__map__tooltip" style={this.state.tooltipStyle}>
59+
{this.state.pointedLocation}
60+
</div>
61+
</div>
62+
</article>
63+
);
64+
}
65+
}
66+
67+
export default HeatMap;

package-lock.json

Lines changed: 31 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@
7979
"src/*.jsx"
8080
]
8181
}
82-
}
82+
}

0 commit comments

Comments
 (0)