@@ -3,7 +3,6 @@ var $table = null;
33function Array2DTracer ( module ) {
44 if ( Tracer . call ( this , module || Array2DTracer ) ) {
55 initTable ( ) ;
6- initNavigator ( this ) ;
76 return true ;
87 }
98 return false ;
@@ -44,12 +43,20 @@ Array2DTracer.prototype.createRandomData = function (N, M, min, max) {
4443// Override
4544Array2DTracer . prototype . setData = function ( D ) {
4645 this . D = D ;
47- if ( Tracer . prototype . setData . call ( this , arguments ) ) return true ;
48-
4946 this . viewX = this . viewY = 0 ;
5047 this . paddingH = 6 ;
5148 this . paddingV = 3 ;
5249 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+
5360 $table . empty ( ) ;
5461 for ( var i = 0 ; i < D . length ; i ++ ) {
5562 var $row = $ ( '<div class="mtbl-row">' ) ;
@@ -167,8 +174,8 @@ Array2DTracer.prototype.processStep = function (step, options) {
167174
168175Array2DTracer . prototype . getCellCss = function ( ) {
169176 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'
172179 } ;
173180} ;
174181
@@ -198,48 +205,58 @@ Array2DTracer.prototype.prevStep = function () {
198205 this . step ( finalIndex ) ;
199206} ;
200207
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 ;
205215} ;
206216
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 ) ;
243260} ;
244261
245262var paintColor = function ( sx , sy , ex , ey , colorClass , addClass ) {
@@ -254,7 +271,7 @@ var paintColor = function (sx, sy, ex, ey, colorClass, addClass) {
254271} ;
255272
256273var clearTableColor = function ( ) {
257- $table . find ( '.mtbl-cell' ) . css ( 'background' , '' ) ;
274+ $table . find ( '.mtbl-cell' ) . removeClass ( Object . keys ( tableColorClass ) . join ( ' ' ) ) ;
258275} ;
259276
260277var tableColorClass = {
0 commit comments