Commits

jeremy goecks  committed 501641b

Add utility function to circster that determines whether an element is visible.

  • Participants
  • Parent commits b7fdcf8

Comments (0)

Files changed (1)

File static/scripts/viz/circster.js

 // General backbone style inheritence
 var Base = function() { this.initialize && this.initialize.apply(this, arguments); }; Base.extend = Backbone.Model.extend;
 
+var SVGUtils = Backbone.Model.extend({
+
+    /**
+     * Returns true if element is visible.
+     */
+    is_visible: function(svg_elt, svg) {
+        var eltBRect = svg_elt.getBoundingClientRect(),
+            svgBRect = $('svg')[0].getBoundingClientRect();
+
+        if (// To the left of screen?
+            eltBRect.right < 0 ||
+            // To the right of screen?
+            eltBRect.left > svgBRect.right ||
+            // Above screen?
+            eltBRect.bottom < 0 || 
+            // Below screen?
+            eltBRect.top > svgBRect.bottom) {
+            return false;
+        }
+        return true;
+    }
+
+});
+
 /**
- * Renders a full circster visualization
+ * Renders a full circster visualization.
  */ 
 var CircsterView = Backbone.View.extend({
     className: 'circster',
             height = self.$el.height(),
             // Compute radius start based on model, will be centered 
             // and fit entirely inside element by default
-            init_radius_start = ( Math.min(width,height)/2 - 
+            init_radius_start = ( Math.min(width, height)/2 - 
                                   this.model.get('tracks').length * (this.dataset_arc_height + this.track_gap) );
 
         // Set up SVG element.
                     svg.attr("transform",
                       "translate(" + d3.event.translate + ")" + 
                       " scale(" + d3.event.scale + ")");
+                    var utils = new SVGUtils();
+                    var visible_elts = d3.selectAll('path').filter(function(d, i) {
+                        return utils.is_visible(this, svg);
+                    });
+                    visible_elts.each(function(d, i) {
+                        console.log(this.attr('title'));
+                    });
                 }))
                 .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")")
               .append('svg:g');
                 total_gap: self.total_gap
             });
 
-            track_renderer.render( svg );
+            track_renderer.render(svg);
 
         });
     }