From cfa40c31dd9fdff3ef00bfaceaa4ae96475f257d Mon Sep 17 00:00:00 2001 From: Pyro Nicampt <81565698+PyroNicampt@users.noreply.github.com> Date: Sun, 22 Dec 2024 19:15:19 -0600 Subject: [PATCH] Add key to legend --- index.html | 30 ++++++++---------------------- js/utillib.js | 2 +- legend.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ style.css | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 23 deletions(-) diff --git a/index.html b/index.html index 4303aa4..104ffe6 100644 --- a/index.html +++ b/index.html @@ -11,28 +11,6 @@

Hover over tracks and objects for detailed information.
+
+

Key

+
+
+

Map Settings


diff --git a/js/utillib.js b/js/utillib.js index 0a2651d..df46002 100644 --- a/js/utillib.js +++ b/js/utillib.js @@ -1,6 +1,6 @@ 'use strict'; -const gradeIncrements = [ +export const gradeIncrements = [ 0.0498, 0.04, 0.035, diff --git a/legend.js b/legend.js index 563748c..0248f81 100644 --- a/legend.js +++ b/legend.js @@ -1,5 +1,7 @@ 'use strict'; +import * as Utils from './js/utillib.js'; + let settingEntries = [ { label: 'Signage', @@ -38,6 +40,8 @@ let settingEntries = [ }, ]; +const legendKey = document.getElementById('legendKey'); + document.addEventListener('DOMContentLoaded', async () => { const settingsPanel = document.getElementById('settingsPanel'); for(let thisSetting of settingEntries){ @@ -54,6 +58,7 @@ document.addEventListener('DOMContentLoaded', async () => { }; legendButton.addEventListener('click', legendButtonEvent); legendButtonEvent(); + populateKey(); }); function addSettingEntry(thisSetting, parent, indent=0){ @@ -94,4 +99,44 @@ function addSettingEntry(thisSetting, parent, indent=0){ addSettingEntry(child, parent, indent+1); } } +} + +function populateKey(){ + addKeyEntry(null, '(Grade arrows point uphill)'); + const getGradeValue = gradeIndex => {return Math.round(Utils.gradeIncrements[Utils.gradeIncrements.length-gradeIndex-1]*10000)/100}; + for(let i=-1; i=0){ + gradeValue = `${getGradeValue(i)}`; + gradeIndex = i; + } + if(i == Utils.gradeIncrements.length-1){ + gradeValue = '> '+gradeValue+'%'; + }else if(i >= 0){ + gradeValue += ` - ${getGradeValue(i+1)}%`; + } + let gradeIcon = document.createElement('svg'); + gradeIcon.classList.add('inlineSvg'); + gradeIcon.setAttribute('viewBox', '-50 -50 100 100'); + gradeIcon.innerHTML = ``; + addKeyEntry(gradeIcon, ` ${gradeValue} Grade`); + } + let speedSignIcon = document.createElement('svg'); + speedSignIcon.classList.add('inlineSvg'); + speedSignIcon.setAttribute('viewBox', '-50 -50 100 100'); + speedSignIcon.innerHTML = ``; + addKeyEntry(speedSignIcon, ' Speed Limit'); +} + +/** + * Add an entry to the map key. + * @param {Element} keyImage + * @param {string} keyLabel + */ +function addKeyEntry(keyImage, keyLabel){ + let keyDiv = document.createElement('div'); + if(keyImage) keyDiv.appendChild(keyImage); + keyDiv.innerHTML += keyLabel; + legendKey.appendChild(keyDiv); } \ No newline at end of file diff --git a/style.css b/style.css index fa52ea5..08f5e31 100644 --- a/style.css +++ b/style.css @@ -1,5 +1,28 @@ @import url('https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wdth,wght@0,62.5..100,100..900;1,62.5..100,100..900&family=Protest+Strike&display=swap'); +:root{ + --grade_flat: #ffff; + --grade_0: #f4f7cd; + --grade_1: #f8ff99; + --grade_2: #edfc1b; + --grade_3: #fcb520; + --grade_4: #f07837; + --grade_5: #e66441; + --grade_6: #ce3f57; + --grade_7: #c33577; + --grade_8: #a3008d; + --grade_9: #690097; + + --signScale: 1; + --cullThreshold_state_0: none; + --cullThreshold_state_1: none; + --cullThreshold_state_2: none; + --cullThreshold_state_3: none; + --cullThreshold_state_4: none; + --cullThreshold_state_5: none; + --cullThreshold_state_6: none; +} + html, body, #map, #mapContainer, h1, h2, h3, h4, h5{ padding: 0px; margin: 0px; @@ -64,6 +87,10 @@ a:visited{ transition: transform 200ms ease; } +#legendKey{ + font-size: 15px; +} + #footer{ position: fixed; width: fit-content; @@ -88,4 +115,10 @@ a:visited{ cursor: grab; user-select: none; background: linear-gradient(#444, #333); +} + +.inlineSvg { + width: 1em; + height: 1em; + vertical-align: -0.1em; } \ No newline at end of file