Skip to content

Commit fa78c4c

Browse files
committed
add _separate/_deseparate methods in array2d
1 parent c3f08a8 commit fa78c4c

2 files changed

Lines changed: 87 additions & 13 deletions

File tree

‎css/stylesheet.css‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ body {
66
}
77

88
body {
9-
background: rgb(60, 63, 65);
9+
background: rgb(63, 63, 63);
1010
font-family: 'Roboto', sans-serif;
1111
color: rgb(187, 187, 187);
1212
-webkit-font-smoothing: subpixel-antialiased;
@@ -405,17 +405,29 @@ pre {
405405
display: table-row;
406406
}
407407

408-
.mtbl-cell {
408+
.mtbl-col {
409409
display: table-cell;
410410
vertical-align: middle;
411411
text-align: center;
412412
background: #888;
413413
}
414414

415-
.mtbl-cell.selected {
415+
.mtbl-empty-row {
416+
display: table-row;
417+
background: rgb(63, 63, 63);
418+
height: 2px;
419+
}
420+
421+
.mtbl-empty-col {
422+
display: table-cell;
423+
background: rgb(63, 63, 63);
424+
width: 2px;
425+
}
426+
427+
.mtbl-col.selected {
416428
background: #00f;
417429
}
418430

419-
.mtbl-cell.notified {
431+
.mtbl-col.notified {
420432
background: #f00;
421433
}

‎js/module/array2d.js‎

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)