Просмотр исходного кода

HUE-2373 [search] Heatmap can break

Toggled visibility on Selected dimensions labels
Fixed problem with multibarChart when no data is available
Fixed problem with pieChart when the slices have value of 0
Enrico Berti 11 лет назад
Родитель
Сommit
83c7e3666a

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

@@ -852,7 +852,7 @@ ${ dashboard.layout_skeleton() }
     </div>
     </div>
 
 
     <div data-bind="with: $root.collection.getFacetById($parent.id())">
     <div data-bind="with: $root.collection.getFacetById($parent.id())">
-      <div class="dimensions-header margin-bottom-10">
+      <div class="dimensions-header margin-bottom-10" data-bind="visible: $root.isEditing() && $data.properties.facets().length > 0">
         <span class="muted">${ _('Selected dimensions') }</span>
         <span class="muted">${ _('Selected dimensions') }</span>
       </div>
       </div>
       <div data-bind="foreach: $data.properties.facets, visible: $root.isEditing">
       <div data-bind="foreach: $data.properties.facets, visible: $root.isEditing">
@@ -921,7 +921,7 @@ ${ dashboard.layout_skeleton() }
     </div>
     </div>
 
 
     <div data-bind="with: $root.collection.getFacetById($parent.id())">
     <div data-bind="with: $root.collection.getFacetById($parent.id())">
-      <div class="dimensions-header margin-bottom-10">
+      <div class="dimensions-header margin-bottom-10" data-bind="visible: $root.isEditing() && $data.properties.facets().length > 0">
         <span class="muted">${ _('Selected dimension') }</span>
         <span class="muted">${ _('Selected dimension') }</span>
       </div>
       </div>
       <div data-bind="foreach: $data.properties.facets, visible: $root.isEditing">
       <div data-bind="foreach: $data.properties.facets, visible: $root.isEditing">

+ 16 - 14
desktop/core/static/js/ko.charts.js

@@ -543,21 +543,23 @@ function barChartBuilder(element, options, isTimeline) {
             }
             }
           }).call(_chart);
           }).call(_chart);
 
 
-      $.each(options.fqs(), function (cnt, item) {
-        if (item.field() == options.field) {
-          _chart.selectBars($.map(item.filter(), function (it) {
-            return it.value();
-          }));
-        }
-        if (item.field().indexOf(":") > -1) {
-          _chart.selectBars({
-            field: item.field(),
-            selected: $.map(item.filter(), function (it) {
+      if (_chart.selectBars) {
+        $.each(options.fqs(), function (cnt, item) {
+          if (item.field() == options.field) {
+            _chart.selectBars($.map(item.filter(), function (it) {
               return it.value();
               return it.value();
-            })
-          });
-        }
-      });
+            }));
+          }
+          if (item.field().indexOf(":") > -1) {
+            _chart.selectBars({
+              field: item.field(),
+              selected: $.map(item.filter(), function (it) {
+                return it.value();
+              })
+            });
+          }
+        });
+      }
 
 
       nv.utils.windowResize(_chart.update);
       nv.utils.windowResize(_chart.update);
 
 

+ 54 - 36
desktop/core/static/js/nv.d3.growingPie.js

