Skip to content

Commit

Permalink
Added Select All in network panel table. Completed #105. From Howie Z…
Browse files Browse the repository at this point in the history
…hang.
  • Loading branch information
liana-yang authored and yubowenok committed Sep 19, 2016
1 parent d78e03b commit 8901e80
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 20 deletions.
12 changes: 3 additions & 9 deletions src/components/network/network-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,9 @@ genotet.NetworkLoader.prototype.subNetwork = function(inPolygon) {
return;
}
var genesToDelete;
if (inPolygon) {
genesToDelete = this.data.genes.filter(function(gene) {
return !(gene in this.data.selectedNodes);
}, this);
} else {
genesToDelete = this.data.genes.filter(function(gene) {
return gene in this.data.selectedNodes;
}, this);
}
genesToDelete = this.data.genes.filter(function(gene) {
return inPolygon ^ (gene in this.data.selectedNodes);
}, this);

this.deleteGenes_(genesToDelete);
};
8 changes: 2 additions & 6 deletions src/components/network/network-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,11 @@ genotet.NetworkPanel.prototype.initPanel = function() {
// Sub-network
this.container.find('#keep-selected')
.click(function() {
this.signal('subNetwork', {
inPolygon: true
});
this.signal('subNetwork', {inPolygon: true});
}.bind(this));
this.container.find('#exclude-selected')
.click(function() {
this.signal('subNetwork', {
inPolygon: false
});
this.signal('subNetwork', {inPolygon: false});
}.bind(this));

// Input type update
Expand Down
8 changes: 4 additions & 4 deletions src/components/network/network-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ genotet.NetworkRenderer.prototype.polygonSelectionInit_ = function() {
return false;
});
coords = [];
this.svgPath_.selectAll('path').remove();
this.svgPath_.select('path').remove();
}.bind(this))
.on('drag', function() {
coords.push(d3.mouse(this.canvas.node()));
Expand Down Expand Up @@ -622,15 +622,15 @@ genotet.NetworkRenderer.prototype.switchMode = function() {
if (this.data.options.mouseZoom) {
this.zoomMode_();
} else {
this.polyMode_();
this.selectionMode_();
}
};

/**
* Transfers the network view to polygon selection mode.
* @private
*/
genotet.NetworkRenderer.prototype.polyMode_ = function() {
genotet.NetworkRenderer.prototype.selectionMode_ = function() {
this.canvas.on('.zoom', null);
this.polygonSelectionInit_();
this.canvas.call(this.drag_);
Expand Down Expand Up @@ -664,6 +664,6 @@ genotet.NetworkRenderer.prototype.drawPath_ = function(terminator, coords,
id: 'terminator',
d: line([coords[0], coords[coords.length - 1]])
});
this.svgPath_.selectAll('path').remove();
this.svgPath_.select('path').remove();
}
};
47 changes: 47 additions & 0 deletions src/components/network/network-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,53 @@ genotet.NetworkTable.prototype.create = function(table, edges) {
dt.buttons(1).enable(false); // the removal button
}.bind(this),
enabled: false
},
{
text: 'Select All',
action: function(e, dt, node, config) {
dt.rows().select();
var data = /** @type {!Array<genotet.EdgeForTable>} */
(dt.rows({selected: true}).data());
if (data.length > 0) {
var allSame = true;
if (data.length > 1) {
for (var i = 1; i < data.length; i++) {
if (data[i].added != data[i - 1].added) {
allSame = false;
break;
}
}
}
if (allSame) {
var firstEdge = data[0];
// the addition button
dt.button(0).enable(!firstEdge.added);
// the removal button
dt.button(1).enable(firstEdge.added);
} else {
dt.button(0).disable();
dt.button(1).disable();
}
var edgeIds = [];
for (var i = 0; i < data.length; i++) {
if (data[i].added) {
edgeIds.push(data[i].id);
}
}
if (edgeIds.length == 1) {
var networkEdge = dt.data.network.edgeMap[edgeIds[0]];
this.signal('showEdgeInfo', networkEdge);
} else if (edgeIds.length > 1) {
this.signal('multiEdgeInfo');
} else {
this.signal('hideEdgeInfo', {
edges: [],
force: true
});
}
this.signal('highlightEdges', edgeIds);
}
}.bind(this)
}
],
lengthMenu: [5, 10, 20, 50],
Expand Down
2 changes: 1 addition & 1 deletion src/vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ genotet.vector = {};
* Calculates whether the point is in the polygon.
* @param {!Array<number>} point The point.
* @param {!Array<Array<number>>} vertices The vertices of the polygon.
* @return {boolean} The result.
* @return {boolean}
*/
genotet.vector.pointInPolygon = function(point, vertices) {
// ray-casting algorithm based on
Expand Down

0 comments on commit 8901e80

Please sign in to comment.