diff --git a/analytics/client/locales/fi.json b/analytics/client/locales/fi.json index 82b5fb6..e4128e7 100644 --- a/analytics/client/locales/fi.json +++ b/analytics/client/locales/fi.json @@ -25,7 +25,7 @@ "choose-area": "Valitse tarkasteltava alue", "site-name": "Liikkumisen hiilijalanjälkilaskurin analytiikkatyökalu", "show-reflexive-trips": "Näytä valittuun alueeseen kohdistuvat matkat", - "transport-mode-share-km": "Kulkumuodon osuus matkasuoritteesta", - "transport-mode-share-trips": "Kulkumuodon osuus matkoista", + "transport-mode-share-km": "Kulkumuodon osuus matkasuoritteesta %", + "transport-mode-share-trips": "Kulkumuodon osuus matkoista %", "transport-modes": "Kulkumuoto" } diff --git a/analytics/client/src/ColorLegend.js b/analytics/client/src/ColorLegend.js index c48c5c5..250c193 100644 --- a/analytics/client/src/ColorLegend.js +++ b/analytics/client/src/ColorLegend.js @@ -4,6 +4,9 @@ import { formatDecimal, formatFloat } from './utils'; export default function ColorLegend({title, elements}) { + if (elements == null || elements.length == 0) { + return null; + } const style = { position: 'absolute', fontSize: 12, @@ -26,16 +29,32 @@ export default function ColorLegend({title, elements}) { borderColor: chroma(color).darken().hex() }) ); + let elementPairs = elements; + if (parseFloat(elements[0][1])) { + elementPairs = elements.map((el, idx, arr) => { + if (idx === arr.length - 1) { + return; + } + return [el[0], [el[1], arr[idx+1][1]]]; + }).filter(el => el != null).reverse(); + } + const formatValuePair = (value) => { + const x = value.map( + v => (<>{parseFloat(v) ? formatFloat(v*100) : v})); + x.splice(1, 0, <>–); + return x; + }; + const formatValue = (value) => (Array.isArray(value) ? formatValuePair(value) : value); return (
- { elements.map(([color, value]) => ( + { elementPairs.map(([color, value]) => ( ))} diff --git a/analytics/client/src/Map.js b/analytics/client/src/Map.js index 299fe49..4b264ff 100644 --- a/analytics/client/src/Map.js +++ b/analytics/client/src/Map.js @@ -55,24 +55,15 @@ function AreaMap({ geoData, getFillColor, getElevation, getTooltip, colorStateKe let elements = []; let title = null; if (scales != null) { - if (scales.classes()) { - title = t('transport-mode-share-km') - elements = scales?.classes().map(val => ( - [scales(val).alpha(AREA_ALPHA).hex(), val])); - } - else { - title = t('transport-mode-share-trips') - for (let i=0; i<11; i++) { - let val = i*0.1; - elements.push([scales(val).alpha(AREA_ALPHA).hex(), val]) - } - } + title = t('transport-mode-share-km') + elements = scales?.classes().map(val => ( + [scales(val).alpha(AREA_ALPHA).hex(), val])); } return (
- { elements && } + { elements && } { hoverInfo.object && ( {
{title}
- { parseFloat(value) ? formatFloat(value*100) + '%' : value } + { formatValue(value) }