Bearloga has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/375074 )

Change subject: Fix legend positions and rename type of API calls
......................................................................


Fix legend positions and rename type of API calls

Bug: T172452
Change-Id: Ie03a33551afe50df10f33bd8f6c35095097b91c8
---
M modules/api.R
M modules/key_performance_metrics/api_usage.R
M ui.R
M utils.R
4 files changed, 36 insertions(+), 22 deletions(-)

Approvals:
  Bearloga: Verified; Looks good to me, approved



diff --git a/modules/api.R b/modules/api.R
index 495065d..790b29e 100644
--- a/modules/api.R
+++ b/modules/api.R
@@ -1,22 +1,22 @@
 output$cirrus_aggregate <- renderDygraph({
-  split_dataset$cirrus %>%
+  split_dataset$`full-text via API` %>%
     tidyr::spread(referrer, calls) %>%
     polloi::reorder_columns() %>%
     polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, input$smoothing_fulltext_search)) 
%>%
     polloi::make_dygraph(xlab = "Date", ylab = "Searches", title = "Daily 
Full-text search API usage by referrer", legend_name = "Searches") %>%
-    dyLegend(width = 1000, show = "always") %>%
+    dyLegend(labelsDiv = "cirrus_aggregate_legend", width = 600) %>%
     dyRangeSelector %>%
     dyEvent(as.Date("2017-01-01"), "R (reportupdater)", labelLoc = "bottom") 
%>%
     dyEvent(as.Date("2017-06-29"), "U (new UDF)", labelLoc = "bottom")
 })
 
 output$morelike_aggregate <- renderDygraph({
-  split_dataset$`cirrus (more like)` %>%
+  split_dataset$`morelike via API` %>%
     tidyr::spread(referrer, calls) %>%
     polloi::reorder_columns() %>%
     polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, input$smoothing_morelike_search)) 
%>%
     polloi::make_dygraph(xlab = "Date", ylab = "Searches", title = "Daily 
Morelike search API usage by referrer", legend_name = "Searches") %>%
-    dyLegend(width = 1000, show = "always") %>%
+    dyLegend(labelsDiv = "morelike_aggregate_legend", width = 600) %>%
     dyRangeSelector
 })
 
@@ -26,7 +26,7 @@
     polloi::reorder_columns() %>%
     polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, input$smoothing_open_search)) %>%
     polloi::make_dygraph(xlab = "Date", ylab = "Searches", title = "Daily 
OpenSearch API usage by referrer", legend_name = "Searches") %>%
-    dyLegend(width = 1000, show = "always") %>%
+    dyLegend(labelsDiv = "open_aggregate_legend", width = 600) %>%
     dyRangeSelector %>%
     dyEvent(as.Date("2017-01-01"), "R (reportupdater)", labelLoc = "bottom") 
%>%
     dyEvent(as.Date("2017-06-29"), "U (new UDF)", labelLoc = "bottom")
@@ -38,7 +38,7 @@
     polloi::reorder_columns() %>%
     polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, input$smoothing_geo_search)) %>%
     polloi::make_dygraph(xlab = "Date", ylab = "Searches", title = "Daily Geo 
Search API usage by referrer", legend_name = "Searches") %>%
-    dyLegend(width = 1000, show = "always") %>%
+    dyLegend(labelsDiv = "geo_aggregate_legend", width = 600) %>%
     dyRangeSelector %>%
     dyEvent(as.Date("2017-01-01"), "R (reportupdater)", labelLoc = "bottom") 
%>%
     dyEvent(as.Date("2017-06-29"), "U (new UDF)", labelLoc = "bottom")
@@ -50,7 +50,7 @@
     polloi::reorder_columns() %>%
     polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, input$smoothing_language_search)) 
