Bearloga has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/295601

Change subject: Add forward-compatibility in preparation for region-level 
geodata
......................................................................

Add forward-compatibility in preparation for region-level geodata

Bug: T136257
Depends-On: Ia1d27922b911a3efd3106ac165ffda689e685261
Change-Id: Ibba3cf39d084eea6b4d633819bcf99c7acf51132
---
M server.R
M ui.R
2 files changed, 31 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/discovery/prince 
refs/changes/01/295601/1

diff --git a/server.R b/server.R
index 0b47c21..898d84a 100644
--- a/server.R
+++ b/server.R
@@ -64,12 +64,36 @@
   })
   
   output$country_breakdown_dygraph <- renderDygraph({
-    country_data %>%
+    if (input$group_us_regions) {
+      temp <- country_data
+      temp$`United States` <- rowSums(temp[, grepl("(United States)|(U\\.S\\. 
)", colnames(temp)), drop = FALSE])
+      temp <- temp[, grep("U.S.", colnames(temp), value = TRUE, invert = TRUE, 
fixed = TRUE)]
+    } else {
+      temp <- country_data
+    }
+    if (input$hide_less_than_5) {
+      temp[, -1] <- apply(temp[, -1], 2, function(y) {
+        return(replace(y, y < 5, NA))
+      })
+    }
+    temp %>%
       polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, 
input$smoothing_country_breakdown)) %>%
-      polloi::make_dygraph(xlab = "", ylab = "Users (%)", title = "Geographic 
breakdown of portal visitors") %>%
-      dyCSS(css = "www/inverse.css") %>%
+      { .[, apply(., 2, function(y) { return(sum(!is.na(y))) }) > 0] } %>%
+      {
+        if (ncol(.) > 13) { # Maximum colors that color brewer supports is 12
+          # If we have more than 12 countries, we need to make the dygraph 
manually:
+          . <- xts::xts(.[, -1], order.by = .$date)
+          dg <- dygraph(., xlab = "Date", ylab = "Users (%)", main = 
"Geographic breakdown of portal visitors")
+          dg <- dyOptions(dg, strokeWidth = 3, colors = 
colorspace::rainbow_hcl(ncol(temp)-1),
+                          drawPoints = FALSE, pointSize = 3, labelsKMB = TRUE, 
includeZero = TRUE)
+          dg
+        } else {
+          polloi::make_dygraph(., xlab = "Date", ylab = "Users (%)", title = 
"Geographic breakdown of portal visitors")
+        }
+      } %>%
+      dyLegend(labelsDiv = "country_breakdown_legend", show = "always", width 
= 400) %>%
       dyAxis("x", axisLabelFormatter = polloi::custom_axis_formatter, 
axisLabelWidth = 70) %>%
-      dyLegend(labelsDiv = "country_breakdown_legend", show = "always", width 
= 400)
+      dyCSS(css = "www/inverse.css")
   })
   
   output$browser_selector_container <- renderUI({
diff --git a/ui.R b/ui.R
index db5a8a1..43b7a90 100644
--- a/ui.R
+++ b/ui.R
@@ -62,7 +62,9 @@
             includeMarkdown("./tab_documentation/dwelltime.md")
     ),
     tabItem(tabName = "country_breakdown",
-            polloi::smooth_select("smoothing_country_breakdown"),
+            
fluidRow(column(polloi::smooth_select("smoothing_country_breakdown"), width = 
4),
+                     column(checkboxInput("group_us_regions", "Group U.S. 
regions", value = FALSE), width = 4),
+                     column(checkboxInput("hide_less_than_5", "Hide countries 
with <5% traffic share", value = FALSE), width = 4)),
             div(dygraphOutput("country_breakdown_dygraph"),
                 div(id = "country_breakdown_legend",
                     style = "height: 60px; padding-top: 30px; padding-left: 
20px;"),

-- 
To view, visit https://gerrit.wikimedia.org/r/295601
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibba3cf39d084eea6b4d633819bcf99c7acf51132
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/discovery/prince
Gerrit-Branch: master
Gerrit-Owner: Bearloga <mpo...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to