Skip to content

Commit 032d064

Browse files
author
Philip Guo
committed
simple heap transition animations
1 parent 772dcb9 commit 032d064

File tree

2 files changed

+30
-44
lines changed

2 files changed

+30
-44
lines changed

PyTutorGAE/css/pytutor.css

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,10 @@ div#heap {
562562
}
563563

564564
td.toplevelHeapObject {
565-
margin-left: 0px;
566-
margin-right: 20px;
567-
565+
/* to make room for transition animations */
568566
padding: 8px;
569-
border: 2px dotted white; /* to make room for transition animations */
567+
border: 2px dotted white;
568+
border-color: white; /* needed for d3 to do transitions */
570569
}
571570

572571
table.heapRow {

PyTutorGAE/js/pytutor.js

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,7 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
11561156
});
11571157

11581158

1159+
11591160
// use d3 to render the heap by mapping curToplevelLayout into <table class="heapRow">
11601161
// and <td class="toplevelHeapObject"> elements
11611162

@@ -1166,21 +1167,42 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
11661167
});
11671168

11681169

1170+
// insert new heap rows
1171+
heapRows.enter().append('table')
1172+
//.each(function(objLst, i) {console.log('NEW ROW:', objLst, i);})
1173+
.attr('class', 'heapRow')
1174+
.append('tr')
1175+
1176+
// delete a heap row
1177+
heapRows.exit()
1178+
//.each(function(objLst, i) {console.log('DEL ROW:', objLst, i);})
1179+
.remove();
1180+
1181+
11691182
// update an existing heap row
11701183
var heapColumns = heapRows
1171-
//.each(function(objLst, i) { console.log('UPDATE ROW:', objLst, i); })
1184+
.each(function(objLst, i) { console.log('UPDATE ROW:', objLst, i); })
11721185
.selectAll('td')
11731186
.data(function(d, i) {return d.slice(1, d.length);}, /* map over each row, skipping row ID tag */
11741187
function(objID) {return objID;} /* each object ID is unique for constancy */);
11751188

1176-
// ENTER
1189+
// insert a new toplevelHeapObject
11771190
heapColumns.enter().append('td')
11781191
.attr('class', 'toplevelHeapObject')
1179-
.attr('id', function(d, i) {return 'toplevel_heap_object_' + d;});
1192+
.attr('id', function(d, i) {return 'toplevel_heap_object_' + d;})
1193+
.style('opacity', '0')
1194+
.style('border-color', 'red')
11801195
// remember that the enter selection is added to the update
11811196
// selection so that we can process it later ...
1197+
.transition()
1198+
.style('opacity', '1') /* fade in */
1199+
.duration(500)
1200+
.transition()
1201+
.style('border-color', 'white')
1202+
.delay(500)
1203+
.duration(300);
11821204

1183-
// UPDATE
1205+
// update a toplevelHeapObject
11841206
heapColumns
11851207
.order() // VERY IMPORTANT to put in the order corresponding to data elements
11861208
.each(function(objID, i) {
@@ -1192,46 +1214,11 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
11921214
renderCompoundObject(objID, $(this), true);
11931215
});
11941216

1195-
// EXIT
1217+
// delete a toplevelHeapObject
11961218
heapColumns.exit()
11971219
.remove();
11981220

11991221

1200-
// insert new heap rows
1201-
heapRows.enter().append('table')
1202-
//.each(function(objLst, i) {console.log('NEW ROW:', objLst, i);})
1203-
.attr('class', 'heapRow')
1204-
.append('tr')
1205-
.selectAll('td')
1206-
.data(function(d, i) {return d.slice(1, d.length);}, /* map over each row, skipping row ID tag */
1207-
function(objID) {return objID;} /* each object ID is unique for constancy */)
1208-
.enter().append('td')
1209-
.attr('class', 'toplevelHeapObject')
1210-
.attr('id', function(d, i) {return 'toplevel_heap_object_' + d;})
1211-
.each(function(objID, i) {
1212-
//console.log('NEW ELT', objID);
1213-
1214-
// TODO: add a smoother transition in the future
1215-
renderCompoundObject(objID, $(this), true);
1216-
})
1217-
/*
1218-
.transition()
1219-
.style('border-color', 'red')
1220-
.duration(100)
1221-
.transition()
1222-
.style('border-color', 'white')
1223-
.delay(100)
1224-
.duration(600)
1225-
*/
1226-
1227-
1228-
1229-
// remove deleted rows
1230-
heapRows.exit()
1231-
//.each(function(objLst, i) {console.log('DEL ROW:', objLst, i);})
1232-
.remove();
1233-
1234-
12351222

12361223
function renderNestedObject(obj, d3DomElement) {
12371224
if (isPrimitiveType(obj)) {

0 commit comments

Comments
 (0)