%>%
     polloi::make_dygraph(xlab = "Date", ylab = "Searches", title = "Daily 
Language search API usage by referrer", legend_name = "Searches") %>%
-    dyLegend(width = 1000, show = "always") %>%
+    dyLegend(labelsDiv = "language_aggregate_legend", width = 600) %>%
     dyRangeSelector %>%
     dyEvent(as.Date("2017-01-01"), "R (reportupdater)", labelLoc = "bottom") 
%>%
     dyEvent(as.Date("2017-06-29"), "U (new UDF)", labelLoc = "bottom")
@@ -62,7 +62,7 @@
     polloi::reorder_columns() %>%
     polloi::smoother(smooth_level = 
polloi::smooth_switch(input$smoothing_global, input$smoothing_prefix_search)) 
%>%
     polloi::make_dygraph(xlab = "Date", ylab = "Searches", title = "Daily 
Prefix search API usage by referrer", legend_name = "Searches") %>%
-    dyLegend(width = 1000, show = "always") %>%
+    dyLegend(labelsDiv = "prefix_aggregate_legend", width = 600) %>%
     dyRangeSelector %>%
     dyEvent(as.Date("2017-01-01"), "R (reportupdater)", labelLoc = "bottom") 
%>%
     dyEvent(as.Date("2017-06-29"), "U (new UDF)", labelLoc = "bottom")
@@ -84,6 +84,6 @@
     polloi::make_dygraph(xlab = "Date",
                          ylab = ifelse(input$referer_breakdown_prop, "API 
Calls Share (%)", "API Calls"),
                          title = "Daily API usage by referrer", legend_name = 
"API Calls") %>%
-    dyLegend(width = 1000, show = "always") %>%
+    dyLegend(labelsDiv = "referer_breakdown_plot_legend", width = 600) %>%
     dyRangeSelector
 })
diff --git a/modules/key_performance_metrics/api_usage.R 
b/modules/key_performance_metrics/api_usage.R
index 91fac9f..112ba56 100644
--- a/modules/key_performance_metrics/api_usage.R
+++ b/modules/key_performance_metrics/api_usage.R
@@ -17,16 +17,15 @@
     } %>%
     dplyr::bind_rows(.id = "api") %>%
     tidyr::spread("api", "calls")
