colouring-montreal/app/src/frontend/legend.js

127 lines
4.4 KiB
JavaScript
Raw Normal View History

2018-09-10 16:49:58 -04:00
import React, { Component, Fragment } from 'react';
import { Link, NavLink } from 'react-router-dom';
2018-09-10 07:41:00 -04:00
2018-09-11 15:59:37 -04:00
import Sidebar from './sidebar';
2018-10-02 16:47:59 -04:00
import './legend.css';
2018-09-11 15:59:37 -04:00
2018-09-10 16:49:58 -04:00
const data_map = [
{
slug: 'date_year',
label: 'Age',
elements: [
{
slug: 'date_year',
label: 'Year Built',
elements: [
{ color: '#f0eaba', text: '≥2000' },
2018-10-02 16:47:59 -04:00
{ color: '#fae269', text: '19802000' },
{ color: '#fbaf27', text: '19601980' },
{ color: '#e6711d', text: '19401960' },
{ color: '#d73d3a', text: '19201940' },
{ color: '#ba221c', text: '19001920' },
{ color: '#bb859b', text: '18801900' },
{ color: '#8b3654', text: '18601880' },
{ color: '#8f5385', text: '18401860' },
{ color: '#56619b', text: '18201840' },
{ color: '#6793b2', text: '18001820' },
{ color: '#83c3b3', text: '17801800' },
{ color: '#adc88f', text: '17601780' },
{ color: '#83a663', text: '17401760' },
{ color: '#77852d', text: '17201740' },
{ color: '#69814e', text: '17001720' },
{ color: '#d0c291', text: '16801700' },
{ color: '#918158', text: '16601680' },
2018-09-10 16:49:58 -04:00
{ color: '#7a5732', text: '<1660' },
]
}
]
},
{
slug: 'size_storeys',
label: 'Size',
elements: [
{
slug: 'size_storeys',
label: 'Number of storeys',
elements: [
{ color: '#ffc584', text: '≥20' },
2018-10-02 16:47:59 -04:00
{ color: '#f46259', text: '1020' },
{ color: '#da456a', text: '510' },
2018-09-10 16:49:58 -04:00
{ color: '#a8327d', text: '4' },
{ color: '#7c2383', text: '3' },
{ color: '#5b167f', text: '2' },
{ color: '#360f69', text: '1' },
]
}
]
}
];
2018-09-10 07:41:00 -04:00
2018-09-10 16:49:58 -04:00
const LegendItem = (props) => (
<li>
<span className="key" style={ { background: props.color } }>-</span>
{ props.text }
</li>
2018-09-10 07:41:00 -04:00
);
2018-09-10 16:49:58 -04:00
const LegendSection = (props) => (
<Fragment>
<dt>
2018-09-10 18:34:56 -04:00
<Link to={`/map/${ props.slug }.html`}>{ props.label }</Link>
2018-09-10 16:49:58 -04:00
</dt>
<dd>
<ul className="data-legend">
{ props.children }
</ul>
</dd>
</Fragment>
);
const LegendGroup = (props) => (
<div className="data-section legend">
<NavLink className={`bullet-prefix ${ props.slug }`} to={`/map/${ props.slug }.html`}>
<h3 className="h3">{ props.label }</h3>
</NavLink>
2018-09-10 16:49:58 -04:00
<dl className="data-list">
{ props.children }
</dl>
</div>
);
class Legend extends Component {
render() {
var data_layer = undefined;
if (this.props.match && this.props.match.params && this.props.match.params.map) {
data_layer = this.props.match.params.map;
}
return (
2018-09-11 15:59:37 -04:00
<Sidebar title="Maps">
2018-09-10 16:49:58 -04:00
{
data_map.map((data_group) => (
2018-09-10 18:34:56 -04:00
<LegendGroup {...data_group} key={data_group.slug}>
2018-09-10 16:49:58 -04:00
{
( data_layer.match(data_group.slug) )
? data_group.elements.map((data_section) => (
2018-09-10 18:34:56 -04:00
<LegendSection {...data_section} key={data_section.slug}>
2018-09-10 16:49:58 -04:00
{
( data_layer.match(data_section.slug) )
? data_section.elements.map((data_item) => (
2018-09-10 18:34:56 -04:00
<LegendItem {...data_item} key={data_item.color} />
2018-09-10 16:49:58 -04:00
))
: null
}
</LegendSection>
))
: null
}
</LegendGroup>
))
}
2018-09-11 15:59:37 -04:00
</Sidebar>
2018-09-10 16:49:58 -04:00
);
}
}
2018-09-10 07:41:00 -04:00
export default Legend;