浏览代码

HUE-5116 [search] Add analytics timeline to the widget

Romain Rigaux 9 年之前
父节点
当前提交
fe293b3

+ 3 - 0
apps/search/src/search/models.py

@@ -837,6 +837,9 @@ def augment_solr_response(response, collection, query):
           dimension = 3
           # Single dimension or dimension 2 with analytics
           if not collection_facet['properties']['facets'] or collection_facet['properties']['facets'][0]['aggregate']['function'] != 'count':
+            agg_keys = ['count']
+            _augment_stats_2d(name, facet, counts, selected_values, agg_keys, rows)
+
             counts = [_v for _f in counts for _v in (_f['val'], _f['d2'] if 'd2' in _f else _f['count'])]
             counts = range_pair(facet['field'], name, selected_values.get(facet['id'], []), counts, 1, collection_facet)
           else:

+ 4 - 1
apps/search/src/search/static/search/js/search.ko.js

@@ -665,7 +665,10 @@ var Collection = function (vm, collection) {
       });
       
       facet.template.chartSettings.chartType.subscribe(function(newValue) {
-        facet.widgetType(newValue == ko.HUE_CHARTS.TYPES.PIECHART ? 'pie2-widget' : 'bucket-widget');
+        facet.widgetType(
+            newValue == ko.HUE_CHARTS.TYPES.PIECHART ? 'pie2-widget' :
+            (newValue == ko.HUE_CHARTS.TYPES.TIMELINECHART ? 'timeline-widget' : 'bucket-widget')
+        );
       });
     }
   }

+ 30 - 17
apps/search/src/search/templates/common_search.mako

@@ -1291,7 +1291,8 @@ ${ dashboard.layout_skeleton() }
 
   <!-- ko if: $root.getFacetFromQuery(id()).has_data() -->
   <div class="row-fluid" data-bind="with: $root.getFacetFromQuery(id())">
-    <div data-bind="with: $root.collection.getFacetById($parent.id())" style="margin-bottom: 20px">
+    <!-- ko with: $root.collection.getFacetById($parent.id()) -->
+    <div style="margin-bottom: 20px">
       <span data-bind="template: { name: 'facet-toggle2' }"></span>
     </div>
 
@@ -1316,16 +1317,8 @@ ${ dashboard.layout_skeleton() }
       <select class="input-medium" data-bind="visible: $root.query.multiqs().length > 1, options: $root.query.multiqs, optionsValue: 'id', optionsText: 'label', value: $root.query.selectedMultiq"></select>
     </div>
 
-    <!-- ko if: $root.collection.getFacetById($parent.id()) -->
-      <div data-bind="timelineChart: {datum: {counts: counts(), extraSeries: extraSeries(), widget_id: $parent.id(), label: label()}, stacked: $root.collection.getFacetById($parent.id()).properties.stacked(), field: field, label: label(), transformer: timelineChartDataTransformer,
-        type: $root.collection.getFacetById($parent.id()).properties.timelineChartType,
-        fqs: $root.query.fqs,
-        onSelectRange: function(from, to){ $root.collection.selectTimelineFacet({from: from, to: to, cat: field, widget_id: $parent.id()}) },
-        onStateChange: function(state){ $root.collection.getFacetById($parent.id()).properties.stacked(state.stacked); },
-        onClick: function(d){ $root.query.selectRangeFacet({count: d.obj.value, widget_id: $parent.id(), from: d.obj.from, to: d.obj.to, cat: d.obj.field}) },
-        onComplete: function(){ $root.getWidgetById($parent.id()).isLoading(false) }}" />
-      <div class="clearfix"></div>
-    <!-- /ko -->
+    <span data-bind="template: { name: 'data-grid' }"></span>
+  <!-- /ko -->
   </div>
   <!-- /ko -->
 </script>
@@ -1395,12 +1388,10 @@ ${ dashboard.layout_skeleton() }
           <a class="grid-side-btn" style="padding-right:0" href="javascript:void(0)"
              data-bind="css: {'active': template.showChart() }, click: function(){ template.showChart(true); template.showGrid(false); huePubSub.publish('gridChartForceUpdate'); }">
             <i class="hcha hcha-bar-chart fa-fw" data-bind="visible: template.chartSettings.chartType() == ko.HUE_CHARTS.TYPES.BARCHART"></i>
