From d7bdf280550f8b0419a33dde686ede2c82df3885 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 3 Jul 2019 11:10:23 +0200 Subject: [PATCH] Node Children Implemented --- FloatingSpace/FloatingObject.js | 9 + .../FunctionLibraries/NodeChildren.js | 350 ++++++++++++++++++ StrategySpace/Workspace/Workspace.js | 12 +- 3 files changed, 366 insertions(+), 5 deletions(-) create mode 100644 StrategySpace/Workspace/FunctionLibraries/NodeChildren.js diff --git a/FloatingSpace/FloatingObject.js b/FloatingSpace/FloatingObject.js index 3cf5f06e3..268ead678 100644 --- a/FloatingSpace/FloatingObject.js +++ b/FloatingSpace/FloatingObject.js @@ -170,12 +170,21 @@ function newFloatingObject () { } function tensionPhysics () { + /* Tension Inheritance */ if (thisObject.tensedManually === false) { let parent = thisObject.payload.chainParent if (parent !== undefined) { thisObject.isTensed = parent.payload.floatingObject.isTensed } } + + /* Tension Effect */ + if (thisObject.isTensed === true) { + let parent = thisObject.payload.chainParent + if (parent !== undefined) { + let distanceToChainParent = Math.sqrt(Math.pow(parent.payload.position.x - thisObject.container.frame.position.x, 2) + Math.pow(parent.payload.position.y - thisObject.container.frame.position.y, 2)) // ... we calculate the distance ... + } + } } function thisObjectPhysics () { diff --git a/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js b/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js new file mode 100644 index 000000000..040df4f64 --- /dev/null +++ b/StrategySpace/Workspace/FunctionLibraries/NodeChildren.js @@ -0,0 +1,350 @@ +function newNodeChildren () { + thisObject = { + childrenCount: childrenCount + } + + return thisObject + + function childrenCount (node) { + switch (node.type) { + + case 'Trading System': { + return countChildrenTradingSystem(node) + } + case 'Parameters': { + return countChildrenParameters(node) + } + case 'Base Asset': { + return countChildrenBaseAsset(node) + } + case 'Strategy': { + return countChildrenStrategy(node) + } + case 'Trigger Stage': { + return countChildrenTriggerStage(node) + } + case 'Open Stage': { + return countChildrenOpenStage(node) + } + case 'Manage Stage': { + return countChildrenManageStage(node) + } + case 'Close Stage': { + return countChildrenCloseStage(node) + } + case 'Position Size': { + return countChildrenPositionSize(node) + } + case 'Initial Definition': { + return countChildrenInitialDefinition(node) + } + case 'Event': { + return countChildrenEvent(node) + } + case 'Managed Item': { + return countChildrenManagedItem(node) + } + case 'Phase': { + return countChildrenPhase(node) + } + case 'Formula': { + return countChildrenFormula(node) + } + case 'Situation': { + return countChildrenSituation(node) + } + case 'Condition': { + return countChildrenCondition(node) + } + case 'Code': { + return countChildrenCode(node) + } + } + } + + function countChildrenTradingSystem (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + + for (let i = 0; i < node.strategies.length; i++) { + let child = node.strategies[i] + response.childrenCount++ + if (child.id === node.id) { + response.childIndex = response.childrenCount + } + } + + if (node.parameters !== undefined) { + response.childrenCount++ + if (node.parameters.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenParameters (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.baseAsset !== undefined) { + response.childrenCount++ + if (node.baseAsset.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenBaseAsset (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.formula !== undefined) { + response.childrenCount++ + if (node.formula.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenStrategy (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.triggerStage !== undefined) { + response.childrenCount++ + if (node.triggerStage.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.openStage !== undefined) { + response.childrenCount++ + if (node.openStage.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.manageStage !== undefined) { + response.childrenCount++ + if (node.manageStage.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.closeStage !== undefined) { + response.childrenCount++ + if (node.closeStage.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenTriggerStage (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.triggerOn !== undefined) { + response.childrenCount++ + if (node.triggerOn.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.triggerOff !== undefined) { + response.childrenCount++ + if (node.triggerOff.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.takePosition !== undefined) { + response.childrenCount++ + if (node.takePosition.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.positionSize !== undefined) { + response.childrenCount++ + if (node.positionSize.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenOpenStage (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.initialDefinition !== undefined) { + response.childrenCount++ + if (node.initialDefinition.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenManageStage (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.stopLoss !== undefined) { + response.childrenCount++ + if (node.stopLoss.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.takeProfit !== undefined) { + response.childrenCount++ + if (node.takeProfit.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenCloseStage (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + return response + } + + function countChildrenPositionSize (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.formula !== undefined) { + response.childrenCount++ + if (node.formula.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenInitialDefinition (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.stopLoss !== undefined) { + response.childrenCount++ + if (node.stopLoss.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.takeProfit !== undefined) { + response.childrenCount++ + if (node.takeProfit.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenEvent (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + for (let i = 0; i < node.situations.length; i++) { + let child = node.situations[i] + response.childrenCount++ + if (child.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenManagedItem (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + for (let i = 0; i < node.phases.length; i++) { + let child = node.phases[i] + response.childrenCount++ + if (child.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenPhase (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.formula !== undefined) { + response.childrenCount++ + if (node.formula.id === node.id) { + response.childIndex = response.childrenCount + } + } + if (node.nextPhaseEvent !== undefined) { + response.childrenCount++ + if (node.nextPhaseEvent.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenFormula (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + return response + } + + function countChildrenSituation (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + for (let i = 0; i < node.conditions.length; i++) { + let child = node.conditions[i] + response.childrenCount++ + if (child.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenCondition (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + if (node.code !== undefined) { + response.childrenCount++ + if (node.code.id === node.id) { + response.childIndex = response.childrenCount + } + } + return response + } + + function countChildrenCode (node) { + let response = { + childrenCount: 0, + childIndex: undefined + } + return response + } +} diff --git a/StrategySpace/Workspace/Workspace.js b/StrategySpace/Workspace/Workspace.js index a8b947318..31da4d66a 100644 --- a/StrategySpace/Workspace/Workspace.js +++ b/StrategySpace/Workspace/Workspace.js @@ -6,6 +6,7 @@ function newWorkspace () { tradingSystem: undefined, container: undefined, enabled: false, + nodeChilren: undefined, onMenuItemClick: onMenuItemClick, getProtocolTradingSystem: getProtocolTradingSystem, physics: physics, @@ -36,11 +37,12 @@ function newWorkspace () { let workspaceNode = {} workspaceNode.rootNodes = [] - functionLibraryAttachDetach = newAttachDetach() - functionLibraryNodeDeleter = newNodeDeleter() - functionLibraryPartsFromNodes = newPartsFromNodes() - functionLibraryProtocolNode = newProtocolNode() - functionLibraryWorkspaceNodes = newStringifyNode() + let functionLibraryAttachDetach = newAttachDetach() + let functionLibraryNodeDeleter = newNodeDeleter() + let functionLibraryPartsFromNodes = newPartsFromNodes() + let functionLibraryProtocolNode = newProtocolNode() + let functionLibraryWorkspaceNodes = newStringifyNode() + thisObject.nodeChilren = newNodeChildren() return thisObject