From 8814e288172bb57ceaa5e1fedd4b1d1679516600 Mon Sep 17 00:00:00 2001 From: Chase Porter Date: Wed, 3 Nov 2021 15:22:36 -0700 Subject: [PATCH] REFACTOR: Refactors buildCheckBox util function to take an object as input instead of a long list of parameters. --- fdds/js/components/layerController.js | 28 ++++++++++++++++++++++++---- fdds/js/components/timeSeriesController.js | 9 ++++++++- fdds/js/util.js | 4 ++-- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/fdds/js/components/layerController.js b/fdds/js/components/layerController.js index 1a64618..20b1046 100644 --- a/fdds/js/components/layerController.js +++ b/fdds/js/components/layerController.js @@ -153,8 +153,18 @@ export class LayerController extends HTMLElement { } for (const [layerName, layer] of Object.entries(simVars.baseLayerDict)) { let checked = layerName == this.currentMapType; - let mapCheckBox = buildCheckBox(layerName, 'radio', 'base', - checked, mapCheckCallback, [layerName, layer]); + let checkBoxParams = { + id: layerName, + text: layerName, + type: 'radio', + name: 'base', + checked: checked, + callback: mapCheckCallback, + args: [layerName, layer], + } + // let mapCheckBox = buildCheckBox(layerName, 'radio', 'base', + // checked, mapCheckCallback, [layerName, layer]); + let mapCheckBox = buildCheckBox(checkBoxParams); baseMapDiv.appendChild(mapCheckBox); } } @@ -332,8 +342,18 @@ export class LayerController extends HTMLElement { } for (let layerName in layerDict) { let isChecked = simVars.overlayOrder.includes(layerName); - let layerBox = buildCheckBox(layerName, 'checkbox', 'layers', - isChecked, layerClick, layerName); + let layerBoxParams = { + id: layerName, + text: layerName, + type: 'checkbox', + name: 'layers', + checked: isChecked, + callback: layerClick, + args: layerName, + } + // let layerBox = buildCheckBox(layerName, 'checkbox', 'layers', + // isChecked, layerClick, layerName); + let layerBox = buildCheckBox(layerBoxParams); layerDiv.appendChild(layerBox); } } diff --git a/fdds/js/components/timeSeriesController.js b/fdds/js/components/timeSeriesController.js index c55e381..08c8c7f 100644 --- a/fdds/js/components/timeSeriesController.js +++ b/fdds/js/components/timeSeriesController.js @@ -47,7 +47,14 @@ export class TimeSeriesController extends LayerController { const showMarkersCallback = () => { simVars.showMarkers = !simVars.showMarkers; } - const checkbox = buildCheckBox('show-markers', 'checkbox', 'show-markers', true, showMarkersCallback); + const checkBoxParams = { + id: 'show-markers', + text: 'Default Show Marker Labels', + type: 'checkbox', + callback: showMarkersCallback, + checked: true, + } + const checkbox = buildCheckBox(checkBoxParams); timeSeriesDiv.appendChild(h4); timeSeriesDiv.appendChild(checkbox); timeSeriesDiv.appendChild(this.timeSeriesButton); diff --git a/fdds/js/util.js b/fdds/js/util.js index 18f7d6b..5022ac3 100644 --- a/fdds/js/util.js +++ b/fdds/js/util.js @@ -192,7 +192,7 @@ export function createElement(id=null, className=null) { } /** Creates the htmlElement for each checkbox in the LayerController. */ -export function buildCheckBox(id, type, name, checked, callback, args=null) { +export function buildCheckBox({id, type, name, checked, callback, args=null, text}) { let div = document.createElement('div'); div.className = 'layer-checkbox'; @@ -207,7 +207,7 @@ export function buildCheckBox(id, type, name, checked, callback, args=null) { let label = document.createElement('label'); label.for = id; - label.innerText = id; + label.innerText = text; div.appendChild(input); div.appendChild(label); return div; -- 2.11.4.GIT