-  api_usage <- dplyr::mutate(api_usage, all = cirrus + 
dplyr::if_else(is.na(`cirrus (more like)`), 0, `cirrus (more like)`) + geo + 
language + prefix) %>%
-    polloi::reorder_columns() %>%
-    dplyr::rename("full-text via API" = cirrus, "morelike via API" = `cirrus 
(more like)`)
+  api_usage <- dplyr::mutate(api_usage, all = `full-text via API` + 
dplyr::if_else(is.na(`morelike via API`), 0, `morelike via API`) + geo + 
language + prefix) %>%
+    polloi::reorder_columns()
   if ( input$kpi_api_usage_series_data == "raw" ) {
     api_usage %<>%
       polloi::smoother(ifelse(smooth_level == "global", 
input$smoothing_global, smooth_level), rename = FALSE) %>%
       { xts::xts(.[, -1], order.by = .$date) }
     return(dygraph(api_usage, main = "Calls over time", xlab = "Date",
                    ylab = ifelse(input$kpi_api_usage_series_log_scale, "Calls 
(log10 scale)", "Calls")) %>%
-              dyLegend(width = 1000, show = "always") %>%
+             dyLegend(labelsDiv = "kpi_api_usage_series_legend", width = 600) 
%>%
              dyOptions(
                strokeWidth = 3, colors = RColorBrewer::brewer.pal(7, 
"Set2")[7:1],
                drawPoints = FALSE, pointSize = 3, labelsKMB = TRUE,
@@ -52,7 +51,7 @@
       polloi::smoother(ifelse(smooth_level == "global", 
input$smoothing_global, smooth_level), rename = FALSE) %>%
       { xts::xts(.[, -1], .$date) }
     return(dygraph(api_usage_change, main = "Day-to-day % change over time", 
xlab = "Date", ylab = "% change") %>%
-             dyLegend(width = 1000, show = "always") %>%
+             dyLegend(labelsDiv = "kpi_api_usage_series_legend", width = 600) 
%>%
              dyOptions(
                strokeWidth = 3, colors = RColorBrewer::brewer.pal(7, "Set2"),
                drawPoints = FALSE, pointSize = 3, labelsKMB = TRUE, 
includeZero = TRUE
diff --git a/ui.R b/ui.R
index 74dc20a..bbed6f2 100644
--- a/ui.R
+++ b/ui.R
@@ -149,6 +149,7 @@
                                               value = FALSE),
                                 width = 4),
                          
column(polloi::smooth_select("smoothing_kpi_api_usage"), width = 4)),
+                div(id = "kpi_api_usage_series_legend", style = "text-align: 
right;"),
                 dygraphOutput("kpi_api_usage_series"),
                 includeMarkdown("./tab_documentation/kpi_api_usage.md")),
         tabItem(tabName = "kpi_augmented_clickthroughs",
@@ -223,31 +224,37 @@
         ),
         tabItem(tabName = "fulltext_search",
                 polloi::smooth_select("smoothing_fulltext_search"),
+                div(id = "cirrus_aggregate_legend", style = "text-align: 
right;"),
                 dygraphOutput("cirrus_aggregate"),
                 includeMarkdown("./tab_documentation/fulltext_basic.md")
         ),
         tabItem(tabName = "morelike_search",
                 polloi::smooth_select("smoothing_morelike_search"),
+                div(id = "morelike_aggregate_legend", style = "text-align: 
right;"),
                 dygraphOutput("morelike_aggregate"),
                 includeMarkdown("./tab_documentation/morelike_basic.md")
         ),
         tabItem(tabName = "open_search",
                 polloi::smooth_select("smoothing_open_search"),
+                div(id = "open_aggregate_legend", style = "text-align: 
right;"),
                 dygraphOutput("open_aggregate"),
                 includeMarkdown("./tab_documentation/open_basic.md")
         ),
         tabItem(tabName = "geo_search",
                 polloi::smooth_select("smoothing_geo_search"),
+                div(id = "geo_aggregate_legend", style = "text-align: right;"),
                 dygraphOutput("geo_aggregate"),
                 includeMarkdown("./tab_documentation/geo_basic.md")
         ),
         tabItem(tabName = "prefix_search",
                 polloi::smooth_select("smoothing_prefix_search"),
+                div(id = "prefix_aggregate_legend", style = "text-align: 
right;"),
                 dygraphOutput("prefix_aggregate"),
                 includeMarkdown("./tab_documentation/prefix_basic.md")
         ),
         tabItem(tabName = "language_search",
                 polloi::smooth_select("smoothing_language_search"),
+                div(id = "language_aggregate_legend", style = "text-align: 
right;"),
                 dygraphOutput("language_aggregate"),
                 includeMarkdown("./tab_documentation/language_basic.md")
         ),
@@ -260,6 +267,7 @@
                   ),
                   column(polloi::smooth_select("smoothing_referer_breakdown"), 
width = 10)
                 ),
+                div(id = "referer_breakdown_plot_legend", style = "text-align: 
right;"),
                 dygraphOutput("referer_breakdown_plot"),
                 includeMarkdown("./tab_documentation/referer_breakdown.md")
         ),
diff --git a/utils.R b/utils.R
index 5a5cee8..27c4b0e 100644
--- a/utils.R
+++ b/utils.R
@@ -91,14 +91,21 @@
     dplyr::filter(!is.na(api), !is.na(referer_class), !is.na(calls)) %>%
     dplyr::distinct(date, api, referer_class, .keep_all = TRUE) %>%
     dplyr::arrange(api, date) %>%
-    dplyr::mutate(referer_class = forcats::fct_recode(
-      referer_class,
-      `None (direct)` = "none",
-      `Search engine` = "external (search engine)",
-      `External (but not search engine)` = "external",
-      Internal = "internal",
-      Unknown = "unknown"
-    )) %>%
+    dplyr::mutate(
+      referer_class = forcats::fct_recode(
+        referer_class,
+        `None (direct)` = "none",
+        `Search engine` = "external (search engine)",
+        `External (but not search engine)` = "external",
+        Internal = "internal",
+        Unknown = "unknown"
+      ),
+      api = forcats::fct_recode(
+        api,
+        `full-text via API` = "cirrus",
+        `morelike via API` = "cirrus (more like)"
+      )
+    ) %>%
     tidyr::spread(referer_class, calls) %>%
     dplyr::mutate(All = ifelse(is.na(All), rowSums(.[, -c(1, 2)], na.rm = 
TRUE), All)) %>%
     tidyr::gather(referrer, calls, -c(date, api)) %>%

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie03a33551afe50df10f33bd8f6c35095097b91c8
Gerrit-PatchSet: 2
Gerrit-Project: wikimedia/discovery/rainbow
Gerrit-Branch: develop
Gerrit-Owner: Chelsyx <c...@wikimedia.org>
Gerrit-Reviewer: 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