@@ -2,7 +2,7 @@ var $table = null;
2
2
3
3
function Array2DTracer ( module ) {
4
4
if ( Tracer . call ( this , module || Array2DTracer ) ) {
5
- initTable ( ) ;
5
+ Array2D . initTable ( ) ;
6
6
return true ;
7
7
}
8
8
return false ;
@@ -12,55 +12,30 @@ Array2DTracer.prototype = Object.create(Tracer.prototype);
12
12
Array2DTracer . prototype . constructor = Array2DTracer ;
13
13
14
14
// Override
15
- Array2DTracer . prototype . resize = function ( ) {
15
+ Array2DTracer . prototype . resize = function ( ) {
16
16
Tracer . prototype . resize . call ( this ) ;
17
17
18
18
this . refresh ( ) ;
19
19
} ;
20
20
21
21
// Override
22
- Array2DTracer . prototype . clear = function ( ) {
22
+ Array2DTracer . prototype . clear = function ( ) {
23
23
Tracer . prototype . clear . call ( this ) ;
24
24
25
- clearTableColor ( ) ;
26
- } ;
27
-
28
- var Array2D = {
29
- random : function ( N , M , min , max ) {
30
- if ( ! N ) N = 10 ;
31
- if ( ! M ) M = 10 ;
32
- if ( min === undefined ) min = 1 ;
33
- if ( max === undefined ) max = 9 ;
34
- var D = [ ] ;
35
- for ( var i = 0 ; i < N ; i ++ ) {
36
- D . push ( [ ] ) ;
37
- for ( var j = 0 ; j < M ; j ++ ) {
38
- D [ i ] . push ( ( Math . random ( ) * ( max - min + 1 ) | 0 ) + min ) ;
39
- }
40
- }
41
- return D ;
42
- } ,
43
-
44
- randomSorted : function ( N , M , min , max ) {
45
- return this . random ( N , M , min , max ) . map ( function ( arr ) {
46
- return arr . sort ( function ( a , b ) {
47
- return a - b ;
48
- } ) ;
49
- } ) ;
50
- }
25
+ Array2D . clearTableColor ( ) ;
51
26
} ;
52
27
53
28
// Override
54
- Array2DTracer . prototype . _setData = function ( D ) {
29
+ Array2DTracer . prototype . _setData = function ( D ) {
55
30
this . D = D ;
56
31
this . viewX = this . viewY = 0 ;
57
32
this . paddingH = 6 ;
58
33
this . paddingV = 3 ;
59
34
this . fontSize = 16 ;
60
35
61
36
if ( Tracer . prototype . _setData . call ( this , arguments ) ) {
62
- $ ( '.mtbl-row' ) . each ( function ( i ) {
63
- $ ( this ) . children ( ) . each ( function ( j ) {
37
+ $ ( '.mtbl-row' ) . each ( function ( i ) {
38
+ $ ( this ) . children ( ) . each ( function ( j ) {
64
39
$ ( this ) . text ( D [ i ] [ j ] ) ;
65
40
} ) ;
66
41
} ) ;
@@ -83,7 +58,7 @@ Array2DTracer.prototype._setData = function(D) {
83
58
return false ;
84
59
} ;
85
60
86
- Array2DTracer . prototype . _notify = function ( x1 , y1 , x2 , y2 ) {
61
+ Array2DTracer . prototype . _notify = function ( x1 , y1 , x2 , y2 ) {
87
62
var second = x2 !== undefined && y2 !== undefined ;
88
63
this . pushStep ( {
89
64
type : 'notifying' ,
@@ -109,39 +84,39 @@ Array2DTracer.prototype._notify = function(x1, y1, x2, y2) {
109
84
} , false ) ;
110
85
} ;
111
86
112
- Array2DTracer . prototype . _select = function ( sx , sy , ex , ey ) {
87
+ Array2DTracer . prototype . _select = function ( sx , sy , ex , ey ) {
113
88
this . pushSelectingStep ( 'select' , null , arguments ) ;
114
89
} ;
115
90
116
- Array2DTracer . prototype . _selectRow = function ( x , sy , ey ) {
91
+ Array2DTracer . prototype . _selectRow = function ( x , sy , ey ) {
117
92
this . pushSelectingStep ( 'select' , 'row' , arguments ) ;
118
93
} ;
119
94
120
- Array2DTracer . prototype . _selectCol = function ( y , sx , ex ) {
95
+ Array2DTracer . prototype . _selectCol = function ( y , sx , ex ) {
121
96
this . pushSelectingStep ( 'select' , 'col' , arguments ) ;
122
97
} ;
123
98
124
- Array2DTracer . prototype . _selectSet = function ( coords ) {
99
+ Array2DTracer . prototype . _selectSet = function ( coords ) {
125
100
this . pushSelectingStep ( 'select' , 'set' , arguments ) ;
126
101
} ;
127
102
128
- Array2DTracer . prototype . _deselect = function ( sx , sy , ex , ey ) {
103
+ Array2DTracer . prototype . _deselect = function ( sx , sy , ex , ey ) {
129
104
this . pushSelectingStep ( 'deselect' , null , arguments ) ;
130
105
} ;
131
106
132
- Array2DTracer . prototype . _deselectRow = function ( x , sy , ey ) {
107
+ Array2DTracer . prototype . _deselectRow = function ( x , sy , ey ) {
133
108
this . pushSelectingStep ( 'deselect' , 'row' , arguments ) ;
134
109
} ;
135
110
136
- Array2DTracer . prototype . _deselectCol = function ( y , sx , ex ) {
111
+ Array2DTracer . prototype . _deselectCol = function ( y , sx , ex ) {
137
112
this . pushSelectingStep ( 'deselect' , 'col' , arguments ) ;
138
113
} ;
139
114
140
- Array2DTracer . prototype . _deselectSet = function ( coords ) {
115
+ Array2DTracer . prototype . _deselectSet = function ( coords ) {
141
116
this . pushSelectingStep ( 'deselect' , 'set' , arguments ) ;
142
117
} ;
143
118
144
- Array2DTracer . prototype . pushSelectingStep = function ( ) {
119
+ Array2DTracer . prototype . pushSelectingStep = function ( ) {
145
120
var args = Array . prototype . slice . call ( arguments ) ;
146
121
var type = args . shift ( ) ;
147
122
var mode = args . shift ( ) ;
@@ -189,21 +164,21 @@ Array2DTracer.prototype.pushSelectingStep = function() {
189
164
this . pushStep ( step , type == 'select' ) ;
190
165
} ;
191
166
192
- Array2DTracer . prototype . processStep = function ( step , options ) {
167
+ Array2DTracer . prototype . processStep = function ( step , options ) {
193
168
switch ( step . type ) {
194
169
case 'notifying' :
195
170
var $row = $table . find ( '.mtbl-row' ) . eq ( step . x ) ;
196
171
$row . find ( '.mtbl-cell' ) . eq ( step . y ) . text ( step . value ) ;
197
172
case 'notified' :
198
173
case 'select' :
199
174
case 'deselect' :
200
- var colorClass = step . type == 'select' || step . type == 'deselect' ? tableColorClass . selected : tableColorClass . notifying ;
175
+ var colorClass = step . type == 'select' || step . type == 'deselect' ? Array2D . tableColorClass . selected : Array2D . tableColorClass . notifying ;
201
176
var addClass = step . type == 'select' || step . type == 'notifying' ;
202
177
if ( step . coords ) {
203
- step . coords . forEach ( function ( coord ) {
178
+ step . coords . forEach ( function ( coord ) {
204
179
var x = coord . x ;
205
180
var y = coord . y ;
206
- paintColor ( x , y , x , y , colorClass , addClass ) ;
181
+ Array2D . paintColor ( x , y , x , y , colorClass , addClass ) ;
207
182
} ) ;
208
183
} else {
209
184
var sx = step . sx ;
@@ -214,21 +189,21 @@ Array2DTracer.prototype.processStep = function(step, options) {
214
189
if ( sy === undefined ) sy = step . y ;
215
190
if ( ex === undefined ) ex = step . x ;
216
191
if ( ey === undefined ) ey = step . y ;
217
- paintColor ( sx , sy , ex , ey , colorClass , addClass ) ;
192
+ Array2D . paintColor ( sx , sy , ex , ey , colorClass , addClass ) ;
218
193
}
219
194
break ;
220
195
}
221
196
} ;
222
197
223
- Array2DTracer . prototype . getCellCss = function ( ) {
198
+ Array2DTracer . prototype . getCellCss = function ( ) {
224
199
return {
225
200
padding : this . paddingV . toFixed ( 1 ) + 'px ' + this . paddingH . toFixed ( 1 ) + 'px' ,
226
201
'font-size' : this . fontSize . toFixed ( 1 ) + 'px'
227
202
} ;
228
203
} ;
229
204
230
205
// Override
231
- Array2DTracer . prototype . refresh = function ( ) {
206
+ Array2DTracer . prototype . refresh = function ( ) {
232
207
Tracer . prototype . refresh . call ( this ) ;
233
208
234
209
var $parent = $table . parent ( ) ;
@@ -239,7 +214,7 @@ Array2DTracer.prototype.refresh = function() {
239
214
} ;
240
215
241
216
// Override
242
- Array2DTracer . prototype . prevStep = function ( ) {
217
+ Array2DTracer . prototype . prevStep = function ( ) {
243
218
this . clear ( ) ;
244
219
$ ( '#tab_trace .wrapper' ) . empty ( ) ;
245
220
var finalIndex = this . traceIndex - 1 ;
@@ -256,7 +231,7 @@ Array2DTracer.prototype.prevStep = function() {
256
231
} ;
257
232
258
233
// Override
259
- Array2DTracer . prototype . mousedown = function ( e ) {
234
+ Array2DTracer . prototype . mousedown = function ( e ) {
260
235
Tracer . prototype . mousedown . call ( this , e ) ;
261
236
262
237
this . dragX = e . pageX ;
@@ -265,7 +240,7 @@ Array2DTracer.prototype.mousedown = function(e) {
265
240
} ;
266
241
267
242
// Override
268
- Array2DTracer . prototype . mousemove = function ( e ) {
243
+ Array2DTracer . prototype . mousemove = function ( e ) {
269
244
Tracer . prototype . mousemove . call ( this , e ) ;
270
245
271
246
if ( this . dragging ) {
@@ -278,14 +253,14 @@ Array2DTracer.prototype.mousemove = function(e) {
278
253
} ;
279
254
280
255
// Override
281
- Array2DTracer . prototype . mouseup = function ( e ) {
256
+ Array2DTracer . prototype . mouseup = function ( e ) {
282
257
Tracer . prototype . mouseup . call ( this , e ) ;
283
258
284
259
this . dragging = false ;
285
260
} ;
286
261
287
262
// Override
288
- Array2DTracer . prototype . mousewheel = function ( e ) {
263
+ Array2DTracer . prototype . mousewheel = function ( e ) {
289
264
Tracer . prototype . mousewheel . call ( this , e ) ;
290
265
291
266
e . preventDefault ( ) ;
@@ -303,27 +278,47 @@ Array2DTracer.prototype.mousewheel = function(e) {
303
278
this . refresh ( ) ;
304
279
} ;
305
280
306
- var initTable = function ( ) {
307
- $table = $ ( '<div class="mtbl-table">' ) ;
308
- $module_container . append ( $table ) ;
309
- } ;
310
-
311
- var paintColor = function ( sx , sy , ex , ey , colorClass , addClass ) {
312
- for ( var i = sx ; i <= ex ; i ++ ) {
313
- var $row = $table . find ( '.mtbl-row' ) . eq ( i ) ;
314
- for ( var j = sy ; j <= ey ; j ++ ) {
315
- var $cell = $row . find ( '.mtbl-cell' ) . eq ( j ) ;
316
- if ( addClass ) $cell . addClass ( colorClass ) ;
317
- else $cell . removeClass ( colorClass ) ;
281
+ var Array2D = {
282
+ random : function ( N , M , min , max ) {
283
+ if ( ! N ) N = 10 ;
284
+ if ( ! M ) M = 10 ;
285
+ if ( min === undefined ) min = 1 ;
286
+ if ( max === undefined ) max = 9 ;
287
+ var D = [ ] ;
288
+ for ( var i = 0 ; i < N ; i ++ ) {
289
+ D . push ( [ ] ) ;
290
+ for ( var j = 0 ; j < M ; j ++ ) {
291
+ D [ i ] . push ( ( Math . random ( ) * ( max - min + 1 ) | 0 ) + min ) ;
292
+ }
293
+ }
294
+ return D ;
295
+ } ,
296
+ randomSorted : function ( N , M , min , max ) {
297
+ return this . random ( N , M , min , max ) . map ( function ( arr ) {
298
+ return arr . sort ( function ( a , b ) {
299
+ return a - b ;
300
+ } ) ;
301
+ } ) ;
302
+ } ,
303
+ initTable : function ( ) {
304
+ $table = $ ( '<div class="mtbl-table">' ) ;
305
+ $module_container . append ( $table ) ;
306
+ } ,
307
+ paintColor : function ( sx , sy , ex , ey , colorClass , addClass ) {
308
+ for ( var i = sx ; i <= ex ; i ++ ) {
309
+ var $row = $table . find ( '.mtbl-row' ) . eq ( i ) ;
310
+ for ( var j = sy ; j <= ey ; j ++ ) {
311
+ var $cell = $row . find ( '.mtbl-cell' ) . eq ( j ) ;
312
+ if ( addClass ) $cell . addClass ( colorClass ) ;
313
+ else $cell . removeClass ( colorClass ) ;
314
+ }
318
315
}
316
+ } ,
317
+ clearTableColor : function ( ) {
318
+ $table . find ( '.mtbl-cell' ) . removeClass ( Object . keys ( Array2D . tableColorClass ) . join ( ' ' ) ) ;
319
+ } ,
320
+ tableColorClass : {
321
+ selected : 'selected' ,
322
+ notifying : 'notifying'
319
323
}
320
- } ;
321
-
322
- var clearTableColor = function ( ) {
323
- $table . find ( '.mtbl-cell' ) . removeClass ( Object . keys ( tableColorClass ) . join ( ' ' ) ) ;
324
- } ;
325
-
326
- var tableColorClass = {
327
- selected : 'selected' ,
328
- notifying : 'notifying'
329
324
} ;
0 commit comments