diff --git a/font/sbolv/interaction-arrows/inhibitorArrow.js b/font/sbolv/interaction-arrows/inhibitorArrow.js index 29399a2..60e1b16 100644 --- a/font/sbolv/interaction-arrows/inhibitorArrow.js +++ b/font/sbolv/interaction-arrows/inhibitorArrow.js @@ -7,9 +7,9 @@ function createGeometry(boxSize) { return { top: Vec2(boxSize.x/2,0), - bottomLeft: Vec2(boxSize.x/4,(2*boxSize.y)/4), - bottomRight: Vec2((boxSize.x * 3 )/4, (2*boxSize.y)/4), - middleBottom: Vec2(boxSize.x/2, (2*boxSize.y)/4) + bottomLeft: Vec2(boxSize.x/4,boxSize.y * 0.6), + bottomRight: Vec2((boxSize.x * 3 )/4, boxSize.y * 0.6), + middleBottom: Vec2(boxSize.x/2, boxSize.y * 0.6) }; } diff --git a/font/sbolv/interaction-arrows/main.js b/font/sbolv/interaction-arrows/main.js index 2a32874..9d0b607 100644 --- a/font/sbolv/interaction-arrows/main.js +++ b/font/sbolv/interaction-arrows/main.js @@ -2,7 +2,7 @@ module.exports = { 'InhibitorArrow': require('./inhibitorArrow'), 'ProductArrow': require('./productArrow'), -'SimulatorArrow': require('./simulatorArrow'), +'StimulatorArrow': require('./stimulatorArrow'), 'ReactantArrow': require('./reactantArrow'), 'DegradationArrow': require('./degradationArrow') } diff --git a/font/sbolv/interaction-arrows/productArrow.js b/font/sbolv/interaction-arrows/productArrow.js index 9c0b025..815455a 100644 --- a/font/sbolv/interaction-arrows/productArrow.js +++ b/font/sbolv/interaction-arrows/productArrow.js @@ -7,7 +7,7 @@ function createGeometry(boxSize) { return { top: Vec2(boxSize.x/2, boxSize.y/4), - bottom: Vec2(boxSize.x/2, boxSize.y), + bottom: Vec2(boxSize.x/2, boxSize.y * 0.8), left: Vec2(boxSize.x/3,boxSize.y/4), right: Vec2((boxSize.x * 2 )/3, boxSize.y/4), diff --git a/font/sbolv/interaction-arrows/simulatorArrow.js b/font/sbolv/interaction-arrows/stimulatorArrow.js similarity index 96% rename from font/sbolv/interaction-arrows/simulatorArrow.js rename to font/sbolv/interaction-arrows/stimulatorArrow.js index bab51db..dbb6cdd 100644 --- a/font/sbolv/interaction-arrows/simulatorArrow.js +++ b/font/sbolv/interaction-arrows/stimulatorArrow.js @@ -6,7 +6,7 @@ function createGeometry(boxSize) { return { - top: Vec2(boxSize.x/2, boxSize.y * 0.1), + top: Vec2(boxSize.x/2, boxSize.y * 0.2), bottom: Vec2(boxSize.x/2, boxSize.y * 0.8), left: Vec2(boxSize.x/3,boxSize.y * 0.8), diff --git a/lib/component.js b/lib/component.js index b879f1c..e05e74c 100755 --- a/lib/component.js +++ b/lib/component.js @@ -55,7 +55,7 @@ helper.circuit_is_participant = function(segment, interactions) { else { for (interaction of interactions) { for (participant of interaction.participants) { - if (participant.SO && segment.name === participant.name) { + if (participant.SO && segment.name === participant.segment.name) { return true; } } diff --git a/lib/design.js b/lib/design.js index a37df72..a38fe3e 100755 --- a/lib/design.js +++ b/lib/design.js @@ -141,7 +141,8 @@ Design.prototype = { * otherwise it doesn't know where to render them */ let componentBoxHeight = this.geom.componentBoxHeight; - this.interactions = this.displayList.interactions.map(function(interactionObject) { + console.log(this.displayList.combinedInteractions, 'interactions') + this.interactions = this.displayList.combinedInteractions.map(function(interactionObject) { var interaction = Interaction.render(design, interactionObject, design.displayList.interactions); let interactionPosition = design.geom.interactionPosition; diff --git a/lib/displayList.js b/lib/displayList.js index 42b5f22..71d8a9b 100755 --- a/lib/displayList.js +++ b/lib/displayList.js @@ -6,6 +6,7 @@ function DisplayList(displayListObject) { this.components = []; this.processes = []; this.interactions = []; + this.combinedInteractions = []; this.refs = Object.create(null); @@ -36,27 +37,10 @@ function DisplayList(displayListObject) { * Add rendering Info to participants of the interaction, right now it's just for inhibition */ if(displayListObject.interactions !== undefined) { - - - this.interactions = displayListObject.interactions.map(function(interaction) { - - //this is the set of interaction types that currently our code is able to rende - /*let AvailableInteractions = ["SBO:0000169", "SBO:0000170", "SBO:0000177", "SBO:0000179", "SBO:0000589"]; - - if (AvailableInteractions.indexOf(interaction.SBO) !== -1) { - for (let i in interaction.participants) { - - //find the segment for the circuit participating in the interaction, this way we can simply render the segment using renderSegment - for ( let j in displayList.components[0].segments ) { - - if (displayList.components[0].segments[j].name === interaction.participants[i].name ) { - interaction.participants[i].segment = displayList.components[0].segments[j]; - } - } - } - }*/ - return interaction; - }); + + this.interactions = displayListObject.interactions; + this.combinedInteractions = DisplayList.combinedInteractions(displayList, displayListObject.interactions) + } @@ -194,6 +178,81 @@ DisplayList.Entity = function Entity(displayList, entity) { this.name = entity.name; } +/* +******************************************************************************************* +*/ +DisplayList.combinedInteractions = function combinedInteractions(displayList, interactions) { + + let combinedInteractionsDict = {} + let combinedInteractionsList = [] + let degradationsDict = {} + let degraded_NonDNAs = [] + for(interaction of interactions) { + + //this is the set of interaction types that currently our code is able to rende + let AvailableInteractions = ["SBO:0000169", "SBO:0000170", "SBO:0000589"]; + //let AvailableInteractions = ["SBO:0000169", "SBO:0000170", "SBO:0000177", "SBO:0000179", "SBO:0000589"]; + + if (AvailableInteractions.indexOf(interaction.SBO) !== -1) { + + for (participant of interaction.participants) { + + if (participant.SO) { + + if (participant.segment.segmentId in combinedInteractionsDict) { + + combinedInteractionsDict[participant.segment.segmentId]['interactions'].push(interaction) + + } + else { + segmentInfoDict = {} + segmentInfoDict['segment'] = participant.segment + segmentInfoDict['interactions'] = [] + segmentInfoDict['interactions'].push(interaction) + combinedInteractionsDict[participant.segment.segmentId] = segmentInfoDict + + } + } + } + } + + if (interaction.SBO === "SBO:0000179") { + degraded_NonDNAs.push(interaction.participants[0].segment.segmentId) + degradationsDict[interaction.participants[0].segment.segmentId] = interaction + } + + if (interaction.SBO === "SBO:0000177") { + combinedInteractionsList.push(interaction) + } + } + + for (key in combinedInteractionsDict) { + for (interaction of combinedInteractionsDict[key]['interactions']) { + for (participant of interaction.participants) { + if (!participant.SO && degraded_NonDNAs.indexOf(participant.segment.segmentId) != -1) { + participant.isDegraded = true + degradationsDict[participant.segment.segmentId] = null + } + } + } + } + + //add interactions of type degradation which are not participating in circiut interactions + for (key in degradationsDict) { + if (degradationsDict[key] !== null) { + combinedInteractionsList.push(degradationsDict[key]) + } + } + + //get the values aa a list + for (key in combinedInteractionsDict) { + combinedInteractionsList.push(combinedInteractionsDict[key]) + } + + return combinedInteractionsList +} + +/////////////////////////////////////////////////////////////////////////////////////// DisplayList.prototype = { getObjectByID: function getObjectByID(id) { diff --git a/lib/getDisplayList.js b/lib/getDisplayList.js index fcde465..aea3790 100644 --- a/lib/getDisplayList.js +++ b/lib/getDisplayList.js @@ -54,7 +54,7 @@ function recurseGetDisplayList(componentDefinition, segments, config, share, max } } - + segments = recurseGetDisplayList(component.definition, segments, config, share) } @@ -63,7 +63,7 @@ function recurseGetDisplayList(componentDefinition, segments, config, share, max return segments.map(segment => trimSequence(segment, max)) } -function getDisplayListSegment(componentDefinition, config, share) { +function getDisplayListSegment(componentDefinition, config, share,i) { var displayName = componentDefinition.displayId if (componentDefinition.name != '' && componentDefinition.name != componentDefinition.displayId) { @@ -105,7 +105,6 @@ function getDisplayListSegment(componentDefinition, config, share) { if (componentDefinition.sequenceAnnotations.length === 0 && componentDefinition.components.length === 0) { - //console.log(componentDefinition); var glyph = 'unspecified' var name = componentDefinition.name != '' ? componentDefinition.name : componentDefinition.displayId var roles = componentDefinition.roles @@ -173,6 +172,8 @@ function getDisplayListSegment(componentDefinition, config, share) { return { name: displayName, + //extra field for identity of a segment + segmentId: componentDefinition.uri.toString(), sequence: [{ strand: "positive", type: glyph, @@ -189,6 +190,8 @@ function getDisplayListSegment(componentDefinition, config, share) { return { name: displayName, + //extra field for identity of a segment + segmentId: componentDefinition.uri.toString(), sequence: sortedSequenceAnnotations(componentDefinition).map((sequenceAnnotation) => { var glyph = 'unspecified' diff --git a/lib/getInteractionList.js b/lib/getInteractionList.js index 2cf642b..92cf791 100644 --- a/lib/getInteractionList.js +++ b/lib/getInteractionList.js @@ -3,7 +3,7 @@ var sboToInteractionType = require('./sboToInteractionType') var sboToRole = require('./sboToRole') var getDisplayListSegment = require('./getDisplayList').getDisplayListSegment -function getInteractionList(moduleDefinition) { +function getInteractionList(moduleDefinition, config, share) { let interactions = []; @@ -30,30 +30,34 @@ function getInteractionList(moduleDefinition) { let participantObj = {}; - participantObj.displayId = participation.displayId; - participantObj.segment = getDisplayListSegment(participation.participant.definition) - participantObj.name = participation.participant.definition.displayId; + if (participation.displayId !== undefined) { + participantObj.displayId = participation.displayId; + } + + if (participation.participant.definition) { + participantObj.segment = getDisplayListSegment(participation.participant.definition,config,share) + participantObj.name = participation.participant.definition.displayId; - //Attaching type when participant is Non-DNA - if( /*participation.participant.definition.roles.length === 0 */participation.participant.definition.types[0]._parts.fragment != "DnaRegion") { + //Attaching type when participant is Non-DNA + if(participation.participant.definition.types[0]._parts.fragment != "DnaRegion") { - if (participation.participant.definition.types.length === 1) { - //Attaching type - participantObj.type = participation.participant.definition.types[0]._parts.fragment; - } - } + if (participation.participant.definition.types.length === 1) { + //Attaching type + participantObj.type = participation.participant.definition.types[0]._parts.fragment; + } + } - //Attaching type when participant is DNA - else if( participation.participant.definition.roles.length === 1 ) { + //Attaching type when participant is DNA + else if( participation.participant.definition.roles.length === 1 ) { - var SOCode = participation.participant.definition.roles[0]._parts.path.split('/').pop(); - //var SOCode = participation._roles[0]._parts.path.split('/').pop(); - // This property only exists for DNA parts - participantObj.SO = SOCode ; - participantObj.type = soToGlyphType(SOCode); - - } + var SOCode = participation.participant.definition.roles[0]._parts.path.split('/').pop(); + //var SOCode = participation._roles[0]._parts.path.split('/').pop(); + // This property only exists for DNA parts + participantObj.SO = SOCode ; + participantObj.type = soToGlyphType(SOCode); + } + } if (participation.roles.length === 1) { diff --git a/lib/interaction.js b/lib/interaction.js index b54ee43..57c9d1c 100644 --- a/lib/interaction.js +++ b/lib/interaction.js @@ -10,47 +10,100 @@ var Segment = require('./segment'), Vec2 = require('./geom/vec2'), Matrix = require('./geom/matrix') +/* +* helper function to sort interactions on top of circuit +* this method puts all the interactinos of type stimulation and inhibtion +* to the left of interactions of type genetic production +*/ +function sortInteractions(interactionsList) { + + let interactions = interactionsList; + let currentProductionIndex = interactions.length - 1; + let numProduction = 0; + + for (interaction of interactionsList) { + + if (interaction.SBO === "SBO:0000589") { + numProduction++; + } + } + + for (let i = 0; i < interactionsList.length - numProduction; ++i) { + + if (interactionsList[i].SBO === "SBO:0000589") { + temp = interactionsList[currentProductionIndex]; + interactionsList[currentProductionIndex] = interactionsList[i]; + interactionsList[i] = temp; + currentProductionIndex--; + } + } +} -function renderInteraction(design, interaction, interactions) { +function renderInteraction(design, combinedInteraction, interactions) { var interactionPos = Matrix(); var segments = []; let pos = 0 - - if (interaction.SBO === "SBO:0000169") { - - Inhibition.render(design, interaction, segments, interactions); - } + onDNAsVerticalOffset = 0; + + if (combinedInteraction.segment) { - else if (interaction.SBO === "SBO:0000589") { + //first sort the interactions + sortInteractions(combinedInteraction['interactions']); - Production.render(design, interaction, segments, interactions); + if (combinedInteraction.segment.sequence.length > 1) { + combinedInteraction.segment.isCircuit = true; + } + combinedInteraction.segment.isParticipant = true; + var segment = Segment.render(design, combinedInteraction.segment, interactions); + segments.push(segment) + + if (combinedInteraction.interactions.length === 1) { + nonDNAshorizontalOffset = (segment.bbox().width)/2 + } + else if (combinedInteraction.interactions.length > 1) { + numInteraction = combinedInteraction.interactions.length + nonDNAshorizontalOffset = (segment.bbox().width - (design.geom.defaultGlyphSize.x * numInteraction))/numInteraction + } + + for (interaction of combinedInteraction['interactions']) { + + if (interaction.SBO === "SBO:0000169") { + + Inhibition.render(design, interaction, segments, interactions, nonDNAshorizontalOffset); + nonDNAshorizontalOffset += segments[segments.length -1].bbox().width + 50 + } + + else if (interaction.SBO === "SBO:0000589") { - } + Production.render(design, interaction, segments, interactions, nonDNAshorizontalOffset); + nonDNAshorizontalOffset += segments[segments.length -1].bbox().width + 50 + } - else if (interaction.SBO === "SBO:0000170") { + else if (interaction.SBO === "SBO:0000170") { - Stimulation.render(design, interaction, segments, interactions); - + Stimulation.render(design, interaction, segments, interactions, nonDNAshorizontalOffset); + nonDNAshorizontalOffset += segments[segments.length -1].bbox().width + 50 + } + } } - - else if (interaction.SBO === "SBO:0000177") { - - nonCovelantBinding.render(design, interaction, segments, interactions); - + else { + + if (combinedInteraction.SBO === "SBO:0000177") { + nonCovelantBinding.render(design, combinedInteraction, segments, interactions); } - else if (interaction.SBO === "SBO:0000179") { - - Degradation.render(design, interaction, segments, interactions); + else if (combinedInteraction.SBO === "SBO:0000179") { + Degradation.render(design, combinedInteraction, segments, interactions); } else { + console.log("COmbinedInteraction", combinedInteraction) console.log("Unknown interaction type") return; } - + } var group = design.surface.group(); segments.forEach(group.add.bind(group)); @@ -73,28 +126,29 @@ function renderInteraction(design, interaction, interactions) { group.add(box); design.geom.interactionPosition = design.geom.interactionPosition + group.bbox().height + design.geom.interactionPadding; + var labelTextString = ''; + if(combinedInteraction.segment !== undefined) { + labelTextString = combinedInteraction.segment.name + " interactions"; + } + else if(combinedInteraction.displayId !== undefined) { + labelTextString = combinedInteraction.displayId; + } - if(interaction.displayId !== undefined) { - - var labelText = design.surface.text(''); - labelText.font({ anchor: 'left' }); - labelText.build(true); + var labelText = design.surface.text(''); + labelText.font({ anchor: 'left' }); + labelText.build(true); - var label = labelText.tspan(interaction.displayId); + var label = labelText.tspan(labelTextString); - label.attr('alignment-baseline', 'middle'); - labelText.build(false); + label.attr('alignment-baseline', 'middle'); + labelText.build(false); - labelText.dy(-box.bbox().height) - labelText.dx(-100) - group.add(labelText); - - } - + labelText.dy(-box.bbox().height) + labelText.dx(-100) + group.add(labelText); + group.displayList = segments; - interaction.svg = group; - return group; } diff --git a/lib/interactions/degradation.js b/lib/interactions/degradation.js index b709499..bcbe77e 100644 --- a/lib/interactions/degradation.js +++ b/lib/interactions/degradation.js @@ -20,7 +20,7 @@ function render(design, interaction, segments, interactions) { } interaction.participants[i].segment.isParticipant = true; - var segment = Segment.render(design, interaction.participants[i].segment, interactions); + var segment = Segment.render(design, interaction.participants[i].segment, interactions, interaction); segments.push(segment); } } diff --git a/lib/interactions/inhibition.js b/lib/interactions/inhibition.js index 38d6163..a9d49cb 100644 --- a/lib/interactions/inhibition.js +++ b/lib/interactions/inhibition.js @@ -2,7 +2,7 @@ var Segment = require('../segment'), Helper = require('./helper') -function render(design, interaction, segments, interactions) { +function render(design, interaction, segments, interactions, nonDNAshorizontalOffset) { //make sure right type of interaction is passed to the function if (interaction.SBO !== "SBO:0000169") { @@ -22,7 +22,7 @@ function render(design, interaction, segments, interactions) { Helper.sortParticipants(interaction.participants); nonDNAsVerticalOffset = 0; - nonDNAshorizontalOffset = 0; + //nonDNAshorizontalOffset = 0; isCircuit = true; if (interaction.participants[0].type !== "engineered-region") { isCircuit = false; @@ -35,30 +35,20 @@ function render(design, interaction, segments, interactions) { //need to set it to true since we don't want to show the label for the segments interaction.participants[i].segment.isParticipant = true; - //if participant is a Dna part or circuit - if (interaction.participants[i].SO) { - - if (isCircuit) { - interaction.participants[i].segment.isCircuit = true; - } - //update participant offset - design.geom.participantOffset = Helper.find_participant_offset(interaction.participants[i], interaction.displayId, "inhibition"); - var segment = Segment.render(design, interaction.participants[i].segment, interactions); - nonDNAVerticalOffset = segment.bbox().height + 8; - nonDNAshorizontalOffset = (segment.bbox().width)/2; - } - + nonDNAVerticalOffset = segments[0].bbox().height + 20 if (!interaction.participants[i].SO) { //need to set the role for the segment to be able to add the rendering for inhibition arrow in reder segment interaction.participants[i].segment.role = "inhibition_nonDNA"; + if (interaction.participants[i].isDegraded) { + interaction.participants[i].segment.isDegradated = true + } interaction.participants[i].segment.participantRole = interaction.participants[i].role; - var segment = Segment.render(design, interaction.participants[i].segment, interactions); + var segment = Segment.render(design, interaction.participants[i].segment, interactions, interaction); //move the nonDna part horizontally to put it above the DNA part interacting with it if (isCircuit) { - //segment.dx( (design.geom.participantOffset -1) * (design.geom.defaultGlyphSize.x + design.geom.glyphPadding) + design.geom.glyphPadding + design.geom.defaultGlyphSize.x/2 + 25) segment.dx(nonDNAshorizontalOffset - segment.bbox().width) //move the nonDNA part vertically segment.dy(-nonDNAVerticalOffset); @@ -69,9 +59,8 @@ function render(design, interaction, segments, interactions) { //move the nonDNA part vertically segment.dy(-90); } - } - - segments.push(segment); + segments.push(segment); + } } } diff --git a/lib/interactions/non-covelant-binding.js b/lib/interactions/non-covelant-binding.js index 3417c9f..87f2c22 100644 --- a/lib/interactions/non-covelant-binding.js +++ b/lib/interactions/non-covelant-binding.js @@ -19,16 +19,12 @@ function render(design, interaction, segments, interactions) { let reactantNumber = 0; let productOffset = 0; + let reactant2Offset = 0; let width = 0; for (let i in interaction.participants) { - - if (!interaction.participants[i].segment) { - console.log(interaction.participants[i], "partcipant") - console.log(interaction, "interaction") - } + //clear all the previous rolles attached to participant segment interaction.participants[i].segment.role = null; - if (interaction.participants[i].role === "reactant") { reactantNumber++; @@ -38,23 +34,22 @@ function render(design, interaction, segments, interactions) { interaction.participants[i].segment.isParticipant = true; - var segment = Segment.render(design, interaction.participants[i].segment, interactions); + var segment = Segment.render(design, interaction.participants[i].segment, interactions, interaction); if (i == 0) { productOffset = interaction.segmentWidth; - } if (interaction.participants[i].role === "product") { //segment.dx(110); + reactant2Offset = segment.bbox().width + productOffset segment.dx(productOffset); - } else if (interaction.participants[i].segment.role === "reactant2") { segment.dx(220); - + //segment.dx(reactant2Offset); } segments.push(segment); @@ -68,3 +63,4 @@ module.exports = { + diff --git a/lib/interactions/production.js b/lib/interactions/production.js index 29700b8..022c0b3 100644 --- a/lib/interactions/production.js +++ b/lib/interactions/production.js @@ -2,7 +2,7 @@ var Segment = require('../segment'), Helper = require('./helper') -function render(design, interaction, segments, interactions) { +function render(design, interaction, segments, interactions, nonDNAshorizontalOffset) { //make sure right type of interaction is passed to the function if (interaction.SBO !== "SBO:0000589") { @@ -22,44 +22,35 @@ function render(design, interaction, segments, interactions) { */ Helper.sortParticipants(interaction.participants); nonDNAsVerticalOffset = 0; - nonDNAshorizontalOffset = 0; + //nonDNAshorizontalOffset = 0; isCircuit = true; if (interaction.participants[0].type !== "engineered-region") { isCircuit = false; } for (let i in interaction.participants) { - //clear all the previous rolles attached to participant segment - interaction.participants[i].segment.role = null; + //clear all the previous rolles attached to participant segment + interaction.participants[i].segment.role = null; - //need to set it to true since we don't want to show the label for the segments - interaction.participants[i].segment.isParticipant = true; - - //if participant is a Dna part or circuit - if (interaction.participants[i].SO) { - if (isCircuit) { - interaction.participants[i].segment.isCircuit = true; - } - //update participant offset - design.geom.participantOffset = Helper.find_participant_offset(interaction.participants[i], interaction.displayId, "production"); - var segment = Segment.render(design, interaction.participants[i].segment, interactions); - nonDNAVerticalOffset = segment.bbox().height + 30; - console.log(segment.bbox().height) - nonDNAshorizontalOffset = (segment.bbox().width)/2; - } - + //need to set it to true since we don't want to show the label for the segments + interaction.participants[i].segment.isParticipant = true; + + nonDNAVerticalOffset = segments[0].bbox().height + 20 if (!interaction.participants[i].SO) { interaction.participants[i].segment.role = "production_nonDNA"; + if (interaction.participants[i].isDegraded) { + interaction.participants[i].segment.isDegradated = true + } interaction.participants[i].segment.participantRole = interaction.participants[i].role; - var segment = Segment.render(design, interaction.participants[i].segment, interactions); + var segment = Segment.render(design, interaction.participants[i].segment, interactions, interaction); if (isCircuit) { - //segment.dx( (design.geom.participantOffset -1) * (design.geom.defaultGlyphSize.x + design.geom.glyphPadding) + design.geom.glyphPadding + design.geom.defaultGlyphSize.x/2) segment.dx(nonDNAshorizontalOffset - segment.bbox().width) //move the nonDNA part vertically segment.dy(-nonDNAVerticalOffset); + } else if (!isCircuit) { segment.dx(0) @@ -67,8 +58,8 @@ function render(design, interaction, segments, interactions) { segment.dy(-90); //segment.dx(nonDNAshorizontalOffset - segment.bbox().width) } - } - segments.push(segment); + segments.push(segment); + } } } diff --git a/lib/interactions/stimulation.js b/lib/interactions/stimulation.js index 1cae515..6c342bb 100644 --- a/lib/interactions/stimulation.js +++ b/lib/interactions/stimulation.js @@ -2,7 +2,7 @@ var Segment = require('../segment'), Helper = require('./helper') -function render(design, interaction, segments, interactions) { +function render(design, interaction, segments, interactions, nonDNAshorizontalOffset) { //make sure right type of interaction is passed to the function @@ -23,7 +23,7 @@ function render(design, interaction, segments, interactions) { */ Helper.sortParticipants(interaction.participants); nonDNAsVerticalOffset = 0; - nonDNAshorizontalOffset = 0; + //nonDNAshorizontalOffset = 0; isCircuit = true; if (interaction.participants[0].type !== "engineered-region") { isCircuit = false; @@ -35,31 +35,20 @@ function render(design, interaction, segments, interactions) { //need to set it to true since we don't want to show the label for the segments interaction.participants[i].segment.isParticipant = true; - - //if participant is a Dna part or circuit - if (interaction.participants[i].SO) { - - if (isCircuit) { - interaction.participants[i].segment.isCircuit = true; - } - - //update participant offset - design.geom.participantOffset = Helper.find_participant_offset(interaction.participants[i], interaction.displayId, "simulation"); - var segment = Segment.render(design, interaction.participants[i].segment, interactions); - nonDNAVerticalOffset = segment.bbox().height + 30; - nonDNAshorizontalOffset = (segment.bbox().width)/2; - } + nonDNAVerticalOffset = segments[0].bbox().height + 25 if (!interaction.participants[i].SO) { //need to set the role for the segment to be able to add the rendering for inhibition arrow in reder segment - interaction.participants[i].segment.role = "simulation_nonDNA"; + interaction.participants[i].segment.role = "stimulation_nonDNA"; + if (interaction.participants[i].isDegraded) { + interaction.participants[i].segment.isDegradated = true + } interaction.participants[i].segment.participantRole = interaction.participants[i].role; - var segment = Segment.render(design, interaction.participants[i].segment, interactions); + var segment = Segment.render(design, interaction.participants[i].segment, interactions, interaction); if (isCircuit ) { - //segment.dx( (design.geom.participantOffset -1) * (design.geom.defaultGlyphSize.x + design.geom.glyphPadding) + design.geom.glyphPadding + design.geom.defaultGlyphSize.x/2) segment.dx(nonDNAshorizontalOffset - segment.bbox().width); segment.dy(-nonDNAVerticalOffset); } @@ -68,8 +57,8 @@ function render(design, interaction, segments, interactions) { segment.dy(-90); //segment.dx(nonDNAshorizontalOffset - segment.bbox().width) } - } - segments.push(segment); + segments.push(segment); + } } } diff --git a/lib/segment.js b/lib/segment.js index 9257a95..aaae149 100755 --- a/lib/segment.js +++ b/lib/segment.js @@ -8,7 +8,7 @@ var Rect = require('./geom/rect'), Arrows = require('../font/sbolv/interaction-arrows/main') -function renderSegment(design, segment, interactions,) { +function renderSegment(design, segment, interactions, interaction) { var surface = design.surface; @@ -253,15 +253,15 @@ function renderSegment(design, segment, interactions,) { group.add(arrowGlyph); } - //if glyph object has the role of a simulator in a simulation, Add simulation arrow to the object - else if (segment.role === "simulation_nonDNA") { + //if glyph object has the role of a stimulator in a simulation, Add simulation arrow to the object + else if (segment.role === "stimulation_nonDNA") { - var arrowProps = Arrows.SimulatorArrow.render(design, glyphObject, boundingBoxSize ); + var arrowProps = Arrows.StimulatorArrow.render(design, glyphObject, boundingBoxSize ); var arrowGlyph = arrowProps.glyph; - //if role of nonDNA part is not simulator flip the direction of simulation arrow + //if role of nonDNA part is not stimulator flip the direction of simulation arrow //biologically it might never be the case - if (segment.participantRole !== "simulator") { + if (segment.participantRole !== "stimulator") { var arrowPos = Matrix(); var arrowTransform = Matrix.rotate(arrowPos, 180, { x:24, y:27}); arrowGlyph.transform({ matrix: Matrix.toSVGString(arrowTransform) }); @@ -280,7 +280,6 @@ function renderSegment(design, segment, interactions,) { var arrowGlyph = arrowProps.glyph; arrowGlyph.transform({ matrix: Matrix.toSVGString(arrowTransform) }); group.add(arrowGlyph); - //interaction.participants.segmentWidth = group.bbox().width interaction.segmentWidth = group.bbox().width } @@ -311,6 +310,21 @@ function renderSegment(design, segment, interactions,) { } + + if (segment.isDegradated === true) { + + var arrowPos = Matrix(); + //deponding on the implementation of the glyph, (if it starts from negative x area) we set the offset of degradation arrow + var effectiveOffset = glyphProps.glyphLength ? glyphProps.glyphLength : Math.max(glyph.bbox().width, glyphLength); + var arrowOffset = Vec2(effectiveOffset + 5, -boundingBoxSize.y); + var arrowTransform = Matrix.multiply( Matrix.translation(arrowOffset), arrowPos ); + var arrowProps = Arrows.DegradationArrow.render(design, glyphObject, boundingBoxSize ); + var arrowGlyph = arrowProps.glyph; + arrowGlyph.transform({ matrix: Matrix.toSVGString(arrowTransform) }); + group.add(arrowGlyph); + } + + if(labelText !== undefined) group.add(labelText); @@ -403,15 +417,12 @@ function renderSegment(design, segment, interactions,) { if (!segment.isParticipant) { group.add(labelText); - } - - - + } } - group.displayList = segment; - segment.svg = group; - console.log(group.bbox().height) + group.displayList = segment; + segment.svg = group; + return group; }