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

Change subject: Implement showLastDays option on tab layout
......................................................................


Implement showLastDays option on tab layout

If specified, showLastDays will limit the graph to show at most the
integer number of days provided.  If not specified, it defaults to
values configured in tabs.js, namely 35 days for pie charts and all time
for other graphs.  Legal values are "all" or any integer.

Bug: T160796
Change-Id: I3546ab374f7723b4348a337338a8fe50014c238c
---
M src/components/layouts/tabs/tabs.js
M src/components/visualizers/visualizer/visualizer.js
2 files changed, 27 insertions(+), 13 deletions(-)

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



diff --git a/src/components/layouts/tabs/tabs.js 
b/src/components/layouts/tabs/tabs.js
index 3f0edc8..46b04cf 100644
--- a/src/components/layouts/tabs/tabs.js
+++ b/src/components/layouts/tabs/tabs.js
@@ -16,6 +16,15 @@
         return g && g.id && g.title;
     }
 
+    var visualizers = {
+        'sunburst'              : { defaultDays: 35, icon: 'pie' },
+        'stacked-bars'          : { defaultDays: 35, icon: 'bar' },
+        'dygraphs-timeseries'   : { defaultDays: 'all', icon: 'line' },
+        'table-timeseries'      : { defaultDays: 'all', icon: 'table' },
+    };
+    // these two graphs work the same
+    visualizers.hierarchy = visualizers.sunburst;
+
     function TabsLayout() {
 
         this.config = ko.observable({});
@@ -55,16 +64,12 @@
                         return g === dashboard.selectedGraph();
                     });
 
+                    g.showLastDays = g.showLastDays || 
visualizers[g.type].defaultDays;
+
                     if (t.dataRange) {
                         g.startDate = t.dataRange.startDate;
                     }
-                    // TODO: define this kind of property on the visualizers 
themselves
-                    // and just reference here by looking up e.g. 
visualizers[g.type].typeIcon
-                    g.typeIcon =
-                        (g.type === 'sunburst' || g.type === 'hierarchy') ? 
'pie' :
-                        g.type === 'stacked-bars' ? 'bar' :
-                        g.type === 'dygraphs-timeseries' ? 'line' :
-                        g.type === 'table-timeseries' ? 'table' : '';
+                    g.typeIcon = visualizers[g.type].icon;
 
                     // Fetch annotations if present
                     var annotationsInfo = g.annotations;
diff --git a/src/components/visualizers/visualizer/visualizer.js 
b/src/components/visualizers/visualizer/visualizer.js
index 4abf9b0..53cd529 100644
--- a/src/components/visualizers/visualizer/visualizer.js
+++ b/src/components/visualizers/visualizer/visualizer.js
@@ -12,6 +12,8 @@
 
     require('knockout.datepicker');
 
+    var dateFormat = 'YYYY-MM-DD';
+
     function Visualizer(params) {
         var apiType = params.aqs? 'aqsApi' : 'datasets';
         var api = apiFinder({
@@ -52,21 +54,28 @@
                 this.data(data);
             }.bind(this));
 
-
         } else {
             api.getData(graph, ['all']).done(this.data);
         }
 
-
-
-        this.startDate = ko.observable(graph.startDate);
-        this.minDate = ko.observable(graph.startDate);
+        graph.minDate = graph.startDate;
+        if (graph.showLastDays) {
+            var days = parseInt(graph.showLastDays, 10) || 0;
+            if (days > 0) {
+                var earliestDate = moment().add(-1 * days, 
'days').format(dateFormat);
+                if (graph.startDate < earliestDate) {
+                    graph.startDate = earliestDate;
+                }
+            }
+        }
+        this.startDate = ko.observable(moment(graph.startDate).valueOf());
+        this.minDate = ko.observable(moment(graph.minDate).valueOf());
         this.endDate = ko.observable();
 
         /** If date is a unix tiemstamp change it to ISO format **/
         this.prettyDate = function (value) {
             if (Number.isInteger(value())) {
-                return moment(value()).format('YYYY-MM-DD');
+                return moment(value()).format(dateFormat);
             }
             return value;
         };

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I3546ab374f7723b4348a337338a8fe50014c238c
Gerrit-PatchSet: 2
Gerrit-Project: analytics/dashiki
Gerrit-Branch: master
Gerrit-Owner: Milimetric <[email protected]>
Gerrit-Reviewer: Fdans <[email protected]>
Gerrit-Reviewer: Milimetric <[email protected]>
Gerrit-Reviewer: Nuria <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to