@@ -3,7 +3,6 @@ var $table = null;
3
3
function Array2DTracer ( module ) {
4
4
if ( Tracer . call ( this , module || Array2DTracer ) ) {
5
5
initTable ( ) ;
6
- initNavigator ( this ) ;
7
6
return true ;
8
7
}
9
8
return false ;
@@ -44,12 +43,20 @@ Array2DTracer.prototype.createRandomData = function (N, M, min, max) {
44
43
// Override
45
44
Array2DTracer . prototype . setData = function ( D ) {
46
45
this . D = D ;
47
- if ( Tracer . prototype . setData . call ( this , arguments ) ) return true ;
48
-
49
46
this . viewX = this . viewY = 0 ;
50
47
this . paddingH = 6 ;
51
48
this . paddingV = 3 ;
52
49
this . fontSize = 16 ;
50
+
51
+ if ( Tracer . prototype . setData . call ( this , arguments ) ) {
52
+ $ ( '.mtbl-row' ) . each ( function ( i ) {
53
+ $ ( this ) . children ( ) . each ( function ( j ) {
54
+ $ ( this ) . text ( D [ i ] [ j ] ) ;
55
+ } ) ;
56
+ } ) ;
57
+ return true ;
58
+ }
59
+
53
60
$table . empty ( ) ;
54
61
for ( var i = 0 ; i < D . length ; i ++ ) {
55
62
var $row = $ ( '<div class="mtbl-row">' ) ;
@@ -167,8 +174,8 @@ Array2DTracer.prototype.processStep = function (step, options) {
167
174
168
175
Array2DTracer . prototype . getCellCss = function ( ) {
169
176
return {
170
- padding : this . paddingV + 'px ' + this . paddingH + 'px' ,
171
- 'font-size' : this . fontSize
177
+ padding : this . paddingV . toFixed ( 1 ) + 'px ' + this . paddingH . toFixed ( 1 ) + 'px' ,
178
+ 'font-size' : this . fontSize . toFixed ( 1 ) + 'px'
172
179
} ;
173
180
} ;
174
181
@@ -198,48 +205,58 @@ Array2DTracer.prototype.prevStep = function () {
198
205
this . step ( finalIndex ) ;
199
206
} ;
200
207
201
- var initTable = function ( ) {
202
- $ ( '.module_container' ) . empty ( ) ;
203
- $table = $ ( '<div class="mtbl-table">' ) ;
204
- $ ( '.module_container' ) . append ( $table ) ;
208
+ // Override
209
+ Array2DTracer . prototype . mousedown = function ( e ) {
210
+ Tracer . prototype . mousedown . call ( this , e ) ;
211
+
212
+ this . dragX = e . pageX ;
213
+ this . dragY = e . pageY ;
214
+ this . dragging = true ;
205
215
} ;
206
216
207
- var initNavigator = function ( tracer ) {
208
- var x , y , dragging = false ;
209
- var $parent = $table . parent ( ) ;
210
- $parent . mousedown ( function ( e ) {
211
- x = e . pageX ;
212
- y = e . pageY ;
213
- dragging = true ;
214
- } ) ;
215
- $parent . mousemove ( function ( e ) {
216
- if ( dragging ) {
217
- tracer . viewX += e . pageX - x ;
218
- tracer . viewY += e . pageY - y ;
219
- x = e . pageX ;
220
- y = e . pageY ;
221
- tracer . refresh ( ) ;
222
- }
223
- } ) ;
224
- $ ( document ) . mouseup ( function ( e ) {
225
- dragging = false ;
226
- } ) ;
227
-
228
- $parent . bind ( 'DOMMouseScroll mousewheel' , function ( e , delta ) {
229
- e = e . originalEvent ;
230
- var delta = ( e . wheelDelta !== undefined && e . wheelDelta ) ||
231
- ( e . detail !== undefined && - e . detail ) ;
232
- var weight = 1.01 ;
233
- var ratio = delta > 0 ? 1 / weight : weight ;
234
- if ( tracer . fontSize < 8 && ratio < 1 ) return false ;
235
- if ( tracer . fontSize > 36 && ratio > 1 ) return false ;
236
- tracer . paddingV *= ratio ;
237
- tracer . paddingH *= ratio ;
238
- tracer . fontSize *= ratio ;
239
- $ ( '.mtbl-cell' ) . css ( tracer . getCellCss ( ) ) ;
240
- tracer . refresh ( ) ;
241
- e . preventDefault ( ) ;
242
- } ) ;
217
+ // Override
218
+ Array2DTracer . prototype . mousemove = function ( e ) {
219
+ Tracer . prototype . mousemove . call ( this , e ) ;
220
+
221
+ if ( this . dragging ) {
222
+ this . viewX += e . pageX - this . dragX ;
223
+ this . viewY += e . pageY - this . dragY ;
224
+ this . dragX = e . pageX ;
225
+ this . dragY = e . pageY ;
226
+ this . refresh ( ) ;
227
+ }
228
+ } ;
229
+
230
+ // Override
231
+ Array2DTracer . prototype . mouseup = function ( e ) {
232
+ Tracer . prototype . mouseup . call ( this , e ) ;
233
+
234
+ this . dragging = false ;
235
+ } ;
236
+
237
+ // Override
238
+ Array2DTracer . prototype . mousewheel = function ( e ) {
239
+ Tracer . prototype . mousewheel . call ( this , e ) ;
240
+
241
+ e . preventDefault ( ) ;
242
+ e = e . originalEvent ;
243
+ var delta = ( e . wheelDelta !== undefined && e . wheelDelta ) ||
244
+ ( e . detail !== undefined && - e . detail ) ;
245
+ var weight = 1.01 ;
246
+ var ratio = delta > 0 ? 1 / weight : weight ;
247
+ if ( this . fontSize < 4 && ratio < 1 ) return ;
248
+ if ( this . fontSize > 40 && ratio > 1 ) return ;
249
+ this . paddingV *= ratio ;
250
+ this . paddingH *= ratio ;
251
+ this . fontSize *= ratio ;
252
+ $ ( '.mtbl-cell' ) . css ( this . getCellCss ( ) ) ;
253
+ this . refresh ( ) ;
254
+ } ;
255
+
256
+ var initTable = function ( ) {
257
+ $module_container . empty ( ) ;
258
+ $table = $ ( '<div class="mtbl-table">' ) ;
259
+ $module_container . append ( $table ) ;
243
260
} ;
244
261
245
262
var paintColor = function ( sx , sy , ex , ey , colorClass , addClass ) {
@@ -254,7 +271,7 @@ var paintColor = function (sx, sy, ex, ey, colorClass, addClass) {
254
271
} ;
255
272
256
273
var clearTableColor = function ( ) {
257
- $table . find ( '.mtbl-cell' ) . css ( 'background' , '' ) ;
274
+ $table . find ( '.mtbl-cell' ) . removeClass ( Object . keys ( tableColorClass ) . join ( ' ' ) ) ;
258
275
} ;
259
276
260
277
var tableColorClass = {
0 commit comments