Flat, round, designer-friendly pseudo-3D engine for canvas & SVG
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 68 lines 1.5 kB view raw
1/** 2 * Group 3 */ 4 5( function( root, factory ) { 6 // module definition 7 if ( typeof module == 'object' && module.exports ) { 8 // CommonJS 9 module.exports = factory( require('./anchor') ); 10 } else { 11 // browser global 12 var Zdog = root.Zdog; 13 Zdog.Group = factory( Zdog.Anchor ); 14 } 15}( this, function factory( Anchor ) { 16 17var Group = Anchor.subclass({ 18 updateSort: false, 19 visible: true, 20}); 21 22Group.type = 'Group'; 23 24 25// ----- update ----- // 26 27Group.prototype.updateSortValue = function() { 28 var sortValueTotal = 0; 29 this.flatGraph.forEach( function( item ) { 30 item.updateSortValue(); 31 sortValueTotal += item.sortValue; 32 } ); 33 // average sort value of all points 34 // def not geometrically correct, but works for me 35 this.sortValue = sortValueTotal / this.flatGraph.length; 36 37 if ( this.updateSort ) { 38 this.flatGraph.sort( Anchor.shapeSorter ); 39 } 40}; 41 42// ----- render ----- // 43 44Group.prototype.render = function( ctx, renderer ) { 45 if ( !this.visible ) { 46 return; 47 } 48 49 this.flatGraph.forEach( function( item ) { 50 item.render( ctx, renderer ); 51 } ); 52}; 53 54// actual group flatGraph only used inside group 55Group.prototype.updateFlatGraph = function() { 56 // do not include self 57 var flatGraph = []; 58 this.flatGraph = this.addChildFlatGraph( flatGraph ); 59}; 60 61// do not include children, group handles rendering & sorting internally 62Group.prototype.getFlatGraph = function() { 63 return [ this ]; 64}; 65 66return Group; 67 68} ) );