From ece73a9be455799f8248a404236520eaa181cb88 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Wed, 28 Jun 2017 17:21:15 -0400 Subject: [PATCH] =?UTF-8?q?Infobox=20=E2=8C=98I=20now=20toggle=20all=20wid?= =?UTF-8?q?gets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/ui/info.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/ui/info.js b/modules/ui/info.js index 7c4046477..02e8cf62a 100644 --- a/modules/ui/info.js +++ b/modules/ui/info.js @@ -8,6 +8,7 @@ import { uiInfoWidgets } from './info/index'; export function uiInfo(context) { var ids = Object.keys(uiInfoWidgets), + wasActive = ['measurement'], widgets = {}, active = {}; @@ -23,7 +24,7 @@ export function uiInfo(context) { function info(selection) { function redraw() { - var activeids = ids.filter(function(k) { return active[k]; }); + var activeids = ids.filter(function(k) { return active[k]; }).sort(); var containers = infobox.selectAll('.widget-container') .data(activeids, function(k) { return k; }); @@ -79,8 +80,21 @@ export function uiInfo(context) { function toggle(which) { if (d3.event) d3.event.preventDefault(); - if (!which) which = 'measurement'; - active[which] = !active[which]; + var activeids = ids.filter(function(k) { return active[k]; }); + + if (which) { // toggle one + active[which] = !active[which]; + if (activeids.length === 1 && activeids[0] === which) { // none active anymore + wasActive = [which]; + } + } else { // toggle all + if (activeids.length) { + wasActive = activeids; + activeids.forEach(function(k) { active[k] = false; }); + } else { + wasActive.forEach(function(k) { active[k] = true; }); + } + } redraw(); }