Skip to content

Commit 409000a

Browse files
committed
merge upstream
2 parents cf91c4f + 71a59f6 commit 409000a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2210
-441
lines changed

app/javascript/components/charts/composed-chart/composed-chart-component.js app/javascript/components/charts/composed-chart/composed-chart-component.jsx

+55-14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
33
import { format } from 'd3-format';
44
import maxBy from 'lodash/maxBy';
55
import max from 'lodash/max';
6+
import cx from 'classnames';
67
import {
78
Line,
89
Bar,
@@ -18,6 +19,7 @@ import {
1819

1920
import ChartToolTip from '../components/chart-tooltip';
2021
import CustomTick from './custom-tick-component';
22+
import CustomBackground from './custom-background-component';
2123
import './composed-chart-styles.scss';
2224

2325
class CustomComposedChart extends PureComponent {
@@ -48,6 +50,8 @@ class CustomComposedChart extends PureComponent {
4850
render() {
4951
const {
5052
xKey,
53+
yKey,
54+
xKeys,
5155
yKeys,
5256
xAxis,
5357
yAxis,
@@ -58,21 +62,26 @@ class CustomComposedChart extends PureComponent {
5862
height,
5963
margin
6064
} = this.props.config;
65+
6166
const {
6267
className,
6368
data,
6469
config,
6570
simple,
6671
handleMouseMove,
67-
handleMouseLeave
72+
handleMouseLeave,
73+
handleClick,
74+
barBackground
6875
} = this.props;
6976

70-
const { lines, bars, areas } = yKeys;
77+
const isVertical = !!xKeys;
78+
const dataKeys = yKeys || xKeys;
79+
const { lines, bars, areas } = dataKeys;
7180
const maxYValue = this.findMaxValue(data, config);
7281

7382
return (
7483
<div
75-
className={`c-composed-chart ${className}`}
84+
className={cx('c-composed-chart', className)}
7685
style={{ height: simple ? 100 : height || 250 }}
7786
>
7887
<ResponsiveContainer width="99%">
@@ -81,14 +90,16 @@ class CustomComposedChart extends PureComponent {
8190
margin={
8291
margin || {
8392
top: !simple ? 15 : 0,
84-
right: 0,
85-
left: !simple ? 42 : 0,
93+
right: isVertical ? 10 : 0,
94+
left: simple || isVertical ? 0 : 42,
8695
bottom: 0
8796
}
8897
}
8998
padding={{ left: 50 }}
9099
onMouseMove={handleMouseMove}
91100
onMouseLeave={handleMouseLeave}
101+
onClick={handleClick}
102+
layout={isVertical ? 'vertical' : 'horizontal'}
92103
>
93104
<defs>
94105
{gradients &&
@@ -121,35 +132,50 @@ class CustomComposedChart extends PureComponent {
121132
/>
122133
{!simple && (
123134
<YAxis
135+
dataKey={yKey || ''}
136+
tickLine={!isVertical}
124137
axisLine={false}
125-
strokeDasharray="3 4"
126-
tickSize={-42}
127-
mirror
128-
tickMargin={0}
138+
{...(!isVertical
139+
? {
140+
strokeDasharray: '3 4',
141+
tickSize: -42,
142+
mirror: true,
143+
tickMargin: 0
144+
}
145+
: {})}
129146
tick={
130147
<CustomTick
131-
dataMax={maxYValue}
148+
dataMax={xKeys && maxYValue}
132149
unit={unit || ''}
133150
unitFormat={
134151
unitFormat ||
135152
(value =>
136153
(value < 1 ? format('.2r')(value) : format('.2s')(value)))
137154
}
138155
fill="#555555"
156+
vertical={isVertical}
139157
/>
140158
}
141159
{...yAxis}
142160
/>
143161
)}
144162
{!simple && (
145-
<CartesianGrid vertical={false} strokeDasharray="3 4" />
163+
<CartesianGrid
164+
vertical={isVertical}
165+
horizontal={!isVertical}
166+
strokeDasharray="3 4"
167+
/>
146168
)}
169+
147170
<Tooltip
148171
simple={simple}
149172
cursor={{
150173
opacity: 0.5,
151174
stroke: '#d6d6d9',
152-
...(!!bars && { strokeWidth: `${1.2 * (100 / data.length)}%` })
175+
...(!!bars && {
176+
strokeWidth: `${1.2 *
177+
((isVertical ? 45 : 100) / data.length)}%`
178+
})
153179
}}
154180
content={<ChartToolTip settings={tooltip} />}
155181
/>
@@ -169,7 +195,20 @@ class CustomComposedChart extends PureComponent {
169195
))}
170196
{bars &&
171197
Object.keys(bars).map(key => (
172-
<Bar key={key} dataKey={key} dot={false} {...bars[key]}>
198+
<Bar
199+
key={key}
200+
dataKey={key}
201+
dot={false}
202+
background={d =>
203+
barBackground && (
204+
<CustomBackground
205+
{...d}
206+
activeIndex={barBackground.activeIndex}
207+
/>
208+
)
209+
}
210+
{...bars[key]}
211+
>
173212
{bars[key].itemColor &&
174213
data.map(item => (
175214
<Cell key={`c_${item.color}`} fill={item.color} />
@@ -190,7 +229,9 @@ CustomComposedChart.propTypes = {
190229
simple: PropTypes.bool,
191230
handleMouseMove: PropTypes.func,
192231
handleMouseLeave: PropTypes.func,
193-
backgroundColor: PropTypes.string
232+
handleClick: PropTypes.func,
233+
backgroundColor: PropTypes.string,
234+
barBackground: PropTypes.object
194235
};
195236

196237
export default CustomComposedChart;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
const CustomBackground = props => (
5+
<svg
6+
key={props.index}
7+
x={props.x}
8+
y={props.y - 3}
9+
width={props.width + 1}
10+
height={1.2 * props.height}
11+
viewBox={`0 0 ${props.width} ${props.height}`}
12+
>
13+
<g>
14+
<rect
15+
fill={props.index === props.activeIndex ? '#4a4a4a' : 'transparent'}
16+
opacity="0.1"
17+
x="-5"
18+
y="0"
19+
width={props.width + 5}
20+
height={1.2 * props.height}
21+
/>
22+
{props.index === props.activeIndex && (
23+
<polygon
24+
fill="#FFFFFF"
25+
points={`${props.width -
26+
Math.sqrt(
27+
(1.2 * props.height - 30) ** 2 +
28+
((1.2 * props.height - 30) / 2) ** 2
29+
) +
30+
5} ${1.2 * props.height / 2} ${props.width} ${1.2 * props.height -
31+
15} ${props.width} 15`}
32+
/>
33+
)}
34+
</g>
35+
</svg>
36+
);
37+
38+
CustomBackground.propTypes = {
39+
x: PropTypes.number,
40+
y: PropTypes.number,
41+
index: PropTypes.number,
42+
height: PropTypes.number,
43+
width: PropTypes.number,
44+
activeIndex: PropTypes.number
45+
};
46+
47+
export default CustomBackground;

app/javascript/components/charts/composed-chart/custom-tick-component.jsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ const CustomTick = ({
99
unit,
1010
unitFormat,
1111
fill,
12-
backgroundColor
12+
fontSize,
13+
backgroundColor,
14+
vertical
1315
}) => {
1416
const tickValue = payload && payload.value;
1517
const formattedTick = tickValue ? unitFormat(tickValue) : 0;
@@ -27,8 +29,8 @@ const CustomTick = ({
2729
filter="url(#solid)"
2830
x="0"
2931
y="3"
30-
textAnchor="start"
31-
fontSize="12px"
32+
textAnchor={vertical ? 'end' : 'start'}
33+
fontSize={fontSize || '12px'}
3234
fill={fill}
3335
>
3436
{tick}
@@ -45,7 +47,9 @@ CustomTick.propTypes = {
4547
unit: PropTypes.string,
4648
unitFormat: PropTypes.func,
4749
fill: PropTypes.string,
48-
backgroundColor: PropTypes.string
50+
fontSize: PropTypes.string,
51+
backgroundColor: PropTypes.string,
52+
vertical: PropTypes.bool
4953
};
5054

5155
export default CustomTick;

app/javascript/components/maps/components/analysis/selectors.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,25 @@ export const getLayerEndpoints = createSelector(
119119
);
120120

121121
const groupedEndpoints = groupBy(endpoints, 'slug');
122-
const parsedEndpoints = Object.keys(groupedEndpoints).map(slug => {
123-
let params = {};
124-
groupedEndpoints[slug].forEach(e => {
125-
params = {
126-
...params,
127-
...e.params
122+
const parsedEndpoints = Object.keys(groupedEndpoints)
123+
.filter(slug => slug !== 'undefined')
124+
.map(slug => {
125+
let params = {};
126+
groupedEndpoints[slug].forEach(e => {
127+
params = {
128+
...params,
129+
...e.params
130+
};
131+
});
132+
133+
return {
134+
slug,
135+
params,
136+
version: groupedEndpoints[slug][0].version,
137+
name: groupedEndpoints[slug][0].name
128138
};
129139
});
130140

131-
return {
132-
slug,
133-
params,
134-
version: groupedEndpoints[slug][0].version,
135-
name: groupedEndpoints[slug][0].name
136-
};
137-
});
138-
139141
return adm2
140142
? parsedEndpoints.filter(e => !e.slug.includes('forma'))
141143
: parsedEndpoints;

app/javascript/components/maps/main-map/components/data-analysis-menu/component.jsx

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class DataAnalysisMenu extends PureComponent {
1414
links,
1515
clearAnalysisError,
1616
setMainMapSettings,
17+
setMapSettings,
1718
showAnalysis,
1819
hidden
1920
} = this.props;
@@ -27,6 +28,7 @@ class DataAnalysisMenu extends PureComponent {
2728
(showAnalysis && l.active && !hidden) ||
2829
(!showAnalysis && l.active && !hidden)
2930
});
31+
setMapSettings({ draw: false });
3032
clearAnalysisError();
3133
}
3234
}));
@@ -70,6 +72,7 @@ DataAnalysisMenu.propTypes = {
7072
menuSection: PropTypes.object,
7173
links: PropTypes.array,
7274
setMainMapSettings: PropTypes.func,
75+
setMapSettings: PropTypes.func,
7376
clearAnalysisError: PropTypes.func,
7477
embed: PropTypes.bool
7578
};

app/javascript/components/maps/main-map/components/data-analysis-menu/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { connect } from 'react-redux';
22

33
import { clearAnalysisError } from 'components/maps/components/analysis/actions';
44
import { setMainMapSettings } from 'components/maps/main-map/actions';
5+
import { setMapSettings } from 'components/maps/map/actions';
56
import { getDataAnalysisMenuProps } from './selectors';
67
import Component from './component';
78

89
export default connect(getDataAnalysisMenuProps, {
910
clearAnalysisError,
10-
setMainMapSettings
11+
setMainMapSettings,
12+
setMapSettings
1113
})(Component);

app/javascript/components/maps/main-map/components/map-controls/map-controls-component.jsx

+8-12
Original file line numberDiff line numberDiff line change
@@ -196,29 +196,29 @@ class MapControlsButtons extends PureComponent {
196196

197197
renderZoomButtons = () => {
198198
const { mapSettings, setMapSettings } = this.props;
199-
const { zoom, minZoom, maxZoom } = mapSettings || {};
199+
const { minZoom, maxZoom, zoom } = mapSettings || {};
200200

201201
return (
202202
<Fragment>
203203
<Button
204204
theme="theme-button-map-control"
205205
onClick={() => {
206-
setMapSettings({ zoom: zoom - 1 });
206+
setMapSettings({ zoom: zoom - 1 < minZoom ? minZoom : zoom - 1 });
207207
track('zoomOut');
208208
}}
209209
tooltip={{ text: 'Zoom out' }}
210-
disabled={zoom === minZoom}
210+
disabled={zoom <= minZoom}
211211
>
212212
<Icon icon={minusIcon} className="minus-icon" />
213213
</Button>
214214
<Button
215215
theme="theme-button-map-control"
216216
onClick={() => {
217-
setMapSettings({ zoom: zoom + 1 });
217+
setMapSettings({ zoom: zoom + 1 > maxZoom ? maxZoom : zoom + 1 });
218218
track('zoomIn');
219219
}}
220220
tooltip={{ text: 'Zoom in' }}
221-
disabled={zoom === maxZoom}
221+
disabled={zoom >= maxZoom}
222222
>
223223
<Icon icon={plusIcon} className="plus-icon" />
224224
</Button>
@@ -298,16 +298,12 @@ class MapControlsButtons extends PureComponent {
298298
);
299299

300300
renderMapPosition = () => {
301-
const { mapSettings } = this.props;
302-
const { zoom, center } = mapSettings || {};
301+
const { mapSettings: { center: { lat, lng }, zoom } } = this.props;
303302

304303
return (
305304
<div className="map-position">
306-
<span>zoom: {zoom}</span>
307-
<span>
308-
lat,lon:{' '}
309-
{`${format('.5f')(center.lat)}, ${format('.5f')(center.lng)}`}
310-
</span>
305+
<span>zoom: {format('.2f')(zoom)}</span>
306+
<span>lat,lon: {`${format('.5f')(lat)}, ${format('.5f')(lng)}`}</span>
311307
</div>
312308
);
313309
};

0 commit comments

Comments
 (0)