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

162 lines
5.3 KiB
JavaScript
Raw Normal View History

2018-10-04 17:50:33 -04:00
import React, { Fragment } from 'react';
import { 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-04 17:50:33 -04:00
import { HelpIcon } from './icons';
2018-10-02 16:47:59 -04:00
import './legend.css';
2018-09-11 15:59:37 -04:00
2018-10-04 17:50:33 -04:00
import CONFIG from './fields-config.json';
const LEGEND_CONFIG = {
location: [
{
title: 'Location Information (number of data entries)',
slug: 'location',
elements: [
{ color: '#f0f9e8', text: '>5' },
{ color: '#bae4bc', text: '4' },
{ color: '#7bccc4', text: '3' },
{ color: '#43a2ca', text: '2' },
{ color: '#0868ac', text: '1' }
]
}
],
2018-10-04 17:50:33 -04:00
age: [
{
title: 'Year Built',
slug: 'date_year',
elements: [
{ color: '#f0eaba', text: '≥2000' },
{ 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' },
{ color: '#7a5732', text: '<1660' },
]
}
],
size: [
{
title: 'Number of storeys',
slug: 'size_storeys',
elements: [
2018-10-25 05:07:05 -04:00
{ color: '#fef0d9', text: '≥20' },
{ color: '#fdd49e', text: '1020' },
{ color: '#fdbb84', text: '510' },
{ color: '#fc8d59', text: '4' },
{ color: '#ef6548', text: '3' },
{ color: '#d7301f', text: '2' },
{ color: '#990000', text: '1' },
2018-10-04 17:50:33 -04:00
]
}
],
like: [
{
2018-10-05 16:05:49 -04:00
title: 'Which buildings do you like?',
2018-10-04 17:50:33 -04:00
slug: 'like',
elements: [
2018-10-05 16:05:49 -04:00
{ color: '#f65400', text: 'We like these buildings 👍 🎉 +1' },
2018-10-04 17:50:33 -04:00
]
}
]
};
const Legend = (props) => {
var data_layer = undefined;
if (props.match && props.match.params && props.match.params.map) {
data_layer = props.match.params.map;
2018-09-10 16:49:58 -04:00
}
2018-09-10 07:41:00 -04:00
2018-10-04 17:50:33 -04:00
return (
<Sidebar title="Colouring Maps">
2018-10-05 16:05:49 -04:00
<p className="data-intro">Click on the map to see more information about a building&hellip;</p>
{
CONFIG.map((data_group) => (
<LegendGroup {...data_group} maps={LEGEND_CONFIG[data_group.slug]}
data_layer={data_layer} key={data_group.slug} />
))
}
2018-10-04 17:50:33 -04:00
</Sidebar>
);
}
const LegendGroup = (props) => {
const match = props.data_layer === props.slug;
const inactive = props.inactive || !props.maps;
return (
<section className={(inactive? "inactive ": "") + "data-section legend"}>
<header className={(match? "active " : "") + " section-header view"}>
2018-10-04 17:50:33 -04:00
<NavLink
to={match? "/map/base.html": `/map/${props.slug}.html`}
isActive={() => match}
title={(inactive)? 'Coming soon… Click the ? for more info.' :
(match)? '' : 'Show on map'}>
2018-10-04 17:50:33 -04:00
<h3 className="h3">{props.title}</h3>
</NavLink>
{
props.help?
2018-10-05 04:10:20 -04:00
<nav className="icon-buttons">
<a className="icon-button help" title="Find out more" href={props.help}>
Help
2018-10-05 04:10:20 -04:00
<HelpIcon />
</a>
</nav>
2018-10-04 17:50:33 -04:00
: null
}
</header>
<dl className="data-list">
{
(match && props.maps)?
props.maps.map((data_section) => (
<LegendSection {...data_section} key={data_section.slug}>
{
data_section.elements.map((data_item) => (
<LegendItem {...data_item} key={data_item.color} />
))
}
</LegendSection>
))
: null
}
</dl>
</section>
)
};
2018-09-10 07:41:00 -04:00
2018-09-10 16:49:58 -04:00
const LegendSection = (props) => (
<Fragment>
<dt>
2018-10-04 17:50:33 -04:00
{ props.title }
2018-09-10 16:49:58 -04:00
</dt>
<dd>
<ul className="data-legend">
{ props.children }
</ul>
</dd>
</Fragment>
);
2018-10-04 17:50:33 -04:00
const LegendItem = (props) => (
<li>
<span className="key" style={ { background: props.color } }>-</span>
{ props.text }
</li>
2018-09-10 16:49:58 -04:00
);
2018-09-10 07:41:00 -04:00
export default Legend;