@@ -195,36 +195,38 @@ nv.models.growingPie = function() {
 
 
           pieLabels.enter().append("g").classed("nv-label",true)
           pieLabels.enter().append("g").classed("nv-label",true)
             .each(function(d,i) {
             .each(function(d,i) {
-                var group = d3.select(this);
-
-                group
-                  .attr('transform', function(d) {
-                       if (labelSunbeamLayout) {
-                         d.outerRadius = arcRadius + 10; // Set Outer Coordinate
-                         d.innerRadius = arcRadius + 15; // Set Inner Coordinate
-                         var rotateAngle = (d.startAngle + d.endAngle) / 2 * (180 / Math.PI);
-                         if ((d.startAngle+d.endAngle)/2 < Math.PI) {
-                           rotateAngle -= 90;
+                if (d.value > 0) {
+                  var group = d3.select(this);
+
+                  group
+                    .attr('transform', function(d) {
+                         if (labelSunbeamLayout) {
+                           d.outerRadius = arcRadius + 10; // Set Outer Coordinate
+                           d.innerRadius = arcRadius + 15; // Set Inner Coordinate
+                           var rotateAngle = (d.startAngle + d.endAngle) / 2 * (180 / Math.PI);
+                           if ((d.startAngle+d.endAngle)/2 < Math.PI) {
+                             rotateAngle -= 90;
+                           } else {
+                             rotateAngle += 90;
+                           }
+                           return 'translate(' + labelsArc.centroid(d) + ') rotate(' + rotateAngle + ')';
                          } else {
                          } else {
-                           rotateAngle += 90;
+                           d.outerRadius = radius + 10; // Set Outer Coordinate
+                           d.innerRadius = radius + 15; // Set Inner Coordinate
+                           return 'translate(' + labelsArc.centroid(d) + ')'
                          }
                          }
-                         return 'translate(' + labelsArc.centroid(d) + ') rotate(' + rotateAngle + ')';
-                       } else {
-                         d.outerRadius = radius + 10; // Set Outer Coordinate
-                         d.innerRadius = radius + 15; // Set Inner Coordinate
-                         return 'translate(' + labelsArc.centroid(d) + ')'
-                       }
-                  });
-
-                group.append('rect')
-                    .style('stroke', '#fff')
-                    .style('fill', '#fff')
-                    .attr("rx", 3)
-                    .attr("ry", 3);
-
-                group.append('text')
-                    .style('text-anchor', labelSunbeamLayout ? ((d.startAngle + d.endAngle) / 2 < Math.PI ? 'start' : 'end') : 'middle') //center the text on it's origin or begin/end if orthogonal aligned
-                    .style('fill', '#000')
+                    });
+
+                  group.append('rect')
+                      .style('stroke', '#fff')
+                      .style('fill', '#fff')
+                      .attr("rx", 3)
+                      .attr("ry", 3);
+
+                  group.append('text')
+                      .style('text-anchor', labelSunbeamLayout ? ((d.startAngle + d.endAngle) / 2 < Math.PI ? 'start' : 'end') : 'middle') //center the text on it's origin or begin/end if orthogonal aligned
+                      .style('fill', '#000')
+                }
 
 
             });
             });
 
 
@@ -237,6 +239,7 @@ nv.models.growingPie = function() {
           };
           };
           pieLabels.transition()
           pieLabels.transition()
                 .attr('transform', function(d) {
                 .attr('transform', function(d) {
+                if (d.value > 0) {
                   if (labelSunbeamLayout) {
                   if (labelSunbeamLayout) {
                       d.outerRadius = arcRadius + 10; // Set Outer Coordinate
                       d.outerRadius = arcRadius + 10; // Set Outer Coordinate
                       d.innerRadius = arcRadius + 15; // Set Inner Coordinate
                       d.innerRadius = arcRadius + 15; // Set Inner Coordinate
@@ -264,17 +267,32 @@ nv.models.growingPie = function() {
                       labelLocationHash[createHashKey(center)] = true;
                       labelLocationHash[createHashKey(center)] = true;
                       return 'translate(' + center + ')'
                       return 'translate(' + center + ')'
                     }
                     }
+                  }
                 });
                 });
           pieLabels.select(".nv-label text")
           pieLabels.select(".nv-label text")
-                .style('text-anchor', labelSunbeamLayout ? ((d.startAngle + d.endAngle) / 2 < Math.PI ? 'start' : 'end') : 'middle') //center the text on it's origin or begin/end if orthogonal aligned
+                .style('text-anchor', function(d){
+                  if (d.value > 0) {
+                    if (labelSunbeamLayout) {
+                      return ((d.startAngle + d.endAngle) / 2 < Math.PI ? 'start' : 'end'); //center the text on it's origin or begin/end if orthogonal aligned
+                    }
+                    else {
+                       return 'middle';
+                    }
+                  }
+                })
                 .text(function(d, i) {
                 .text(function(d, i) {
-                  var percent = (d.endAngle - d.startAngle) / (2 * Math.PI);
-                  var labelTypes = {
-                    "key" : getX(d.data),
-                    "value": getY(d.data),
-                    "percent": d3.format('%')(percent)
-                  };
-                  return (d.value && percent > labelThreshold) ? labelTypes[labelType] : '';
+                  if (d.value > 0) {
+                    var percent = (d.endAngle - d.startAngle) / (2 * Math.PI);
+                    var labelTypes = {
+                      "key": getX(d.data),
+                      "value": getY(d.data),
+                      "percent": d3.format('%')(percent)
+                    };
+                    return (d.value && percent > labelThreshold) ? labelTypes[labelType] : '';
+                  }
+                  else {
+                    return '';
+                  }
                 });
                 });
         }
         }
 
 

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

@@ -268,7 +268,6 @@ nv.models.multiBarWithBrushChart = function() {
 
 
       selectBars = multibar.selectBars;
       selectBars = multibar.selectBars;
 
 
-
       var dataBars = data.filter(function(d) { return !d.disabled && d.bar });
       var dataBars = data.filter(function(d) { return !d.disabled && d.bar });
       var barsWrap = g.select('.nv-barsWrap')
       var barsWrap = g.select('.nv-barsWrap')
           .datum(data.filter(function(d) { return !d.disabled }))
           .datum(data.filter(function(d) { return !d.disabled }))
@@ -685,7 +684,9 @@ nv.models.multiBarWithBrushChart = function() {
 
 
   chart.selectBars = function(args) {
   chart.selectBars = function(args) {
     if (!arguments.length) return selectBars;
     if (!arguments.length) return selectBars;
-    selectBars(args);
+    if (selectBars) {
+      selectBars(args);
+    }
     return chart;
     return chart;
   };
   };