11/* global Layout:true */
2- KityMinder . registerLayout ( 'filetree' , kity . createClass ( {
3- base : Layout ,
4-
5- doLayout : function ( parent , children ) {
6- var pBox = parent . getContentBox ( ) ;
7- var indent = 20 ;
8-
9- parent . setVertexOut ( new kity . Point ( pBox . left + indent , pBox . bottom ) ) ;
10- parent . setLayoutVectorOut ( new kity . Vector ( 0 , 1 ) ) ;
11-
12- if ( ! children . length ) return ;
13-
14- children . forEach ( function ( child ) {
15- var cbox = child . getContentBox ( ) ;
16- child . setLayoutTransform ( new kity . Matrix ( ) ) ;
17-
18- child . setVertexIn ( new kity . Point ( cbox . left , cbox . cy ) ) ;
19- child . setLayoutVectorIn ( new kity . Vector ( 1 , 0 ) ) ;
20- } ) ;
21-
22- this . align ( children , 'left' ) ;
23- this . stack ( children , 'y' ) ;
24-
25- var xAdjust = 0 ;
26- xAdjust += pBox . left ;
27- xAdjust += indent ;
28- xAdjust += children [ 0 ] . getStyle ( 'margin-left' ) ;
29- var yAdjust = 0 ;
30- yAdjust += pBox . bottom ;
31- yAdjust += parent . getStyle ( 'margin-bottom' ) ;
32- yAdjust += children [ 0 ] . getStyle ( 'margin-top' ) ;
33-
34- this . move ( children , xAdjust , yAdjust ) ;
35-
36- } ,
37-
38- getOrderHint : function ( node ) {
39- var hint = [ ] ;
40- var box = node . getLayoutBox ( ) ;
41- var offset = node . getLevel ( ) > 1 ? 3 : 5 ;
42-
43- hint . push ( {
44- type : 'up' ,
45- node : node ,
46- area : {
47- x : box . x ,
48- y : box . top - node . getStyle ( 'margin-top' ) - offset ,
49- width : box . width ,
50- height : node . getStyle ( 'margin-top' )
51- } ,
52- path : [ 'M' , box . x , box . top - offset , 'L' , box . right , box . top - offset ]
53- } ) ;
54-
55- hint . push ( {
56- type : 'down' ,
57- node : node ,
58- area : {
59- x : box . x ,
60- y : box . bottom + offset ,
61- width : box . width ,
62- height : node . getStyle ( 'margin-bottom' )
63- } ,
64- path : [ 'M' , box . x , box . bottom + offset , 'L' , box . right , box . bottom + offset ]
65- } ) ;
66- return hint ;
67- }
68- } ) ) ;
2+
3+ [ - 1 , 1 ] . forEach ( function ( dir ) {
4+ var name = 'filetree-' + ( dir > 0 ? 'down' : 'up' ) ;
5+
6+ KityMinder . registerLayout ( name , kity . createClass ( {
7+ base : Layout ,
8+
9+ doLayout : function ( parent , children , round ) {
10+ var pBox = parent . getContentBox ( ) ;
11+ var indent = 20 ;
12+
13+ parent . setVertexOut ( new kity . Point ( pBox . left + indent , dir > 0 ? pBox . bottom : pBox . top ) ) ;
14+ parent . setLayoutVectorOut ( new kity . Vector ( 0 , dir ) ) ;
15+
16+ if ( ! children . length ) return ;
17+
18+ children . forEach ( function ( child ) {
19+ var cbox = child . getContentBox ( ) ;
20+ child . setLayoutTransform ( new kity . Matrix ( ) ) ;
21+
22+ child . setVertexIn ( new kity . Point ( cbox . left , cbox . cy ) ) ;
23+ child . setLayoutVectorIn ( new kity . Vector ( 1 , 0 ) ) ;
24+ } ) ;
25+
26+ this . align ( children , 'left' ) ;
27+ this . stack ( children , 'y' ) ;
28+
29+ var xAdjust = 0 ;
30+ xAdjust += pBox . left ;
31+ xAdjust += indent ;
32+ xAdjust += children [ 0 ] . getStyle ( 'margin-left' ) ;
33+
34+ var yAdjust = 0 ;
35+
36+ if ( dir > 0 ) {
37+ yAdjust += pBox . bottom ;
38+ yAdjust += parent . getStyle ( 'margin-bottom' ) ;
39+ yAdjust += children [ 0 ] . getStyle ( 'margin-top' ) ;
40+ } else {
41+ yAdjust -= this . getTreeBox ( children ) . bottom ;
42+ yAdjust += pBox . top ;
43+ yAdjust -= parent . getStyle ( 'margin-top' ) ;
44+ yAdjust -= children [ 0 ] . getStyle ( 'margin-bottom' ) ;
45+ }
46+
47+ this . move ( children , xAdjust , yAdjust ) ;
48+
49+ } ,
50+
51+ getOrderHint : function ( node ) {
52+ var hint = [ ] ;
53+ var box = node . getLayoutBox ( ) ;
54+ var offset = node . getLevel ( ) > 1 ? 3 : 5 ;
55+
56+ hint . push ( {
57+ type : 'up' ,
58+ node : node ,
59+ area : {
60+ x : box . x ,
61+ y : box . top - node . getStyle ( 'margin-top' ) - offset ,
62+ width : box . width ,
63+ height : node . getStyle ( 'margin-top' )
64+ } ,
65+ path : [ 'M' , box . x , box . top - offset , 'L' , box . right , box . top - offset ]
66+ } ) ;
67+
68+ hint . push ( {
69+ type : 'down' ,
70+ node : node ,
71+ area : {
72+ x : box . x ,
73+ y : box . bottom + offset ,
74+ width : box . width ,
75+ height : node . getStyle ( 'margin-bottom' )
76+ } ,
77+ path : [ 'M' , box . x , box . bottom + offset , 'L' , box . right , box . bottom + offset ]
78+ } ) ;
79+ return hint ;
80+ }
81+ } ) ) ;
82+
83+ } ) ;
0 commit comments