From 4a68dc5172ec919890af9a71b453276afeac5c50 Mon Sep 17 00:00:00 2001 From: paulseamer Date: Fri, 17 May 2024 13:41:21 +0100 Subject: [PATCH] Change pod names in dropdown menus Implements a lookup from the short pod names used in the data files to more meaningful names for the line chart and histogram dropdown menus. --- app/src/main.mjs | 3 ++- app/src/shared/controls.mjs | 12 ++++++------ app/src/shared/pods.mjs | 12 ++++++++++++ 3 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 app/src/shared/pods.mjs diff --git a/app/src/main.mjs b/app/src/main.mjs index 1fe1eb08..d6c18cca 100644 --- a/app/src/main.mjs +++ b/app/src/main.mjs @@ -1,6 +1,7 @@ import { select } from 'd3-selection'; import { initLookup } from './shared/lookup.mjs'; import { initVariants } from './shared/variants.mjs'; +import { initPods } from './shared/pods.mjs'; import { initPyramid } from './pyramid/index.mjs'; import { initLineCharts } from './line-charts/index.mjs'; import { initHistograms } from './histograms/index.mjs'; @@ -8,7 +9,7 @@ import { initHistograms } from './histograms/index.mjs'; async function main() { // Asynchronously load the json files from root of data/ into memory - await Promise.all([initLookup(), initVariants()]); + await Promise.all([initLookup(), initVariants(), initPods()]); // Initialise our charts in order initPyramid(select('#pyramid')); initLineCharts(select('#line-charts')); diff --git a/app/src/shared/controls.mjs b/app/src/shared/controls.mjs index bae6b5a0..fb853bdc 100644 --- a/app/src/shared/controls.mjs +++ b/app/src/shared/controls.mjs @@ -7,6 +7,7 @@ import { ticks as d3Ticks } from 'd3-array'; import { scaleLinear } from 'd3-scale'; import { lookup } from './lookup.mjs'; import { variants } from '../shared/variants.mjs'; +import { pods } from '../shared/pods.mjs'; import { constants } from './constants.mjs'; @@ -192,16 +193,15 @@ function initAreaSelect(container, setState) { function initPodSelect(dropdown, setState) { - const pods = ['aae', 'apc', 'opc']; const callback = evt => setState({ 'pod': evt.target.value }); - dropdown.on('change', callback); + const podSelect = dropdown.on('change', callback); - dropdown.selectAll('option') - .data(pods) + podSelect.selectAll('option') + .data(Array.from(Object.entries(pods))) .enter() .append('option') - .attr('value', d => d) - .text(d => d); + .attr('value', d => d[0]) + .text(d => d[1].name); return dropdown.node().value; } diff --git a/app/src/shared/pods.mjs b/app/src/shared/pods.mjs new file mode 100644 index 00000000..467afec1 --- /dev/null +++ b/app/src/shared/pods.mjs @@ -0,0 +1,12 @@ +// Module for loading pod data +import { load } from './load.mjs'; + +let pods; + + +async function initPods() { + [pods] = await Promise.all([load('pods')]); +} + + +export { pods, initPods }; \ No newline at end of file