Browse Source

Keyboard shortcuts

Bring up info panel first
Petra Lamborn 3 years ago
parent
commit
f91a1d18a6
2 changed files with 65 additions and 16 deletions
  1. 19
    13
      viz/app.R
  2. 46
    3
      viz/extras.R

+ 19
- 13
viz/app.R View File

@@ -56,8 +56,8 @@ ui <- fluidPage(
56 56
                 radioButtons("radioeduemp", 
57 57
                              label = "Commuters (age 15+) travelling to",
58 58
                              choiceNames = list(
59
-                               HTML("<span>E<u>m</u>ployment</span>"),
60
-                               HTML("<span>E<u>d</u>ucation</span>")
59
+                               HTML("Em<span class='shortcut'>p</span>loyment"),
60
+                               HTML("E<span class='shortcut'>d</span>ucation")
61 61
                              ),
62 62
                              choiceValues = list(
63 63
                                "Employment", "Education"
@@ -65,8 +65,8 @@ ui <- fluidPage(
65 65
                              inline = TRUE),
66 66
                 radioButtons("radioinout", label="Show commuters who",
67 67
                              choiceNames = list(
68
-                               HTML("<span>Commute <u>f</u>rom selected area</span>"),
69
-                               HTML("<span>Commute <u>t</u>o selected area</span>")),
68
+                           HTML("Commute <span class='shortcut'>f</span>rom selected area"),
69
+                           HTML("Commute <span class='shortcut'>t</span>o selected area")),
70 70
                              choiceValues = list(
71 71
                                "res",
72 72
                                "work"
@@ -75,8 +75,8 @@ ui <- fluidPage(
75 75
                 radioButtons("radiocolour",
76 76
                              label = "Colour by",
77 77
                              choiceNames = list(
78
-                               HTML("<span>M<u>o</u>st common commute method</span>"),
79
-                               HTML("<span>N<u>u</u>mber of commuters</span>")
78
+                           HTML("M<span class='shortcut'>o</span>st common commute method"),
79
+                           HTML("N<span class='shortcut'>u</span>mber of commuters")
80 80
                              ),
81 81
                              choiceValues = list(
82 82
                                "type",
@@ -96,13 +96,16 @@ ui <- fluidPage(
96 96
   absolutePanel(bottom=26, right=10, left=10, top=10, id="infopanel",
97 97
                 infotext),
98 98
   absolutePanel(bottom=10, left=10, id="infobuttoncontainer",
99
-    prettyToggle("mapinfobutton", label_on = "Info",
100
-                 label_off = "Info", icon_on=icon("times"),
99
+    prettyToggle("mapinfobutton", 
100
+                 label_on = HTML("<span class='shortcut'>I</span>nfo"),
101
+                 label_off = HTML("<span class='shortcut'>I</span>nfo"),
102
+                 icon_on=icon("times"),
101 103
                  icon_off = icon("info"),
102 104
                  animation = "pulse",
103 105
                  inline = TRUE,
104 106
                  status_on = "danger",
105
-                 status_off = "info")
107
+                 status_off = "info",
108
+                 value = TRUE)
106 109
   )
107 110
 )
108 111
 
@@ -327,9 +330,6 @@ server <- function(input, output) {
327 330
   observeEvent(input$radioinout, ignoreInit = TRUE, {
328 331
     updateMap()
329 332
   })
330
-  observeEvent(input$infobutton, {
331
-    print(input$infobutton)
332
-  })
333 333
   observeEvent(input$radiocolour, ignoreInit = TRUE, {
334 334
     updateMap()
335 335
   })
@@ -338,8 +338,14 @@ server <- function(input, output) {
338 338
                            time = 0.5)
339 339
   })
340 340
   observeEvent(input$mapinfobutton, ignoreInit = TRUE, {
341
-    shinyjs::toggleElement("infopanel", anim=TRUE,
341
+    if (input$mapinfobutton) {
342
+      shinyjs::showElement("infopanel", anim=TRUE,
343
+                           time = 0.5)
344
+    } else {
345
+      shinyjs::hideElement("infopanel", anim=TRUE,
342 346
                            time = 0.5)
347
+      shinyjs::runjs("document.getElementById('map').focus()")
348
+    }
343 349
   })
344 350
   output$lochtml <- renderUI({
345 351
     seled <- sel.SA2.code()

+ 46
- 3
viz/extras.R View File

@@ -11,6 +11,7 @@ html, body {
11 11
 }
12 12
 #loading {
13 13
   cursor: progress !important;
14
+  z-index: 1002;
14 15
 }
15 16
 #loading p {
16 17
   border-radius: 5px;
@@ -41,7 +42,6 @@ html, body {
41 42
   display: none;
42 43
 }
43 44
 #infopanel {
44
-  display: none;
45 45
   background-color: rgba(255, 255, 255, 0.9);
46 46
   padding: 10px;
47 47
   z-index: 1001;
@@ -115,6 +115,22 @@ hr {
115 115
 .leaflet-control-search {
116 116
   box-shadow: none;
117 117
 }
118
+.shortcut {
119
+  text-decoration: underline 1px dotted;
120
+}
121
+#shortcutlist {
122
+  columns: 20em 2;
123
+}
124
+kbd {
125
+  color: #444;
126
+  background-color: #eee;
127
+  border-radius: 4px;
128
+  padding: 0px 2px;
129
+  border-color: #444;
130
+  border-width: 1px;
131
+  -webkit-box-shadow: 1px 1px #444;
132
+  box-shadow: 1px 1px #444;
133
+}
118 134
 "
119 135
 
120 136
 attribhtml <- '
@@ -130,7 +146,7 @@ title="A method of preserving confidentiality and anonymity">
130 146
 random rounding</a>
131 147
 '
132 148
 
133
-infotext <- div(class="overflowable",
149
+infotext <- div(class="overflowable", id="infoint", tabindex="2",
134 150
   h3("How did Kiwis commute in 2018?"),
135 151
   p("This tool maps the 2018 census",
136 152
   a(href=
@@ -159,6 +175,17 @@ again-data-visualisation-competition", "data visualisation competition",
159 175
     "(including the people who commute within the area). When no area is ",
160 176
     "selected, colouring is according to commutes to or from all ",
161 177
     "localities. Hover over areas for a summary (on a tablet, hold press)."),
178
+  h4("Keyboard shortcuts"),
179
+  shiny::tags$ul(id="shortcutlist",
180
+    shiny::tags$li(shiny::tags$kbd("I"), ": toggle this info page"),
181
+    shiny::tags$li(shiny::tags$kbd("M"), ": focus map"),
182
+    shiny::tags$li(shiny::tags$kbd("P"), ": show employment"),
183
+    shiny::tags$li(shiny::tags$kbd("D"), ": show education"),
184
+    shiny::tags$li(shiny::tags$kbd("F"), ": show people commuting from localities"),
185
+    shiny::tags$li(shiny::tags$kbd("T"), ": show people commuting to localities"),
186
+    shiny::tags$li(shiny::tags$kbd("O"), ": colour by most common commute type"),
187
+    shiny::tags$li(shiny::tags$kbd("U"), ": colour by number of commuters")
188
+  ),
162 189
   h4("FAQ"),
163 190
   shiny::tags$blockquote("Why are so many areas marked as 'works at ",
164 191
                          "home'?"),
@@ -191,31 +218,47 @@ again-data-visualisation-competition", "data visualisation competition",
191 218
 keyboardjs <- tags$head(tags$script(HTML("
192 219
 $(function(){ 
193 220
   $(document).keyup(function(e) {
221
+    var active = document.activeElement
222
+    if (active.id == 'searchtext9') return;
194 223
     switch(e.key) {
195
-      case 'm':
224
+      case 'p':
225
+      case 'P':
196 226
         document.getElementsByName('radioeduemp')[0].checked = true;
197 227
         Shiny.onInputChange('radioeduemp', 'Employment')
198 228
         break;
199 229
       case 'd':
230
+      case 'D':
200 231
         document.getElementsByName('radioeduemp')[1].checked = true;
201 232
         Shiny.onInputChange('radioeduemp', 'Education')
202 233
         break;
203 234
       case 'f':
235
+      case 'F':
204 236
         document.getElementsByName('radioinout')[0].checked = true;
205 237
         Shiny.onInputChange('radioinout', 'res')
206 238
         break;
207 239
       case 't':
240
+      case 'T':
208 241
         document.getElementsByName('radioinout')[1].checked = true;
209 242
         Shiny.onInputChange('radioinout', 'work')
210 243
         break;
211 244
       case 'o':
245
+      case 'O':
212 246
         document.getElementsByName('radiocolour')[0].checked = true;
213 247
         Shiny.onInputChange('radiocolour', 'type')
214 248
         break;
215 249
       case 'u':
250
+      case 'U':
216 251
         document.getElementsByName('radiocolour')[1].checked = true;
217 252
         Shiny.onInputChange('radiocolour', 'number')
218 253
         break;
254
+      case 'i':
255
+      case 'I':
256
+        shinyjs.click('mapinfobutton')
257
+        break;
258
+      case 'm':
259
+      case 'M':
260
+        document.getElementById('map').focus()
261
+        break;
219 262
       default:
220 263
         break;
221 264
     }