From 8b26ccc2504cb270e7866a1c28a5e54218192344 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 21 May 2019 15:12:42 +0200 Subject: [PATCH 01/30] Naming changes to aprox Protocol 0.1 --- FloatingSpace/StrategyPartConstructor.js | 12 ++++++------ FloatingSpace/StrategyPartTitle.js | 6 +++--- Spaces/StrategySpace.js | 7 +++---- StrategySpace/Workspace.js | 24 ++++++++++++------------ 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/FloatingSpace/StrategyPartConstructor.js b/FloatingSpace/StrategyPartConstructor.js index 687a01332..4fc2cca5a 100644 --- a/FloatingSpace/StrategyPartConstructor.js +++ b/FloatingSpace/StrategyPartConstructor.js @@ -154,7 +154,7 @@ function newStrategyPartConstructor () { }] break } - case 'Strategy Entry Event': { + case 'Trigger On Event': { menuItemsInitialValues = [ { action: 'Pin / Unpin', @@ -196,7 +196,7 @@ function newStrategyPartConstructor () { }] break } - case 'Strategy Exit Event': { + case 'Trigger Off Event': { menuItemsInitialValues = [ { action: 'Pin / Unpin', @@ -238,7 +238,7 @@ function newStrategyPartConstructor () { }] break } - case 'Trade Entry Event': { + case 'Take Position Event': { menuItemsInitialValues = [ { action: 'Pin / Unpin', @@ -569,15 +569,15 @@ function newStrategyPartConstructor () { level_1() break } - case 'Strategy Entry Event': { + case 'Trigger On Event': { level_2() break } - case 'Strategy Exit Event': { + case 'Trigger Off Event': { level_2() break } - case 'Trade Entry Event': { + case 'Take Position Event': { level_2() break } diff --git a/FloatingSpace/StrategyPartTitle.js b/FloatingSpace/StrategyPartTitle.js index 0af02da79..4bd50a5f1 100644 --- a/FloatingSpace/StrategyPartTitle.js +++ b/FloatingSpace/StrategyPartTitle.js @@ -55,13 +55,13 @@ function newStrategyPartTitle () { thisObject.allwaysVisible = true break } - case 'Strategy Entry Event': { + case 'Trigger On Event': { break } - case 'Strategy Exit Event': { + case 'Trigger Off Event': { break } - case 'Trade Entry Event': { + case 'Take Position Event': { break } case 'Stop': { diff --git a/Spaces/StrategySpace.js b/Spaces/StrategySpace.js index c4b646d3a..c24ffadbc 100644 --- a/Spaces/StrategySpace.js +++ b/Spaces/StrategySpace.js @@ -46,9 +46,9 @@ function newStrategySpace () { const relationshipArray = [ ['Trading System', 'analysis'], ['Strategy', 'quality'], - ['Strategy Entry Event', 'startup'], - ['Strategy Exit Event', 'support'], - ['Trade Entry Event', 'compass'], + ['Trigger On Event', 'startup'], + ['Trigger Off Event', 'support'], + ['Take Position Event', 'compass'], ['Stop', 'pixel'], ['Take Profit', 'competition'], ['Phase', 'placeholder'], @@ -180,4 +180,3 @@ function newStrategySpace () { } } } - diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index c118b191a..094659ad1 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -92,10 +92,10 @@ function newWorkspace () { let strategy = tradingSystem.strategies[m] createPart('Strategy', strategy.name, strategy, tradingSystem, tradingSystem) - createPart('Strategy Entry Event', '', strategy.entryPoint, strategy, strategy) + createPart('Trigger On Event', '', strategy.entryPoint, strategy, strategy) for (let k = 0; k < strategy.entryPoint.situations.length; k++) { let situation = strategy.entryPoint.situations[k] - createPart('Situation', situation.name, situation, strategy.entryPoint, strategy.entryPoint, 'Strategy Entry' + ' ' + 'Situation') + createPart('Situation', situation.name, situation, strategy.entryPoint, strategy.entryPoint, 'Trigger On' + ' ' + 'Situation') for (let m = 0; m < situation.conditions.length; m++) { let condition = situation.conditions[m] @@ -103,10 +103,10 @@ function newWorkspace () { } } - createPart('Strategy Exit Event', '', strategy.exitPoint, strategy, strategy) + createPart('Trigger Off Event', '', strategy.exitPoint, strategy, strategy) for (let k = 0; k < strategy.exitPoint.situations.length; k++) { let situation = strategy.exitPoint.situations[k] - createPart('Situation', situation.name, situation, strategy.exitPoint, strategy.exitPoint, 'Strategy Exit' + ' ' + 'Situation') + createPart('Situation', situation.name, situation, strategy.exitPoint, strategy.exitPoint, 'Trigger Off' + ' ' + 'Situation') for (let m = 0; m < situation.conditions.length; m++) { let condition = situation.conditions[m] @@ -114,10 +114,10 @@ function newWorkspace () { } } - createPart('Trade Entry Event', '', strategy.sellPoint, strategy, strategy) + createPart('Take Position Event', '', strategy.sellPoint, strategy, strategy) for (let k = 0; k < strategy.sellPoint.situations.length; k++) { let situation = strategy.sellPoint.situations[k] - createPart('Situation', situation.name, situation, strategy.sellPoint, strategy.sellPoint, 'Trade Entry' + ' ' + 'Situation') + createPart('Situation', situation.name, situation, strategy.sellPoint, strategy.sellPoint, 'Take Position' + ' ' + 'Situation') for (let m = 0; m < situation.conditions.length; m++) { let condition = situation.conditions[m] @@ -230,9 +230,9 @@ function newWorkspace () { strategyParent.strategies.push(strategy) createPart('Strategy', strategy.name, strategy, strategyParent, strategyParent, 'Strategy') - createPart('Strategy Entry Event', '', strategy.entryPoint, strategy, strategy) - createPart('Strategy Exit Event', '', strategy.exitPoint, strategy, strategy) - createPart('Trade Entry Event', '', strategy.sellPoint, strategy, strategy) + createPart('Trigger On Event', '', strategy.entryPoint, strategy, strategy) + createPart('Trigger Off Event', '', strategy.exitPoint, strategy, strategy) + createPart('Take Position Event', '', strategy.sellPoint, strategy, strategy) createPart('Stop', '', strategy.stopLoss, strategy, strategy) createPart('Take Profit', '', strategy.buyOrder, strategy, strategy) } @@ -486,7 +486,7 @@ function newWorkspace () { return takeProfit break } - case 'Trade Entry Event': { + case 'Take Position Event': { let event = { type: node.type, subType: node.subType, @@ -501,7 +501,7 @@ function newWorkspace () { return event break } - case 'Strategy Entry Event': { + case 'Trigger On Event': { let event = { type: node.type, subType: node.subType, @@ -516,7 +516,7 @@ function newWorkspace () { return event break } - case 'Strategy Exit Event': { + case 'Trigger Off Event': { let event = { type: node.type, subType: node.subType, From 37bd44e928fa973b77d549c7f9636b409f017cd6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 21 May 2019 17:20:29 +0200 Subject: [PATCH 02/30] Detaching from chainParent Implemented --- FloatingSpace/StrategyPart.js | 30 ++++++++++++++++++++++++++++-- StrategySpace/Workspace.js | 5 +++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index dfeae626b..140686c63 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -47,6 +47,8 @@ function newStrategyPart () { let isHighlighted let highlightCounter = 0 + let previousDistance + let detachFuse = 100 return thisObject function finalize () { @@ -127,8 +129,8 @@ function newStrategyPart () { } if (thisObject.payload.chainParent === undefined) { - thisObject.payload.targetPosition.x = canvas.floatingSpace.container.frame.width / 2, - thisObject.payload.targetPosition.y = canvas.floatingSpace.container.frame.height / 2 + thisObject.payload.targetPosition.x = thisObject.payload.position.x, + thisObject.payload.targetPosition.y = thisObject.payload.position.y } else { thisObject.payload.targetPosition.x = thisObject.payload.chainParent.payload.position.x thisObject.payload.targetPosition.y = thisObject.payload.chainParent.payload.position.y @@ -136,6 +138,30 @@ function newStrategyPart () { iconPhysics() highlightPhisycs() + detachingPhysics() + } + + function detachingPhysics () { + let THRESHOLD + if (thisObject.payload.floatingObject.isPinned === true) { + THRESHOLD = 1.10 + } else { + THRESHOLD = 2.00 + } + + detachFuse-- + if (detachFuse < 0) { + detachFuse = 0 + if (thisObject.payload.chainParent !== undefined) { + let distanceToChainParent = Math.sqrt(Math.pow(thisObject.payload.position.x - thisObject.payload.targetPosition.x, 2) + Math.pow(thisObject.payload.position.y - thisObject.payload.targetPosition.y, 2)) + if (previousDistance !== undefined) { + if (distanceToChainParent / previousDistance > 1.25) { + canvas.strategySpace.workspace.detachNode(thisObject.payload.node) + } + } + previousDistance = distanceToChainParent + } + } } function highlightPhisycs () { diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index 094659ad1..631b4d76d 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -5,6 +5,7 @@ function newWorkspace () { let thisObject = { tradingSystem: undefined, container: undefined, + detachNode: detachNode, getContainer: getContainer, initialize: initialize, finalize: finalize @@ -43,6 +44,10 @@ function newWorkspace () { } + function detachNode (node) { + node.payload.chainParent = undefined + } + function createPart (partType, name, node, parentNode, chainParent, title) { let payload = {} if (chainParent === undefined) { From df67bec0c5e33fe2adbe0b7e92038909c3e3bb04 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 21 May 2019 17:32:12 +0200 Subject: [PATCH 03/30] Filetring out what can not be detached --- StrategySpace/Workspace.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index 631b4d76d..2e4662590 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -45,6 +45,37 @@ function newWorkspace () { } function detachNode (node) { + switch (node.type) { + case 'Trading System': { + return + } + case 'Strategy': { + + } + break + case 'Trigger On Event': { + return + } + break + case 'Trigger Off Event': { + return + } + break + case 'Take Position Event': { + return + } + break + case 'Stop': { + return + } + break + case 'Take Profit': { + return + } + break + default: + + } node.payload.chainParent = undefined } From bf3919d3b1b130f9d4f8b64c5f42be75bb62715e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 22 May 2019 10:21:35 +0200 Subject: [PATCH 04/30] detaching physics corrected --- FloatingSpace/StrategyPart.js | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index 140686c63..576da26ba 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -48,7 +48,6 @@ function newStrategyPart () { let highlightCounter = 0 let previousDistance - let detachFuse = 100 return thisObject function finalize () { @@ -142,25 +141,21 @@ function newStrategyPart () { } function detachingPhysics () { - let THRESHOLD - if (thisObject.payload.floatingObject.isPinned === true) { - THRESHOLD = 1.10 - } else { - THRESHOLD = 2.00 - } + if (thisObject.isOnFocus !== true) { return } - detachFuse-- - if (detachFuse < 0) { - detachFuse = 0 - if (thisObject.payload.chainParent !== undefined) { - let distanceToChainParent = Math.sqrt(Math.pow(thisObject.payload.position.x - thisObject.payload.targetPosition.x, 2) + Math.pow(thisObject.payload.position.y - thisObject.payload.targetPosition.y, 2)) - if (previousDistance !== undefined) { - if (distanceToChainParent / previousDistance > 1.25) { - canvas.strategySpace.workspace.detachNode(thisObject.payload.node) + let THRESHOLD = 1.15 + if (thisObject.payload.chainParent !== undefined) { + let distanceToChainParent = Math.sqrt(Math.pow(thisObject.payload.position.x - thisObject.payload.targetPosition.x, 2) + Math.pow(thisObject.payload.position.y - thisObject.payload.targetPosition.y, 2)) + if (previousDistance !== undefined) { + if (distanceToChainParent / previousDistance > THRESHOLD) { + canvas.strategySpace.workspace.detachNode(thisObject.payload.node) + } else { + if (distanceToChainParent / previousDistance > 1) { + console.log(distanceToChainParent / previousDistance) } } - previousDistance = distanceToChainParent } + previousDistance = distanceToChainParent } } From 8cd8c75752d1468c77bfacd283f8db9cac6d69ba Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 22 May 2019 10:34:12 +0200 Subject: [PATCH 05/30] Detaching handling desconnecting from the structure --- FloatingSpace/StrategyPart.js | 45 +++++++++++++++++++++++------------ StrategySpace/Workspace.js | 21 ++++++++++++++++ 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index 576da26ba..315fcbdb9 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -328,35 +328,50 @@ function newStrategyPart () { switch (thisObject.payload.node.type) { case 'Phase': { let parent = thisObject.payload.parentNode - for (let i = 0; i < parent.phases.length; i++) { - let phase = parent.phases[i] - if (phase.id === thisObject.payload.node.id) { - label = label + ' #' + (i + 1) - return label + if (parent !== undefined) { + for (let i = 0; i < parent.phases.length; i++) { + let phase = parent.phases[i] + if (phase.id === thisObject.payload.node.id) { + label = label + ' #' + (i + 1) + return label + } } + } else { + return label } + break } case 'Situation': { let parent = thisObject.payload.parentNode - for (let i = 0; i < parent.situations.length; i++) { - let situation = parent.situations[i] - if (situation.id === thisObject.payload.node.id) { - label = label + ' #' + (i + 1) - return label + if (parent !== undefined) { + for (let i = 0; i < parent.situations.length; i++) { + let situation = parent.situations[i] + if (situation.id === thisObject.payload.node.id) { + label = label + ' #' + (i + 1) + return label + } } + } else { + return label } + break } case 'Condition': { let parent = thisObject.payload.parentNode - for (let i = 0; i < parent.conditions.length; i++) { - let condition = parent.conditions[i] - if (condition.id === thisObject.payload.node.id) { - label = label + ' #' + (i + 1) - return label + if (parent !== undefined) { + for (let i = 0; i < parent.conditions.length; i++) { + let condition = parent.conditions[i] + if (condition.id === thisObject.payload.node.id) { + label = label + ' #' + (i + 1) + return label + } } + } else { + return label } + break } default: { diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index 2e4662590..2a8a312da 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -73,10 +73,31 @@ function newWorkspace () { return } break + case 'Condition': { + let payload = node.payload + for (let i = 0; i < payload.parentNode.conditions.length; i++) { + let condition = payload.parentNode.conditions[i] + if (condition.id === node.id) { + payload.parentNode.conditions.splice(i, 1) + } + } + } + break + case 'Situation': { + let payload = node.payload + for (let i = 0; i < payload.parentNode.situations.length; i++) { + let situation = payload.parentNode.situations[i] + if (situation.id === node.id) { + payload.parentNode.situations.splice(i, 1) + } + } + } + break default: } node.payload.chainParent = undefined + node.payload.parentNode = undefined } function createPart (partType, name, node, parentNode, chainParent, title) { From 3c46d3ec910288b3bc72f27aad22cf1b3a296f0b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 22 May 2019 11:22:16 +0200 Subject: [PATCH 06/30] Phases correctly detached --- FloatingSpace/StrategyPart.js | 22 +++++++++++----------- StrategySpace/Workspace.js | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index 315fcbdb9..d52b3a7eb 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -142,21 +142,22 @@ function newStrategyPart () { function detachingPhysics () { if (thisObject.isOnFocus !== true) { return } + if (thisObject.payload.chainParent === undefined) { return } + if (thisObject.payload.parentNode === undefined) { return } let THRESHOLD = 1.15 - if (thisObject.payload.chainParent !== undefined) { - let distanceToChainParent = Math.sqrt(Math.pow(thisObject.payload.position.x - thisObject.payload.targetPosition.x, 2) + Math.pow(thisObject.payload.position.y - thisObject.payload.targetPosition.y, 2)) - if (previousDistance !== undefined) { - if (distanceToChainParent / previousDistance > THRESHOLD) { - canvas.strategySpace.workspace.detachNode(thisObject.payload.node) - } else { - if (distanceToChainParent / previousDistance > 1) { - console.log(distanceToChainParent / previousDistance) - } + + let distanceToChainParent = Math.sqrt(Math.pow(thisObject.payload.position.x - thisObject.payload.targetPosition.x, 2) + Math.pow(thisObject.payload.position.y - thisObject.payload.targetPosition.y, 2)) + if (previousDistance !== undefined) { + if (distanceToChainParent / previousDistance > THRESHOLD) { + canvas.strategySpace.workspace.detachNode(thisObject.payload.node) + } else { + if (distanceToChainParent / previousDistance > 1) { + console.log(distanceToChainParent / previousDistance) } } - previousDistance = distanceToChainParent } + previousDistance = distanceToChainParent } function highlightPhisycs () { @@ -464,4 +465,3 @@ function newStrategyPart () { } } } - diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index 2a8a312da..dcd3a9f40 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -93,6 +93,21 @@ function newWorkspace () { } } break + case 'Phase': { + let payload = node.payload + for (let i = 0; i < payload.parentNode.phases.length; i++) { + let phase = payload.parentNode.phases[i] + if (phase.id === node.id) { + for (let j = i + 1; j < payload.parentNode.phases.length; j++) { + let phaseNode = payload.parentNode.phases[j] + phaseNode.payload.parentNode = undefined + } + payload.parentNode.phases.splice(i, payload.parentNode.phases.length) + } + } + } + break + default: } From 547884a5a6a283d0a2971b3827a29c291a6faa7c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 22 May 2019 11:22:53 +0200 Subject: [PATCH 07/30] no more logging --- FloatingSpace/StrategyPart.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index d52b3a7eb..f08eb6d47 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -151,10 +151,6 @@ function newStrategyPart () { if (previousDistance !== undefined) { if (distanceToChainParent / previousDistance > THRESHOLD) { canvas.strategySpace.workspace.detachNode(thisObject.payload.node) - } else { - if (distanceToChainParent / previousDistance > 1) { - console.log(distanceToChainParent / previousDistance) - } } } previousDistance = distanceToChainParent From e3292cf0656bb449b87c0dd4ceb25436c5e0fd16 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 22 May 2019 11:28:45 +0200 Subject: [PATCH 08/30] Detaching Strategies working. --- StrategySpace/Workspace.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index dcd3a9f40..b8b7a01d0 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -50,7 +50,13 @@ function newWorkspace () { return } case 'Strategy': { - + let payload = node.payload + for (let i = 0; i < payload.parentNode.strategies.length; i++) { + let strategy = payload.parentNode.strategies[i] + if (strategy.id === node.id) { + payload.parentNode.strategies.splice(i, 1) + } + } } break case 'Trigger On Event': { @@ -107,9 +113,6 @@ function newWorkspace () { } } break - - default: - } node.payload.chainParent = undefined node.payload.parentNode = undefined From 85d0974e5cd1874dc7d4744ff53745bbd2ca1124 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 22 May 2019 12:00:44 +0200 Subject: [PATCH 09/30] var to let --- FloatingSpace/FloatingLayer.js | 167 ++++++++++++++++++++++----------- 1 file changed, 111 insertions(+), 56 deletions(-) diff --git a/FloatingSpace/FloatingLayer.js b/FloatingSpace/FloatingLayer.js index f3889b6f1..12b19983f 100644 --- a/FloatingSpace/FloatingLayer.js +++ b/FloatingSpace/FloatingLayer.js @@ -15,7 +15,6 @@ function newFloatingLayer () { const MODULE_NAME = 'Floating Layer' - const INFO_LOG = false const ERROR_LOG = true const logger = newWebDebugLog() logger.fileName = MODULE_NAME @@ -121,8 +120,6 @@ function newFloatingLayer () { */ try { - if (INFO_LOG === true) { logger.write('[INFO] getFloatingObject -> Entering function.') } - if (pFloatingObjectHandle !== undefined) { for (let i = 0; i < invisibleFloatingObjects.length; i++) { let floatingObject = invisibleFloatingObjects[i] @@ -436,36 +433,36 @@ function newFloatingLayer () { const coulomb = 0.00001 const minForce = 0.01 - var d = Math.sqrt(Math.pow(payload.targetPosition.x - floatingObject.container.frame.position.x, 2) + Math.pow(payload.targetPosition.y - floatingObject.container.frame.position.y, 2)) // ... we calculate the distance ... + let d = Math.sqrt(Math.pow(payload.targetPosition.x - floatingObject.container.frame.position.x, 2) + Math.pow(payload.targetPosition.y - floatingObject.container.frame.position.y, 2)) // ... we calculate the distance ... - var force = coulomb * d * d / floatingObject.currentMass // In this case the mass of the floatingObject affects the gravity force that it receives, that gives priority to target position to bigger floatingObjects. + let force = coulomb * d * d / floatingObject.currentMass // In this case the mass of the floatingObject affects the gravity force that it receives, that gives priority to target position to bigger floatingObjects. if (force < minForce) { // We need this attraction force to overcome the friction we imposed to the system. force = minForce } - var pos1 = { + let pos1 = { x: floatingObject.container.frame.position.x, y: floatingObject.container.frame.position.y } - var pos2 = { + let pos2 = { x: payload.targetPosition.x, y: payload.targetPosition.y } - var posDiff = { // Next we need the vector resulting from the 2 positions. + let posDiff = { // Next we need the vector resulting from the 2 positions. x: pos2.x - pos1.x, y: pos2.y - pos1.y } if (d !== 0) { - var unitVector = { // To find the unit vector, we divide each component by the magnitude of the vector. + let unitVector = { // To find the unit vector, we divide each component by the magnitude of the vector. x: posDiff.x / d, y: posDiff.y / d } - var forceVector = { + let forceVector = { x: unitVector.x * force, y: unitVector.y * force } @@ -486,19 +483,19 @@ function newFloatingLayer () { const coulomb = 2 - var floatingObject1 = visibleFloatingObjects[currentFloatingObject] + let floatingObject1 = visibleFloatingObjects[currentFloatingObject] - for (var i = 0; i < visibleFloatingObjects.length; i++) { + for (let i = 0; i < visibleFloatingObjects.length; i++) { // The force to be applied is considering all other floatingObjects... if (i !== currentFloatingObject) { // ... except for the current one. - var floatingObject2 = visibleFloatingObjects[i] // So, for each floatingObject... + let floatingObject2 = visibleFloatingObjects[i] // So, for each floatingObject... - var d = Math.sqrt(Math.pow(floatingObject2.container.frame.position.x - floatingObject1.container.frame.position.x, 2) + Math.pow(floatingObject2.container.frame.position.y - floatingObject1.container.frame.position.y, 2)) // ... we calculate the distance ... + let d = Math.sqrt(Math.pow(floatingObject2.container.frame.position.x - floatingObject1.container.frame.position.x, 2) + Math.pow(floatingObject2.container.frame.position.y - floatingObject1.container.frame.position.y, 2)) // ... we calculate the distance ... - var force = coulomb * floatingObject2.currentMass / (d * d) // ... and with it the repulsion force. + let force = coulomb * floatingObject2.currentMass / (d * d) // ... and with it the repulsion force. /* We need to put a hard limit to this force, in order to to eject very little floatingObjects to the infinite and beyond. */ @@ -506,27 +503,85 @@ function newFloatingLayer () { force = 1 } - var pos1 = { + let pos1 = { x: floatingObject1.container.frame.position.x, y: floatingObject1.container.frame.position.y } - var pos2 = { + let pos2 = { x: floatingObject2.container.frame.position.x, y: floatingObject2.container.frame.position.y } - var posDiff = { // Next we need the vector resulting from the 2 positions. + let posDiff = { // Next we need the vector resulting from the 2 positions. x: pos2.x - pos1.x, y: pos2.y - pos1.y } - var unitVector = { // To find the unit vector, we divide each component by the magnitude of the vector. + let unitVector = { // To find the unit vector, we divide each component by the magnitude of the vector. x: posDiff.x / d, y: posDiff.y / d } - var forceVector = { + let forceVector = { + x: unitVector.x * force, + y: unitVector.y * force + } + + /* We substract the force vector to the speed vector of the current floatingObject */ + + floatingObject1.currentSpeed.x = floatingObject1.currentSpeed.x - forceVector.x + floatingObject1.currentSpeed.y = floatingObject1.currentSpeed.y - forceVector.y + } + } + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] repulsionForceBetweenFloatingObjects -> err= ' + err.stack) } + } + } + + function proximityBetweenFloatingObjects (currentFloatingObject) { + try { + let floatingObject1 = visibleFloatingObjects[currentFloatingObject] + + for (let i = 0; i < visibleFloatingObjects.length; i++) { + // The force to be applied is considering all other floatingObjects... + + if (i !== currentFloatingObject) { + // ... except for the current one. + + let floatingObject2 = visibleFloatingObjects[i] // So, for each floatingObject... + + let d = Math.sqrt(Math.pow(floatingObject2.container.frame.position.x - floatingObject1.container.frame.position.x, 2) + Math.pow(floatingObject2.container.frame.position.y - floatingObject1.container.frame.position.y, 2)) // ... we calculate the distance ... + + let force = coulomb * floatingObject2.currentMass / (d * d) // ... and with it the repulsion force. + + /* We need to put a hard limit to this force, in order to to eject very little floatingObjects to the infinite and beyond. */ + + if (force > 1) { + force = 1 + } + + let pos1 = { + x: floatingObject1.container.frame.position.x, + y: floatingObject1.container.frame.position.y + } + + let pos2 = { + x: floatingObject2.container.frame.position.x, + y: floatingObject2.container.frame.position.y + } + + let posDiff = { // Next we need the vector resulting from the 2 positions. + x: pos2.x - pos1.x, + y: pos2.y - pos1.y + } + + let unitVector = { // To find the unit vector, we divide each component by the magnitude of the vector. + x: posDiff.x / d, + y: posDiff.y / d + } + + let forceVector = { x: unitVector.x * force, y: unitVector.y * force } @@ -548,12 +603,12 @@ function newFloatingLayer () { const coulomb = 2 - var floatingObject1 = visibleFloatingObjects[currentFloatingObject] + let floatingObject1 = visibleFloatingObjects[currentFloatingObject] - for (var i = 0; i < visibleFloatingObjects.length; i++) { + for (let i = 0; i < visibleFloatingObjects.length; i++) { // The force to be applied is considering all other floatingObjects... - var floatingObject2 = visibleFloatingObjects[i] // So, for each floatingObject... + let floatingObject2 = visibleFloatingObjects[i] // So, for each floatingObject... let payload = { position: undefined @@ -578,9 +633,9 @@ function newFloatingLayer () { } } - var d = Math.sqrt(Math.pow(payload.targetPosition.x - floatingObject1.container.frame.position.x, 2) + Math.pow(payload.targetPosition.y - floatingObject1.container.frame.position.y, 2)) // ... we calculate the distance ... + let d = Math.sqrt(Math.pow(payload.targetPosition.x - floatingObject1.container.frame.position.x, 2) + Math.pow(payload.targetPosition.y - floatingObject1.container.frame.position.y, 2)) // ... we calculate the distance ... - var force = coulomb * floatingObject2.currentMass / (d * d) // ... and with it the repulsion force. + let force = coulomb * floatingObject2.currentMass / (d * d) // ... and with it the repulsion force. /* We need to put a hard limit to this force, in order to to eject very little floatingObjects to the infinite and beyond. */ @@ -588,28 +643,28 @@ function newFloatingLayer () { force = maxTargetRepulsionForce } - var pos1 = { + let pos1 = { x: floatingObject1.container.frame.position.x, y: floatingObject1.container.frame.position.y } - var pos2 = { + let pos2 = { x: payload.targetPosition.x, y: payload.targetPosition.y } - var posDiff = { // Next we need the vector resulting from the 2 positions. + let posDiff = { // Next we need the vector resulting from the 2 positions. x: pos2.x - pos1.x, y: pos2.y - pos1.y } if (d !== 0) { - var unitVector = { // To find the unit vector, we divide each component by the magnitude of the vector. + let unitVector = { // To find the unit vector, we divide each component by the magnitude of the vector. x: posDiff.x / d, y: posDiff.y / d } - var forceVector = { + let forceVector = { x: unitVector.x * force, y: unitVector.y * force } @@ -647,10 +702,10 @@ function newFloatingLayer () { try { /* This function detects weather 2 floatingObjects collide with each other. */ - var r1 = floatingObject1.container.frame.radius - var r2 = floatingObject2.container.frame.radius + let r1 = floatingObject1.container.frame.radius + let r2 = floatingObject2.container.frame.radius - var distance = Math.sqrt(Math.pow(floatingObject2.container.frame.position.x - floatingObject1.container.frame.position.x, 2) + Math.pow(floatingObject2.container.frame.position.y - floatingObject1.container.frame.position.y, 2)) + let distance = Math.sqrt(Math.pow(floatingObject2.container.frame.position.x - floatingObject1.container.frame.position.x, 2) + Math.pow(floatingObject2.container.frame.position.y - floatingObject1.container.frame.position.y, 2)) if (distance > (r1 + r2)) { // No solutions, the circles are too far apart. @@ -675,26 +730,26 @@ function newFloatingLayer () { try { /* This function changes speed and position of floatingObjects that are in collision */ - var collisionision_angle = Math.atan2((floatingObject2.container.frame.position.y - floatingObject1.container.frame.position.y), (floatingObject2.container.frame.position.x - floatingObject1.container.frame.position.x)) + let collisionision_angle = Math.atan2((floatingObject2.container.frame.position.y - floatingObject1.container.frame.position.y), (floatingObject2.container.frame.position.x - floatingObject1.container.frame.position.x)) - var speed1 = Math.sqrt(floatingObject1.currentSpeed.x * floatingObject1.currentSpeed.x + floatingObject1.currentSpeed.y * floatingObject1.currentSpeed.y) // Magnitude of Speed Vector for floatingObject 1 - var speed2 = Math.sqrt(floatingObject2.currentSpeed.x * floatingObject2.currentSpeed.x + floatingObject2.currentSpeed.y * floatingObject2.currentSpeed.y) // Magnitude of Speed Vector for floatingObject 2 + let speed1 = Math.sqrt(floatingObject1.currentSpeed.x * floatingObject1.currentSpeed.x + floatingObject1.currentSpeed.y * floatingObject1.currentSpeed.y) // Magnitude of Speed Vector for floatingObject 1 + let speed2 = Math.sqrt(floatingObject2.currentSpeed.x * floatingObject2.currentSpeed.x + floatingObject2.currentSpeed.y * floatingObject2.currentSpeed.y) // Magnitude of Speed Vector for floatingObject 2 - var direction_1 = Math.atan2(floatingObject1.currentSpeed.y, floatingObject1.currentSpeed.x) - var direction_2 = Math.atan2(floatingObject2.currentSpeed.y, floatingObject2.currentSpeed.x) + let direction_1 = Math.atan2(floatingObject1.currentSpeed.y, floatingObject1.currentSpeed.x) + let direction_2 = Math.atan2(floatingObject2.currentSpeed.y, floatingObject2.currentSpeed.x) - var new_xspeed_1 = speed1 * Math.cos(direction_1 - collisionision_angle) - var new_yspeed_1 = speed1 * Math.sin(direction_1 - collisionision_angle) - var new_xspeed_2 = speed2 * Math.cos(direction_2 - collisionision_angle) - var new_yspeed_2 = speed2 * Math.sin(direction_2 - collisionision_angle) + let new_xspeed_1 = speed1 * Math.cos(direction_1 - collisionision_angle) + let new_yspeed_1 = speed1 * Math.sin(direction_1 - collisionision_angle) + let new_xspeed_2 = speed2 * Math.cos(direction_2 - collisionision_angle) + let new_yspeed_2 = speed2 * Math.sin(direction_2 - collisionision_angle) - var final_xspeed_1 = ((floatingObject1.currentMass - floatingObject2.currentMass) * new_xspeed_1 + (floatingObject2.currentMass + floatingObject2.currentMass) * new_xspeed_2) / (floatingObject1.currentMass + floatingObject2.currentMass) - var final_xspeed_2 = ((floatingObject1.currentMass + floatingObject1.currentMass) * new_xspeed_1 + (floatingObject2.currentMass - floatingObject1.currentMass) * new_xspeed_2) / (floatingObject1.currentMass + floatingObject2.currentMass) - var final_yspeed_1 = new_yspeed_1 - var final_yspeed_2 = new_yspeed_2 + let final_xspeed_1 = ((floatingObject1.currentMass - floatingObject2.currentMass) * new_xspeed_1 + (floatingObject2.currentMass + floatingObject2.currentMass) * new_xspeed_2) / (floatingObject1.currentMass + floatingObject2.currentMass) + let final_xspeed_2 = ((floatingObject1.currentMass + floatingObject1.currentMass) * new_xspeed_1 + (floatingObject2.currentMass - floatingObject1.currentMass) * new_xspeed_2) / (floatingObject1.currentMass + floatingObject2.currentMass) + let final_yspeed_1 = new_yspeed_1 + let final_yspeed_2 = new_yspeed_2 - var cosAngle = Math.cos(collisionision_angle) - var sinAngle = Math.sin(collisionision_angle) + let cosAngle = Math.cos(collisionision_angle) + let sinAngle = Math.sin(collisionision_angle) floatingObject1.currentSpeed.x = cosAngle * final_xspeed_1 - sinAngle * final_yspeed_1 floatingObject1.currentSpeed.y = sinAngle * final_xspeed_1 + cosAngle * final_yspeed_1 @@ -702,36 +757,36 @@ function newFloatingLayer () { floatingObject2.currentSpeed.x = cosAngle * final_xspeed_2 - sinAngle * final_yspeed_2 floatingObject2.currentSpeed.y = sinAngle * final_xspeed_2 + cosAngle * final_yspeed_2 - var pos1 = { + let pos1 = { x: floatingObject1.container.frame.position.x, y: floatingObject1.container.frame.position.y } - var pos2 = { + let pos2 = { x: floatingObject2.container.frame.position.x, y: floatingObject2.container.frame.position.y } // get the mtd - var posDiff = { + let posDiff = { x: pos1.x - pos2.x, y: pos1.y - pos2.y } - var d = Math.sqrt(Math.pow(floatingObject2.container.frame.position.x - floatingObject1.container.frame.position.x, 2) + Math.pow(floatingObject2.container.frame.position.y - floatingObject1.container.frame.position.y, 2)) + let d = Math.sqrt(Math.pow(floatingObject2.container.frame.position.x - floatingObject1.container.frame.position.x, 2) + Math.pow(floatingObject2.container.frame.position.y - floatingObject1.container.frame.position.y, 2)) // minimum translation distance to push floatingObjects apart after intersecting - var scalar = (((floatingObject1.container.frame.radius + floatingObject2.container.frame.radius) - d) / d) + let scalar = (((floatingObject1.container.frame.radius + floatingObject2.container.frame.radius) - d) / d) - var minTD = { + let minTD = { x: posDiff.x * scalar, y: posDiff.y * scalar } // resolve intersection -- // computing inverse mass quantities - var im1 = 1 / floatingObject1.currentMass - var im2 = 1 / floatingObject2.currentMass + let im1 = 1 / floatingObject1.currentMass + let im2 = 1 / floatingObject2.currentMass // push-pull them apart based off their mass From 96413ad733aa4d06f3f466817435745457a76ecc Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 22 May 2019 12:54:10 +0200 Subject: [PATCH 10/30] Attaching Implemented --- FloatingSpace/FloatingLayer.js | 63 ++++++------------- FloatingSpace/FloatingObject.js | 2 + FloatingSpace/StrategyPart.js | 107 ++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 43 deletions(-) diff --git a/FloatingSpace/FloatingLayer.js b/FloatingSpace/FloatingLayer.js index 12b19983f..7a8d20863 100644 --- a/FloatingSpace/FloatingLayer.js +++ b/FloatingSpace/FloatingLayer.js @@ -394,6 +394,8 @@ function newFloatingLayer () { targetRepulsionForce(i) gravityForce(floatingObject, payload) + + proximityBetweenFloatingObjects(i) } } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] physics -> applyPhysics -> err= ' + err.stack) } @@ -542,58 +544,34 @@ function newFloatingLayer () { function proximityBetweenFloatingObjects (currentFloatingObject) { try { let floatingObject1 = visibleFloatingObjects[currentFloatingObject] - + floatingObject1.nearbyFloatingObjects = [] for (let i = 0; i < visibleFloatingObjects.length; i++) { - // The force to be applied is considering all other floatingObjects... - if (i !== currentFloatingObject) { - // ... except for the current one. - let floatingObject2 = visibleFloatingObjects[i] // So, for each floatingObject... let d = Math.sqrt(Math.pow(floatingObject2.container.frame.position.x - floatingObject1.container.frame.position.x, 2) + Math.pow(floatingObject2.container.frame.position.y - floatingObject1.container.frame.position.y, 2)) // ... we calculate the distance ... - let force = coulomb * floatingObject2.currentMass / (d * d) // ... and with it the repulsion force. - - /* We need to put a hard limit to this force, in order to to eject very little floatingObjects to the infinite and beyond. */ - - if (force > 1) { - force = 1 + if (floatingObject1.nearbyFloatingObjects.length === 0) { + floatingObject1.nearbyFloatingObjects.push([d, floatingObject2]) + } else { + let recordAdded = false + for (let j = 0; j < floatingObject1.nearbyFloatingObjects.length; j++) { + let recordedDistance = floatingObject1.nearbyFloatingObjects[0] + if (d < recordedDistance) { + floatingObject1.nearbyFloatingObjects.splice(j, 0, [d, floatingObject2]) + recordAdded = true + break + } + } + if (recordAdded === false) { + floatingObject1.nearbyFloatingObjects.push([d, floatingObject2]) + } } - - let pos1 = { - x: floatingObject1.container.frame.position.x, - y: floatingObject1.container.frame.position.y - } - - let pos2 = { - x: floatingObject2.container.frame.position.x, - y: floatingObject2.container.frame.position.y - } - - let posDiff = { // Next we need the vector resulting from the 2 positions. - x: pos2.x - pos1.x, - y: pos2.y - pos1.y - } - - let unitVector = { // To find the unit vector, we divide each component by the magnitude of the vector. - x: posDiff.x / d, - y: posDiff.y / d - } - - let forceVector = { - x: unitVector.x * force, - y: unitVector.y * force - } - - /* We substract the force vector to the speed vector of the current floatingObject */ - - floatingObject1.currentSpeed.x = floatingObject1.currentSpeed.x - forceVector.x - floatingObject1.currentSpeed.y = floatingObject1.currentSpeed.y - forceVector.y + floatingObject1.nearbyFloatingObjects.splice(10, floatingObject1.nearbyFloatingObjects.length) } } } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] repulsionForceBetweenFloatingObjects -> err= ' + err.stack) } + if (ERROR_LOG === true) { logger.write('[ERROR] proximityBetweenFloatingObjects -> err= ' + err.stack) } } } @@ -806,4 +784,3 @@ function newFloatingLayer () { } } } - diff --git a/FloatingSpace/FloatingObject.js b/FloatingSpace/FloatingObject.js index a6a8c9bef..266a7cd0c 100644 --- a/FloatingSpace/FloatingObject.js +++ b/FloatingSpace/FloatingObject.js @@ -20,6 +20,7 @@ function newFloatingObject () { rawRadius: 0, // This is the radius of this floating object without zoom. targetRadius: 0, // This is the target radius of the floating object with zoom applied. It should be animated until reaching this value. isPinned: false, + nearbyFloatingObjects: [], pinToggle: pinToggle, physics: physics, initializeMass: initializeMass, @@ -65,6 +66,7 @@ function newFloatingObject () { thisObject.container = undefined thisObject.payload = undefined thisObject.fitFunction = undefined + thisObject.nearbyFloatingObjects = undefined } function initialize (type, payload) { diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index f08eb6d47..a369e2508 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -17,6 +17,8 @@ function newStrategyPart () { codeEditor: undefined, partTitle: undefined, isExecuting: undefined, + getReadyToAttach: getReadyToAttach, + showAvailabilityToAttach: showAvailabilityToAttach, highlight: highlight, unHighlight: unHighlight, physics: physics, @@ -48,6 +50,12 @@ function newStrategyPart () { let highlightCounter = 0 let previousDistance + + let readyToAttachCounter + let isReadyToAttach + let availableToAttachCounter + let isAvailableToAttach + return thisObject function finalize () { @@ -138,6 +146,75 @@ function newStrategyPart () { iconPhysics() highlightPhisycs() detachingPhysics() + attachingPhysics() + } + + function attachingPhysics () { + attacchingCounters() + + if (thisObject.isOnFocus !== true) { return } + + let nearbyFloatingObjects = thisObject.payload.floatingObject.nearbyFloatingObjects + let compatibleType + let compatibleSubType + switch (thisObject.payload.node.type) { + case 'Strategy': + compatibleType = 'Trading System' + compatibleSubType = undefined + break + case 'Phase': + compatibleType = 'Stop' + compatibleSubType = undefined + break + case 'Situation': + compatibleType = 'Phase' + compatibleSubType = undefined + break + case 'Condition': + compatibleType = 'Situation' + compatibleSubType = undefined + break + } + for (let i = 0; i < nearbyFloatingObjects.length; i++) { + let nearby = nearbyFloatingObjects[i] + let distance = nearby[0] + let floatingObject = nearby[1] + let nearbyNode = floatingObject.payload.node + if (nearbyNode.type === compatibleType) { + if (i === 0) { + if (distance < thisObject.container.frame.radius + floatingObject.container.frame.radius) { + nearbyNode.payload.uiObject.getReadyToAttach() + } + } + nearbyNode.payload.uiObject.showAvailabilityToAttach() + } + } + } + + function attacchingCounters () { + readyToAttachCounter-- + if (readyToAttachCounter < 0) { + readyToAttachCounter = 0 + isReadyToAttach = false + } else { + isReadyToAttach = true + } + + availableToAttachCounter-- + if (availableToAttachCounter < 0) { + availableToAttachCounter = 0 + isAvailableToAttach = false + } else { + isAvailableToAttach = true + } + } + + function getReadyToAttach () { + readyToAttachCounter = 10 + } + + function showAvailabilityToAttach () { + availableToAttachCounter = 10 } function detachingPhysics () { @@ -428,6 +505,36 @@ function newStrategyPart () { browserCanvasContext.setLineDash([4, 20]) browserCanvasContext.stroke() } + + if (isReadyToAttach === true) { + VISIBLE_RADIUS = thisObject.container.frame.radius + let OPACITY = readyToAttachCounter / 10 + + browserCanvasContext.beginPath() + browserCanvasContext.arc(visiblePosition.x, visiblePosition.y, VISIBLE_RADIUS, 0, Math.PI * 2, true) + browserCanvasContext.closePath() + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + OPACITY + ')' + + browserCanvasContext.lineWidth = 10 + browserCanvasContext.setLineDash([16, 20]) + browserCanvasContext.stroke() + } + + if (isAvailableToAttach === true) { + VISIBLE_RADIUS = thisObject.container.frame.radius + let OPACITY = availableToAttachCounter / 10 + + browserCanvasContext.beginPath() + browserCanvasContext.arc(visiblePosition.x, visiblePosition.y, VISIBLE_RADIUS, 0, Math.PI * 2, true) + browserCanvasContext.closePath() + + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TURQUOISE + ', ' + OPACITY + ')' + + browserCanvasContext.lineWidth = 10 + browserCanvasContext.setLineDash([8, 20]) + browserCanvasContext.stroke() + } } /* Image */ From 29a3a83041d43a5f6b1278e7a8c0ccc7065fe336 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 22 May 2019 13:24:58 +0200 Subject: [PATCH 11/30] BUG correcting in nearby calculation --- FloatingSpace/FloatingLayer.js | 3 ++- FloatingSpace/StrategyPart.js | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/FloatingSpace/FloatingLayer.js b/FloatingSpace/FloatingLayer.js index 7a8d20863..a366a4b40 100644 --- a/FloatingSpace/FloatingLayer.js +++ b/FloatingSpace/FloatingLayer.js @@ -556,7 +556,7 @@ function newFloatingLayer () { } else { let recordAdded = false for (let j = 0; j < floatingObject1.nearbyFloatingObjects.length; j++) { - let recordedDistance = floatingObject1.nearbyFloatingObjects[0] + let recordedDistance = floatingObject1.nearbyFloatingObjects[j][0] if (d < recordedDistance) { floatingObject1.nearbyFloatingObjects.splice(j, 0, [d, floatingObject2]) recordAdded = true @@ -784,3 +784,4 @@ function newFloatingLayer () { } } } + diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index a369e2508..ba614449c 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -51,9 +51,9 @@ function newStrategyPart () { let previousDistance - let readyToAttachCounter + let readyToAttachCounter = 0 let isReadyToAttach - let availableToAttachCounter + let availableToAttachCounter = 0 let isAvailableToAttach return thisObject @@ -182,7 +182,7 @@ function newStrategyPart () { let nearbyNode = floatingObject.payload.node if (nearbyNode.type === compatibleType) { if (i === 0) { - if (distance < thisObject.container.frame.radius + floatingObject.container.frame.radius) { + if (distance < thisObject.container.frame.radius * 1.5 + floatingObject.container.frame.radius * 1.5) { nearbyNode.payload.uiObject.getReadyToAttach() } } @@ -193,7 +193,7 @@ function newStrategyPart () { function attacchingCounters () { readyToAttachCounter-- - if (readyToAttachCounter < 0) { + if (readyToAttachCounter <= 0) { readyToAttachCounter = 0 isReadyToAttach = false } else { @@ -201,7 +201,7 @@ function newStrategyPart () { } availableToAttachCounter-- - if (availableToAttachCounter < 0) { + if (availableToAttachCounter <= 0) { availableToAttachCounter = 0 isAvailableToAttach = false } else { @@ -507,22 +507,22 @@ function newStrategyPart () { } if (isReadyToAttach === true) { - VISIBLE_RADIUS = thisObject.container.frame.radius + VISIBLE_RADIUS = thisObject.container.frame.radius * 2 let OPACITY = readyToAttachCounter / 10 browserCanvasContext.beginPath() browserCanvasContext.arc(visiblePosition.x, visiblePosition.y, VISIBLE_RADIUS, 0, Math.PI * 2, true) browserCanvasContext.closePath() - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + OPACITY + ')' + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + OPACITY + ')' - browserCanvasContext.lineWidth = 10 - browserCanvasContext.setLineDash([16, 20]) + browserCanvasContext.lineWidth = 20 + browserCanvasContext.setLineDash([12, 20]) browserCanvasContext.stroke() } if (isAvailableToAttach === true) { - VISIBLE_RADIUS = thisObject.container.frame.radius + VISIBLE_RADIUS = thisObject.container.frame.radius * 1.5 let OPACITY = availableToAttachCounter / 10 browserCanvasContext.beginPath() @@ -568,3 +568,4 @@ function newStrategyPart () { } } } + From ba65a6062c4a6a1024269edd03aa74aaa45147c3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 22 May 2019 13:33:59 +0200 Subject: [PATCH 12/30] Approximation to attach ready --- FloatingSpace/StrategyPart.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index ba614449c..fd65783a1 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -153,6 +153,7 @@ function newStrategyPart () { attacchingCounters() if (thisObject.isOnFocus !== true) { return } + if (thisObject.payload.chainParent !== undefined) { return } let nearbyFloatingObjects = thisObject.payload.floatingObject.nearbyFloatingObjects let compatibleType @@ -175,15 +176,17 @@ function newStrategyPart () { compatibleSubType = undefined break } + let foundCompatible = false for (let i = 0; i < nearbyFloatingObjects.length; i++) { let nearby = nearbyFloatingObjects[i] let distance = nearby[0] let floatingObject = nearby[1] let nearbyNode = floatingObject.payload.node if (nearbyNode.type === compatibleType) { - if (i === 0) { + if (foundCompatible === false) { if (distance < thisObject.container.frame.radius * 1.5 + floatingObject.container.frame.radius * 1.5) { nearbyNode.payload.uiObject.getReadyToAttach() + foundCompatible = true } } nearbyNode.payload.uiObject.showAvailabilityToAttach() @@ -521,7 +524,7 @@ function newStrategyPart () { browserCanvasContext.stroke() } - if (isAvailableToAttach === true) { + if (isAvailableToAttach === true && isReadyToAttach === false) { VISIBLE_RADIUS = thisObject.container.frame.radius * 1.5 let OPACITY = availableToAttachCounter / 10 From f06f27834ea39a2933cd442734401f86af6c9d1d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 22 May 2019 13:55:40 +0200 Subject: [PATCH 13/30] Attaching Working with Bugs --- FloatingSpace/StrategyPart.js | 39 ++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index fd65783a1..ba43c3691 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -56,6 +56,9 @@ function newStrategyPart () { let availableToAttachCounter = 0 let isAvailableToAttach + let isAttaching = false + let attachToNode + return thisObject function finalize () { @@ -79,6 +82,7 @@ function newStrategyPart () { } icon = undefined + attachToNode = undefined } function initialize (payload, menuItemsInitialValues) { @@ -177,6 +181,9 @@ function newStrategyPart () { break } let foundCompatible = false + attachToNode = undefined + isAttaching = false + for (let i = 0; i < nearbyFloatingObjects.length; i++) { let nearby = nearbyFloatingObjects[i] let distance = nearby[0] @@ -186,6 +193,8 @@ function newStrategyPart () { if (foundCompatible === false) { if (distance < thisObject.container.frame.radius * 1.5 + floatingObject.container.frame.radius * 1.5) { nearbyNode.payload.uiObject.getReadyToAttach() + isAttaching = true + attachToNode = nearbyNode foundCompatible = true } } @@ -268,6 +277,35 @@ function newStrategyPart () { if (thisObject.codeEditor !== undefined) { thisObject.codeEditor.deactivate() } + + if (isAttaching === true) { + switch (thisObject.payload.node.type) { + case 'Strategy': { + thisObject.payload.parentNode = attachToNode + thisObject.payload.chainParent = attachToNode + thisObject.payload.parentNode.strategies.push(thisObject.payload.node) + } + break + case 'Phase': { + thisObject.payload.parentNode = attachToNode + thisObject.payload.chainParent = attachToNode + thisObject.payload.parentNode.phases.push(thisObject.payload.node) + } + break + case 'Situation': { + thisObject.payload.parentNode = attachToNode + thisObject.payload.chainParent = attachToNode + thisObject.payload.parentNode.situations.push(thisObject.payload.node) + } + break + case 'Condition': { + thisObject.payload.parentNode = attachToNode + thisObject.payload.chainParent = attachToNode + thisObject.payload.parentNode.conditions.push(thisObject.payload.node) + } + break + } + } } function onDisplace (event) { @@ -571,4 +609,3 @@ function newStrategyPart () { } } } - From 5eee5fceeb34fd5e639a89f2a6bbb5b232fb0435 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 22 May 2019 15:45:14 +0200 Subject: [PATCH 14/30] Bug Fixed: previous distance --- FloatingSpace/StrategyPart.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index ba43c3691..ed8dc39e5 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -230,19 +230,20 @@ function newStrategyPart () { } function detachingPhysics () { + let distanceToChainParent = Math.sqrt(Math.pow(thisObject.payload.position.x - thisObject.payload.targetPosition.x, 2) + Math.pow(thisObject.payload.position.y - thisObject.payload.targetPosition.y, 2)) + let ratio = distanceToChainParent / previousDistance + previousDistance = distanceToChainParent if (thisObject.isOnFocus !== true) { return } if (thisObject.payload.chainParent === undefined) { return } if (thisObject.payload.parentNode === undefined) { return } let THRESHOLD = 1.15 - let distanceToChainParent = Math.sqrt(Math.pow(thisObject.payload.position.x - thisObject.payload.targetPosition.x, 2) + Math.pow(thisObject.payload.position.y - thisObject.payload.targetPosition.y, 2)) if (previousDistance !== undefined) { - if (distanceToChainParent / previousDistance > THRESHOLD) { + if (ratio > THRESHOLD) { canvas.strategySpace.workspace.detachNode(thisObject.payload.node) } } - previousDistance = distanceToChainParent } function highlightPhisycs () { @@ -609,3 +610,4 @@ function newStrategyPart () { } } } + From 64a77297d00e2f6053a0d71c61c54d78bc5e1024 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 22 May 2019 16:33:16 +0200 Subject: [PATCH 15/30] Yellow Animation --- FloatingSpace/StrategyPart.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index ed8dc39e5..f6bf6d841 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -51,6 +51,9 @@ function newStrategyPart () { let previousDistance + let readyToAttachDisplayCounter = 5 + let readyToAttachDisplayIncrement = 0.1 + let readyToAttachCounter = 0 let isReadyToAttach let availableToAttachCounter = 0 @@ -204,6 +207,16 @@ function newStrategyPart () { } function attacchingCounters () { + if (readyToAttachDisplayCounter > 15) { + readyToAttachDisplayIncrement = -0.25 + } + + if (readyToAttachDisplayCounter < 5) { + readyToAttachDisplayIncrement = 0.25 + } + + readyToAttachDisplayCounter = readyToAttachDisplayCounter + readyToAttachDisplayIncrement + readyToAttachCounter-- if (readyToAttachCounter <= 0) { readyToAttachCounter = 0 @@ -549,7 +562,7 @@ function newStrategyPart () { } if (isReadyToAttach === true) { - VISIBLE_RADIUS = thisObject.container.frame.radius * 2 + VISIBLE_RADIUS = thisObject.container.frame.radius * 2 + readyToAttachDisplayCounter * 2 let OPACITY = readyToAttachCounter / 10 browserCanvasContext.beginPath() @@ -558,8 +571,8 @@ function newStrategyPart () { browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', ' + OPACITY + ')' - browserCanvasContext.lineWidth = 20 - browserCanvasContext.setLineDash([12, 20]) + browserCanvasContext.lineWidth = 10 + browserCanvasContext.setLineDash([readyToAttachDisplayCounter, readyToAttachDisplayCounter * 2]) browserCanvasContext.stroke() } From 40cceecd25a7a6aca7e0f768565873d223cdba50 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 22 May 2019 16:54:25 +0200 Subject: [PATCH 16/30] Attaching Situations Done --- FloatingSpace/StrategyPart.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index f6bf6d841..a095f7dfc 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -171,11 +171,11 @@ function newStrategyPart () { compatibleSubType = undefined break case 'Phase': - compatibleType = 'Stop' + compatibleType = 'Stop' + '.' + 'Take Profit' + '.' + 'Phase' compatibleSubType = undefined break case 'Situation': - compatibleType = 'Phase' + compatibleType = 'Phase' + '.' + 'Take Position Event' + '.' + 'Trigger On Event' + '.' + 'Trigger Off Event' compatibleSubType = undefined break case 'Condition': @@ -192,7 +192,7 @@ function newStrategyPart () { let distance = nearby[0] let floatingObject = nearby[1] let nearbyNode = floatingObject.payload.node - if (nearbyNode.type === compatibleType) { + if (compatibleType.indexOf(nearbyNode.type) >= 0) { if (foundCompatible === false) { if (distance < thisObject.container.frame.radius * 1.5 + floatingObject.container.frame.radius * 1.5) { nearbyNode.payload.uiObject.getReadyToAttach() @@ -623,4 +623,3 @@ function newStrategyPart () { } } } - From 683657ec58636e395da05ec36918328d74be5c73 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 22 May 2019 17:53:24 +0200 Subject: [PATCH 17/30] Bug Fixed: while deleting parts without parent --- FloatingSpace/StrategyPart.js | 47 ++++++++++++- StrategySpace/Workspace.js | 125 ++++++++++++++++++++++------------ 2 files changed, 124 insertions(+), 48 deletions(-) diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index a095f7dfc..c459212e3 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -301,9 +301,49 @@ function newStrategyPart () { } break case 'Phase': { - thisObject.payload.parentNode = attachToNode - thisObject.payload.chainParent = attachToNode - thisObject.payload.parentNode.phases.push(thisObject.payload.node) + switch (attachToNode.type) { + case 'Stop': { + thisObject.payload.parentNode = attachToNode + if (attachToNode.phases.length > 0) { + let phase = attachToNode.phases[attachToNode.phases.length - 1] + thisObject.payload.chainParent = phase + } else { + thisObject.payload.chainParent = attachToNode + } + attachToNode.phases.push(thisObject.payload.node) + } + break + case 'Take Profit': { + thisObject.payload.parentNode = attachToNode + if (attachToNode.phases.length > 0) { + let phase = attachToNode.phases[attachToNode.phases.length - 1] + thisObject.payload.chainParent = phase + } else { + thisObject.payload.chainParent = attachToNode + } + attachToNode.phases.push(thisObject.payload.node) + } + break + case 'Phase': { + thisObject.payload.parentNode = attachToNode.payload.parentNode + for (let i = 0; i < thisObject.payload.parentNode.phases.length; i++) { + let phase = thisObject.payload.parentNode.phases[i] + if (attachToNode.id === phase.id) { + if (i === thisObject.payload.parentNode.phases.length - 1) { + thisObject.payload.chainParent = attachToNode + thisObject.payload.parentNode.phases.push(thisObject.payload.node) + } else { + thisObject.payload.chainParent = attachToNode + let nextPhase = thisObject.payload.parentNode.phases[i + 1] + nextPhase.payload.chainParent = thisObject.payload.node + thisObject.payload.parentNode.phases.splice(i + 1, 0, thisObject.payload.node) + break + } + } + } + } + break + } } break case 'Situation': { @@ -623,3 +663,4 @@ function newStrategyPart () { } } } + diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index b8b7a01d0..a8f654e24 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -378,19 +378,29 @@ function newWorkspace () { function deleteStrategy (node) { let payload = node.payload - for (let j = 0; j < payload.parentNode.strategies.length; j++) { - let strategy = payload.parentNode.strategies[j] - if (strategy.id === node.id) { - deleteEvent(strategy.entryPoint) - deleteEvent(strategy.exitPoint) - deleteEvent(strategy.sellPoint) - deleteManagedItem(strategy.stopLoss) - deleteManagedItem(strategy.buyOrder) - destroyPart(strategy) - payload.parentNode.strategies.splice(j, 1) - cleanNode(strategy) - return + if (payload.parentNode !== undefined) { + for (let j = 0; j < payload.parentNode.strategies.length; j++) { + let strategy = payload.parentNode.strategies[j] + if (strategy.id === node.id) { + deleteEvent(strategy.entryPoint) + deleteEvent(strategy.exitPoint) + deleteEvent(strategy.sellPoint) + deleteManagedItem(strategy.stopLoss) + deleteManagedItem(strategy.buyOrder) + destroyPart(strategy) + payload.parentNode.strategies.splice(j, 1) + cleanNode(strategy) + return + } } + } else { + deleteEvent(node.entryPoint) + deleteEvent(node.exitPoint) + deleteEvent(node.sellPoint) + deleteManagedItem(node.stopLoss) + deleteManagedItem(node.buyOrder) + destroyPart(node) + cleanNode(node) } } @@ -412,55 +422,80 @@ function newWorkspace () { function deletePhase (node) { let payload = node.payload - for (let k = 0; k < payload.parentNode.phases.length; k++) { - let phase = payload.parentNode.phases[k] - if (phase.id === node.id) { - while (phase.situations.length > 0) { - let situation = phase.situations[0] - deleteSituation(situation) - } - phase.situations = [] + if (payload.parentNode !== undefined) { + for (let k = 0; k < payload.parentNode.phases.length; k++) { + let phase = payload.parentNode.phases[k] + if (phase.id === node.id) { + while (phase.situations.length > 0) { + let situation = phase.situations[0] + deleteSituation(situation) + } + phase.situations = [] /* Before deleting this phase we need to give its chainParent to the next phase down the chain */ - if (k < payload.parentNode.phases.length - 1) { - payload.parentNode.phases[k + 1].payload.chainParent = payload.chainParent - } + if (k < payload.parentNode.phases.length - 1) { + payload.parentNode.phases[k + 1].payload.chainParent = payload.chainParent + } /* Continue destroying this phase */ - destroyPart(phase) - payload.parentNode.phases.splice(k, 1) - cleanNode(phase) - return + destroyPart(phase) + payload.parentNode.phases.splice(k, 1) + cleanNode(phase) + return + } } + } else { + while (node.situations.length > 0) { + let situation = node.situations[0] + deleteSituation(situation) + } + node.situations = [] + destroyPart(node) + cleanNode(node) } } function deleteSituation (node) { let payload = node.payload - for (let j = 0; j < payload.parentNode.situations.length; j++) { - let situation = payload.parentNode.situations[j] - if (situation.id === node.id) { - while (situation.conditions.length > 0) { - let condition = situation.conditions[0] - deleteCondition(condition) + if (payload.parentNode !== undefined) { + for (let j = 0; j < payload.parentNode.situations.length; j++) { + let situation = payload.parentNode.situations[j] + if (situation.id === node.id) { + while (situation.conditions.length > 0) { + let condition = situation.conditions[0] + deleteCondition(condition) + } + situation.conditions = [] + destroyPart(situation) + payload.parentNode.situations.splice(j, 1) + cleanNode(situation) + return } - situation.conditions = [] - destroyPart(situation) - payload.parentNode.situations.splice(j, 1) - cleanNode(situation) - return } + } else { + while (node.conditions.length > 0) { + let condition = node.conditions[0] + deleteCondition(condition) + } + node.conditions = [] + destroyPart(node) + cleanNode(node) } } function deleteCondition (node) { let payload = node.payload - for (let i = 0; i < payload.parentNode.conditions.length; i++) { - let condition = payload.parentNode.conditions[i] - if (condition.id === node.id) { - destroyPart(node) - payload.parentNode.conditions.splice(i, 1) - cleanNode(condition) - return + if (payload.parentNode !== undefined) { + for (let i = 0; i < payload.parentNode.conditions.length; i++) { + let condition = payload.parentNode.conditions[i] + if (condition.id === node.id) { + destroyPart(node) + payload.parentNode.conditions.splice(i, 1) + cleanNode(condition) + return + } } + } else { + destroyPart(node) + cleanNode(node) } } From b4512bbbe5b525cb22116f4dc262182f5c1f3615 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 23 May 2019 09:20:49 +0200 Subject: [PATCH 18/30] BUG FIXED: Phases were not detaching correctly --- StrategySpace/Workspace.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index a8f654e24..2a6e5008c 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -104,11 +104,16 @@ function newWorkspace () { for (let i = 0; i < payload.parentNode.phases.length; i++) { let phase = payload.parentNode.phases[i] if (phase.id === node.id) { - for (let j = i + 1; j < payload.parentNode.phases.length; j++) { - let phaseNode = payload.parentNode.phases[j] - phaseNode.payload.parentNode = undefined + if (i < payload.parentNode.phases.length - 1) { + let nextPhase = payload.parentNode.phases[i + 1] + if (i > 0) { + let previousPhase = payload.parentNode.phases[i - 1] + nextPhase.payload.chainParent = previousPhase + } else { + nextPhase.payload.chainParent = payload.parentNode + } } - payload.parentNode.phases.splice(i, payload.parentNode.phases.length) + payload.parentNode.phases.splice(i, 1) } } } From c1b7da23d408e41012efb5f62ced42fed6218114 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 23 May 2019 09:33:06 +0200 Subject: [PATCH 19/30] Logic moved to workspace --- FloatingSpace/StrategyPart.js | 67 +-------------------------------- StrategySpace/Workspace.js | 70 +++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 66 deletions(-) diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index c459212e3..3ebd69607 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -293,72 +293,7 @@ function newStrategyPart () { } if (isAttaching === true) { - switch (thisObject.payload.node.type) { - case 'Strategy': { - thisObject.payload.parentNode = attachToNode - thisObject.payload.chainParent = attachToNode - thisObject.payload.parentNode.strategies.push(thisObject.payload.node) - } - break - case 'Phase': { - switch (attachToNode.type) { - case 'Stop': { - thisObject.payload.parentNode = attachToNode - if (attachToNode.phases.length > 0) { - let phase = attachToNode.phases[attachToNode.phases.length - 1] - thisObject.payload.chainParent = phase - } else { - thisObject.payload.chainParent = attachToNode - } - attachToNode.phases.push(thisObject.payload.node) - } - break - case 'Take Profit': { - thisObject.payload.parentNode = attachToNode - if (attachToNode.phases.length > 0) { - let phase = attachToNode.phases[attachToNode.phases.length - 1] - thisObject.payload.chainParent = phase - } else { - thisObject.payload.chainParent = attachToNode - } - attachToNode.phases.push(thisObject.payload.node) - } - break - case 'Phase': { - thisObject.payload.parentNode = attachToNode.payload.parentNode - for (let i = 0; i < thisObject.payload.parentNode.phases.length; i++) { - let phase = thisObject.payload.parentNode.phases[i] - if (attachToNode.id === phase.id) { - if (i === thisObject.payload.parentNode.phases.length - 1) { - thisObject.payload.chainParent = attachToNode - thisObject.payload.parentNode.phases.push(thisObject.payload.node) - } else { - thisObject.payload.chainParent = attachToNode - let nextPhase = thisObject.payload.parentNode.phases[i + 1] - nextPhase.payload.chainParent = thisObject.payload.node - thisObject.payload.parentNode.phases.splice(i + 1, 0, thisObject.payload.node) - break - } - } - } - } - break - } - } - break - case 'Situation': { - thisObject.payload.parentNode = attachToNode - thisObject.payload.chainParent = attachToNode - thisObject.payload.parentNode.situations.push(thisObject.payload.node) - } - break - case 'Condition': { - thisObject.payload.parentNode = attachToNode - thisObject.payload.chainParent = attachToNode - thisObject.payload.parentNode.conditions.push(thisObject.payload.node) - } - break - } + canvas.strategySpace.workspace.attachNode(thisObject.payload.node, attachToNode) } } diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index 2a6e5008c..0a94f54bf 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -6,6 +6,7 @@ function newWorkspace () { tradingSystem: undefined, container: undefined, detachNode: detachNode, + attachNode: attachNode, getContainer: getContainer, initialize: initialize, finalize: finalize @@ -123,6 +124,75 @@ function newWorkspace () { node.payload.parentNode = undefined } + function attachNode (node, attachToNode) { + switch (node.type) { + case 'Strategy': { + node.payload.parentNode = attachToNode + node.payload.chainParent = attachToNode + node.payload.parentNode.strategies.push(node) + } + break + case 'Phase': { + switch (attachToNode.type) { + case 'Stop': { + node.payload.parentNode = attachToNode + if (attachToNode.phases.length > 0) { + let phase = attachToNode.phases[attachToNode.phases.length - 1] + node.payload.chainParent = phase + } else { + node.payload.chainParent = attachToNode + } + attachToNode.phases.push(node) + } + break + case 'Take Profit': { + node.payload.parentNode = attachToNode + if (attachToNode.phases.length > 0) { + let phase = attachToNode.phases[attachToNode.phases.length - 1] + node.payload.chainParent = phase + } else { + node.payload.chainParent = attachToNode + } + attachToNode.phases.push(node) + } + break + case 'Phase': { + node.payload.parentNode = attachToNode.payload.parentNode + for (let i = 0; i < node.payload.parentNode.phases.length; i++) { + let phase = node.payload.parentNode.phases[i] + if (attachToNode.id === phase.id) { + if (i === node.payload.parentNode.phases.length - 1) { + node.payload.chainParent = attachToNode + node.payload.parentNode.phases.push(node) + } else { + node.payload.chainParent = attachToNode + let nextPhase = node.payload.parentNode.phases[i + 1] + nextPhase.payload.chainParent = node + node.payload.parentNode.phases.splice(i + 1, 0, node) + break + } + } + } + } + break + } + } + break + case 'Situation': { + node.payload.parentNode = attachToNode + node.payload.chainParent = attachToNode + node.payload.parentNode.situations.push(node) + } + break + case 'Condition': { + node.payload.parentNode = attachToNode + node.payload.chainParent = attachToNode + node.payload.parentNode.conditions.push(node) + } + break + } + } + function createPart (partType, name, node, parentNode, chainParent, title) { let payload = {} if (chainParent === undefined) { From cd71abcf2e2156be50052679f13989c5785aab21 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 23 May 2019 09:59:58 +0200 Subject: [PATCH 20/30] BUG FIXED: not allowed types to attach --- FloatingSpace/StrategyPart.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index 3ebd69607..f85a812b1 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -182,6 +182,8 @@ function newStrategyPart () { compatibleType = 'Situation' compatibleSubType = undefined break + default: + return } let foundCompatible = false attachToNode = undefined @@ -193,6 +195,7 @@ function newStrategyPart () { let floatingObject = nearby[1] let nearbyNode = floatingObject.payload.node if (compatibleType.indexOf(nearbyNode.type) >= 0) { + if (thisObject.payload.node.type === 'Phase' && nearbyNode.type === 'Phase' && nearbyNode.payload.parentNode === undefined) { continue } if (foundCompatible === false) { if (distance < thisObject.container.frame.radius * 1.5 + floatingObject.container.frame.radius * 1.5) { nearbyNode.payload.uiObject.getReadyToAttach() From d54f4bcdd6f5c7359523689ba892e4ad27c97371 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 23 May 2019 10:10:28 +0200 Subject: [PATCH 21/30] Back to displaying long titles --- FloatingSpace/StrategyPartTitle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FloatingSpace/StrategyPartTitle.js b/FloatingSpace/StrategyPartTitle.js index 4bd50a5f1..ec1c0497f 100644 --- a/FloatingSpace/StrategyPartTitle.js +++ b/FloatingSpace/StrategyPartTitle.js @@ -252,7 +252,7 @@ function newStrategyPartTitle () { } function trimTitle (title) { - const MAX_LABEL_LENGTH = 15 + const MAX_LABEL_LENGTH = 35 if (title.length > MAX_LABEL_LENGTH) { title = title.substring(0, MAX_LABEL_LENGTH) + '...' } From 605e68a51ef6827d2b4ad05e386f5fdffdeddf08 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 23 May 2019 10:31:37 +0200 Subject: [PATCH 22/30] Bug Fixed detaching phases from phases --- StrategySpace/Workspace.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index 0a94f54bf..a68c0097c 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -88,6 +88,8 @@ function newWorkspace () { payload.parentNode.conditions.splice(i, 1) } } + node.payload.chainParent = undefined + node.payload.parentNode = undefined } break case 'Situation': { @@ -98,6 +100,8 @@ function newWorkspace () { payload.parentNode.situations.splice(i, 1) } } + node.payload.chainParent = undefined + node.payload.parentNode = undefined } break case 'Phase': { @@ -115,13 +119,12 @@ function newWorkspace () { } } payload.parentNode.phases.splice(i, 1) + payload.parentNode = undefined + return } } } - break } - node.payload.chainParent = undefined - node.payload.parentNode = undefined } function attachNode (node, attachToNode) { @@ -169,12 +172,11 @@ function newWorkspace () { let nextPhase = node.payload.parentNode.phases[i + 1] nextPhase.payload.chainParent = node node.payload.parentNode.phases.splice(i + 1, 0, node) - break + return } } } } - break } } break From dd6af5cd6b3ecd6c9f6b120e16d125f221d645da Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 23 May 2019 12:30:58 +0200 Subject: [PATCH 23/30] Drag Strated and Finished events implemented --- Canvas.js | 9 ++++++++ Container.js | 26 +++++++++++++++++++++++- FloatingSpace/StrategyPart.js | 14 +++++++++++++ FloatingSpace/StrategyPartConstructor.js | 2 +- StrategySpace/Workspace.js | 10 +++++---- 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/Canvas.js b/Canvas.js index f41ffc738..28f8a003b 100644 --- a/Canvas.js +++ b/Canvas.js @@ -202,6 +202,7 @@ function newCanvas () { if (container !== undefined && container.isDraggeable === true) { containerBeingDragged = container containerDragStarted = true + containerBeingDragged.eventHandler.raiseEvent('onDragStarted', point) return } @@ -216,6 +217,7 @@ function newCanvas () { if (container !== undefined && container.isDraggeable === true) { containerBeingDragged = container containerDragStarted = true + containerBeingDragged.eventHandler.raiseEvent('onDragStarted', point) return } @@ -226,6 +228,7 @@ function newCanvas () { if (container !== undefined && container.isDraggeable === true) { containerBeingDragged = container containerDragStarted = true + containerBeingDragged.eventHandler.raiseEvent('onDragStarted', point) return } @@ -241,6 +244,7 @@ function newCanvas () { if (container !== undefined && container.isDraggeable === true && event.button === 2) { containerBeingDragged = container containerDragStarted = true + containerBeingDragged.eventHandler.raiseEvent('onDragStarted', point) return } @@ -257,6 +261,7 @@ function newCanvas () { if (container.isDraggeable === true) { containerBeingDragged = container containerDragStarted = true + containerBeingDragged.eventHandler.raiseEvent('onDragStarted', point) return } else { viewPortBeingDragged = true @@ -270,6 +275,7 @@ function newCanvas () { containerBeingDragged = container containerDragStarted = true floatingObjectDragStarted = true + containerBeingDragged.eventHandler.raiseEvent('onDragStarted', point) return } @@ -386,6 +392,7 @@ function newCanvas () { floatingObjectDragStarted = false viewPortBeingDragged = false + containerBeingDragged.eventHandler.raiseEvent('onDragFinished', point) containerBeingDragged = undefined browserCanvas.style.cursor = 'auto' @@ -409,6 +416,7 @@ function newCanvas () { let targetContainer = thisObject.floatingSpace.getContainer(point) if (targetContainer !== undefined) { if (targetContainer.id !== containerBeingDragged.id) { + containerBeingDragged.eventHandler.raiseEvent('onDragFinished', point) containerBeingDragged = undefined containerDragStarted = false floatingObjectDragStarted = false @@ -417,6 +425,7 @@ function newCanvas () { return } } else { + containerBeingDragged.eventHandler.raiseEvent('onDragFinished', point) containerDragStarted = false containerBeingDragged = undefined floatingObjectDragStarted = false diff --git a/Container.js b/Container.js index 2b467470f..2753e96d9 100644 --- a/Container.js +++ b/Container.js @@ -33,6 +33,8 @@ function newContainer () { let onFocusParentEvent = false let onNotFocusParentEvent = false let onDisplaceParentEvent = false + let onDragStartedParentEvent = false + let onDragFinishedParentEvent = false let isConnectedToParent = false @@ -42,6 +44,8 @@ function newContainer () { let onFocusEventSubscriptionId let onNotFocusEventSubscriptionId let onDisplaceEventSubscriptionId + let onDragStartedEventSubscriptionId + let onDragFinishedEventSubscriptionId return thisObject @@ -53,6 +57,8 @@ function newContainer () { thisObject.parentContainer.eventHandler.stopListening(onFocusEventSubscriptionId) thisObject.parentContainer.eventHandler.stopListening(onNotFocusEventSubscriptionId) thisObject.parentContainer.eventHandler.stopListening(onDisplaceEventSubscriptionId) + thisObject.parentContainer.eventHandler.stopListening(onDragStartedEventSubscriptionId) + thisObject.parentContainer.eventHandler.stopListening(onDragFinishedEventSubscriptionId) thisObject.parentContainer = undefined thisObject.eventHandler.finalize() @@ -86,7 +92,9 @@ function newContainer () { onMouseNotOverEvent, onFocusEvent, onNotFocusEvent, - onDisplaceEvent + onDisplaceEvent, + onDragStartedEvent, + onDragFinishedEvent ) { connectedToParentWidth = onWidth connectedToParentHeight = onHeight @@ -98,6 +106,8 @@ function newContainer () { onFocusParentEvent = onFocusEvent onNotFocusParentEvent = onNotFocusEvent onDisplaceParentEvent = onDisplaceEvent + onDragStartedParentEvent = onDragStartedEvent + onDragFinishedParentEvent = onDragFinishedEvent isConnectedToParent = true @@ -123,6 +133,12 @@ function newContainer () { if (onDisplaceParentEvent === true) { onDisplaceEventSubscriptionId = thisObject.parentContainer.eventHandler.listenToEvent('onDisplace', onDisplace) } + if (onDragStartedParentEvent === true) { + onDragStartedEventSubscriptionId = thisObject.parentContainer.eventHandler.listenToEvent('onDragStarted', onDragStarted) + } + if (onDragFinishedParentEvent === true) { + onDragFinishedEventSubscriptionId = thisObject.parentContainer.eventHandler.listenToEvent('onDragFinished', onDragFinished) + } if (connectedToParentWidth) { thisObject.frame.width = thisObject.parentContainer.frame.width @@ -175,6 +191,14 @@ function newContainer () { thisObject.eventHandler.raiseEvent('onDisplace', event) } + function onDragStarted (event) { + thisObject.eventHandler.raiseEvent('onDragStarted', event) + } + + function onDragFinished (event) { + thisObject.eventHandler.raiseEvent('onDragFinished', event) + } + function isForThisPurpose (purpose) { if (purpose !== undefined) { switch (purpose) { diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index f85a812b1..b27fcb468 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -45,6 +45,8 @@ function newStrategyPart () { let selfFocusEventSubscriptionId let selfNotFocuskEventSubscriptionId let selfDisplaceEventSubscriptionId + let selfDragStartedEventSubscriptionId + let selfDragFinishedEventSubscriptionId let isHighlighted let highlightCounter = 0 @@ -68,6 +70,8 @@ function newStrategyPart () { thisObject.container.eventHandler.stopListening(selfFocusEventSubscriptionId) thisObject.container.eventHandler.stopListening(selfNotFocuskEventSubscriptionId) thisObject.container.eventHandler.stopListening(selfDisplaceEventSubscriptionId) + thisObject.container.eventHandler.stopListening(selfDragStartedEventSubscriptionId) + thisObject.container.eventHandler.stopListening(selfDragFinishedEventSubscriptionId) thisObject.container.finalize() thisObject.container = undefined @@ -111,6 +115,8 @@ function newStrategyPart () { selfFocusEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onFocus', onFocus) selfNotFocuskEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onNotFocus', onNotFocus) selfDisplaceEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onDisplace', onDisplace) + selfDragStartedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onDragStarted', onDragStarted) + selfDragFinishedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onDragFinished', onDragFinished) } function getContainer (point) { @@ -304,6 +310,14 @@ function newStrategyPart () { thisObject.partTitle.exitEditMode() } + function onDragStarted (event) { + console.log('DRAG STARED') + } + + function onDragFinished (event) { + console.log('DRAG FINISHED') + } + function drawBackground () { if (thisObject.isOnFocus === false) { drawConnectingLine() diff --git a/FloatingSpace/StrategyPartConstructor.js b/FloatingSpace/StrategyPartConstructor.js index 4fc2cca5a..bbe0151e8 100644 --- a/FloatingSpace/StrategyPartConstructor.js +++ b/FloatingSpace/StrategyPartConstructor.js @@ -41,7 +41,7 @@ function newStrategyPartConstructor () { strategyPart.isVisibleFunction = canvas.floatingSpace.isThisPointVisible let menuItemsInitialValues = getMenuItemsInitialValues(strategyPart, floatingObject, payload) strategyPart.initialize(payload, menuItemsInitialValues) - strategyPart.container.connectToParent(floatingObject.container, false, false, true, true, false, false, true, true, true) + strategyPart.container.connectToParent(floatingObject.container, false, false, true, true, false, false, true, true, true, true, true) payload.uiObject = strategyPart setFloatingObjectBasicProperties(floatingObject, payload) diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index a68c0097c..557fefa01 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -120,6 +120,7 @@ function newWorkspace () { } payload.parentNode.phases.splice(i, 1) payload.parentNode = undefined + payload.chainParent = undefined return } } @@ -464,8 +465,8 @@ function newWorkspace () { deleteEvent(strategy.sellPoint) deleteManagedItem(strategy.stopLoss) deleteManagedItem(strategy.buyOrder) - destroyPart(strategy) payload.parentNode.strategies.splice(j, 1) + destroyPart(strategy) cleanNode(strategy) return } @@ -513,8 +514,8 @@ function newWorkspace () { payload.parentNode.phases[k + 1].payload.chainParent = payload.chainParent } /* Continue destroying this phase */ - destroyPart(phase) payload.parentNode.phases.splice(k, 1) + destroyPart(phase) cleanNode(phase) return } @@ -541,8 +542,8 @@ function newWorkspace () { deleteCondition(condition) } situation.conditions = [] - destroyPart(situation) payload.parentNode.situations.splice(j, 1) + destroyPart(situation) cleanNode(situation) return } @@ -564,8 +565,8 @@ function newWorkspace () { for (let i = 0; i < payload.parentNode.conditions.length; i++) { let condition = payload.parentNode.conditions[i] if (condition.id === node.id) { - destroyPart(node) payload.parentNode.conditions.splice(i, 1) + destroyPart(node) cleanNode(condition) return } @@ -750,3 +751,4 @@ function newWorkspace () { } } } + From d07b885988ffce19b1bac63cecfb139f16df8fda Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 23 May 2019 12:47:49 +0200 Subject: [PATCH 24/30] Drag amd drop working well --- Canvas.js | 7 +++-- FloatingSpace/StrategyPart.js | 58 +++++++++++++++++++++++------------ 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/Canvas.js b/Canvas.js index 28f8a003b..eca8cf0d9 100644 --- a/Canvas.js +++ b/Canvas.js @@ -392,8 +392,10 @@ function newCanvas () { floatingObjectDragStarted = false viewPortBeingDragged = false - containerBeingDragged.eventHandler.raiseEvent('onDragFinished', point) - containerBeingDragged = undefined + if (containerBeingDragged !== undefined) { + containerBeingDragged.eventHandler.raiseEvent('onDragFinished', event) + containerBeingDragged = undefined + } browserCanvas.style.cursor = 'auto' } catch (err) { @@ -655,3 +657,4 @@ function newCanvas () { } } } + diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index b27fcb468..5d2e35c6b 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -62,6 +62,7 @@ function newStrategyPart () { let isAvailableToAttach let isAttaching = false + let isDragging = false let attachToNode return thisObject @@ -122,17 +123,19 @@ function newStrategyPart () { function getContainer (point) { let container - if (thisObject.codeEditor !== undefined) { - container = thisObject.codeEditor.getContainer(point) + if (isDragging === false && thisObject.isOnFocus === true) { + if (thisObject.codeEditor !== undefined) { + container = thisObject.codeEditor.getContainer(point) + if (container !== undefined) { return container } + } + + container = thisObject.partTitle.getContainer(point) + if (container !== undefined) { return container } + + container = thisObject.menu.getContainer(point) if (container !== undefined) { return container } } - container = thisObject.partTitle.getContainer(point) - if (container !== undefined) { return container } - - container = thisObject.menu.getContainer(point) - if (container !== undefined) { return container } - if (thisObject.container.frame.isThisPointHere(point, true) === true) { return thisObject.container } else { @@ -166,6 +169,7 @@ function newStrategyPart () { attacchingCounters() if (thisObject.isOnFocus !== true) { return } + if (thisObject.isDragging !== true) { return } if (thisObject.payload.chainParent !== undefined) { return } let nearbyFloatingObjects = thisObject.payload.floatingObject.nearbyFloatingObjects @@ -252,6 +256,8 @@ function newStrategyPart () { } function detachingPhysics () { + if (thisObject.isDragging !== true) { return } + let distanceToChainParent = Math.sqrt(Math.pow(thisObject.payload.position.x - thisObject.payload.targetPosition.x, 2) + Math.pow(thisObject.payload.position.y - thisObject.payload.targetPosition.y, 2)) let ratio = distanceToChainParent / previousDistance previousDistance = distanceToChainParent @@ -300,10 +306,6 @@ function newStrategyPart () { if (thisObject.codeEditor !== undefined) { thisObject.codeEditor.deactivate() } - - if (isAttaching === true) { - canvas.strategySpace.workspace.attachNode(thisObject.payload.node, attachToNode) - } } function onDisplace (event) { @@ -311,17 +313,27 @@ function newStrategyPart () { } function onDragStarted (event) { - console.log('DRAG STARED') + thisObject.partTitle.exitEditMode() + if (thisObject.codeEditor !== undefined) { + thisObject.codeEditor.deactivate() + } + isDragging = true } function onDragFinished (event) { - console.log('DRAG FINISHED') + if (isAttaching === true) { + canvas.strategySpace.workspace.attachNode(thisObject.payload.node, attachToNode) + } + isDragging = false } function drawBackground () { if (thisObject.isOnFocus === false) { drawConnectingLine() - thisObject.menu.drawBackground() + + if (isDragging === false && thisObject.isOnFocus === true) { + thisObject.menu.drawBackground() + } } } @@ -335,7 +347,9 @@ function newStrategyPart () { function drawForeground () { if (thisObject.isOnFocus === false) { drawBodyAndPicture() - thisObject.menu.drawForeground() + if (isDragging === false) { + thisObject.menu.drawForeground() + } } } @@ -354,13 +368,17 @@ function newStrategyPart () { if (thisObject.codeEditor !== undefined) { if (thisObject.codeEditor.visible === false) { drawBodyAndPicture() - thisObject.menu.drawBackground() - thisObject.menu.drawForeground() + if (isDragging === false) { + thisObject.menu.drawBackground() + thisObject.menu.drawForeground() + } } } else { drawBodyAndPicture() - thisObject.menu.drawBackground() - thisObject.menu.drawForeground() + if (isDragging === false) { + thisObject.menu.drawBackground() + thisObject.menu.drawForeground() + } } } } From e8a5204a31062d45e1531288461541884c7a4d4b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 23 May 2019 12:55:04 +0200 Subject: [PATCH 25/30] Last bug from detaching corrected --- FloatingSpace/StrategyPart.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/FloatingSpace/StrategyPart.js b/FloatingSpace/StrategyPart.js index 5d2e35c6b..664ec9fc8 100644 --- a/FloatingSpace/StrategyPart.js +++ b/FloatingSpace/StrategyPart.js @@ -169,7 +169,7 @@ function newStrategyPart () { attacchingCounters() if (thisObject.isOnFocus !== true) { return } - if (thisObject.isDragging !== true) { return } + if (isDragging !== true) { return } if (thisObject.payload.chainParent !== undefined) { return } let nearbyFloatingObjects = thisObject.payload.floatingObject.nearbyFloatingObjects @@ -256,7 +256,7 @@ function newStrategyPart () { } function detachingPhysics () { - if (thisObject.isDragging !== true) { return } + if (isDragging !== true) { return } let distanceToChainParent = Math.sqrt(Math.pow(thisObject.payload.position.x - thisObject.payload.targetPosition.x, 2) + Math.pow(thisObject.payload.position.y - thisObject.payload.targetPosition.y, 2)) let ratio = distanceToChainParent / previousDistance @@ -633,4 +633,3 @@ function newStrategyPart () { } } } - From e6f405cb02157738735497d3539c7907e9ab53c9 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 23 May 2019 13:09:32 +0200 Subject: [PATCH 26/30] Strategy Detaching Bug corrected --- StrategySpace/Workspace.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index 557fefa01..3ad5e8b68 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -57,6 +57,8 @@ function newWorkspace () { if (strategy.id === node.id) { payload.parentNode.strategies.splice(i, 1) } + payload.parentNode = undefined + payload.chainParent = undefined } } break From 88fe045281bc49dc9f13ca98b826dc0f57158c23 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 23 May 2019 16:34:59 +0200 Subject: [PATCH 27/30] Drag and Drop of files implemented --- Canvas.js | 162 ++++++++++++++++++++++++------------- Spaces/CockpitSpace.js | 10 +++ StrategySpace/Workspace.js | 7 +- 3 files changed, 121 insertions(+), 58 deletions(-) diff --git a/Canvas.js b/Canvas.js index eca8cf0d9..a8751bdf4 100644 --- a/Canvas.js +++ b/Canvas.js @@ -60,16 +60,15 @@ function newCanvas () { browserCanvas.removeEventListener('click', onMouseClick, false) browserCanvas.removeEventListener('mouseout', onMouseOut, false) - /* Mouse wheel events. */ - if (browserCanvas.removeEventListener) { - // IE9, Chrome, Safari, Opera - browserCanvas.removeEventListener('mousewheel', onMouseWheel, false) - // Firefox - browserCanvas.removeEventListener('DOMMouseScroll', onMouseWheel, false) - } - // IE 6/7/8 - else browserCanvas.detachEvent('onmousewheel', onMouseWheel) + browserCanvas.removeEventListener('mousewheel', onMouseWheel, false)// IE9, Chrome, Safari, Opera + browserCanvas.removeEventListener('DOMMouseScroll', onMouseWheel, false) // Firefox + } else browserCanvas.detachEvent('onmousewheel', onMouseWheel) // IE 6/7/8 + + browserCanvas.removeEventListener('dragenter', onDragEnter, false) + browserCanvas.removeEventListener('dragleave', onDragLeave, false) + browserCanvas.removeEventListener('dragover', onDragOver, false) + browserCanvas.removeEventListener('drop', onDragDrop, false) } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err.stack) } } @@ -110,9 +109,6 @@ function newCanvas () { if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onCharSpaceInitialized -> err = ' + err.stack) } } } - - /* Splash Screen */ - splashScreen = newSplashScreen() splashScreen.initialize() @@ -121,8 +117,6 @@ function newCanvas () { thisObject.animation = animation - /* Here we add all the functions that will be called during the animation cycle. */ - animation.addCallBackFunction('Floating Space Draw', thisObject.floatingSpace.draw) animation.addCallBackFunction('Floating Space Physics', thisObject.floatingSpace.physics) animation.addCallBackFunction('Chart Space Background', thisObject.chartSpace.drawBackground) @@ -144,7 +138,6 @@ function newCanvas () { function initializeBrowserCanvas () { try { browserCanvasContext = browserCanvas.getContext('2d') - // browserCanvasContext.font = 'italic small-caps bold 12px Saira' browserCanvasContext.font = 'Saira' viewPort.initialize() @@ -155,24 +148,23 @@ function newCanvas () { function addCanvasEvents () { try { - /* Mouse down and up events to control the drag of the canvas. */ - browserCanvas.addEventListener('mousedown', onMouseDown, false) browserCanvas.addEventListener('mouseup', onMouseUp, false) browserCanvas.addEventListener('mousemove', onMouseMove, false) browserCanvas.addEventListener('click', onMouseClick, false) browserCanvas.addEventListener('mouseout', onMouseOut, false) - /* Mouse wheel events. */ - if (browserCanvas.addEventListener) { - // IE9, Chrome, Safari, Opera - browserCanvas.addEventListener('mousewheel', onMouseWheel, false) - // Firefox - browserCanvas.addEventListener('DOMMouseScroll', onMouseWheel, false) - } - // IE 6/7/8 - else browserCanvas.attachEvent('onmousewheel', onMouseWheel) + browserCanvas.addEventListener('mousewheel', onMouseWheel, false) // IE9, Chrome, Safari, Opera + browserCanvas.addEventListener('DOMMouseScroll', onMouseWheel, false) // Firefox + } else browserCanvas.attachEvent('onmousewheel', onMouseWheel)// IE 6/7/8 + + /* Dragging Files Over the Canvas */ + + browserCanvas.addEventListener('dragenter', onDragEnter, false) + browserCanvas.addEventListener('dragleave', onDragLeave, false) + browserCanvas.addEventListener('dragover', onDragOver, false) + browserCanvas.addEventListener('drop', onDragDrop, false) // Disables the context menu when you right mouse click the canvas. browserCanvas.oncontextmenu = function (e) { @@ -183,6 +175,63 @@ function newCanvas () { } } + function onDragEnter (event) { + try { + event.preventDefault() + event.stopPropagation() + thisObject.cockpitSpace.toTop() + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] onDragEnter -> err = ' + err.stack) } + } + } + + function onDragLeave (event) { + try { + event.preventDefault() + event.stopPropagation() + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] onDragLeave -> err = ' + err.stack) } + } + } + + function onDragOver (event) { + try { + event.preventDefault() + event.stopPropagation() + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] onDragOver -> err = ' + err.stack) } + } + } + + function onDragDrop (event) { + try { + event.preventDefault() + event.stopPropagation() + console.log(event) + + let files = event.dataTransfer.files + + handleFiles(files) + function handleFiles (files) { + ([...files]).forEach(loadFileData) + } + + function loadFileData (file) { + let reader = new FileReader() + reader.readAsText(file) + reader.onloadend = function () { + let mousePosition = { + x: event.x, + y: event.y + } + thisObject.strategySpace.spawn(reader.result, mousePosition) + } + } + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] onDragDrop -> err = ' + err.stack) } + } + } + function onMouseDown (event) { try { let point = { @@ -373,36 +422,6 @@ function newCanvas () { deactivateDragging(event) } - function deactivateDragging (event) { - try { - if (containerDragStarted || viewPortBeingDragged || floatingObjectDragStarted) { - thisObject.eventHandler.raiseEvent('Drag Finished', undefined) - } - - if ( - containerDragStarted || - floatingObjectDragStarted || - viewPortBeingDragged - ) { - ignoreNextClick = true - } - /* Turn off all the possible things that can be dragged. */ - - containerDragStarted = false - floatingObjectDragStarted = false - viewPortBeingDragged = false - - if (containerBeingDragged !== undefined) { - containerBeingDragged.eventHandler.raiseEvent('onDragFinished', event) - containerBeingDragged = undefined - } - - browserCanvas.style.cursor = 'auto' - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] onMouseUp -> err = ' + err.stack) } - } - } - function onMouseMove (event) { try { let point = { @@ -599,6 +618,36 @@ function newCanvas () { } } + function deactivateDragging (event) { + try { + if (containerDragStarted || viewPortBeingDragged || floatingObjectDragStarted) { + thisObject.eventHandler.raiseEvent('Drag Finished', undefined) + } + + if ( + containerDragStarted || + floatingObjectDragStarted || + viewPortBeingDragged + ) { + ignoreNextClick = true + } + /* Turn off all the possible things that can be dragged. */ + + containerDragStarted = false + floatingObjectDragStarted = false + viewPortBeingDragged = false + + if (containerBeingDragged !== undefined) { + containerBeingDragged.eventHandler.raiseEvent('onDragFinished', event) + containerBeingDragged = undefined + } + + browserCanvas.style.cursor = 'auto' + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] deactivateDragging -> err = ' + err.stack) } + } + } + function checkDrag (event) { try { if (containerDragStarted === true || floatingObjectDragStarted === true || viewPortBeingDragged === true) { @@ -657,4 +706,3 @@ function newCanvas () { } } } - diff --git a/Spaces/CockpitSpace.js b/Spaces/CockpitSpace.js index afff50bad..92cb0e922 100644 --- a/Spaces/CockpitSpace.js +++ b/Spaces/CockpitSpace.js @@ -8,6 +8,8 @@ assetBalances: undefined, restartSimulation: undefined, fullscreen: undefined, + toTop: toTop, + toBottom: toBottom, draw: draw, physics: physics, getContainer: getContainer, @@ -76,6 +78,14 @@ thisObject.container.frame.height = COCKPIT_SPACE_HEIGHT } + function toTop () { + thisObject.container.frame.position.y = 0 + } + + function toBottom () { + thisObject.container.frame.position.y = browserCanvas.height - COCKPIT_SPACE_HEIGHT + } + function physics () { thisObjectPhysics() childrenPhysics() diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index 3ad5e8b68..ba68cb819 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -5,6 +5,7 @@ function newWorkspace () { let thisObject = { tradingSystem: undefined, container: undefined, + spawn: spawn, detachNode: detachNode, attachNode: attachNode, getContainer: getContainer, @@ -45,6 +46,11 @@ function newWorkspace () { } + function spawn (nodeText, point) { + let dirtyNode = JSON.parse(nodeText) + let node = getProtocolNode(dirtyNode) + } + function detachNode (node) { switch (node.type) { case 'Trading System': { @@ -753,4 +759,3 @@ function newWorkspace () { } } } - From fe6750a9b9bea0a221699aeee1291986f62bdb70 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 23 May 2019 20:36:07 +0200 Subject: [PATCH 28/30] Creating Parts From File Implemented --- Canvas.js | 3 +- StrategySpace/Workspace.js | 117 +++++++++++++++++++++++++++++++++++-- 2 files changed, 113 insertions(+), 7 deletions(-) diff --git a/Canvas.js b/Canvas.js index a8751bdf4..24e86e009 100644 --- a/Canvas.js +++ b/Canvas.js @@ -224,7 +224,7 @@ function newCanvas () { x: event.x, y: event.y } - thisObject.strategySpace.spawn(reader.result, mousePosition) + thisObject.strategySpace.workspace.spawn(reader.result, mousePosition) } } } catch (err) { @@ -706,3 +706,4 @@ function newCanvas () { } } } + diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index ba68cb819..2cc678e91 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -28,7 +28,6 @@ function newWorkspace () { return thisObject function finalize () { - destroyStrategyParts() thisObject.tradingSystem = undefined thisObject.container.finalize() thisObject.container = undefined @@ -48,7 +47,117 @@ function newWorkspace () { function spawn (nodeText, point) { let dirtyNode = JSON.parse(nodeText) - let node = getProtocolNode(dirtyNode) + let rootNode = getProtocolNode(dirtyNode) + createPartFromNode(rootNode, undefined, undefined) + } + + function createPartFromNode (node, parentNode, chainParent) { + switch (node.type) { + case 'Condition': + { + let condition = node + createPart('Condition', condition.name, condition, parentNode, chainParent, 'Condition') + return + } + case 'Situation': { + let situation = node + createPart('Situation', situation.name, situation, parentNode, chainParent, 'Situation') + for (let m = 0; m < node.conditions.length; m++) { + let condition = node.conditions[m] + createPartFromNode(condition, situation, situation) + } + return + } + case 'Phase': { + let phase = node + createPart('Phase', phase.name, phase, parentNode, chainParent, phase.subType) + for (let m = 0; m < node.situations.length; m++) { + let situation = node.situations[m] + createPartFromNode(situation, phase, phase) + } + return + } + case 'Stop': { + let stop = node + createPart('Stop', stop.name, stop, parentNode, chainParent, 'Stop') + for (let m = 0; m < node.phases.length; m++) { + let phase = node.phases[m] + let thisChainParent + let lastPhase + if (m === 0) { + thisChainParent = node + } else { + thisChainParent = lastPhase + } + lastPhase = phase + createPartFromNode(phase, stop, thisChainParent) + } + return + } + case 'Take Profit': { + let takeProfit = node + createPart('Take Profit', takeProfit.name, takeProfit, parentNode, chainParent, 'Take Profit') + for (let m = 0; m < node.phases.length; m++) { + let phase = node.phases[m] + let thisChainParent + let lastPhase + if (m === 0) { + thisChainParent = node + } else { + thisChainParent = lastPhase + } + lastPhase = phase + createPartFromNode(phase, takeProfit, thisChainParent) + } + return + } + case 'Take Position Event': { + let event = node + createPart('Take Position Event', event.name, event, parentNode, chainParent, 'Take Position Event') + for (let m = 0; m < node.situations.length; m++) { + let situation = node.situations[m] + createPartFromNode(situation, event, event) + } + return + } + case 'Trigger On Event': { + let event = node + createPart('Trigger On Event', event.name, event, parentNode, chainParent, 'Trigger On Event') + for (let m = 0; m < node.situations.length; m++) { + let situation = node.situations[m] + createPartFromNode(situation, event, event) + } + return + } + case 'Trigger Off Event': { + let event = node + createPart('Trigger Off Event', event.name, event, parentNode, chainParent, 'Trigger Off Event') + for (let m = 0; m < node.situations.length; m++) { + let situation = node.situations[m] + createPartFromNode(situation, event, event) + } + return + } + case 'Strategy': { + let strategy = node + createPart('Strategy', strategy.name, strategy, parentNode, chainParent, 'Strategy') + createPartFromNode(node.entryPoint, strategy, strategy) + createPartFromNode(node.exitPoint, strategy, strategy) + createPartFromNode(node.sellPoint, strategy, strategy) + createPartFromNode(node.stopLoss, strategy, strategy) + createPartFromNode(node.buyOrder, strategy, strategy) + return + } + case 'Trading System': { + let tradingSystem = node + createPart('Trading System', tradingSystem.name, tradingSystem, parentNode, chainParent, 'Trading System') + for (let m = 0; m < node.strategies.length; m++) { + let strategy = node.strategies[m] + createPartFromNode(strategy, tradingSystem, tradingSystem) + } + return + } + } } function detachNode (node) { @@ -335,10 +444,6 @@ function newWorkspace () { } } - function destroyStrategyParts () { - - } - async function onMenuItemClick (payload, action) { switch (action) { case 'Save Trading System': From d9d8b512e558447030d983363cdd2bcc29fdbd40 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 23 May 2019 21:02:30 +0200 Subject: [PATCH 29/30] Bug Fixed when loading from file --- FloatingSpace/StrategyPartTitle.js | 2 ++ StrategySpace/Workspace.js | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/FloatingSpace/StrategyPartTitle.js b/FloatingSpace/StrategyPartTitle.js index ec1c0497f..296b05772 100644 --- a/FloatingSpace/StrategyPartTitle.js +++ b/FloatingSpace/StrategyPartTitle.js @@ -110,6 +110,7 @@ function newStrategyPartTitle () { } function physics () { + if (thisObject.payload.title === undefined) { return } let title = trimTitle(thisObject.payload.title) const FRAME_HEIGHT = 25 @@ -252,6 +253,7 @@ function newStrategyPartTitle () { } function trimTitle (title) { + if (title === undefined) { return } const MAX_LABEL_LENGTH = 35 if (title.length > MAX_LABEL_LENGTH) { title = title.substring(0, MAX_LABEL_LENGTH) + '...' diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index 2cc678e91..c47121601 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -78,12 +78,12 @@ function newWorkspace () { return } case 'Stop': { + let lastPhase let stop = node createPart('Stop', stop.name, stop, parentNode, chainParent, 'Stop') for (let m = 0; m < node.phases.length; m++) { let phase = node.phases[m] let thisChainParent - let lastPhase if (m === 0) { thisChainParent = node } else { @@ -95,12 +95,12 @@ function newWorkspace () { return } case 'Take Profit': { + let lastPhase let takeProfit = node createPart('Take Profit', takeProfit.name, takeProfit, parentNode, chainParent, 'Take Profit') for (let m = 0; m < node.phases.length; m++) { let phase = node.phases[m] let thisChainParent - let lastPhase if (m === 0) { thisChainParent = node } else { @@ -864,3 +864,4 @@ function newWorkspace () { } } } + From bdac9be6a8ca0bb8c0aabbfd9eacbb040a6ea753 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 23 May 2019 21:18:08 +0200 Subject: [PATCH 30/30] File Uploading Working --- Canvas.js | 1 - StrategySpace/Workspace.js | 14 +++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Canvas.js b/Canvas.js index 24e86e009..19a14f60a 100644 --- a/Canvas.js +++ b/Canvas.js @@ -207,7 +207,6 @@ function newCanvas () { try { event.preventDefault() event.stopPropagation() - console.log(event) let files = event.dataTransfer.files diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index c47121601..ba9d5be83 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -25,6 +25,11 @@ function newWorkspace () { thisObject.container.frame.width = 0 thisObject.container.frame.height = 0 + spawnPosition = { + x: canvas.floatingSpace.container.frame.width / 2, + y: canvas.floatingSpace.container.frame.height / 2 + } + return thisObject function finalize () { @@ -46,6 +51,10 @@ function newWorkspace () { } function spawn (nodeText, point) { + point = canvas.floatingSpace.container.frameThisPoint(point) + spawnPosition.x = point.x + spawnPosition.y = point.y + let dirtyNode = JSON.parse(nodeText) let rootNode = getProtocolNode(dirtyNode) createPartFromNode(rootNode, undefined, undefined) @@ -317,8 +326,8 @@ function newWorkspace () { let payload = {} if (chainParent === undefined) { payload.targetPosition = { - x: canvas.floatingSpace.container.frame.width / 2, - y: canvas.floatingSpace.container.frame.height / 2 + x: spawnPosition.x, + y: spawnPosition.y } } else { payload.targetPosition = { @@ -864,4 +873,3 @@ function newWorkspace () { } } } -