diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/legend.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/legend.test.js index 9bc61646a3b12260d890868330a1446bf3eb469d..a01b6bcfa70352d8fd4109082e41252c02f95870 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/legend.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/legend.test.js @@ -37,7 +37,6 @@ describe('monitoring-location/components/hydrograph/legend module', () => { estimated: false }] }, - '00060:compare': { tsKey: 'compare:P7D', startTime: new Date('2018-03-06T15:45:00.000Z'), @@ -101,7 +100,7 @@ describe('monitoring-location/components/hydrograph/legend module', () => { floodData: { floodLevels: { site_no: '07144100', - action_stage: '20', + action_stage: null, flood_stage: '22', moderate_flood_stage: '25', major_flood_stage: '26' diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.js index 03456d80fd357189042d9a53209470daff527134..3c29cbdab3898ddb336ace42a789d6e2aecdf203 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/legend-data.js @@ -117,31 +117,33 @@ const getMedianMarkers = function(medianMetaData) { }); }; -const getFloodLevelMarkers = function(floodLevels) { - const FLOOD_LEVEL_DISPLAY = { - actionStage: { - label: 'Action Stage', - class: 'action-stage' - }, - floodStage: { - label: 'Flood Stage', - class: 'flood-stage' - }, - moderateFloodStage: { - label: 'Moderate Flood Stage', - class: 'moderate-flood-stage' - }, - majorFloodStage: { - label: 'Major Flood Stage', - class: 'major-flood-stage' +const floodLevelDisplay = function(floodLevels) { + let floodLevelsForDisplay = {}; + Object.keys(floodLevels).forEach(key => { + if (!isNaN(floodLevels[key])) { + const label = key.match(/([A-Z]?[^A-Z]*)/g).slice(0,-1); + + Object.assign(floodLevelsForDisplay, + {[key]: { + 'label': [label.join(' ')], + 'class': [label.join('-').toLowerCase()] + }} + ); } - }; - return Object.keys(floodLevels).map((stage) => { + }); + + return floodLevelsForDisplay; +}; + +const getFloodLevelMarkers = function(floodLevels) { + const floodLevelsForDisplay = floodLevelDisplay(floodLevels); + + return Object.keys(floodLevelsForDisplay).map((stage) => { return [ - defineTextOnlyMarker(FLOOD_LEVEL_DISPLAY[stage].label), + defineTextOnlyMarker(floodLevelsForDisplay[stage].label), defineLineMarker( null, - `waterwatch-data-series ${FLOOD_LEVEL_DISPLAY[stage].class}`, + `waterwatch-data-series ${floodLevelsForDisplay[stage].class}`, `${floodLevels[stage]} ft`) ]; });