Pārlūkot izejas kodu

HUE-5179 [search] Timeline search is not working after the first select

Enrico Berti 9 gadi atpakaļ
vecāks
revīzija
592dfc5604

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

@@ -158,7 +158,8 @@ def _compute_range_facet(widget_type, stat_facet, properties, start=None, end=No
 
     if widget_type == 'histogram-widget':
       properties.update({
-        'timelineChartType': 'bar'
+        'timelineChartType': 'bar',
+        'enableSelection': True
       })
 
 

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

@@ -296,6 +296,8 @@ class Collection(models.Model):
       if facet['widgetType'] == 'histogram-widget':
         if 'timelineChartType' not in properties:
           properties['timelineChartType'] = 'bar'
+        if 'enableSelection' not in properties:
+          properties['enableSelection'] = True
         if 'extraSeries' not in properties:
           properties['extraSeries'] = []
 
@@ -517,6 +519,8 @@ class Collection2(object):
       if facet['widgetType'] == 'histogram-widget':
         if 'timelineChartType' not in properties:
           properties['timelineChartType'] = 'bar'
+        if 'enableSelection' not in properties:
+          properties['enableSelection'] = True
         if 'extraSeries' not in properties:
           properties['extraSeries'] = []
 

+ 2 - 2
apps/search/src/search/templates/common_search.mako

@@ -1408,11 +1408,11 @@ ${ dashboard.layout_skeleton() }
     </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,
+      <div data-bind="timelineChart: {datum: {counts: counts(), extraSeries: extraSeries(), widget_id: $parent.id(), label: label()}, stacked: $root.collection.getFacetById($parent.id()).properties.stacked(), enableSelection: $root.collection.getFacetById($parent.id()).properties.enableSelection(), 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); },
+        onStateChange: function(state){ $root.collection.getFacetById($parent.id()).properties.stacked(state.stacked); $root.collection.getFacetById($parent.id()).properties.enableSelection(state.selectionEnabled); },
         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) }}" />
     <!-- /ko -->

+ 19 - 2
desktop/core/src/desktop/static/desktop/js/ko.charts.js

@@ -278,6 +278,17 @@
       var _chart = $(element).data("chart");
       if (_chart) {
         window.setTimeout(function () {
+          _chart.multibar.stacked(typeof _options.stacked != "undefined" ? _options.stacked : false);
+          var enableSelection = true;
+          if (typeof _options.enableSelection !== 'undefined') {
+            enableSelection = _options.enableSelection;
+          }
+          if (_datum.length > 0 && _datum[0].values.length > 10 && enableSelection) {
+            _chart.enableSelection();
+          }
+          else {
+            _chart.disableSelection();
+          }
           var _d3 = d3.select($(element).find("svg")[0]);
           _d3.datum(_datum)
             .transition().duration(150)
@@ -289,7 +300,6 @@
           _d3.selectAll("g.nv-x.nv-axis g text").each(function (d) {
             insertLinebreaks(d, this);
           });
-          _d3.selectAll(".nv-brush").call(_chart.brush().clear());
           if (_chart.selectBars) {
             var _field = (typeof _options.field == "function") ? _options.field() : _options.field;
             $.each(_options.fqs(), function (cnt, item) {
@@ -1093,9 +1103,16 @@
           }
           _chart = nv.models.multiBarWithBrushChart();
           $(element).data('chart_type', 'multibar_brush');
-          if (_datum.length > 0 && _datum[0].values.length > 10) {
+          var enableSelection = true;
+          if (typeof options.enableSelection !== 'undefined') {
+            enableSelection = options.enableSelection;
+          }
+          if (_datum.length > 0 && _datum[0].values.length > 10 && enableSelection) {
             _chart.enableSelection();
           }
+          else {
+            _chart.disableSelection();
+          }
           if (_hideSelection) {
             _chart.hideSelection();
           }

+ 2 - 1
desktop/core/src/desktop/static/desktop/js/nv.d3.multiBarWithBrushChart.js

@@ -54,7 +54,7 @@ nv.models.multiBarWithBrushChart = function() {
       }
     , x //can be accessed via chart.xScale()
     , y //can be accessed via chart.yScale()
-    , state = { stacked: false }
+    , state = { stacked: false, selectionEnabled: false }
     , defaultState = null
     , noData = "No Data Available."
     , dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState', 'brush')
@@ -450,6 +450,7 @@ nv.models.multiBarWithBrushChart = function() {
         }
 
         state.stacked = multibar.stacked();
+        state.selectionEnabled = selectionEnabled;
         if (onStateChange != null) {
           onStateChange(state);
         }