@@ -53,6 +53,38 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
5353 this . pushSelectingStep ( 'deselect' , 'col' , arguments ) ;
5454 return this ;
5555 } ,
56+ _separate : function ( x , y ) {
57+ this . manager . pushStep ( this . capsule , {
58+ type : 'separate' ,
59+ x : x ,
60+ y : y
61+ } ) ;
62+ return this ;
63+ } ,
64+ _separateRow : function ( x ) {
65+ this . _separate ( x , - 1 ) ;
66+ return this ;
67+ } ,
68+ _separateCol : function ( y ) {
69+ this . _separate ( - 1 , y ) ;
70+ return this ;
71+ } ,
72+ _deseparate : function ( x , y ) {
73+ this . manager . pushStep ( this . capsule , {
74+ type : 'deseparate' ,
75+ x : x ,
76+ y : y
77+ } ) ;
78+ return this ;
79+ } ,
80+ _deseparateRow : function ( x ) {
81+ this . _deseparate ( x , - 1 ) ;
82+ return this ;
83+ } ,
84+ _deseparateCol : function ( y ) {
85+ this . _deseparate ( - 1 , y ) ;
86+ return this ;
87+ } ,
5688 pushSelectingStep : function ( ) {
5789 var args = Array . prototype . slice . call ( arguments ) ;
5890 var type = args . shift ( ) ;
@@ -100,7 +132,8 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
100132 case 'notify' :
101133 if ( step . v ) {
102134 var $row = this . $table . find ( '.mtbl-row' ) . eq ( step . x ) ;
103- $row . find ( '.mtbl-cell' ) . eq ( step . y ) . text ( TracerUtil . refineByType ( step . v ) ) ;
135+ var $col = $row . find ( '.mtbl-col' ) . eq ( step . y ) ;
136+ $col . text ( TracerUtil . refineByType ( step . v ) ) ;
104137 }
105138 case 'denotify' :
106139 case 'select' :
@@ -117,6 +150,13 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
117150 if ( ey === undefined ) ey = step . y ;
118151 this . paintColor ( sx , sy , ex , ey , colorClass , addClass ) ;
119152 break ;
153+ case 'separate' :
154+ this . deseparate ( step . x , step . y ) ;
155+ this . separate ( step . x , step . y ) ;
156+ break ;
157+ case 'deseparate' :
158+ this . deseparate ( step . x , step . y ) ;
159+ break ;
120160 default :
121161 Tracer . prototype . processStep . call ( this , step , options ) ;
122162 }
@@ -129,7 +169,7 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
129169
130170 if ( Tracer . prototype . setData . apply ( this , arguments ) ) {
131171 this . $table . find ( '.mtbl-row' ) . each ( function ( i ) {
132- $ ( this ) . children ( ) . each ( function ( j ) {
172+ $ ( this ) . find ( '.mtbl-col' ) . each ( function ( j ) {
133173 $ ( this ) . text ( TracerUtil . refineByType ( D [ i ] [ j ] ) ) ;
134174 } ) ;
135175 } ) ;
@@ -141,10 +181,10 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
141181 var $row = $ ( '<div class="mtbl-row">' ) ;
142182 this . $table . append ( $row ) ;
143183 for ( var j = 0 ; j < D [ i ] . length ; j ++ ) {
144- var $cell = $ ( '<div class="mtbl-cell ">' )
184+ var $col = $ ( '<div class="mtbl-col ">' )
145185 . css ( this . getCellCss ( ) )
146186 . text ( TracerUtil . refineByType ( D [ i ] [ j ] ) ) ;
147- $row . append ( $cell ) ;
187+ $row . append ( $col ) ;
148188 }
149189 }
150190 this . resize ( ) ;
@@ -160,6 +200,7 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
160200 Tracer . prototype . clear . call ( this ) ;
161201
162202 this . clearColor ( ) ;
203+ this . deseparateAll ( ) ;
163204 } ,
164205 getCellCss : function ( ) {
165206 return {
@@ -213,25 +254,46 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
213254 this . paddingV *= ratio ;
214255 this . paddingH *= ratio ;
215256 this . fontSize *= ratio ;
216- this . $table . find ( '.mtbl-cell ' ) . css ( this . getCellCss ( ) ) ;
257+ this . $table . find ( '.mtbl-col ' ) . css ( this . getCellCss ( ) ) ;
217258 this . refresh ( ) ;
218259 } ,
219260 paintColor : function ( sx , sy , ex , ey , colorClass , addClass ) {
220261 for ( var i = sx ; i <= ex ; i ++ ) {
221262 var $row = this . $table . find ( '.mtbl-row' ) . eq ( i ) ;
222263 for ( var j = sy ; j <= ey ; j ++ ) {
223- var $cell = $row . find ( '.mtbl-cell ' ) . eq ( j ) ;
224- if ( addClass ) $cell . addClass ( colorClass ) ;
225- else $cell . removeClass ( colorClass ) ;
264+ var $col = $row . find ( '.mtbl-col ' ) . eq ( j ) ;
265+ if ( addClass ) $col . addClass ( colorClass ) ;
266+ else $col . removeClass ( colorClass ) ;
226267 }
227268 }
228269 } ,
229270 clearColor : function ( ) {
230- this . $table . find ( '.mtbl-cell ' ) . removeClass ( Object . keys ( this . colorClass ) . join ( ' ' ) ) ;
271+ this . $table . find ( '.mtbl-col ' ) . removeClass ( Object . keys ( this . colorClass ) . join ( ' ' ) ) ;
231272 } ,
232273 colorClass : {
233274 selected : 'selected' ,
234275 notified : 'notified'
276+ } ,
277+ separate : function ( x , y ) {
278+ this . $table . find ( '.mtbl-row' ) . each ( function ( i ) {
279+ var $row = $ ( this ) ;
280+ if ( i == x ) {
281+ $row . after ( $ ( '<div class="mtbl-empty-row">' ) . attr ( 'data-row' , i ) )
282+ }
283+ $row . find ( '.mtbl-col' ) . each ( function ( j ) {
284+ var $col = $ ( this ) ;
285+ if ( j == y ) {
286+ $col . after ( $ ( '<div class="mtbl-empty-col">' ) . attr ( 'data-col' , j ) ) ;
287+ }
288+ } ) ;
289+ } ) ;
290+ } ,
291+ deseparate : function ( x , y ) {
292+ this . $table . find ( '[data-row=' + x + ']' ) . remove ( ) ;
293+ this . $table . find ( '[data-col=' + y + ']' ) . remove ( ) ;
294+ } ,
295+ deseparateAll : function ( ) {
296+ this . $table . find ( '.mtbl-empty-row, .mtbl-empty-col' ) . remove ( ) ;
235297 }
236298} ) ;
237299
0 commit comments