-            <i class="hcha hcha-line-chart fa-fw" data-bind="visible: template.chartSettings.chartType() == ko.HUE_CHARTS.TYPES.LINECHART"
-               style="display: none;"></i>
-            <i class="hcha hcha-pie-chart fa-fw" data-bind="visible: template.chartSettings.chartType() == ko.HUE_CHARTS.TYPES.PIECHART"
-               style="display: none;"></i>
-            <i class="fa fa-fw fa-map-marker" data-bind="visible: template.chartSettings.chartType() == ko.HUE_CHARTS.TYPES.MAP"
-               style="display: none;"></i>
+            <i class="hcha hcha-line-chart fa-fw" data-bind="visible: template.chartSettings.chartType() == ko.HUE_CHARTS.TYPES.LINECHART" style="display: none;"></i>
+            <i class="hcha hcha-pie-chart fa-fw" data-bind="visible: template.chartSettings.chartType() == ko.HUE_CHARTS.TYPES.PIECHART" style="display: none;"></i>
+            <i class="fa fa-fw fa-line-chart" data-bind="visible: template.chartSettings.chartType() == ko.HUE_CHARTS.TYPES.TIMELINECHART" style="display: none;"></i>
+            <i class="fa fa-fw fa-map-marker" data-bind="visible: template.chartSettings.chartType() == ko.HUE_CHARTS.TYPES.MAP" style="display: none;"></i>
           </a>
           <a class="dropdown-toggle grid-side-btn" style="padding:0" data-toggle="dropdown"
              href="javascript: void(0)" data-bind="css: {'active': template.showChart()}">
@@ -1427,6 +1418,14 @@ ${ dashboard.layout_skeleton() }
                 <i class="hcha hcha-pie-chart fa-fw"></i> ${_('Pie')}
               </a>
             </li>
+            <!-- ko if: widgetType() != 'resultset-widget' -->
+            <li>
+              <a href="javascript:void(0)"
+                 data-bind="css: {'active': template.chartSettings.chartType() == ko.HUE_CHARTS.TYPES.TIMELINECHART}, click: function(){ template.showChart(true); template.chartSettings.chartType(ko.HUE_CHARTS.TYPES.TIMELINECHART); template.showGrid(false); huePubSub.publish('gridChartForceUpdate');}">
+                <i class="fa fa-fw fa-line-chart"></i> ${_('timeline')}
+              </a>
+            </li>
+            <!-- /ko -->
             <li>
               <a href="javascript:void(0)"
                  data-bind="css: {'active': template.chartSettings.chartType() == ko.HUE_CHARTS.TYPES.MAP}, click: function(){ template.showChart(true); template.chartSettings.chartType(ko.HUE_CHARTS.TYPES.MAP); template.showGrid(false); huePubSub.publish('gridChartForceUpdate');}">
@@ -1620,6 +1619,20 @@ ${ dashboard.layout_skeleton() }
          <!-- /ko -->               
 
 
+    <!-- ko if: widgetType() == 'timeline-widget' -->
+      <!-- ko with: $parent -->
+      <div data-bind="timelineChart: {datum: {counts: counts(), extraSeries: extraSeries(), widget_id: $parent.id(), label: label()}, stacked: $root.collection.getFacetById($parent.id()).properties.stacked(), field: field, label: label(), transformer: timelineChartDataTransformer,
+        type: $root.collection.getFacetById($parent.id()).properties.timelineChartType,
+        fqs: $root.query.fqs,
+        onSelectRange: function(from, to){ $root.collection.selectTimelineFacet({from: from, to: to, cat: field, widget_id: $parent.id()}) },
+        onStateChange: function(state){ $root.collection.getFacetById($parent.id()).properties.stacked(state.stacked); },
+        onClick: function(d){ $root.query.selectRangeFacet({count: d.obj.value, widget_id: $parent.id(), from: d.obj.from, to: d.obj.to, cat: d.obj.field}) },
+        onComplete: function(){ $root.getWidgetById($parent.id()).isLoading(false) }}" />
+      <div class="clearfix"></div>
+      <!-- /ko -->
+    <!-- /ko -->
+
+
     <!-- ko if: widgetType() == 'pie2-widget' -->
       <!-- ko if: type() == 'range' -->
       <div data-bind="pieChart: {data: {counts: $parent.counts(), widget_id: $parent.id()}, field: field, fqs: $root.query.fqs,

+ 2 - 1
apps/search/src/search/views.py

@@ -579,6 +579,7 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
   elif widget_type == 'gradient-map-widget':
     facet_type = 'nested'
     properties['facets'] = []
+    properties['domain'] = {'blockParent': [], 'blockChildren': []}
     properties['facets_form'] = {'field': '', 'mincount': 1, 'limit': 10, 'aggregate': 'count'}
     properties['scope'] = 'world'
     properties['limit'] = 100
@@ -642,7 +643,7 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
         "showGrid": False,
         "showChart": True,
         "chartSettings" : {
-          'chartType': 'bars', # Depends on widget type
+          'chartType': 'pie' if widget_type == 'pie2-widget' else ('timeline' if widget_type == 'timeline-widget' else 'bars'),
           'chartSorting': 'none',
           'chartScatterGroup': None,
           'chartScatterSize': None,