YearsMap.js
4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import React from 'react';
import { Nav, NavItem, NavLink } from 'reactstrap';
/* eslint-disable */
import $ from 'jquery';
import 'imports-loader?$=jquery,this=>window!jquery-mapael/js/maps/world_countries';
import 'imports-loader?$=jquery,this=>window!jquery-mapael/js/jquery.mapael';
/* eslint-enable */
import './YearsMap.scss';
import fakeWorldData from './MapData';
class YearsMap extends React.Component {
constructor(prop) {
super(prop);
this.state = {
activeYear: 2019,
};
this.triggerYear = this.triggerYear.bind(this);
}
componentDidMount() {
this.init();
}
init() {
const $map = $('#mapael');
const data = {
map: {
name: 'world_countries',
defaultArea: {
attrs: {
fill: '#eee', // gray-lighter
stroke: '#666', // 'gray'
'stroke-width': 0.1,
},
attrsHover: {
fill: '#999', // gray-light,
animDuration: 100,
},
},
defaultPlot: {
size: 17,
attrs: {
fill: '#f0b518', // brand-warning,
stroke: '#fff',
'stroke-width': 0,
'stroke-linejoin': 'round',
},
attrsHover: {
'stroke-width': 1,
animDuration: 100,
},
},
zoom: {
enabled: true,
step: 1,
maxLevel: 10,
mousewheel: false,
},
},
legend: {
area: {
display: false,
slices: [
{
max: 5000000,
attrs: {
fill: 'rgb(245, 249, 251)', // lightenColor('#ebeff1', .04)
},
label: 'Less than 5M',
},
{
min: 5000000,
max: 10000000,
attrs: {
fill: '#ebeff1',
},
label: 'Between 5M and 10M',
},
{
min: 10000000,
max: 50000000,
attrs: {
fill: '#eee', // gray-lighter
},
label: 'Between 10M and 50M',
},
{
min: 50000000,
attrs: {
fill: 'rgb(209, 213, 215)', // darkenColor('#ebeff1', .1)
},
label: 'More than 50M',
},
],
},
},
areas: fakeWorldData[this.state.activeYear].areas,
};
const height = 394;
$map.css('height', height);
if ($map.parents('.widget')[0]) {
$map.find('.map').css('height', parseInt($map.parents('.widget').css('height'), 10) - 35);
}
$map.mapael(data);
$map.trigger('zoom', { level: 6, latitude: 59.599254, longitude: 8.863224 });
}
triggerYear(year) {
this.setState({
activeYear: year,
});
const $map = $('#mapael');
$map.trigger('update', [{
mapOptions: fakeWorldData[year],
animDuration: 300,
}]);
}
render() {
return (<div>
<div className="mapael" id="mapael">
<div className="stats">
<h6 className="text-gray-dark">YEARLY <span className="fw-semi-bold">DISTRIBUTIONS</span></h6>
<span className="pull-left mr-xs">
<small><span className="circle bg-warning text-gray-dark">
<i className="fa fa-plus" /></span></small>
</span>
<p className="h4 m-0">
<strong>17% last year</strong>
</p>
</div>
<div className="map">
<span>Alternative content for the map</span>
</div>
<div className="areaLegend">
<span>Alternative content for the legend</span>
</div>
</div>
<Nav className="map-controls" pills fill>
<NavItem>
<NavLink active={this.state.activeYear === 2014} onClick={() => this.triggerYear(2014)}>2014</NavLink>
</NavItem>
<NavItem>
<NavLink active={this.state.activeYear === 2015} onClick={() => this.triggerYear(2015)}>2015</NavLink>
</NavItem>
<NavItem>
<NavLink active={this.state.activeYear === 2016} onClick={() => this.triggerYear(2016)}>2016</NavLink>
</NavItem>
<NavItem>
<NavLink active={this.state.activeYear === 2017} onClick={() => this.triggerYear(2017)}>2017</NavLink>
</NavItem>
<NavItem>
<NavLink active={this.state.activeYear === 2018} onClick={() => this.triggerYear(2018)}>2018</NavLink>
</NavItem>
<NavItem>
<NavLink active={this.state.activeYear === 2019} onClick={() => this.triggerYear(2019)}>2019</NavLink>
</NavItem>
</Nav>
</div>);
}
}
export default YearsMap;