1+ Layouts . Grid = new Class ( {
2+ compute : function ( prop ) {
3+ this . controller . onBeforeCompute ( ) ;
4+ var size = this . canvas . getSize ( ) ,
5+ config = this . config ,
6+ margin = config . margin ,
7+ width = size . width - margin . left - margin . right ,
8+ height = size . height - margin . top - margin . bottom ,
9+ legendX = this . getLegendX ( ) ,
10+ legendY = this . getLegendY ( ) ,
11+ elemWidth = width / legendX . length ,
12+ elemHeight = height / legendY . length ;
13+ this . graph . eachNode ( function ( n ) {
14+ var x = $ . indexOf ( legendX , n . getData ( 'legendX' ) || 0 ) * elemWidth - size . width / 2 + margin . left ,
15+ y = $ . indexOf ( legendY , n . getData ( 'legendY' ) || 0 ) * elemHeight - size . height / 2 + margin . top ;
16+ n . getPos ( prop ) . setc ( x , y ) ;
17+ n . setData ( 'width' , elemWidth ) ;
18+ n . setData ( 'height' , elemHeight ) ;
19+ } ) ;
20+ this . controller . onAfterCompute ( ) ;
21+ } ,
22+
23+ _get : function ( prop ) {
24+ var config = this . config ;
25+ if ( config [ prop ] && config [ prop ] . length ) {
26+ return config [ prop ] ;
27+ }
28+ var ans = [ ] ;
29+ this . graph . eachNode ( function ( n ) {
30+ var leg = n . getData ( prop ) ;
31+ if ( $ . indexOf ( ans , leg ) < 0 ) {
32+ ans . push ( leg ) ;
33+ }
34+ } ) ;
35+ return ans ;
36+ } ,
37+
38+ getLegendX : function ( ) {
39+ return this . _get ( 'legendX' ) ;
40+ } ,
41+
42+ getLegendY : function ( ) {
43+ return this . _get ( 'legendY' ) ;
44+ }
45+ } ) ;
0 commit comments