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.

๐Ÿž fix adding/removing to graph. #21

+ add updateFlatGraph to updateGraph
+ add custom getter/setter for flatGraph, to remove checkFlatGraph
+ refactor flatGraph array
+ add addChildFlatGraph

+25 -22
+18 -8
js/anchor.js
··· 110 110 111 111 Anchor.prototype.updateGraph = function() { 112 112 this.update(); 113 - this.checkFlatGraph(); 113 + this.updateFlatGraph(); 114 114 this.flatGraph.forEach( function( item ) { 115 115 item.updateSortValue(); 116 116 }); ··· 122 122 return a.sortValue - b.sortValue; 123 123 }; 124 124 125 - Anchor.prototype.checkFlatGraph = function() { 126 - if ( !this.flatGraph ) { 127 - this.updateFlatGraph(); 128 - } 129 - }; 125 + // custom getter to check for flatGraph before using it 126 + Object.defineProperty( Anchor.prototype, 'flatGraph', { 127 + get: function() { 128 + if ( !this._flatGraph ) { 129 + this.updateFlatGraph(); 130 + } 131 + return this._flatGraph; 132 + }, 133 + set: function( graph ) { 134 + this._flatGraph = graph; 135 + }, 136 + }); 130 137 131 138 Anchor.prototype.updateFlatGraph = function() { 132 139 this.flatGraph = this.getFlatGraph(); ··· 135 142 // return Array of self & all child graph items 136 143 Anchor.prototype.getFlatGraph = function() { 137 144 var flatGraph = [ this ]; 145 + return this.addChildFlatGraph( flatGraph ); 146 + }; 147 + 148 + Anchor.prototype.addChildFlatGraph = function( flatGraph ) { 138 149 this.children.forEach( function( child ) { 139 150 var childFlatGraph = child.getFlatGraph(); 140 - flatGraph = flatGraph.concat( childFlatGraph ); 151 + Array.prototype.push.apply( flatGraph, childFlatGraph ); 141 152 }); 142 153 return flatGraph; 143 154 }; ··· 156 167 throw new Error( 'ctx is ' + ctx + '. ' + 157 168 'Canvas context required for render. Check .renderGraphCanvas( ctx ).' ); 158 169 } 159 - this.checkFlatGraph(); 160 170 this.flatGraph.forEach( function( item ) { 161 171 item.render( ctx, CanvasRenderer ); 162 172 });
+7 -14
js/group.js
··· 23 23 24 24 Group.prototype.updateSortValue = function() { 25 25 var sortValueTotal = 0; 26 - this.checkFlatGraph(); 27 26 this.flatGraph.forEach( function( item ) { 28 27 item.updateSortValue(); 29 28 sortValueTotal += item.sortValue; ··· 44 43 return; 45 44 } 46 45 47 - this.checkFlatGraph(); 48 46 this.flatGraph.forEach( function( item ) { 49 47 item.render( ctx, renderer ); 50 48 }); 51 49 }; 52 50 51 + // actual group flatGraph only used inside group 52 + Group.prototype.updateFlatGraph = function() { 53 + // do not include self 54 + var flatGraph = []; 55 + this.flatGraph = this.addChildFlatGraph( flatGraph ); 56 + }; 57 + 53 58 // do not include children, group handles rendering & sorting internally 54 59 Group.prototype.getFlatGraph = function() { 55 60 return [ this ]; 56 - }; 57 - 58 - // get flat graph only used for group 59 - // do not include in parent flatGraphs 60 - Group.prototype.updateFlatGraph = function() { 61 - // do not include self 62 - var flatGraph = []; 63 - this.children.forEach( function( child ) { 64 - var childFlatGraph = child.getFlatGraph(); 65 - flatGraph = flatGraph.concat( childFlatGraph ); 66 - }); 67 - this.flatGraph = flatGraph; 68 61 }; 69 62 70 63 return Group;