Add key to legend

This commit is contained in:
Pyro Nicampt committed 2024-12-22 19:15:19 -06:00
1 parent 43be5f0a9d
commit cfa40c31dd
4 files changed
+87 -23

No files matched your search

+8 -22
View File
@@ -11,28 +11,6 @@
<div id="mapContainer"> <div id="mapContainer">
<svg id="map" xmlns="http://www.w3.org/2000/svg" width="1000" height="1000" viewBox="0 0 10000 10000"> <svg id="map" xmlns="http://www.w3.org/2000/svg" width="1000" height="1000" viewBox="0 0 10000 10000">
<style> <style>
:root{
--grade_flat: #ffff;
--grade_0: #fdffde;
--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;
}
.sign{ .sign{
transform: scale(var(--signScale)); transform: scale(var(--signScale));
} }
@@ -87,6 +65,9 @@
stroke: var(--grade_9); stroke: var(--grade_9);
} }
.gradeSign.grade_flat{
fill: var(--grade_flat);
}
.gradeSign.grade_0{ .gradeSign.grade_0{
fill: var(--grade_0); fill: var(--grade_0);
} }
@@ -211,6 +192,11 @@
<hr> <hr>
Hover over tracks and objects for detailed information. Hover over tracks and objects for detailed information.
</div> </div>
<div class="panel">
<h3>Key</h3>
<hr>
<div id="legendKey"></div>
</div>
<div id="settingsPanel" class="panel"> <div id="settingsPanel" class="panel">
<h3>Map Settings</h3> <h3>Map Settings</h3>
<hr> <hr>
+1 -1
View File
@@ -1,6 +1,6 @@
'use strict'; 'use strict';
const gradeIncrements = [ export const gradeIncrements = [
0.0498, 0.0498,
0.04, 0.04,
0.035, 0.035,
+45
View File
@@ -1,5 +1,7 @@
'use strict'; 'use strict';
import * as Utils from './js/utillib.js';
let settingEntries = [ let settingEntries = [
{ {
label: 'Signage', label: 'Signage',
@@ -38,6 +40,8 @@ let settingEntries = [
}, },
]; ];
const legendKey = document.getElementById('legendKey');
document.addEventListener('DOMContentLoaded', async () => { document.addEventListener('DOMContentLoaded', async () => {
const settingsPanel = document.getElementById('settingsPanel'); const settingsPanel = document.getElementById('settingsPanel');
for(let thisSetting of settingEntries){ for(let thisSetting of settingEntries){
@@ -54,6 +58,7 @@ document.addEventListener('DOMContentLoaded', async () => {
}; };
legendButton.addEventListener('click', legendButtonEvent); legendButton.addEventListener('click', legendButtonEvent);
legendButtonEvent(); legendButtonEvent();
populateKey();
}); });
function addSettingEntry(thisSetting, parent, indent=0){ function addSettingEntry(thisSetting, parent, indent=0){
@@ -94,4 +99,44 @@ function addSettingEntry(thisSetting, parent, indent=0){
addSettingEntry(child, parent, indent+1); addSettingEntry(child, parent, indent+1);
} }
} }
}
function populateKey(){
addKeyEntry(null, '<span style="font-size:smaller">(Grade arrows point uphill)</span>');
const getGradeValue = gradeIndex => {return Math.round(Utils.gradeIncrements[Utils.gradeIncrements.length-gradeIndex-1]*10000)/100};
for(let i=-1; i<Utils.gradeIncrements.length; i++){
let gradeValue = `< ${getGradeValue(0)}`;
let gradeIndex = 'flat';
if(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 = `<use class="gradeSign grade_${gradeIndex}" href="#gradeArrow" transform="rotate(90)"/>`;
addKeyEntry(gradeIcon, ` ${gradeValue} Grade`);
}
let speedSignIcon = document.createElement('svg');
speedSignIcon.classList.add('inlineSvg');
speedSignIcon.setAttribute('viewBox', '-50 -50 100 100');
speedSignIcon.innerHTML = `<use class="speedSign" href="#speedSign_5"/>`;
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);
} }
+33
View File
@@ -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'); @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{ html, body, #map, #mapContainer, h1, h2, h3, h4, h5{
padding: 0px; padding: 0px;
margin: 0px; margin: 0px;
@@ -64,6 +87,10 @@ a:visited{
transition: transform 200ms ease; transition: transform 200ms ease;
} }
#legendKey{
font-size: 15px;
}
#footer{ #footer{
position: fixed; position: fixed;
width: fit-content; width: fit-content;
@@ -88,4 +115,10 @@ a:visited{
cursor: grab; cursor: grab;
user-select: none; user-select: none;
background: linear-gradient(#444, #333); background: linear-gradient(#444, #333);
}
.inlineSvg {
width: 1em;
height: 1em;
vertical-align: -0.1em;
} }