Skip to content

Commit

Permalink
WIP: expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
joshkh committed Mar 6, 2017
1 parent c0303d7 commit ea1d41f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
5 changes: 3 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
var model;


$.get( "json/EBI-9691559.json", function( data ) {
$.get( "json/EBI-1202920.json", function( data ) {
model = new MIModel(data).load().then(function(m) {
console.log("model", m);
window.m = m;

});

});
Expand Down
5 changes: 5 additions & 0 deletions src/models/Interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Backbone = require('backbone')
Participants = require('./Participant').Participants
Features = require('./Feature').Features;
Links = require('./Link').Links;
Expand = require('../utils/expand');

_ = require('underscore');

Expand All @@ -15,6 +16,10 @@ Interaction = Backbone.Model.extend({
links: new Links()
},

expand: function() {
Expand(this);
},

initialize: function(participants) {


Expand Down
10 changes: 9 additions & 1 deletion src/models/Participant.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ Participant = Backbone.Model.extend({

Participants = Backbone.Collection.extend({

model: Participant
model: Participant,

withStoichiometry: function(){
filtered = this.filter(function(participant) {
return participant.get("stoichiometry") > 1
});

return new Participants(filtered);
}

});

Expand Down
40 changes: 40 additions & 0 deletions src/utils/expand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var expand;



nextAvailableId = function(participants) {

var ids = participants.map(function(p) {
return p.get("id");
});

return Math.max.apply(null, ids) + 1
};

expand = function(interaction) {
participants = interaction.get("participants").withStoichiometry();

var clones = [];

participants.each(function(p) {

for (var i = 0; i < p.get("stoichiometry"); i++) {
var clone = p.clone();
clone.set("id", nextAvailableId(participants) + i);
clone.set("clone?", true);
clone.set("fromParticipant", p);
interaction.get("participants").add(clone);
}

});


interaction.set("expanded?", true);

// console.log("returning", interaction);

return interaction;

}

module.exports = expand;

0 comments on commit ea1d41f

Please sign in to comment.