From 04b428f5156b189660345ff33e5e5c555e2cffed Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 23 Nov 2019 15:55:06 +0100 Subject: [PATCH 01/41] Splash Screen Improved --- DesignerSpace/Workspace/Workspace.js | 20 +++++--------------- SplashScreen.js | 7 ++++--- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/DesignerSpace/Workspace/Workspace.js b/DesignerSpace/Workspace/Workspace.js index 9ddfc5263..74758bbe4 100644 --- a/DesignerSpace/Workspace/Workspace.js +++ b/DesignerSpace/Workspace/Workspace.js @@ -69,26 +69,16 @@ function newWorkspace () { async function initialize () { try { - let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE_KEY) - if (user === null) { - return - } - user = JSON.parse(user) + let savedWorkspace = window.localStorage.getItem(CANVAS_APP_NAME + '.' + 'Workspace') - let idAtStrategizer = window.localStorage.getItem(CANVAS_APP_NAME + '.' + 'Strategizer Gateway' + '.' + user.alias) - let savedWorkspace = window.localStorage.getItem(CANVAS_APP_NAME + '.' + 'Workspace' + '.' + user.alias) - - if (savedWorkspace === null || idAtStrategizer === null) { + if (savedWorkspace === null) { thisObject.workspaceNode.type = 'Workspace' thisObject.workspaceNode.name = 'My Workspace' - functionLibraryUiObjectsFromNodes.createUiObjectFromNode(thisObject.workspaceNode, undefined, undefined) - spawnPosition.y = spawnPosition.y + 250 - initializeLoadingFromStrategizer() } else { thisObject.workspaceNode = JSON.parse(savedWorkspace) - functionLibraryUiObjectsFromNodes.recreateWorkspace(thisObject.workspaceNode) - thisObject.enabled = true } + functionLibraryUiObjectsFromNodes.recreateWorkspace(thisObject.workspaceNode) + thisObject.enabled = true } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err.stack) } } @@ -131,7 +121,7 @@ function newWorkspace () { user = JSON.parse(user) let textToSave = stringifyWorkspace() - window.localStorage.setItem(CANVAS_APP_NAME + '.' + 'Workspace' + '.' + user.alias, textToSave) + window.localStorage.setItem(CANVAS_APP_NAME + '.' + 'Workspace', textToSave) } function stringifyWorkspace (removePersonalData) { diff --git a/SplashScreen.js b/SplashScreen.js index 6cf8032d3..86e429b7d 100644 --- a/SplashScreen.js +++ b/SplashScreen.js @@ -57,13 +57,14 @@ function newSplashScreen () { function draw () { if (splashScreenNeeded === false) { stepsInitializationCounter = 100 + canDrawLogo = false fadeOutCounter++ - if (fadeOutCounter > 20) { + if (fadeOutCounter > 2) { return } - opacity = opacity - 0.1 + opacity = opacity - 1 } thisObject.container.frame.draw(false, false) @@ -100,7 +101,7 @@ function newSplashScreen () { /* Second the % of Advance. */ let label = '' + Math.trunc(stepsInitializationCounter) + ' %' - stepsInitializationCounter = stepsInitializationCounter + 2.0 + stepsInitializationCounter = stepsInitializationCounter + 5.0 if (stepsInitializationCounter > 99) { splashScreenNeeded = false From 5e281323e801252ad5b1eb003db7ffd13760b3af Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 23 Nov 2019 15:59:41 +0100 Subject: [PATCH 02/41] Strategizer Cleaned Out --- DesignerSpace/StrategizerGateway.js | 95 ---------------------------- DesignerSpace/Workspace/Workspace.js | 13 +--- Spaces/DesignerSpace.js | 5 +- 3 files changed, 2 insertions(+), 111 deletions(-) delete mode 100644 DesignerSpace/StrategizerGateway.js diff --git a/DesignerSpace/StrategizerGateway.js b/DesignerSpace/StrategizerGateway.js deleted file mode 100644 index 2b626447f..000000000 --- a/DesignerSpace/StrategizerGateway.js +++ /dev/null @@ -1,95 +0,0 @@ - -function newStrategizerGateway () { - const MODULE_NAME = 'Strategizer Gateway' - const logger = newWebDebugLog() - logger.fileName = MODULE_NAME - - let thisObject = { - idAtStrategizer: undefined, - strategizerData: undefined, - container: undefined, - loadFromStrategyzer: loadFromStrategyzer - } - - let colletionItems = [] - - thisObject.container = newContainer() - thisObject.container.name = MODULE_NAME - thisObject.container.initialize() - - thisObject.container.frame.width = 0 - thisObject.container.frame.height = 0 - - thisObject.container.frame.position.x = 0 - thisObject.container.frame.position.y = 0 - - thisObject.container.isDraggeable = false - thisObject.container.isClickeable = false - - let graphQLServer - - return thisObject - - async function loadFromStrategyzer () { - try { - const accessToken = window.localStorage.getItem(LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE_KEY) - if (accessToken === null) { - logger.write('[ERROR] loadFromStrategyzer -> Can load from strategizer because the accessToken is missing.') - return - } - - let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE_KEY) - if (user === null) { - logger.write('[ERROR] saveToStrategyzer -> Can not load from strategizer because user is not logged in. ') - return - } - - user = JSON.parse(user) - - if (window.canvasApp.executingAt === 'Local') { - window.localStorage.setItem(CANVAS_APP_NAME + '.' + MODULE_NAME + '.' + user.alias, 'Local File') - thisObject.strategizerData = JSON.parse('{"type":"Definition"}') - thisObject.idAtStrategizer = 'Local File' - return true - } else { - let fbSlug = 'simulator-bot-' + user.alias.replace('.', '') - - graphQLServer = await axios({ - url: window.canvasApp.graphQL.masterAppApiUrl, - method: 'post', - data: { - query: - ` - query($fbSlug: String!){ - strategizer_TradingSystemByFb(fbSlug: $fbSlug){ - id - fbSlug - data - } - } - `, - - variables: { - fbSlug: fbSlug - } - }, - headers: { - authorization: 'Bearer ' + accessToken - } - }) - - if (graphQLServer.data.errors) { - logger.write('[ERROR] loadFromStrategyzer -> GraphQL Error: ' + JSON.stringify(graphQLServer.data.errors)) - return false - } else { - thisObject.strategizerData = JSON.parse(JSON.stringify(graphQLServer.data.data.strategizer_TradingSystemByFb.data)) - thisObject.idAtStrategizer = graphQLServer.data.data.strategizer_TradingSystemByFb.id - window.localStorage.setItem(CANVAS_APP_NAME + '.' + MODULE_NAME + '.' + user.alias, thisObject.idAtStrategizer) - return true - } - } - } catch (err) { - logger.write('[ERROR] loadFromStrategyzer -> err = ' + err.stack) - } - } -} diff --git a/DesignerSpace/Workspace/Workspace.js b/DesignerSpace/Workspace/Workspace.js index 74758bbe4..1c43e2a9b 100644 --- a/DesignerSpace/Workspace/Workspace.js +++ b/DesignerSpace/Workspace/Workspace.js @@ -67,7 +67,7 @@ function newWorkspace () { thisObject.workspaceNode = undefined } - async function initialize () { + function initialize () { try { let savedWorkspace = window.localStorage.getItem(CANVAS_APP_NAME + '.' + 'Workspace') @@ -84,17 +84,6 @@ function newWorkspace () { } } - async function initializeLoadingFromStrategizer () { - let result = await canvas.designerSpace.strategizerGateway.loadFromStrategyzer() - if (result === true) { - thisObject.definition = canvas.designerSpace.strategizerGateway.strategizerData - thisObject.workspaceNode.rootNodes.push(thisObject.definition) - functionLibraryUiObjectsFromNodes.createUiObjectFromNode(thisObject.definition, undefined, undefined) - - thisObject.enabled = true - } - } - function chainDetachNode (node) { functionLibraryChainAttachDetach.chainDetachNode(node, thisObject.workspaceNode.rootNodes) } diff --git a/Spaces/DesignerSpace.js b/Spaces/DesignerSpace.js index be4207f31..ba1413c04 100644 --- a/Spaces/DesignerSpace.js +++ b/Spaces/DesignerSpace.js @@ -3,7 +3,6 @@ function newDesignerSpace () { const MODULE_NAME = 'Strategy Space' let thisObject = { sidePanel: undefined, - strategizerGateway: undefined, container: undefined, iconCollection: undefined, iconByUiObjectType: undefined, @@ -27,12 +26,10 @@ function newDesignerSpace () { return thisObject - async function initialize () { + function initialize () { loadIconCollection() buildIconByUiObjectTypeMap() - thisObject.strategizerGateway = newStrategizerGateway() - thisObject.workspace = newWorkspace() thisObject.workspace.initialize() } From 24d2443c1aaeeddf607a1c3aa73df6ceac42072f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Nov 2019 12:07:19 +0100 Subject: [PATCH 03/41] Formula Automatically Created on Record Properties --- .../Workspace/FunctionLibraries/UiObjectsFromNodes.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js index dc713be6f..742f52a8a 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js +++ b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js @@ -1308,13 +1308,17 @@ function newUiObjectsFromNodes () { let object = { type: 'Record Property', name: 'New Record Property', - code: '{}' + code: '{}', + formula: { + code: DEFAULT_FORMULA_TEXT + } } if (node.properties === undefined) { node.properties = [] } node.properties.push(object) createUiObject(object.type, object.name, object, node, node) + createUiObject('Formula', '', object.formula, object, object) return object } From 419107a38d754a4cf9952707849518e1087a3a75 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Nov 2019 12:58:42 +0100 Subject: [PATCH 04/41] Inheritance of UIObject properties when adding new ones --- .../FunctionLibraries/UiObjectsFromNodes.js | 382 +++++++++--------- FloatingSpace/UiObjectConstructor.js | 18 +- 2 files changed, 208 insertions(+), 192 deletions(-) diff --git a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js index 742f52a8a..f495e75e6 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js +++ b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js @@ -77,7 +77,7 @@ function newUiObjectsFromNodes () { mapOfReferenceParents = new Map() mapOfReferenceChildren = new Map() let workspace = node - createUiObject('Workspace', workspace.name, workspace, undefined, undefined, 'Workspace') + createUiObject(false, 'Workspace', workspace.name, workspace, undefined, undefined, 'Workspace') if (node.rootNodes !== undefined) { for (let i = 0; i < node.rootNodes.length; i++) { let rootNode = node.rootNodes[i] @@ -112,12 +112,12 @@ function newUiObjectsFromNodes () { switch (node.type) { case 'Code': { - createUiObject('Code', node.name, node, parentNode, chainParent, 'Code', positionOffset) + createUiObject(false, 'Code', node.name, node, parentNode, chainParent, 'Code', positionOffset) return } case 'Condition': { - createUiObject('Condition', node.name, node, parentNode, chainParent, 'Condition', positionOffset) + createUiObject(false, 'Condition', node.name, node, parentNode, chainParent, 'Condition', positionOffset) if (node.code !== undefined) { createUiObjectFromNode(node.code, node, node, positionOffset) } @@ -125,7 +125,7 @@ function newUiObjectsFromNodes () { } case 'Situation': { let situation = node - createUiObject('Situation', situation.name, situation, parentNode, chainParent, 'Situation', positionOffset) + createUiObject(false, 'Situation', situation.name, situation, parentNode, chainParent, 'Situation', positionOffset) for (let m = 0; m < node.conditions.length; m++) { let condition = node.conditions[m] createUiObjectFromNode(condition, situation, situation, positionOffset) @@ -134,12 +134,12 @@ function newUiObjectsFromNodes () { } case 'Formula': { - createUiObject('Formula', node.name, node, parentNode, chainParent, 'Formula', positionOffset) + createUiObject(false, 'Formula', node.name, node, parentNode, chainParent, 'Formula', positionOffset) return } case 'Next Phase Event': { - createUiObject('Next Phase Event', node.name, node, parentNode, chainParent, 'Next Phase Event', positionOffset) + createUiObject(false, 'Next Phase Event', node.name, node, parentNode, chainParent, 'Next Phase Event', positionOffset) for (let m = 0; m < node.situations.length; m++) { let situation = node.situations[m] createUiObjectFromNode(situation, node, node, positionOffset) @@ -155,7 +155,7 @@ function newUiObjectsFromNodes () { } case 'Phase': { let phase = node - createUiObject('Phase', phase.name, phase, parentNode, chainParent, phase.subType, positionOffset) + createUiObject(false, 'Phase', phase.name, phase, parentNode, chainParent, phase.subType, positionOffset) if (node.formula !== undefined) { createUiObjectFromNode(node.formula, phase, phase, positionOffset) @@ -175,7 +175,7 @@ function newUiObjectsFromNodes () { case 'Stop': { let lastPhase let stop = node - createUiObject('Stop', stop.name, stop, parentNode, chainParent, 'Stop', positionOffset) + createUiObject(false, 'Stop', stop.name, stop, parentNode, chainParent, 'Stop', positionOffset) for (let m = 0; m < node.phases.length; m++) { let phase = node.phases[m] let thisChainParent @@ -192,7 +192,7 @@ function newUiObjectsFromNodes () { case 'Take Profit': { let lastPhase let takeProfit = node - createUiObject('Take Profit', takeProfit.name, takeProfit, parentNode, chainParent, 'Take Profit', positionOffset) + createUiObject(false, 'Take Profit', takeProfit.name, takeProfit, parentNode, chainParent, 'Take Profit', positionOffset) for (let m = 0; m < node.phases.length; m++) { let phase = node.phases[m] let thisChainParent @@ -208,16 +208,16 @@ function newUiObjectsFromNodes () { } case 'Open Execution': { - createUiObject('Open Execution', node.name, node, parentNode, chainParent, 'Open Execution', positionOffset) + createUiObject(false, 'Open Execution', node.name, node, parentNode, chainParent, 'Open Execution', positionOffset) return } case 'Close Execution': { - createUiObject('Close Execution', node.name, node, parentNode, chainParent, 'Close Execution', positionOffset) + createUiObject(false, 'Close Execution', node.name, node, parentNode, chainParent, 'Close Execution', positionOffset) return } case 'Initial Definition': { - createUiObject('Initial Definition', node.name, node, parentNode, chainParent, 'Initial Definition', positionOffset) + createUiObject(false, 'Initial Definition', node.name, node, parentNode, chainParent, 'Initial Definition', positionOffset) if (node.stopLoss !== undefined) { createUiObjectFromNode(node.stopLoss, node, node, positionOffset) @@ -235,7 +235,7 @@ function newUiObjectsFromNodes () { } case 'Take Position Event': { let event = node - createUiObject('Take Position Event', event.name, event, parentNode, chainParent, 'Take Position Event', positionOffset) + createUiObject(false, 'Take Position Event', event.name, event, parentNode, chainParent, 'Take Position Event', positionOffset) for (let m = 0; m < node.situations.length; m++) { let situation = node.situations[m] createUiObjectFromNode(situation, event, event, positionOffset) @@ -251,7 +251,7 @@ function newUiObjectsFromNodes () { } case 'Trigger On Event': { let event = node - createUiObject('Trigger On Event', event.name, event, parentNode, chainParent, 'Trigger On Event', positionOffset) + createUiObject(false, 'Trigger On Event', event.name, event, parentNode, chainParent, 'Trigger On Event', positionOffset) for (let m = 0; m < node.situations.length; m++) { let situation = node.situations[m] createUiObjectFromNode(situation, event, event, positionOffset) @@ -267,7 +267,7 @@ function newUiObjectsFromNodes () { } case 'Trigger Off Event': { let event = node - createUiObject('Trigger Off Event', event.name, event, parentNode, chainParent, 'Trigger Off Event', positionOffset) + createUiObject(false, 'Trigger Off Event', event.name, event, parentNode, chainParent, 'Trigger Off Event', positionOffset) for (let m = 0; m < node.situations.length; m++) { let situation = node.situations[m] createUiObjectFromNode(situation, event, event, positionOffset) @@ -282,14 +282,14 @@ function newUiObjectsFromNodes () { return } case 'Position Size': { - createUiObject('Position Size', node.name, node, parentNode, chainParent, 'Position Size', positionOffset) + createUiObject(false, 'Position Size', node.name, node, parentNode, chainParent, 'Position Size', positionOffset) if (node.formula !== undefined) { createUiObjectFromNode(node.formula, node, node, positionOffset) } return } case 'Position Rate': { - createUiObject('Position Rate', node.name, node, parentNode, chainParent, 'Position Rate', positionOffset) + createUiObject(false, 'Position Rate', node.name, node, parentNode, chainParent, 'Position Rate', positionOffset) if (node.formula !== undefined) { createUiObjectFromNode(node.formula, node, node, positionOffset) } @@ -297,7 +297,7 @@ function newUiObjectsFromNodes () { } case 'Trigger Stage': { let stage = node - createUiObject('Trigger Stage', stage.name, stage, parentNode, chainParent, 'Trigger Stage', positionOffset) + createUiObject(false, 'Trigger Stage', stage.name, stage, parentNode, chainParent, 'Trigger Stage', positionOffset) if (node.triggerOn !== undefined) { createUiObjectFromNode(node.triggerOn, stage, stage, positionOffset) @@ -312,7 +312,7 @@ function newUiObjectsFromNodes () { } case 'Open Stage': { let stage = node - createUiObject('Open Stage', stage.name, stage, parentNode, chainParent, 'Open Stage', positionOffset) + createUiObject(false, 'Open Stage', stage.name, stage, parentNode, chainParent, 'Open Stage', positionOffset) if (node.initialDefinition !== undefined) { createUiObjectFromNode(node.initialDefinition, stage, stage, positionOffset) @@ -324,7 +324,7 @@ function newUiObjectsFromNodes () { } case 'Manage Stage': { let stage = node - createUiObject('Manage Stage', stage.name, stage, parentNode, chainParent, 'Manage Stage', positionOffset) + createUiObject(false, 'Manage Stage', stage.name, stage, parentNode, chainParent, 'Manage Stage', positionOffset) if (node.stopLoss !== undefined) { createUiObjectFromNode(node.stopLoss, stage, stage, positionOffset) @@ -336,7 +336,7 @@ function newUiObjectsFromNodes () { } case 'Close Stage': { let stage = node - createUiObject('Close Stage', stage.name, stage, parentNode, chainParent, 'Close Stage', positionOffset) + createUiObject(false, 'Close Stage', stage.name, stage, parentNode, chainParent, 'Close Stage', positionOffset) if (node.closeExecution !== undefined) { createUiObjectFromNode(node.closeExecution, stage, stage, positionOffset) @@ -345,7 +345,7 @@ function newUiObjectsFromNodes () { } case 'Strategy': { let strategy = node - createUiObject('Strategy', strategy.name, strategy, parentNode, chainParent, 'Strategy', positionOffset) + createUiObject(false, 'Strategy', strategy.name, strategy, parentNode, chainParent, 'Strategy', positionOffset) if (node.triggerStage !== undefined) { createUiObjectFromNode(node.triggerStage, strategy, strategy, positionOffset) } @@ -361,27 +361,27 @@ function newUiObjectsFromNodes () { return } case 'Base Asset': { - createUiObject('Base Asset', node.name, node, parentNode, chainParent, 'Base Asset', positionOffset) + createUiObject(false, 'Base Asset', node.name, node, parentNode, chainParent, 'Base Asset', positionOffset) return } case 'Time Range': { - createUiObject('Time Range', node.name, node, parentNode, chainParent, 'Time Range', positionOffset) + createUiObject(false, 'Time Range', node.name, node, parentNode, chainParent, 'Time Range', positionOffset) return } case 'Time Period': { - createUiObject('Time Period', node.name, node, parentNode, chainParent, 'Time Period', positionOffset) + createUiObject(false, 'Time Period', node.name, node, parentNode, chainParent, 'Time Period', positionOffset) return } case 'Slippage': { - createUiObject('Slippage', node.name, node, parentNode, chainParent, 'Slippage', positionOffset) + createUiObject(false, 'Slippage', node.name, node, parentNode, chainParent, 'Slippage', positionOffset) return } case 'Fee Structure': { - createUiObject('Fee Structure', node.name, node, parentNode, chainParent, 'Fee Structure', positionOffset) + createUiObject(false, 'Fee Structure', node.name, node, parentNode, chainParent, 'Fee Structure', positionOffset) return } case 'Parameters': { - createUiObject('Parameters', node.name, node, parentNode, chainParent, 'Parameters', positionOffset) + createUiObject(false, 'Parameters', node.name, node, parentNode, chainParent, 'Parameters', positionOffset) if (node.baseAsset !== undefined) { createUiObjectFromNode(node.baseAsset, node, node, positionOffset) } @@ -404,7 +404,7 @@ function newUiObjectsFromNodes () { } case 'Trading System': { let tradingSystem = node - createUiObject('Trading System', tradingSystem.name, tradingSystem, parentNode, chainParent, 'Trading System', positionOffset) + createUiObject(false, 'Trading System', tradingSystem.name, tradingSystem, parentNode, chainParent, 'Trading System', positionOffset) for (let m = 0; m < node.strategies.length; m++) { let strategy = node.strategies[m] createUiObjectFromNode(strategy, tradingSystem, tradingSystem, positionOffset) @@ -415,7 +415,7 @@ function newUiObjectsFromNodes () { return } case 'Personal Data': { - createUiObject('Personal Data', node.name, node, parentNode, chainParent, 'Personal Data', positionOffset) + createUiObject(false, 'Personal Data', node.name, node, parentNode, chainParent, 'Personal Data', positionOffset) for (let m = 0; m < node.exchangeAccounts.length; m++) { let exchangeAccount = node.exchangeAccounts[m] createUiObjectFromNode(exchangeAccount, node, node, positionOffset) @@ -423,7 +423,7 @@ function newUiObjectsFromNodes () { return } case 'Exchange Account': { - createUiObject('Exchange Account', node.name, node, parentNode, chainParent, 'Exchange Account', positionOffset) + createUiObject(false, 'Exchange Account', node.name, node, parentNode, chainParent, 'Exchange Account', positionOffset) for (let m = 0; m < node.assets.length; m++) { let asset = node.assets[m] createUiObjectFromNode(asset, node, node, positionOffset) @@ -435,11 +435,11 @@ function newUiObjectsFromNodes () { return } case 'Exchange Account Asset': { - createUiObject('Exchange Account Asset', node.name, node, parentNode, chainParent, 'Exchange Account Asset', positionOffset) + createUiObject(false, 'Exchange Account Asset', node.name, node, parentNode, chainParent, 'Exchange Account Asset', positionOffset) return } case 'Exchange Account Key': { - createUiObject('Exchange Account Key', node.name, node, parentNode, chainParent, 'Exchange Account Key', positionOffset) + createUiObject(false, 'Exchange Account Key', node.name, node, parentNode, chainParent, 'Exchange Account Key', positionOffset) return } case 'Definition': { @@ -451,7 +451,7 @@ function newUiObjectsFromNodes () { referenceChildren = node.savedPayload.referenceChildren } } - createUiObject('Definition', node.name, node, parentNode, chainParent, 'Definition', positionOffset) + createUiObject(false, 'Definition', node.name, node, parentNode, chainParent, 'Definition', positionOffset) if (node.tradingSystem !== undefined) { createUiObjectFromNode(node.tradingSystem, node, node, positionOffset) } @@ -469,7 +469,7 @@ function newUiObjectsFromNodes () { return } case 'Network': { - createUiObject('Network', node.name, node, parentNode, chainParent, 'Network', positionOffset) + createUiObject(false, 'Network', node.name, node, parentNode, chainParent, 'Network', positionOffset) if (node.networkNodes !== undefined) { for (let m = 0; m < node.networkNodes.length; m++) { let networkNode = node.networkNodes[m] @@ -479,7 +479,7 @@ function newUiObjectsFromNodes () { return } case 'Network Node': { - createUiObject('Network Node', node.name, node, parentNode, chainParent, 'Network Node', positionOffset) + createUiObject(false, 'Network Node', node.name, node, parentNode, chainParent, 'Network Node', positionOffset) if (node.taskManagers !== undefined) { for (let m = 0; m < node.taskManagers.length; m++) { let taskManager = node.taskManagers[m] @@ -489,7 +489,7 @@ function newUiObjectsFromNodes () { return } case 'Social Bots': { - createUiObject('Social Bots', node.name, node, parentNode, chainParent, 'Social Bots', positionOffset) + createUiObject(false, 'Social Bots', node.name, node, parentNode, chainParent, 'Social Bots', positionOffset) for (let m = 0; m < node.bots.length; m++) { let bot = node.bots[m] createUiObjectFromNode(bot, node, node, positionOffset) @@ -497,7 +497,7 @@ function newUiObjectsFromNodes () { return } case 'Telegram Bot': { - createUiObject('Telegram Bot', node.name, node, parentNode, chainParent, 'Telegram Bot', positionOffset) + createUiObject(false, 'Telegram Bot', node.name, node, parentNode, chainParent, 'Telegram Bot', positionOffset) for (let m = 0; m < node.announcements.length; m++) { let announcement = node.announcements[m] createUiObjectFromNode(announcement, node, node, positionOffset) @@ -505,14 +505,14 @@ function newUiObjectsFromNodes () { return } case 'Announcement': { - createUiObject('Announcement', node.name, node, parentNode, chainParent, 'Announcement', positionOffset) + createUiObject(false, 'Announcement', node.name, node, parentNode, chainParent, 'Announcement', positionOffset) if (node.formula !== undefined) { createUiObjectFromNode(node.formula, node, node, positionOffset) } return } case 'Layer Manager': { - createUiObject('Layer Manager', node.name, node, parentNode, chainParent, 'Layer Manager', positionOffset) + createUiObject(false, 'Layer Manager', node.name, node, parentNode, chainParent, 'Layer Manager', positionOffset) for (let m = 0; m < node.layers.length; m++) { let layer = node.layers[m] createUiObjectFromNode(layer, node, node, positionOffset) @@ -520,11 +520,11 @@ function newUiObjectsFromNodes () { return } case 'Layer': { - createUiObject('Layer', node.name, node, parentNode, chainParent, 'Layer', positionOffset) + createUiObject(false, 'Layer', node.name, node, parentNode, chainParent, 'Layer', positionOffset) return } case 'Task Manager': { - createUiObject('Task Manager', node.name, node, parentNode, chainParent, 'Task Manager', positionOffset) + createUiObject(false, 'Task Manager', node.name, node, parentNode, chainParent, 'Task Manager', positionOffset) for (let m = 0; m < node.tasks.length; m++) { let task = node.tasks[m] createUiObjectFromNode(task, node, node, positionOffset) @@ -532,14 +532,14 @@ function newUiObjectsFromNodes () { return } case 'Task': { - createUiObject('Task', node.name, node, parentNode, chainParent, 'Task', positionOffset) + createUiObject(false, 'Task', node.name, node, parentNode, chainParent, 'Task', positionOffset) if (node.bot !== undefined) { createUiObjectFromNode(node.bot, node, node, positionOffset) } return } case 'Sensor Bot Instance': { - createUiObject('Sensor Bot Instance', node.name, node, parentNode, chainParent, 'Sensor Bot Instance', positionOffset) + createUiObject(false, 'Sensor Bot Instance', node.name, node, parentNode, chainParent, 'Sensor Bot Instance', positionOffset) for (let m = 0; m < node.processes.length; m++) { let process = node.processes[m] createUiObjectFromNode(process, node, node, positionOffset) @@ -547,7 +547,7 @@ function newUiObjectsFromNodes () { return } case 'Indicator Bot Instance': { - createUiObject('Indicator Bot Instance', node.name, node, parentNode, chainParent, 'Indicator Bot Instance', positionOffset) + createUiObject(false, 'Indicator Bot Instance', node.name, node, parentNode, chainParent, 'Indicator Bot Instance', positionOffset) for (let m = 0; m < node.processes.length; m++) { let process = node.processes[m] createUiObjectFromNode(process, node, node, positionOffset) @@ -555,7 +555,7 @@ function newUiObjectsFromNodes () { return } case 'Trading Bot Instance': { - createUiObject('Trading Bot Instance', node.name, node, parentNode, chainParent, 'Trading Bot Instance', positionOffset) + createUiObject(false, 'Trading Bot Instance', node.name, node, parentNode, chainParent, 'Trading Bot Instance', positionOffset) for (let m = 0; m < node.processes.length; m++) { let process = node.processes[m] createUiObjectFromNode(process, node, node, positionOffset) @@ -588,7 +588,7 @@ function newUiObjectsFromNodes () { } } } - createUiObject('Process Instance', node.name, node, parentNode, chainParent, 'Process Instance', positionOffset) + createUiObject(false, 'Process Instance', node.name, node, parentNode, chainParent, 'Process Instance', positionOffset) if (node.session !== undefined) { createUiObjectFromNode(node.session, node, node, positionOffset) } @@ -609,7 +609,7 @@ function newUiObjectsFromNodes () { } } } - createUiObject('Backtesting Session', node.name, node, parentNode, chainParent, 'Backtesting Session', positionOffset) + createUiObject(false, 'Backtesting Session', node.name, node, parentNode, chainParent, 'Backtesting Session', positionOffset) if (node.parameters !== undefined) { createUiObjectFromNode(node.parameters, node, node, positionOffset) } @@ -636,7 +636,7 @@ function newUiObjectsFromNodes () { } } } - createUiObject('Live Trading Session', node.name, node, parentNode, chainParent, 'Live Trading Session', positionOffset) + createUiObject(false, 'Live Trading Session', node.name, node, parentNode, chainParent, 'Live Trading Session', positionOffset) if (node.parameters !== undefined) { createUiObjectFromNode(node.parameters, node, node, positionOffset) } @@ -663,7 +663,7 @@ function newUiObjectsFromNodes () { } } } - createUiObject('Fordward Testing Session', node.name, node, parentNode, chainParent, 'Fordward Testing Session', positionOffset) + createUiObject(false, 'Fordward Testing Session', node.name, node, parentNode, chainParent, 'Fordward Testing Session', positionOffset) if (node.parameters !== undefined) { createUiObjectFromNode(node.parameters, node, node, positionOffset) } @@ -690,7 +690,7 @@ function newUiObjectsFromNodes () { } } } - createUiObject('Paper Trading Session', node.name, node, parentNode, chainParent, 'Paper Trading Session', positionOffset) + createUiObject(false, 'Paper Trading Session', node.name, node, parentNode, chainParent, 'Paper Trading Session', positionOffset) if (node.parameters !== undefined) { createUiObjectFromNode(node.parameters, node, node, positionOffset) } @@ -709,7 +709,7 @@ function newUiObjectsFromNodes () { } case 'Team': { - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) for (let m = 0; m < node.sensorBots.length; m++) { let sensorBot = node.sensorBots[m] createUiObjectFromNode(sensorBot, node, node, positionOffset) @@ -729,7 +729,7 @@ function newUiObjectsFromNodes () { return } case 'Sensor Bot': { - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) for (let m = 0; m < node.processes.length; m++) { let process = node.processes[m] createUiObjectFromNode(process, node, node, positionOffset) @@ -741,7 +741,7 @@ function newUiObjectsFromNodes () { return } case 'Indicator Bot': { - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) for (let m = 0; m < node.processes.length; m++) { let process = node.processes[m] createUiObjectFromNode(process, node, node, positionOffset) @@ -753,7 +753,7 @@ function newUiObjectsFromNodes () { return } case 'Trading Bot': { - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) for (let m = 0; m < node.processes.length; m++) { let process = node.processes[m] createUiObjectFromNode(process, node, node, positionOffset) @@ -773,7 +773,7 @@ function newUiObjectsFromNodes () { referenceChildren = node.savedPayload.referenceChildren } } - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (node.processOutput !== undefined) { createUiObjectFromNode(node.processOutput, node, node, positionOffset) } @@ -797,7 +797,7 @@ function newUiObjectsFromNodes () { return } case 'Process Output': { - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) for (let m = 0; m < node.outputDatasets.length; m++) { let outputDataset = node.outputDatasets[m] createUiObjectFromNode(outputDataset, node, node, positionOffset) @@ -805,7 +805,7 @@ function newUiObjectsFromNodes () { return } case 'Process Dependencies': { - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) for (let m = 0; m < node.statusDependencies.length; m++) { let statusDependency = node.statusDependencies[m] createUiObjectFromNode(statusDependency, node, node, positionOffset) @@ -825,7 +825,7 @@ function newUiObjectsFromNodes () { referenceChildren = node.savedPayload.referenceChildren } } - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (referenceChildren !== undefined) { node.savedPayload = { referenceChildren: referenceChildren @@ -843,7 +843,7 @@ function newUiObjectsFromNodes () { } } } - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (referenceParent !== undefined) { node.savedPayload = { referenceParent: referenceParent @@ -860,7 +860,7 @@ function newUiObjectsFromNodes () { referenceChildren = node.savedPayload.referenceChildren } } - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (referenceChildren !== undefined) { node.savedPayload = { referenceChildren: referenceChildren @@ -869,7 +869,7 @@ function newUiObjectsFromNodes () { return } case 'Calculations Procedure': { - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (node.initialization !== undefined) { createUiObjectFromNode(node.initialization, node, node, positionOffset) } @@ -879,7 +879,7 @@ function newUiObjectsFromNodes () { return } case 'Data Building Procedure': { - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (node.initialization !== undefined) { createUiObjectFromNode(node.initialization, node, node, positionOffset) } @@ -889,14 +889,14 @@ function newUiObjectsFromNodes () { return } case 'Procedure Initialization': { - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (node.code !== undefined) { createUiObjectFromNode(node.code, node, node, positionOffset) } return } case 'Procedure Loop': { - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (node.code !== undefined) { createUiObjectFromNode(node.code, node, node, positionOffset) } @@ -912,7 +912,7 @@ function newUiObjectsFromNodes () { } } } - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (referenceParent !== undefined) { node.savedPayload = { referenceParent: referenceParent @@ -930,7 +930,7 @@ function newUiObjectsFromNodes () { } } } - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (referenceParent !== undefined) { node.savedPayload = { referenceParent: referenceParent @@ -948,7 +948,7 @@ function newUiObjectsFromNodes () { } } } - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (referenceParent !== undefined) { node.savedPayload = { referenceParent: referenceParent @@ -957,7 +957,7 @@ function newUiObjectsFromNodes () { return } case 'Product Definition': { - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (node.record !== undefined) { createUiObjectFromNode(node.record, node, node, positionOffset) } @@ -974,7 +974,7 @@ function newUiObjectsFromNodes () { return } case 'Record Definition': { - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) for (let m = 0; m < node.properties.length; m++) { let property = node.properties[m] createUiObjectFromNode(property, node, node, positionOffset) @@ -982,7 +982,7 @@ function newUiObjectsFromNodes () { return } case 'Record Property': { - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (node.formula !== undefined) { createUiObjectFromNode(node.formula, node, node, positionOffset) } @@ -997,7 +997,7 @@ function newUiObjectsFromNodes () { referenceChildren = node.savedPayload.referenceChildren } } - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (referenceChildren !== undefined) { node.savedPayload = { referenceChildren: referenceChildren @@ -1006,7 +1006,7 @@ function newUiObjectsFromNodes () { return } case 'Plotter': { - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) for (let m = 0; m < node.modules.length; m++) { let module = node.modules[m] createUiObjectFromNode(module, node, node, positionOffset) @@ -1014,7 +1014,7 @@ function newUiObjectsFromNodes () { return } case 'Plotter Module': { - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (node.code !== undefined) { createUiObjectFromNode(node.code, node, node, positionOffset) } @@ -1025,7 +1025,7 @@ function newUiObjectsFromNodes () { return } case 'Plotter Panel': { - createUiObject(node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (node.code !== undefined) { createUiObjectFromNode(node.code, node, node, positionOffset) } @@ -1045,7 +1045,7 @@ function newUiObjectsFromNodes () { plotters: [] } node.rootNodes.push(team) - createUiObject(team.type, team.name, team, undefined, undefined) + createUiObject(true, team.type, team.name, team, undefined, undefined) return team } @@ -1061,7 +1061,7 @@ function newUiObjectsFromNodes () { node.sensorBots = [] } node.sensorBots.push(object) - createUiObject(object.type, object.name, object, node, node) + createUiObject(true, object.type, object.name, object, node, node) return object } @@ -1078,7 +1078,7 @@ function newUiObjectsFromNodes () { node.indicatorBots = [] } node.indicatorBots.push(object) - createUiObject(object.type, object.name, object, node, node) + createUiObject(true, object.type, object.name, object, node, node) return object } @@ -1095,7 +1095,7 @@ function newUiObjectsFromNodes () { node.tradingBots = [] } node.tradingBots.push(object) - createUiObject(object.type, object.name, object, node, node) + createUiObject(true, object.type, object.name, object, node, node) return object } @@ -1111,7 +1111,7 @@ function newUiObjectsFromNodes () { node.processes = [] } node.processes.push(object) - createUiObject(object.type, object.name, object, node, node) + createUiObject(true, object.type, object.name, object, node, node) return object } @@ -1136,7 +1136,7 @@ function newUiObjectsFromNodes () { name: 'New Process Output', outputDatasets: [] } - createUiObject(node.processOutput.type, node.processOutput.name, node.processOutput, node, node) + createUiObject(true, node.processOutput.type, node.processOutput.name, node.processOutput, node, node) } return node.processOutput } @@ -1149,7 +1149,7 @@ function newUiObjectsFromNodes () { statusDependencies: [], dataDependencies: [] } - createUiObject(node.processDependencies.type, node.processDependencies.name, node.processDependencies, node, node) + createUiObject(true, node.processDependencies.type, node.processDependencies.name, node.processDependencies, node, node) } return node.processDependencies } @@ -1161,7 +1161,7 @@ function newUiObjectsFromNodes () { name: 'New Status Report', referenceChildren: [] } - createUiObject(node.statusReport.type, node.statusReport.name, node.statusReport, node, node) + createUiObject(true, node.statusReport.type, node.statusReport.name, node.statusReport, node, node) } return node.statusReport } @@ -1172,7 +1172,7 @@ function newUiObjectsFromNodes () { type: 'Execution Started Event', name: 'New Execution Started Event' } - createUiObject(node.executionStartedEvent.type, node.executionStartedEvent.name, node.executionStartedEvent, node, node) + createUiObject(true, node.executionStartedEvent.type, node.executionStartedEvent.name, node.executionStartedEvent, node, node) } return node.executionStartedEvent } @@ -1184,7 +1184,7 @@ function newUiObjectsFromNodes () { name: 'New Execution Finished Event', referenceChildren: [] } - createUiObject(node.executionFinishedEvent.type, node.executionFinishedEvent.name, node.executionFinishedEvent, node, node) + createUiObject(true, node.executionFinishedEvent.type, node.executionFinishedEvent.name, node.executionFinishedEvent, node, node) } return node.executionFinishedEvent } @@ -1195,7 +1195,7 @@ function newUiObjectsFromNodes () { type: 'Calculations Procedure', name: 'New Calculations Procedure' } - createUiObject(node.calculations.type, node.calculations.name, node.calculations, node, node) + createUiObject(true, node.calculations.type, node.calculations.name, node.calculations, node, node) } return node.calculations } @@ -1206,7 +1206,7 @@ function newUiObjectsFromNodes () { type: 'Data Building Procedure', name: 'New Data Building Procedure' } - createUiObject(node.dataBuilding.type, node.dataBuilding.name, node.dataBuilding, node, node) + createUiObject(true, node.dataBuilding.type, node.dataBuilding.name, node.dataBuilding, node, node) } return node.dataBuilding } @@ -1217,7 +1217,7 @@ function newUiObjectsFromNodes () { type: 'Procedure Initialization', name: 'New Procedure Initialization' } - createUiObject(node.initialization.type, node.initialization.name, node.initialization, node, node) + createUiObject(true, node.initialization.type, node.initialization.name, node.initialization, node, node) } return node.initialization } @@ -1228,7 +1228,7 @@ function newUiObjectsFromNodes () { type: 'Procedure Loop', name: 'New Procedure Loop' } - createUiObject(node.loop.type, node.loop.name, node.loop, node, node) + createUiObject(true, node.loop.type, node.loop.name, node.loop, node, node) } return node.loop } @@ -1242,7 +1242,7 @@ function newUiObjectsFromNodes () { node.outputDatasets = [] } node.outputDatasets.push(object) - createUiObject(object.type, object.name, object, node, node) + createUiObject(true, object.type, object.name, object, node, node) return object } @@ -1257,7 +1257,7 @@ function newUiObjectsFromNodes () { node.statusDependencies = [] } node.statusDependencies.push(object) - createUiObject(object.type, object.name, object, node, node) + createUiObject(true, object.type, object.name, object, node, node) return object } @@ -1271,7 +1271,7 @@ function newUiObjectsFromNodes () { node.dataDependencies = [] } node.dataDependencies.push(object) - createUiObject(object.type, object.name, object, node, node) + createUiObject(true, object.type, object.name, object, node, node) return object } @@ -1287,7 +1287,7 @@ function newUiObjectsFromNodes () { node.products = [] } node.products.push(object) - createUiObject(object.type, object.name, object, node, node) + createUiObject(true, object.type, object.name, object, node, node) return object } @@ -1299,7 +1299,7 @@ function newUiObjectsFromNodes () { name: 'New Record Definition', properties: [] } - createUiObject(node.record.type, node.record.name, node.record, node, node) + createUiObject(true, node.record.type, node.record.name, node.record, node, node) } return node.record } @@ -1317,8 +1317,8 @@ function newUiObjectsFromNodes () { node.properties = [] } node.properties.push(object) - createUiObject(object.type, object.name, object, node, node) - createUiObject('Formula', '', object.formula, object, object) + createUiObject(true, object.type, object.name, object, node, node) + createUiObject(true, 'Formula', '', object.formula, object, object) return object } @@ -1334,7 +1334,7 @@ function newUiObjectsFromNodes () { node.datasets = [] } node.datasets.push(object) - createUiObject(object.type, object.name, object, node, node) + createUiObject(true, object.type, object.name, object, node, node) return object } @@ -1349,7 +1349,7 @@ function newUiObjectsFromNodes () { node.plotters = [] } node.plotters.push(object) - createUiObject(object.type, object.name, object, node, node) + createUiObject(true, object.type, object.name, object, node, node) return object } @@ -1364,7 +1364,7 @@ function newUiObjectsFromNodes () { node.modules = [] } node.modules.push(object) - createUiObject(object.type, object.name, object, node, node) + createUiObject(true, object.type, object.name, object, node, node) return object } @@ -1378,7 +1378,7 @@ function newUiObjectsFromNodes () { node.panels = [] } node.panels.push(object) - createUiObject(object.type, object.name, object, node, node) + createUiObject(true, object.type, object.name, object, node, node) return object } @@ -1388,7 +1388,7 @@ function newUiObjectsFromNodes () { name: 'Superalgos' } node.rootNodes.push(network) - createUiObject('Network', network.name, network, node, undefined, 'Network') + createUiObject(true, 'Network', network.name, network, node, undefined, 'Network') return network } @@ -1401,7 +1401,7 @@ function newUiObjectsFromNodes () { node.networkNodes = [] } node.networkNodes.push(networkNode) - createUiObject('Network Node', networkNode.name, networkNode, node, node, 'Network Node') + createUiObject(true, 'Network Node', networkNode.name, networkNode, node, node, 'Network Node') return networkNode } @@ -1412,7 +1412,7 @@ function newUiObjectsFromNodes () { name: 'New Social Bots', bots: [] } - createUiObject('Social Bots', node.socialBots.name, node.socialBots, node, node, 'Social Bots') + createUiObject(true, 'Social Bots', node.socialBots.name, node.socialBots, node, node, 'Social Bots') } return node.socialBots @@ -1425,7 +1425,7 @@ function newUiObjectsFromNodes () { announcements: [] } node.bots.push(bot) - createUiObject('Telegram Bot', bot.name, bot, node, node, 'Telegram Bot') + createUiObject(true, 'Telegram Bot', bot.name, bot, node, node, 'Telegram Bot') return bot } @@ -1436,7 +1436,7 @@ function newUiObjectsFromNodes () { code: '{ \n\"text\": \"Write here what you want to announce.\",\n\"botType\": \"' + node.type + '\",\n\"botId\": \"' + node.id + '\"\n}' } node.announcements.push(announcement) - createUiObject('Announcement', announcement.name, announcement, node, node, 'Announcement') + createUiObject(true, 'Announcement', announcement.name, announcement, node, node, 'Announcement') return announcement } @@ -1447,7 +1447,7 @@ function newUiObjectsFromNodes () { name: 'New Layer Manager', layers: [] } - createUiObject('Layer Manager', node.layerManager.name, node.layerManager, node, node, 'Layer Manager') + createUiObject(true, 'Layer Manager', node.layerManager.name, node.layerManager, node, node, 'Layer Manager') } return node.layerManager @@ -1459,7 +1459,7 @@ function newUiObjectsFromNodes () { code: '{}' } node.layers.push(layer) - createUiObject('Layer', layer.name, layer, node, node, 'Layer') + createUiObject(true, 'Layer', layer.name, layer, node, node, 'Layer') return layer } @@ -1473,7 +1473,7 @@ function newUiObjectsFromNodes () { node.taskManagers = [] } node.taskManagers.push(taskManager) - createUiObject('Task Manager', taskManager.name, taskManager, node, node, 'Task Manager') + createUiObject(true, 'Task Manager', taskManager.name, taskManager, node, node, 'Task Manager') return taskManager } @@ -1483,7 +1483,7 @@ function newUiObjectsFromNodes () { name: 'New Task' } node.tasks.push(task) - createUiObject('Task', task.name, task, node, node, 'Task') + createUiObject(true, 'Task', task.name, task, node, node, 'Task') return task } @@ -1494,7 +1494,7 @@ function newUiObjectsFromNodes () { processes: [], code: '{}' } - createUiObject('Sensor Bot Instance', '', node.bot, node, node) + createUiObject(true, 'Sensor Bot Instance', '', node.bot, node, node) } return node.bot } @@ -1505,7 +1505,7 @@ function newUiObjectsFromNodes () { processes: [], code: '{}' } - createUiObject('Indicator Bot Instance', '', node.bot, node, node) + createUiObject(true, 'Indicator Bot Instance', '', node.bot, node, node) } return node.bot } @@ -1516,7 +1516,7 @@ function newUiObjectsFromNodes () { processes: [], code: '{}' } - createUiObject('Trading Bot Instance', '', node.bot, node, node) + createUiObject(true, 'Trading Bot Instance', '', node.bot, node, node) } return node.bot } @@ -1545,7 +1545,7 @@ function newUiObjectsFromNodes () { } } node.processes.push(process) - createUiObject('Process Instance', process.name, process, node, node, 'Process Instance') + createUiObject(true, 'Process Instance', process.name, process, node, node, 'Process Instance') return process } @@ -1556,7 +1556,7 @@ function newUiObjectsFromNodes () { name: 'New Backtesting Session', code: '{}' } - createUiObject('Backtesting Session', '', node.session, node, node) + createUiObject(true, 'Backtesting Session', '', node.session, node, node) } return node.session @@ -1568,7 +1568,7 @@ function newUiObjectsFromNodes () { name: 'New Live Trading Session', code: '{}' } - createUiObject('Live Trading Session', '', node.session, node, node) + createUiObject(true, 'Live Trading Session', '', node.session, node, node) } return node.session @@ -1580,7 +1580,7 @@ function newUiObjectsFromNodes () { name: 'New Fordward Testing Session', code: '{}' } - createUiObject('Fordward Testing Session', '', node.session, node, node) + createUiObject(true, 'Fordward Testing Session', '', node.session, node, node) } return node.session @@ -1592,7 +1592,7 @@ function newUiObjectsFromNodes () { name: 'New Paper Trading Session', code: '{}' } - createUiObject('Paper Trading Session', '', node.session, node, node) + createUiObject(true, 'Paper Trading Session', '', node.session, node, node) } return node.session @@ -1604,7 +1604,7 @@ function newUiObjectsFromNodes () { referenceChildren: [] } node.rootNodes.push(definition) - createUiObject('Definition', definition.name, definition, node, undefined, 'Definition') + createUiObject(true, 'Definition', definition.name, definition, node, undefined, 'Definition') return definition } @@ -1614,7 +1614,7 @@ function newUiObjectsFromNodes () { node.tradingSystem = { strategies: [] } - createUiObject('Trading System', '', node.tradingSystem, node, node) + createUiObject(true, 'Trading System', '', node.tradingSystem, node, node) } return node.tradingSystem } @@ -1624,7 +1624,7 @@ function newUiObjectsFromNodes () { node.personalData = { exchangeAccounts: [] } - createUiObject('Personal Data', '', node.personalData, node, node) + createUiObject(true, 'Personal Data', '', node.personalData, node, node) } return node.personalData @@ -1638,7 +1638,7 @@ function newUiObjectsFromNodes () { keys: [] } personalData.exchangeAccounts.push(exchangeAccount) - createUiObject('Exchange Account', exchangeAccount.name, exchangeAccount, personalData, personalData, 'Exchange Account') + createUiObject(true, 'Exchange Account', exchangeAccount.name, exchangeAccount, personalData, personalData, 'Exchange Account') return exchangeAccount } @@ -1649,7 +1649,7 @@ function newUiObjectsFromNodes () { name: 'New Asset' } exchangeAccount.assets.push(asset) - createUiObject('Exchange Account Asset', asset.name, asset, exchangeAccount, exchangeAccount, 'Account Asset') + createUiObject(true, 'Exchange Account Asset', asset.name, asset, exchangeAccount, exchangeAccount, 'Account Asset') return asset } @@ -1661,7 +1661,7 @@ function newUiObjectsFromNodes () { code: 'Paste your exchange API secret key here and the put the key name as this key object title. Secret keys are filtered out and NOT exported when using the SHARE menu option on any object at your workspace. Secret keys ARE downloaded when using the download button.' } exchangeAccount.keys.push(key) - createUiObject('Exchange Account Key', key.name, key, exchangeAccount, exchangeAccount, 'Account Key') + createUiObject(true, 'Exchange Account Key', key.name, key, exchangeAccount, exchangeAccount, 'Account Key') return key } @@ -1712,22 +1712,22 @@ function newUiObjectsFromNodes () { } strategyParent.strategies.push(strategy) - createUiObject('Strategy', strategy.name, strategy, strategyParent, strategyParent, 'Strategy') - createUiObject('Trigger Stage', '', strategy.triggerStage, strategy, strategy, 'Trigger Stage') - createUiObject('Open Stage', '', strategy.openStage, strategy, strategy, 'Open Stage') - createUiObject('Manage Stage', '', strategy.manageStage, strategy, strategy, 'Manage Stage') - createUiObject('Close Stage', '', strategy.closeStage, strategy, strategy, 'Close Stage') - createUiObject('Trigger On Event', '', strategy.triggerStage.triggerOn, strategy.triggerStage, strategy.triggerStage) - createUiObject('Trigger Off Event', '', strategy.triggerStage.triggerOff, strategy.triggerStage, strategy.triggerStage) - createUiObject('Take Position Event', '', strategy.triggerStage.takePosition, strategy.triggerStage, strategy.triggerStage) - createUiObject('Initial Definition', '', strategy.openStage.initialDefinition, strategy.openStage, strategy.openStage) - createUiObject('Position Size', '', strategy.openStage.initialDefinition.positionSize, strategy.openStage.initialDefinition, strategy.openStage.initialDefinition) - createUiObject('Position Rate', '', strategy.openStage.initialDefinition.positionRate, strategy.openStage.initialDefinition, strategy.openStage.initialDefinition) - createUiObject('Stop', '', strategy.manageStage.stopLoss, strategy.manageStage, strategy.manageStage) - createUiObject('Take Profit', '', strategy.manageStage.takeProfit, strategy.manageStage, strategy.manageStage) - createUiObject('Stop', 'Initial Stop', strategy.openStage.initialDefinition.stopLoss, strategy.openStage.initialDefinition, strategy.openStage.initialDefinition) - createUiObject('Take Profit', 'Initial Take Profit', strategy.openStage.initialDefinition.takeProfit, strategy.openStage.initialDefinition, strategy.openStage.initialDefinition) - createUiObject('Formula', '', strategy.triggerStage.positionSize.formula, strategy.triggerStage.positionSize, strategy.triggerStage.positionSize) + createUiObject(true, 'Strategy', strategy.name, strategy, strategyParent, strategyParent, 'Strategy') + createUiObject(true, 'Trigger Stage', '', strategy.triggerStage, strategy, strategy, 'Trigger Stage') + createUiObject(true, 'Open Stage', '', strategy.openStage, strategy, strategy, 'Open Stage') + createUiObject(true, 'Manage Stage', '', strategy.manageStage, strategy, strategy, 'Manage Stage') + createUiObject(true, 'Close Stage', '', strategy.closeStage, strategy, strategy, 'Close Stage') + createUiObject(true, 'Trigger On Event', '', strategy.triggerStage.triggerOn, strategy.triggerStage, strategy.triggerStage) + createUiObject(true, 'Trigger Off Event', '', strategy.triggerStage.triggerOff, strategy.triggerStage, strategy.triggerStage) + createUiObject(true, 'Take Position Event', '', strategy.triggerStage.takePosition, strategy.triggerStage, strategy.triggerStage) + createUiObject(true, 'Initial Definition', '', strategy.openStage.initialDefinition, strategy.openStage, strategy.openStage) + createUiObject(true, 'Position Size', '', strategy.openStage.initialDefinition.positionSize, strategy.openStage.initialDefinition, strategy.openStage.initialDefinition) + createUiObject(true, 'Position Rate', '', strategy.openStage.initialDefinition.positionRate, strategy.openStage.initialDefinition, strategy.openStage.initialDefinition) + createUiObject(true, 'Stop', '', strategy.manageStage.stopLoss, strategy.manageStage, strategy.manageStage) + createUiObject(true, 'Take Profit', '', strategy.manageStage.takeProfit, strategy.manageStage, strategy.manageStage) + createUiObject(true, 'Stop', 'Initial Stop', strategy.openStage.initialDefinition.stopLoss, strategy.openStage.initialDefinition, strategy.openStage.initialDefinition) + createUiObject(true, 'Take Profit', 'Initial Take Profit', strategy.openStage.initialDefinition.takeProfit, strategy.openStage.initialDefinition, strategy.openStage.initialDefinition) + createUiObject(true, 'Formula', '', strategy.triggerStage.positionSize.formula, strategy.triggerStage.positionSize, strategy.triggerStage.positionSize) return strategy } @@ -1737,7 +1737,7 @@ function newUiObjectsFromNodes () { node.parameters = { name: 'Parameters' } - createUiObject('Parameters', '', node.parameters, node, node) + createUiObject(true, 'Parameters', '', node.parameters, node, node) addMissingParameters(node.parameters) } @@ -1750,35 +1750,35 @@ function newUiObjectsFromNodes () { name: 'Base Asset', code: DEFAULT_CONFIG_TEXT } - createUiObject('Base Asset', '', node.baseAsset, node, node) + createUiObject(true, 'Base Asset', '', node.baseAsset, node, node) } if (node.timeRange === undefined) { node.timeRange = { name: 'Time Range', code: DEFAULT_CONFIG_TEXT } - createUiObject('Time Range', '', node.timeRange, node, node) + createUiObject(true, 'Time Range', '', node.timeRange, node, node) } if (node.timePeriod === undefined) { node.timePeriod = { name: 'Time Period', code: DEFAULT_CONFIG_TEXT } - createUiObject('Time Period', '', node.timePeriod, node, node) + createUiObject(true, 'Time Period', '', node.timePeriod, node, node) } if (node.slippage === undefined) { node.slippage = { name: 'Slippage', code: DEFAULT_CONFIG_TEXT } - createUiObject('Slippage', '', node.slippage, node, node) + createUiObject(true, 'Slippage', '', node.slippage, node, node) } if (node.feeStructure === undefined) { node.feeStructure = { name: 'Fee Structure', code: DEFAULT_CONFIG_TEXT } - createUiObject('Fee Structure', '', node.feeStructure, node, node) + createUiObject(true, 'Fee Structure', '', node.feeStructure, node, node) } } @@ -1800,11 +1800,11 @@ function newUiObjectsFromNodes () { } } } - createUiObject('Trigger Stage', '', node.triggerStage, node, node, 'Trigger Stage') - createUiObject('Trigger On Event', '', node.triggerStage.triggerOn, node.triggerStage, node.triggerStage) - createUiObject('Trigger Off Event', '', node.triggerStage.triggerOff, node.triggerStage, node.triggerStage) - createUiObject('Take Position Event', '', node.triggerStage.takePosition, node.triggerStage, node.triggerStage) - createUiObject('Formula', '', node.triggerStage.positionSize.formula, node.triggerStage.positionSize, node.triggerStage.positionSize) + createUiObject(true, 'Trigger Stage', '', node.triggerStage, node, node, 'Trigger Stage') + createUiObject(true, 'Trigger On Event', '', node.triggerStage.triggerOn, node.triggerStage, node.triggerStage) + createUiObject(true, 'Trigger Off Event', '', node.triggerStage.triggerOff, node.triggerStage, node.triggerStage) + createUiObject(true, 'Take Position Event', '', node.triggerStage.takePosition, node.triggerStage, node.triggerStage) + createUiObject(true, 'Formula', '', node.triggerStage.positionSize.formula, node.triggerStage.positionSize, node.triggerStage.positionSize) } if (node.openStage === undefined) { node.openStage = { @@ -1819,12 +1819,12 @@ function newUiObjectsFromNodes () { } } } - createUiObject('Open Stage', '', node.openStage, node, node, 'Open Stage') - createUiObject('Initial Definition', '', node.openStage.initialDefinition, node.openStage, node.openStage) - createUiObject('Stop', 'Initial Stop', node.openStage.initialDefinition.stopLoss, node.openStage.initialDefinition, node.openStage.initialDefinition) - createUiObject('Take Profit', 'Initial Take Profit', node.openStage.initialDefinition.takeProfit, node.openStage.initialDefinition, node.openStage.initialDefinition) - createUiObject('Position Size', 'Position Size', node.openStage.initialDefinition.positionSize, node.openStage.initialDefinition, node.openStage.initialDefinition) - createUiObject('Position Rate', 'Position Rate', node.openStage.initialDefinition.positionRate, node.openStage.initialDefinition, node.openStage.initialDefinition) + createUiObject(true, 'Open Stage', '', node.openStage, node, node, 'Open Stage') + createUiObject(true, 'Initial Definition', '', node.openStage.initialDefinition, node.openStage, node.openStage) + createUiObject(true, 'Stop', 'Initial Stop', node.openStage.initialDefinition.stopLoss, node.openStage.initialDefinition, node.openStage.initialDefinition) + createUiObject(true, 'Take Profit', 'Initial Take Profit', node.openStage.initialDefinition.takeProfit, node.openStage.initialDefinition, node.openStage.initialDefinition) + createUiObject(true, 'Position Size', 'Position Size', node.openStage.initialDefinition.positionSize, node.openStage.initialDefinition, node.openStage.initialDefinition) + createUiObject(true, 'Position Rate', 'Position Rate', node.openStage.initialDefinition.positionRate, node.openStage.initialDefinition, node.openStage.initialDefinition) } if (node.manageStage === undefined) { node.manageStage = { @@ -1835,14 +1835,14 @@ function newUiObjectsFromNodes () { phases: [] } } - createUiObject('Manage Stage', '', node.manageStage, node, node, 'Manage Stage') - createUiObject('Stop', '', node.manageStage.stopLoss, node.manageStage, node.manageStage) - createUiObject('Take Profit', '', node.manageStage.takeProfit, node.manageStage, node.manageStage) + createUiObject(true, 'Manage Stage', '', node.manageStage, node, node, 'Manage Stage') + createUiObject(true, 'Stop', '', node.manageStage.stopLoss, node.manageStage, node.manageStage) + createUiObject(true, 'Take Profit', '', node.manageStage.takeProfit, node.manageStage, node.manageStage) } if (node.closeStage === undefined) { node.closeStage = { } - createUiObject('Close Stage', '', node.closeStage, node, node, 'Close Stage') + createUiObject(true, 'Close Stage', '', node.closeStage, node, node, 'Close Stage') } } @@ -1852,21 +1852,21 @@ function newUiObjectsFromNodes () { situations: [], announcements: [] } - createUiObject('Trigger On Event', '', node.triggerOn, node, node) + createUiObject(true, 'Trigger On Event', '', node.triggerOn, node, node) } if (node.triggerOff === undefined) { node.triggerOff = { situations: [], announcements: [] } - createUiObject('Trigger Off Event', '', node.triggerOff, node, node) + createUiObject(true, 'Trigger Off Event', '', node.triggerOff, node, node) } if (node.takePosition === undefined) { node.takePosition = { situations: [], announcements: [] } - createUiObject('Take Position Event', '', node.takePosition, node, node) + createUiObject(true, 'Take Position Event', '', node.takePosition, node, node) } } @@ -1877,14 +1877,14 @@ function newUiObjectsFromNodes () { phases: [], maxPhases: 1 } - createUiObject('Stop', 'Initial Stop', node.stopLoss, node, node) + createUiObject(true, 'Stop', 'Initial Stop', node.stopLoss, node, node) } if (node.takeProfit === undefined) { node.takeProfit = { phases: [], maxPhases: 1 } - createUiObject('Take Profit', 'Initial Take Profit', node.takeProfit, node, node) + createUiObject(true, 'Take Profit', 'Initial Take Profit', node.takeProfit, node, node) } if (node.positionSize === undefined) { node.positionSize = { @@ -1893,8 +1893,8 @@ function newUiObjectsFromNodes () { code: DEFAULT_FORMULA_TEXT } } - createUiObject('Position Size', '', node.positionSize, node, node) - createUiObject('Formula', '', node.positionSize.formula, node.positionSize, node.positionSize) + createUiObject(true, 'Position Size', '', node.positionSize, node, node) + createUiObject(true, 'Formula', '', node.positionSize.formula, node.positionSize, node.positionSize) } if (node.positionRate === undefined) { node.positionRate = { @@ -1903,21 +1903,21 @@ function newUiObjectsFromNodes () { code: DEFAULT_FORMULA_TEXT } } - createUiObject('Position Rate', '', node.positionRate, node, node) - createUiObject('Formula', '', node.positionRate.formula, node.positionRate, node.positionRate) + createUiObject(true, 'Position Rate', '', node.positionRate, node, node) + createUiObject(true, 'Formula', '', node.positionRate.formula, node.positionRate, node.positionRate) } } else { if (node.stopLoss === undefined) { node.stopLoss = { phases: [] } - createUiObject('Stop', '', node.stopLoss, node, node) + createUiObject(true, 'Stop', '', node.stopLoss, node, node) } if (node.takeProfit === undefined) { node.takeProfit = { phases: [] } - createUiObject('Take Profit', '', node.takeProfit, node, node) + createUiObject(true, 'Take Profit', '', node.takeProfit, node, node) } } } @@ -1934,13 +1934,13 @@ function newUiObjectsFromNodes () { maxPhases: 1 } } - createUiObject('Initial Definition', '', node.initialDefinition, node, node) - createUiObject('Stop', 'Initial Stop', node.initialDefinition.stopLoss, node.initialDefinition, node.initialDefinition) - createUiObject('Take Profit', 'Initial Take Profit', node.initialDefinition.takeProfit, node.initialDefinition, node.initialDefinition) - createUiObject('Position Size', '', node.initialDefinition.positionSize, node.initialDefinition, node.initialDefinition) - createUiObject('Formula', '', node.initialDefinition.positionSize.formula, node.initialDefinition.positionSize, node.initialDefinition.positionSize) - createUiObject('Position Rate', '', node.initialDefinition.positionRate, node.initialDefinition, node.initialDefinition) - createUiObject('Formula', '', node.initialDefinition.positionRate.formula, node.initialDefinition.positionRate, node.initialDefinition.positionRate) + createUiObject(true, 'Initial Definition', '', node.initialDefinition, node, node) + createUiObject(true, 'Stop', 'Initial Stop', node.initialDefinition.stopLoss, node.initialDefinition, node.initialDefinition) + createUiObject(true, 'Take Profit', 'Initial Take Profit', node.initialDefinition.takeProfit, node.initialDefinition, node.initialDefinition) + createUiObject(true, 'Position Size', '', node.initialDefinition.positionSize, node.initialDefinition, node.initialDefinition) + createUiObject(true, 'Formula', '', node.initialDefinition.positionSize.formula, node.initialDefinition.positionSize, node.initialDefinition.positionSize) + createUiObject(true, 'Position Rate', '', node.initialDefinition.positionRate, node.initialDefinition, node.initialDefinition) + createUiObject(true, 'Formula', '', node.initialDefinition.positionRate.formula, node.initialDefinition.positionRate, node.initialDefinition.positionRate) } return node.initialDefinition @@ -1949,7 +1949,7 @@ function newUiObjectsFromNodes () { function addOpenExecution (node) { if (node.openExecution === undefined) { node.openExecution = {} - createUiObject('Open Execution', '', node.openExecution, node, node) + createUiObject(true, 'Open Execution', '', node.openExecution, node, node) } return node.openExecution @@ -1958,7 +1958,7 @@ function newUiObjectsFromNodes () { function addCloseExecution (node) { if (node.closeExecution === undefined) { node.closeExecution = {} - createUiObject('Close Execution', '', node.closeExecution, node, node) + createUiObject(true, 'Close Execution', '', node.closeExecution, node, node) } return node.closeExecution @@ -1969,7 +1969,7 @@ function newUiObjectsFromNodes () { node.formula = { code: DEFAULT_FORMULA_TEXT } - createUiObject('Formula', '', node.formula, node, node) + createUiObject(true, 'Formula', '', node.formula, node, node) } return node.formula @@ -1981,7 +1981,7 @@ function newUiObjectsFromNodes () { situations: [], announcements: [] } - createUiObject('Next Phase Event', '', node.nextPhaseEvent, node, node) + createUiObject(true, 'Next Phase Event', '', node.nextPhaseEvent, node, node) } return node.nextPhaseEvent @@ -1992,7 +1992,7 @@ function newUiObjectsFromNodes () { node.code = { code: DEFAULT_CODE_TEXT } - createUiObject('Code', '', node.code, node, node) + createUiObject(true, 'Code', '', node.code, node, node) } return node.code @@ -2028,9 +2028,9 @@ function newUiObjectsFromNodes () { } else { phaseChainParent = phaseParent } - createUiObject('Phase', phase.name, phase, phaseParent, phaseChainParent, 'Phase') - createUiObject('Formula', '', phase.formula, phase, phase, 'Formula') - createUiObject('Next Phase Event', '', phase.nextPhaseEvent, phase, phase) + createUiObject(true, 'Phase', phase.name, phase, phaseParent, phaseChainParent, 'Phase') + createUiObject(true, 'Formula', '', phase.formula, phase, phase, 'Formula') + createUiObject(true, 'Next Phase Event', '', phase.nextPhaseEvent, phase, phase) return phase } @@ -2042,7 +2042,7 @@ function newUiObjectsFromNodes () { conditions: [] } parentNode.situations.push(situation) - createUiObject('Situation', situation.name, situation, parentNode, parentNode, 'Situation') + createUiObject(true, 'Situation', situation.name, situation, parentNode, parentNode, 'Situation') return situation } @@ -2057,13 +2057,13 @@ function newUiObjectsFromNodes () { } } situation.conditions.push(condition) - createUiObject('Condition', condition.name, condition, situation, situation, 'Condition') - createUiObject('Code', '', condition.code, condition, condition, 'Code') + createUiObject(true, 'Condition', condition.name, condition, situation, situation, 'Condition') + createUiObject(true, 'Code', '', condition.code, condition, condition, 'Code') return condition } - function createUiObject (uiObjectType, name, node, parentNode, chainParent, title, positionOffset) { + function createUiObject (userAddingNew, uiObjectType, name, node, parentNode, chainParent, title, positionOffset) { let payload = {} if (name === '' || name === undefined) { name = 'My ' + uiObjectType } @@ -2123,6 +2123,6 @@ function newUiObjectsFromNodes () { } node.payload = payload node.type = uiObjectType - canvas.floatingSpace.uiObjectConstructor.createUiObject(payload) + canvas.floatingSpace.uiObjectConstructor.createUiObject(userAddingNew, payload) } } diff --git a/FloatingSpace/UiObjectConstructor.js b/FloatingSpace/UiObjectConstructor.js index 538d29438..e6c370497 100644 --- a/FloatingSpace/UiObjectConstructor.js +++ b/FloatingSpace/UiObjectConstructor.js @@ -27,7 +27,7 @@ function newUiObjectConstructor () { floatingLayer = pFloatingLayer } - function createUiObject (payload) { + function createUiObject (userAddingNew, payload) { let floatingObject = newFloatingObject() floatingObject.fitFunction = canvas.floatingSpace.fitIntoVisibleArea floatingObject.container.connectToParent(canvas.floatingSpace.container, false, false, false, false, false, false, false, false) @@ -59,6 +59,22 @@ function newUiObjectConstructor () { } } + if (userAddingNew === true) { + /* For brand new objects being created directly by the user, we will make them inherit some properties from their parents. */ + if (payload.parentNode.payload.floatingObject.isPinned === true) { + floatingObject.pinToggle() + } + if (payload.parentNode.payload.floatingObject.isFrozen === true) { + floatingObject.freezeToggle() + } + if (payload.parentNode.payload.floatingObject.isCollapsed === true) { + floatingObject.collapseToggle() + } + if (payload.parentNode.payload.floatingObject.isTensed === true) { + floatingObject.tensionToggle() + } + } + let uiObject = newUiObject() payload.uiObject = uiObject uiObject.fitFunction = canvas.floatingSpace.fitIntoVisibleArea From c9e3b65255577caf34ab1327c7e67a45799f686b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Nov 2019 13:15:08 +0100 Subject: [PATCH 05/41] Avoinding rejection when shortcut keys are used and allowing 0 to 9 digits --- Canvas.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Canvas.js b/Canvas.js index fcc1c23b6..c548081b9 100644 --- a/Canvas.js +++ b/Canvas.js @@ -47,6 +47,7 @@ function newCanvas () { let splashScreen let lastContainerMouseOver + let lastShortcutKeyRejection return thisObject @@ -285,7 +286,7 @@ function newCanvas () { } if ((event.ctrlKey === true || event.metaKey === true) && event.altKey === true) { - if (event.keyCode >= 65 && event.keyCode <= 90) { + if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 65 && event.keyCode <= 90)) { /* From here we prevent the default behaviour */ event.preventDefault() @@ -304,8 +305,16 @@ function newCanvas () { nodeOnFocus.payload.uiObject.setValue('Shortcut Key Removed ') return } else { - nodeOnFocus.payload.uiObject.setErrorMessage('Key already in use by ' + nodeUsingThisKey.type + ' ' + nodeUsingThisKey.name) - return + if (lastShortcutKeyRejection !== event.key + nodeUsingThisKey.type + ' ' + nodeUsingThisKey.name) { + /* The first time we show a warning that this key is in use. */ + nodeOnFocus.payload.uiObject.setErrorMessage('Key already in use by ' + nodeUsingThisKey.type + ' ' + nodeUsingThisKey.name) + lastShortcutKeyRejection = event.key + nodeUsingThisKey.type + ' ' + nodeUsingThisKey.name + return + } else { + /* After the warning, we allow the key to be re-assigned */ + nodeUsingThisKey.payload.uiObject.shortcutKey = '' + nodeUsingThisKey === undefined + } } } /* If there is not node using this key and a node in focus, we assign this key to this node */ From 0a7165d58011d902aee34d843937142f1fd2b825 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Nov 2019 18:02:53 +0100 Subject: [PATCH 06/41] Menu Item of type ADD get disabled once there is already an item attached taking the only place --- FloatingSpace/CircularMenu.js | 2 + FloatingSpace/CircularMenuItem.js | 25 +++++++- FloatingSpace/UiObjectConstructor.js | 91 +++++++++++++++++++++++++--- 3 files changed, 106 insertions(+), 12 deletions(-) diff --git a/FloatingSpace/CircularMenu.js b/FloatingSpace/CircularMenu.js index c8ef434f8..5a63f51a4 100644 --- a/FloatingSpace/CircularMenu.js +++ b/FloatingSpace/CircularMenu.js @@ -76,6 +76,8 @@ function newCircularMenu () { menuItem.dontShowAtFullscreen = menuItemInitialValue.dontShowAtFullscreen menuItem.askConfirmation = menuItemInitialValue.askConfirmation menuItem.confirmationLabel = menuItemInitialValue.confirmationLabel + menuItem.disableIfPropertyIsDefined = menuItemInitialValue.disableIfPropertyIsDefined + menuItem.propertyToCheckFor = menuItemInitialValue.propertyToCheckFor if (menuItem.label === undefined) { menuItem.type = 'Icon Only' diff --git a/FloatingSpace/CircularMenuItem.js b/FloatingSpace/CircularMenuItem.js index 2ce83ed0a..7f9c93cbd 100644 --- a/FloatingSpace/CircularMenuItem.js +++ b/FloatingSpace/CircularMenuItem.js @@ -10,6 +10,8 @@ function newCircularMenuItem () { iconOn: undefined, iconOff: undefined, currentIcon: undefined, + disableIfPropertyIsDefined: undefined, + propertyToCheckFor: undefined, action: undefined, actionFunction: undefined, actionStatus: undefined, @@ -35,6 +37,7 @@ function newCircularMenuItem () { payload: undefined, relatedUiObject: undefined, dontShowAtFullscreen: undefined, + isEnabled: true, internalClick: internalClick, physics: physics, drawBackground: drawBackground, @@ -93,6 +96,8 @@ function newCircularMenuItem () { thisObject.payload = undefined thisObject.actionFunction = undefined thisObject.actionStatus = undefined + thisObject.disableIfPropertyIsDefined = undefined + thisObject.propertyToCheckFor = undefined } function initialize (pPayload) { @@ -143,7 +148,6 @@ function newCircularMenuItem () { thisObject.container.frame.position.y = thisObject.container.frame.radius * 3 / 7 * Math.sin(toRadians(thisObject.angle)) - thisObject.container.frame.height / 2 /* Temporary Status impacts on the label to use and the background of that label */ - if (temporaryStatusCounter > 0) { temporaryStatusCounter-- } @@ -155,6 +159,16 @@ function newCircularMenuItem () { thisObject.nextAction = thisObject.action } + /* Here we will check if we need to monitor a property that influences the status of the Menu Item. */ + if (thisObject.disableIfPropertyIsDefined === true) { + if (thisObject.payload.node[thisObject.propertyToCheckFor] === undefined) { + /* This menu item is enabled. */ + thisObject.isEnabled = true + } else { + /* This menu item is disabled. */ + thisObject.isEnabled = false + } + } iconPhysics() } @@ -211,6 +225,8 @@ function newCircularMenuItem () { } function onMouseClick () { + if (thisObject.isEnabled === false) { return } + if (thisObject.label === undefined) { /* This is what we have in the case of menu items that are only Icons. In this situation there is no complex logic, just execute the specified action. */ thisObject.actionFunction(thisObject.payload, thisObject.action) @@ -322,12 +338,16 @@ function newCircularMenuItem () { if (thisObject.container.frame.position.x > 0 && thisObject.isDeployed === true && thisObject.currentRadius >= thisObject.targetRadius) { if (thisObject.type === 'Icon & Text') { + let backgroundColor = backgroundColorToUse + if (thisObject.isEnabled === false) { + backgroundColor = UI_COLOR.GREY + } let params = { cornerRadius: 3, lineWidth: 0.1, container: thisObject.container, borderColor: UI_COLOR.DARK, - backgroundColor: backgroundColorToUse, + backgroundColor: backgroundColor, castShadow: false, xOffset: 40 } @@ -387,4 +407,3 @@ function newCircularMenuItem () { } } } - diff --git a/FloatingSpace/UiObjectConstructor.js b/FloatingSpace/UiObjectConstructor.js index e6c370497..ca6fbd99b 100644 --- a/FloatingSpace/UiObjectConstructor.js +++ b/FloatingSpace/UiObjectConstructor.js @@ -61,15 +61,6 @@ function newUiObjectConstructor () { if (userAddingNew === true) { /* For brand new objects being created directly by the user, we will make them inherit some properties from their parents. */ - if (payload.parentNode.payload.floatingObject.isPinned === true) { - floatingObject.pinToggle() - } - if (payload.parentNode.payload.floatingObject.isFrozen === true) { - floatingObject.freezeToggle() - } - if (payload.parentNode.payload.floatingObject.isCollapsed === true) { - floatingObject.collapseToggle() - } if (payload.parentNode.payload.floatingObject.isTensed === true) { floatingObject.tensionToggle() } @@ -265,6 +256,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Trading System', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'tradingSystem', actionFunction: payload.onMenuItemClick, label: 'Add Trading System', visible: true, @@ -278,6 +271,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Personal Data', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'personalData', actionFunction: payload.onMenuItemClick, label: 'Add Personal Data', visible: true, @@ -942,6 +937,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Procedure Initialization', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'initialization', actionFunction: payload.onMenuItemClick, label: 'Add Procedure Initialization', visible: true, @@ -955,6 +952,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Procedure Loop', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'loop', actionFunction: payload.onMenuItemClick, label: 'Add Procedure Loop', visible: true, @@ -1002,6 +1001,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Procedure Initialization', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'initialization', actionFunction: payload.onMenuItemClick, label: 'Add Procedure Initialization', visible: true, @@ -1015,6 +1016,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Procedure Loop', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'loop', actionFunction: payload.onMenuItemClick, label: 'Add Procedure Loop', visible: true, @@ -1062,6 +1065,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Code', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'code', actionFunction: payload.onMenuItemClick, label: 'Add Code', visible: true, @@ -1109,6 +1114,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Code', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'code', actionFunction: payload.onMenuItemClick, label: 'Add Code', visible: true, @@ -1296,6 +1303,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Record Definition', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'record', actionFunction: payload.onMenuItemClick, label: 'Add Record Definition', visible: true, @@ -1435,6 +1444,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Formula', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'formula', actionFunction: payload.onMenuItemClick, label: 'Add Formula', visible: true, @@ -1582,6 +1593,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Code', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'code', actionFunction: payload.onMenuItemClick, label: 'Add Code', visible: true, @@ -1642,6 +1655,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Code', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'code', actionFunction: payload.onMenuItemClick, label: 'Add Code', visible: true, @@ -1900,6 +1915,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Formula', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'formula', actionFunction: payload.onMenuItemClick, label: 'Add Formula', visible: true, @@ -2161,6 +2178,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Sensor Bot Instance', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'bot', actionFunction: payload.onMenuItemClick, label: 'Add Sensor Bot Instance', visible: true, @@ -2174,6 +2193,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Indicator Bot Instance', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'bot', actionFunction: payload.onMenuItemClick, label: 'Add Indicator Bot Instance', visible: true, @@ -2187,6 +2208,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Trading Bot Instance', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'bot', actionFunction: payload.onMenuItemClick, label: 'Add Trading Bot Instance', visible: true, @@ -2443,6 +2466,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Backtesting Session', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'session', actionFunction: payload.onMenuItemClick, label: 'Add Backtesting', visible: true, @@ -2456,6 +2481,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Live Trading Session', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'session', actionFunction: payload.onMenuItemClick, label: 'Add Live Trading', visible: true, @@ -2469,6 +2496,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Fordward Testing Session', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'session', actionFunction: payload.onMenuItemClick, label: 'Add Fordward Testing', visible: true, @@ -2482,6 +2511,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Paper Trading Session', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'session', actionFunction: payload.onMenuItemClick, label: 'Add Paper Trading', visible: true, @@ -2623,6 +2654,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Layer Manager', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'layerManager', actionFunction: payload.onMenuItemClick, label: 'Add Layer Manager', visible: true, @@ -2636,6 +2669,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Parameters', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'parameters', actionFunction: payload.onMenuItemClick, label: 'Add Parameters', visible: true, @@ -2649,6 +2684,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Social Bots', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'socialBots', actionFunction: payload.onMenuItemClick, label: 'Add Social Bots', visible: true, @@ -2739,6 +2776,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Layer Manager', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'layerManager', actionFunction: payload.onMenuItemClick, label: 'Add Layer Manager', visible: true, @@ -2752,6 +2791,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Parameters', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'parameters', actionFunction: payload.onMenuItemClick, label: 'Add Parameters', visible: true, @@ -2765,6 +2806,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Social Bots', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'socialBots', actionFunction: payload.onMenuItemClick, label: 'Add Social Bots', visible: true, @@ -2855,6 +2898,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Layer Manager', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'layerManager', actionFunction: payload.onMenuItemClick, label: 'Add Layer Manager', visible: true, @@ -2868,6 +2913,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Parameters', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'parameters', actionFunction: payload.onMenuItemClick, label: 'Add Parameters', visible: true, @@ -2881,6 +2928,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Social Bots', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'socialBots', actionFunction: payload.onMenuItemClick, label: 'Add Social Bots', visible: true, @@ -2971,6 +3020,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Layer Manager', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'layerManager', actionFunction: payload.onMenuItemClick, label: 'Add Layer Manager', visible: true, @@ -2984,6 +3035,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Parameters', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'parameters', actionFunction: payload.onMenuItemClick, label: 'Add Parameters', visible: true, @@ -2997,6 +3050,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Social Bots', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'socialBots', actionFunction: payload.onMenuItemClick, label: 'Add Social Bots', visible: true, @@ -3211,6 +3266,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Parameters', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'parameters', actionFunction: payload.onMenuItemClick, label: 'Add Parameters', visible: true, @@ -3664,6 +3721,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Initial Definition', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'initialDefinition', actionFunction: payload.onMenuItemClick, label: 'Add Initial Definition', visible: true, @@ -3677,6 +3736,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Open Execution', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'openExecution', actionFunction: payload.onMenuItemClick, label: 'Add Open Execution', visible: true, @@ -3771,6 +3832,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Close Execution', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'closeExecution', actionFunction: payload.onMenuItemClick, label: 'Add Close Execution', visible: true, @@ -3818,6 +3881,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Formula', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'formula', actionFunction: payload.onMenuItemClick, label: 'Add Formula', visible: true, @@ -3865,6 +3930,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Formula', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'formula', actionFunction: payload.onMenuItemClick, label: 'Add Formula', visible: true, @@ -4262,6 +4329,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Formula', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'formula', actionFunction: payload.onMenuItemClick, label: 'Add Formula', visible: true, @@ -4275,6 +4344,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Next Phase Event', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'nextPhaseEvent', actionFunction: payload.onMenuItemClick, label: 'Add Next Phase Event', visible: true, @@ -4470,6 +4541,8 @@ function newUiObjectConstructor () { menuItemsInitialValues.push( { action: 'Add Code', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'code', actionFunction: payload.onMenuItemClick, label: 'Add Code', visible: true, From d7ff0b1051928b9c902d6a878206fc7c455756b1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 26 Nov 2019 14:08:12 +0100 Subject: [PATCH 07/41] Improvements on UI to speed up animation --- FloatingSpace/FloatingLayer.js | 7 ++++- FloatingSpace/FloatingObject.js | 6 +++- Spaces/FloatingSpace.js | 51 +++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/FloatingSpace/FloatingLayer.js b/FloatingSpace/FloatingLayer.js index c0c6a7f92..c2781f2ea 100644 --- a/FloatingSpace/FloatingLayer.js +++ b/FloatingSpace/FloatingLayer.js @@ -206,9 +206,11 @@ function newFloatingLayer () { if (floatingObject.isFrozen === false && floatingObject.isParentCollapsed === false) { visibleFloatingObjects.push(floatingObject) invisibleFloatingObjects.splice(i, 1) // Delete item from array. + makeVisible() return // Only one at the time. } } + console.log('INVISIBLE', invisibleFloatingObjects.length) } function makeInvisible () { @@ -218,9 +220,11 @@ function newFloatingLayer () { if (floatingObject.isFrozen === true || floatingObject.isParentCollapsed === true) { invisibleFloatingObjects.push(floatingObject) visibleFloatingObjects.splice(i, 1) // Delete item from array. + makeInvisible() return // Only one at the time. } } + console.log('VISIBLE', visibleFloatingObjects.length) } /******************************************/ @@ -261,6 +265,8 @@ function newFloatingLayer () { for (let i = 0; i < visibleFloatingObjects.length; i++) { let floatingObject = visibleFloatingObjects[i] + if (canvas.floatingSpace.isItFar(floatingObject.payload)) { continue } + if (floatingObject.positionLocked === false) { floatingObject.container.frame.position.x = floatingObject.container.frame.position.x + floatingObject.currentSpeed.x floatingObject.container.frame.position.y = floatingObject.container.frame.position.y + floatingObject.currentSpeed.y @@ -747,4 +753,3 @@ function newFloatingLayer () { } } } - diff --git a/FloatingSpace/FloatingObject.js b/FloatingSpace/FloatingObject.js index 65a6672d5..6fdfcf353 100644 --- a/FloatingSpace/FloatingObject.js +++ b/FloatingSpace/FloatingObject.js @@ -176,10 +176,11 @@ function newFloatingObject () { } function physics () { + collapsePhysics() + if (canvas.floatingSpace.isItFar(thisObject.payload)) { return } thisObjectPhysics() thisObject.payload.uiObject.physics() frozenPhysics() - collapsePhysics() tensionPhysics() } @@ -339,16 +340,19 @@ function newFloatingObject () { } function drawBackground () { + if (canvas.floatingSpace.isItFar(thisObject.payload)) { return } if ((thisObject.isCollapsed === true && thisObject.collapsedManually === false) || thisObject.isParentCollapsed === true) { return } thisObject.payload.uiObject.drawBackground() } function drawMiddleground () { + if (canvas.floatingSpace.isItFar(thisObject.payload)) { return } if ((thisObject.isCollapsed === true && thisObject.collapsedManually === false) || thisObject.isParentCollapsed === true) { return } thisObject.payload.uiObject.drawMiddleground() } function drawForeground () { + if (canvas.floatingSpace.isItFar(thisObject.payload)) { return } if ((thisObject.isCollapsed === true && thisObject.collapsedManually === false) || thisObject.isParentCollapsed === true) { return } thisObject.payload.uiObject.drawForeground() } diff --git a/Spaces/FloatingSpace.js b/Spaces/FloatingSpace.js index da3c213d6..4b0679567 100644 --- a/Spaces/FloatingSpace.js +++ b/Spaces/FloatingSpace.js @@ -20,6 +20,7 @@ function newFloatingSpace () { positionAtNode: positionAtNode, fitIntoVisibleArea: fitIntoVisibleArea, isThisPointVisible: isThisPointVisible, + isItFar: isItFar, makeVisible: makeVisible, makeInvisible: makeInvisible, draw: draw, @@ -46,8 +47,10 @@ function newFloatingSpace () { thisObject.container.frame.position.y = browserCanvas.height / 2 - thisObject.container.frame.height / 2 let visible = false + let warmingUpCounter = 0 const PERCENTAGE_OF_SCREEN_FOR_DISPLACEMENT = 25 + return thisObject function finalize () { @@ -73,6 +76,54 @@ function newFloatingSpace () { thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel) } + function isItFar (payload) { + /* + We need a warm up in order to allow all objects to stabilize into a consistant state. + After that we will start evaluating which ones are too far from the current user view. + */ + + if (warmingUpCounter < 10000) { + warmingUpCounter++ + return false + } + + let radarFactor = 4 // How big is the margin + + /* Exceptions that are never considered far. */ + if ( + payload.node.type === 'Definition' || + payload.node.type === 'Network' || + payload.node.type === 'Team' + ) { + return false + } + + /* Another exception are the ones who have reference parents */ + if (payload.referenceParent !== undefined) { return false } + + /* Here we will check the position of a floatingobject to see if it is outside the screen, with a margin of one screen around. */ + let point = thisObject.container.frame.frameThisPoint(payload.position) + + if (point.x > browserCanvas.width + browserCanvas.width * radarFactor) { + return true + } + + if (point.x < 0 - browserCanvas.width * radarFactor) { + return true + } + + let bottom = COCKPIT_SPACE_POSITION + COCKPIT_SPACE_HEIGHT + let heightDiff = browserCanvas.height - bottom + if (point.y < bottom - heightDiff * radarFactor) { + return true + } + + if (point.y > browserCanvas.height + heightDiff * radarFactor) { + return true + } + return false + } + function fitIntoVisibleArea (point) { /* Here we check the boundaries of the resulting points, so they dont go out of the visible area. */ From 325b782181ac430b3354383429b265fc22a5ad4b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 26 Nov 2019 18:33:16 +0100 Subject: [PATCH 08/41] Unnecesary Logs --- FloatingSpace/FloatingLayer.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/FloatingSpace/FloatingLayer.js b/FloatingSpace/FloatingLayer.js index c2781f2ea..dd8d078ee 100644 --- a/FloatingSpace/FloatingLayer.js +++ b/FloatingSpace/FloatingLayer.js @@ -210,7 +210,6 @@ function newFloatingLayer () { return // Only one at the time. } } - console.log('INVISIBLE', invisibleFloatingObjects.length) } function makeInvisible () { @@ -224,7 +223,6 @@ function newFloatingLayer () { return // Only one at the time. } } - console.log('VISIBLE', visibleFloatingObjects.length) } /******************************************/ From e1fea0cc3fefedb381614e9856f80b9392957587 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 27 Nov 2019 10:47:23 +0100 Subject: [PATCH 09/41] Bug fixed when calculated which objects are too far to be drawn --- Spaces/FloatingSpace.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Spaces/FloatingSpace.js b/Spaces/FloatingSpace.js index 4b0679567..ab007e6d1 100644 --- a/Spaces/FloatingSpace.js +++ b/Spaces/FloatingSpace.js @@ -76,7 +76,7 @@ function newFloatingSpace () { thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel) } - function isItFar (payload) { + function isItFar (payload, dontCheckParent) { /* We need a warm up in order to allow all objects to stabilize into a consistant state. After that we will start evaluating which ones are too far from the current user view. @@ -87,7 +87,14 @@ function newFloatingSpace () { return false } - let radarFactor = 4 // How big is the margin + let radarFactor = 2 // How big is the margin + + /* If the chain parent is not far, they we dont consither this far. */ + if (dontCheckParent !== true) { + if (payload.chainParent !== undefined) { + if (isItFar(payload.chainParent.payload, true) === false) { return false } + } + } /* Exceptions that are never considered far. */ if ( From c2d0876806f912719cbcac076f1e04793ca1c78c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 29 Nov 2019 17:12:05 +0100 Subject: [PATCH 10/41] Bug Fixed when importing workspace --- FloatingSpace/FloatingObject.js | 92 +++++++++++++++++---------------- FloatingSpace/UiObject.js | 2 + Spaces/FloatingSpace.js | 3 ++ 3 files changed, 53 insertions(+), 44 deletions(-) diff --git a/FloatingSpace/FloatingObject.js b/FloatingSpace/FloatingObject.js index 6fdfcf353..01bda09bc 100644 --- a/FloatingSpace/FloatingObject.js +++ b/FloatingSpace/FloatingObject.js @@ -185,21 +185,23 @@ function newFloatingObject () { } function frozenPhysics () { - if (thisObject.frozenManually === false) { - let parent = thisObject.payload.chainParent - if (parent !== undefined && parent.payload !== undefined) { - thisObject.isFrozen = parent.payload.floatingObject.isFrozen - } + if (thisObject.frozenManually !== false) { return } + if (thisObject.payload === undefined) { return } + let parent = thisObject.payload.chainParent + if (parent !== undefined && parent.payload !== undefined) { + thisObject.isFrozen = parent.payload.floatingObject.isFrozen } } function collapsePhysics () { let parent = thisObject.payload.chainParent - if (parent !== undefined) { - thisObject.isParentCollapsed = parent.payload.floatingObject.isCollapsed - if (thisObject.collapsedManually === false) { - thisObject.isCollapsed = parent.payload.floatingObject.isCollapsed - } + if (parent === undefined) { return } + if (parent.payload === undefined) { return } + if (parent.payload.floatingObject === undefined) { return } + + thisObject.isParentCollapsed = parent.payload.floatingObject.isCollapsed + if (thisObject.collapsedManually === false) { + thisObject.isCollapsed = parent.payload.floatingObject.isCollapsed } } @@ -207,48 +209,50 @@ function newFloatingObject () { /* 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 ... - let parentChildren = canvas.designerSpace.workspace.nodeChildren.childrenCount(parent, thisObject.payload.node) - let axisCount = parentChildren.childrenCount - let axisIndex = parentChildren.childIndex - let baseAngle = 0 + if (parent === undefined) { return } + if (parent.payload === undefined) { return } + if (parent.payload.position === undefined) { return } - if (axisIndex === undefined) { - axisCount = 1 - axisIndex = axisCount - } + 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 ... + let parentChildren = canvas.designerSpace.workspace.nodeChildren.childrenCount(parent, thisObject.payload.node) + let axisCount = parentChildren.childrenCount + let axisIndex = parentChildren.childIndex + let baseAngle = 0 - if (parent.payload.chainParent !== undefined && parent.payload.angle !== undefined) { + if (axisIndex === undefined) { + axisCount = 1 + axisIndex = axisCount + } + + if (parent.payload.chainParent !== undefined && parent.payload.angle !== undefined) { + axisCount++ + axisIndex++ + baseAngle = parent.payload.angle + 180 + lastParentAngle = parent.payload.angle + } else { + if (lastParentAngle !== undefined) { axisCount++ axisIndex++ - baseAngle = parent.payload.angle + 180 - lastParentAngle = parent.payload.angle - } else { - if (lastParentAngle !== undefined) { - axisCount++ - axisIndex++ - baseAngle = lastParentAngle + 180 - } + baseAngle = lastParentAngle + 180 } + } - let angleStep = 360 / axisCount + let angleStep = 360 / axisCount - thisObject.payload.angle = baseAngle + (axisIndex - 1) * angleStep - if (thisObject.payload.angle >= 360) { - thisObject.payload.angle = thisObject.payload.angle - 360 - } + thisObject.payload.angle = baseAngle + (axisIndex - 1) * angleStep + if (thisObject.payload.angle >= 360) { + thisObject.payload.angle = thisObject.payload.angle - 360 + } - newPosition = { - x: parent.payload.position.x + distanceToChainParent * Math.cos(toRadians(thisObject.payload.angle)), - y: parent.payload.position.y + distanceToChainParent * Math.sin(toRadians(thisObject.payload.angle)) - } - if (isNaN(newPosition.x) === false) { - thisObject.container.frame.position.x = newPosition.x - } - if (isNaN(newPosition.y) === false) { - thisObject.container.frame.position.y = newPosition.y - } + newPosition = { + x: parent.payload.position.x + distanceToChainParent * Math.cos(toRadians(thisObject.payload.angle)), + y: parent.payload.position.y + distanceToChainParent * Math.sin(toRadians(thisObject.payload.angle)) + } + if (isNaN(newPosition.x) === false) { + thisObject.container.frame.position.x = newPosition.x + } + if (isNaN(newPosition.y) === false) { + thisObject.container.frame.position.y = newPosition.y } } } diff --git a/FloatingSpace/UiObject.js b/FloatingSpace/UiObject.js index 1f77f9847..55506b4c0 100644 --- a/FloatingSpace/UiObject.js +++ b/FloatingSpace/UiObject.js @@ -1089,6 +1089,8 @@ function newUiObject () { function drawReferenceLine () { if (thisObject.payload.referenceParent === undefined) { return } + if (thisObject.payload.referenceParent.payload === undefined) { return } + if (thisObject.payload.referenceParent.payload.floatingObject === undefined) { return } if (thisObject.payload.referenceParent.payload.floatingObject.isParentCollapsed === true) { return } let targetPoint = { diff --git a/Spaces/FloatingSpace.js b/Spaces/FloatingSpace.js index ab007e6d1..d3798cee8 100644 --- a/Spaces/FloatingSpace.js +++ b/Spaces/FloatingSpace.js @@ -77,6 +77,9 @@ function newFloatingSpace () { } function isItFar (payload, dontCheckParent) { + /* If for any reason the paylaod is undefined we return false */ + if (payload === undefined) { return false } + /* We need a warm up in order to allow all objects to stabilize into a consistant state. After that we will start evaluating which ones are too far from the current user view. From c80c31e7bbbfb7658490d5eb56995ac8ad38f583 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 30 Nov 2019 10:09:30 +0100 Subject: [PATCH 11/41] Controlling JSON syntax at UI Objects properties --- FloatingSpace/CodeEditor.js | 8 ++++++++ FloatingSpace/UiObject.js | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/FloatingSpace/CodeEditor.js b/FloatingSpace/CodeEditor.js index 1ed862964..62fcffdae 100644 --- a/FloatingSpace/CodeEditor.js +++ b/FloatingSpace/CodeEditor.js @@ -71,6 +71,13 @@ function newCodeEditor () { let textArea = document.getElementById('textArea') textArea.style.display = 'none' thisObject.payload.node.code = textArea.value + if (thisObject.payload.node.type !== 'Code' && thisObject.payload.node.type !== 'Formula') { + try { + let code = JSON.parse(thisObject.payload.node.code) + } catch (err) { + thisObject.payload.uiObject.setErrorMessage(err.message, 10) + } + } } } @@ -80,6 +87,7 @@ function newCodeEditor () { thisObject.rawRadius = 8 thisObject.targetRadius = thisObject.container.frame.radius thisObject.currentRadius = 0 + thisObject.payload.uiObject.setErrorMessage('', 0) let textArea = document.getElementById('textArea') textArea.value = payload.node.code diff --git a/FloatingSpace/UiObject.js b/FloatingSpace/UiObject.js index 55506b4c0..f702b5e60 100644 --- a/FloatingSpace/UiObject.js +++ b/FloatingSpace/UiObject.js @@ -835,11 +835,12 @@ function newUiObject () { highlightCounter = 30 } - function setErrorMessage (message) { + function setErrorMessage (message, duration) { if (message !== undefined) { errorMessage = message hasError = true - errorMessageCounter = 100 + if (duration === undefined) { duration = 1 } + errorMessageCounter = 100 * duration } } From 87da492d2bb22a3fcca9679b01694d658f68d1e6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 30 Nov 2019 11:08:15 +0100 Subject: [PATCH 12/41] https://github.com/Superalgos/DesktopApp/issues/108 --- DesignerSpace/Workspace/Workspace.js | 4 +++- Panels/ProductsPanel.js | 35 ++++++++++++++-------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/DesignerSpace/Workspace/Workspace.js b/DesignerSpace/Workspace/Workspace.js index 1c43e2a9b..2b150a4e8 100644 --- a/DesignerSpace/Workspace/Workspace.js +++ b/DesignerSpace/Workspace/Workspace.js @@ -161,7 +161,9 @@ function newWorkspace () { for (k = 0; k < taskManager.tasks.length; k++) { let task = taskManager.tasks[k] if (task.bot.type === 'Trading Bot Instance') { - tradingBotInstances.push(task.bot) + if (task.bot.payload.floatingObject.isCollapsed !== true) { + tradingBotInstances.push(task.bot) + } } } } diff --git a/Panels/ProductsPanel.js b/Panels/ProductsPanel.js index 32f500524..a8a0339d8 100644 --- a/Panels/ProductsPanel.js +++ b/Panels/ProductsPanel.js @@ -313,27 +313,28 @@ function newProductsPanel () { if (process.session !== undefined) { if (process.session.layerManager !== undefined) { let layerManager = process.session.layerManager + if (layerManager.payload.floatingObject.isCollapsed !== true) { + if (bot.products !== undefined) { + for (let k = 0; k < bot.products.length; k++) { + let product = bot.products[k] - if (bot.products !== undefined) { - for (let k = 0; k < bot.products.length; k++) { - let product = bot.products[k] - - for (let p = 0; p < layerManager.layers.length; p++) { - let layer = layerManager.layers[p] - let layerCode - try { - layerCode = JSON.parse(layer.code) - } catch (err) { + for (let p = 0; p < layerManager.layers.length; p++) { + let layer = layerManager.layers[p] + let layerCode + try { + layerCode = JSON.parse(layer.code) + } catch (err) { // if we can not parse this, then we ignore this trading engine. - } + } - if (product.codeName === layerCode.product) { + if (product.codeName === layerCode.product) { /* We have a layer that is matching the current product */ - let cardCode = exchange + '-' + market.assetB + '/' + market.assetA + '-' + devTeam.codeName + '-' + bot.codeName + '-' + product.codeName + '-' + process.session.id - let cardFound = removeFromLocalProductCards(cardCode) - if (cardFound !== true) { - productCard = addProductCard(devTeam, bot, product, process.session) - onProductCardStatusChanged(productCard) + let cardCode = exchange + '-' + market.assetB + '/' + market.assetA + '-' + devTeam.codeName + '-' + bot.codeName + '-' + product.codeName + '-' + process.session.id + let cardFound = removeFromLocalProductCards(cardCode) + if (cardFound !== true) { + productCard = addProductCard(devTeam, bot, product, process.session) + onProductCardStatusChanged(productCard) + } } } } From c2af0f7c2c790b95515633e4c75f0741f0226224 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 1 Dec 2019 11:58:44 +0100 Subject: [PATCH 13/41] https://github.com/Superalgos/DesktopApp/issues/109 --- .../Workspace/FunctionLibraries/UiObjectsFromNodes.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js index f495e75e6..57a139f7a 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js +++ b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js @@ -465,6 +465,8 @@ function newUiObjectsFromNodes () { node.savedPayload = { referenceChildren: referenceChildren } + } else { + node.referenceChildren = [] } return } @@ -793,6 +795,8 @@ function newUiObjectsFromNodes () { node.savedPayload = { referenceChildren: referenceChildren } + } else { + node.referenceChildren = [] } return } @@ -830,6 +834,8 @@ function newUiObjectsFromNodes () { node.savedPayload = { referenceChildren: referenceChildren } + } else { + node.referenceChildren = [] } return } @@ -865,6 +871,8 @@ function newUiObjectsFromNodes () { node.savedPayload = { referenceChildren: referenceChildren } + } else { + node.referenceChildren = [] } return } @@ -1002,6 +1010,8 @@ function newUiObjectsFromNodes () { node.savedPayload = { referenceChildren: referenceChildren } + } else { + node.referenceChildren = [] } return } From bd36806930c2e279f05dce2832734849d69dd0e4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 1 Dec 2019 12:45:57 +0100 Subject: [PATCH 14/41] https://github.com/Superalgos/DesktopApp/issues/110 --- .../FunctionLibraries/UiObjectsFromNodes.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js index 57a139f7a..783f7253f 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js +++ b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js @@ -1261,7 +1261,7 @@ function newUiObjectsFromNodes () { let object = { type: 'Status Dependency', name: 'New Status Dependency', - code: '{"mainUtility": "Self Reference|Market Starting Point|Market Ending Point"}' + code: '{ \n\"mainUtility\": \"Self Reference|Market Starting Point|Market Ending Point.\"\n}' } if (node.statusDependencies === undefined) { node.statusDependencies = [] @@ -1431,7 +1431,7 @@ function newUiObjectsFromNodes () { function addTelegramBot (node) { let bot = { name: 'New Telegram Bot', - code: '{ \n\"botToken\": \"Paste here the bot token obtained from Telegram Bot Father\",\n\"chatId\": Write here the chat or group id where the announcements are going to be sent to, as it is a number with no quotes please.\n}', + code: '{ \n\"botToken\": \"Paste here the bot token obtained from Telegram Bot Father\",\n\"chatId\": \"Write here the chat or group id where the announcements are going to be sent to, as it is a number with no quotes please.\"\n}', announcements: [] } node.bots.push(bot) @@ -1466,7 +1466,7 @@ function newUiObjectsFromNodes () { function addLayer (node) { let layer = { name: 'New Layer', - code: '{}' + code: '{ \n\"product\": \"Type here the codeName of the Product\"\n}' } node.layers.push(layer) createUiObject(true, 'Layer', layer.name, layer, node, node, 'Layer') @@ -1564,7 +1564,7 @@ function newUiObjectsFromNodes () { if (node.session === undefined) { node.session = { name: 'New Backtesting Session', - code: '{}' + code: '{ \n\"folderName\": \"Type here the folder name where you want the logs of this process to be stored to.\"\n}' } createUiObject(true, 'Backtesting Session', '', node.session, node, node) } @@ -1588,7 +1588,7 @@ function newUiObjectsFromNodes () { if (node.session === undefined) { node.session = { name: 'New Fordward Testing Session', - code: '{}' + code: '{ \n\"folderName\": \"Type here the folder name where you want the logs of this process to be stored to.\",\n\"balancePercentage\": \"Type here the the % of the balance to be used in this test.\"\n}' } createUiObject(true, 'Fordward Testing Session', '', node.session, node, node) } @@ -1600,7 +1600,7 @@ function newUiObjectsFromNodes () { if (node.session === undefined) { node.session = { name: 'New Paper Trading Session', - code: '{}' + code: '{ \n\"folderName\": \"Type here the folder name where you want the logs of this process to be stored to.\"\n}' } createUiObject(true, 'Paper Trading Session', '', node.session, node, node) } @@ -1758,35 +1758,35 @@ function newUiObjectsFromNodes () { if (node.baseAsset === undefined) { node.baseAsset = { name: 'Base Asset', - code: DEFAULT_CONFIG_TEXT + code: '{ \n\"name\": \"BTC\",\n"initialBalance\": 0.001,\n\"minimumBalance\": 0.0001,\n\"maximumBalance\": 0.1\n}' } createUiObject(true, 'Base Asset', '', node.baseAsset, node, node) } if (node.timeRange === undefined) { node.timeRange = { name: 'Time Range', - code: DEFAULT_CONFIG_TEXT + code: '{ \n\"initialDatetime\": \"2019-07-01T00:00:00.000Z\",\n\"finalDatetime\": \"2019-09-01T00:00:00.000Z\"\n}' } createUiObject(true, 'Time Range', '', node.timeRange, node, node) } if (node.timePeriod === undefined) { node.timePeriod = { name: 'Time Period', - code: DEFAULT_CONFIG_TEXT + code: '01-hs' } createUiObject(true, 'Time Period', '', node.timePeriod, node, node) } if (node.slippage === undefined) { node.slippage = { name: 'Slippage', - code: DEFAULT_CONFIG_TEXT + code: '{ \n\"positionRate\": 0.1,\n"stopLoss\": 0.2,\n"takeProfit\": 0.3\n}' } createUiObject(true, 'Slippage', '', node.slippage, node, node) } if (node.feeStructure === undefined) { node.feeStructure = { name: 'Fee Structure', - code: DEFAULT_CONFIG_TEXT + code: '{ \n\"maker\": 0.15,\n"taker\": 0.25\n}' } createUiObject(true, 'Fee Structure', '', node.feeStructure, node, node) } From 8e0a47bf0a81ec56dc503facdcfbf1c32e43c2b6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 1 Dec 2019 13:17:32 +0100 Subject: [PATCH 15/41] Divider handling with keyboard improved: https://github.com/Superalgos/DesktopApp/issues/112 --- Canvas.js | 27 +++++++++++++++++++++------ DesignerSpace/Workspace/Workspace.js | 8 +++++--- Spaces/CockpitSpace.js | 21 +++++++++++++++++++++ 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/Canvas.js b/Canvas.js index c548081b9..2b3e8f95f 100644 --- a/Canvas.js +++ b/Canvas.js @@ -216,22 +216,37 @@ function newCanvas () { } } - if (event.altKey === true && event.code === 'ArrowUp') { + if (event.shiftKey === true && event.altKey === true && event.ctrlKey === true && event.code === 'ArrowUp') { thisObject.cockpitSpace.toTop() return } - if (event.altKey === true && event.code === 'ArrowDown') { + if (event.shiftKey === true && event.altKey === true && event.ctrlKey && event.code === 'ArrowDown') { thisObject.cockpitSpace.toBottom() return } - if (event.shiftKey === true && event.code === 'ArrowLeft') { + if (event.shiftKey === true && event.altKey === true && event.ctrlKey && event.code === 'ArrowLeft' || event.altKey === true && event.code === 'ArrowRight') { + thisObject.cockpitSpace.toMiddle() + return + } + + if (event.shiftKey === true && event.ctrlKey && event.code === 'ArrowUp') { + thisObject.cockpitSpace.moveUp() + return + } + + if (event.shiftKey === true && event.ctrlKey && event.code === 'ArrowDown') { + thisObject.cockpitSpace.moveDown() + return + } + + if (event.shiftKey === true && event.ctrlKey === false && event.code === 'ArrowLeft') { canvas.chartSpace.oneScreenLeft() return } - if (event.shiftKey === true && event.code === 'ArrowRight') { + if (event.shiftKey === true && event.ctrlKey === false && event.code === 'ArrowRight') { canvas.chartSpace.oneScreenRight() return } @@ -246,7 +261,7 @@ function newCanvas () { return } - if ((event.ctrlKey === true || event.metaKey === true) && event.code === 'ArrowLeft') { + if ((event.ctrlKey === true || event.metaKey === true) && event.shiftKey === false && event.code === 'ArrowLeft') { let displaceVector = canvas.floatingSpace.oneScreenLeft() dragVector.downX = dragVector.downX + displaceVector.x dragVector.downY = dragVector.downY + displaceVector.y @@ -254,7 +269,7 @@ function newCanvas () { return } - if ((event.ctrlKey === true || event.metaKey === true) && event.code === 'ArrowRight') { + if ((event.ctrlKey === true || event.metaKey === true) && event.shiftKey === false && event.code === 'ArrowRight') { let displaceVector = canvas.floatingSpace.oneScreenRight() dragVector.downX = dragVector.downX + displaceVector.x dragVector.downY = dragVector.downY + displaceVector.y diff --git a/DesignerSpace/Workspace/Workspace.js b/DesignerSpace/Workspace/Workspace.js index 2b150a4e8..f900426ef 100644 --- a/DesignerSpace/Workspace/Workspace.js +++ b/DesignerSpace/Workspace/Workspace.js @@ -160,9 +160,11 @@ function newWorkspace () { let taskManager = networkNode.taskManagers[i] for (k = 0; k < taskManager.tasks.length; k++) { let task = taskManager.tasks[k] - if (task.bot.type === 'Trading Bot Instance') { - if (task.bot.payload.floatingObject.isCollapsed !== true) { - tradingBotInstances.push(task.bot) + if (task.bot !== undefined) { + if (task.bot.type === 'Trading Bot Instance') { + if (task.bot.payload.floatingObject.isCollapsed !== true) { + tradingBotInstances.push(task.bot) + } } } } diff --git a/Spaces/CockpitSpace.js b/Spaces/CockpitSpace.js index 453d5e779..39c2f2a0a 100644 --- a/Spaces/CockpitSpace.js +++ b/Spaces/CockpitSpace.js @@ -9,6 +9,9 @@ fullscreen: undefined, toTop: toTop, toBottom: toBottom, + toMiddle: toMiddle, + moveUp: moveUp, + moveDown: moveDown, draw: draw, physics: physics, getContainer: getContainer, @@ -87,6 +90,24 @@ thisObject.container.frame.position.y = browserCanvas.height - COCKPIT_SPACE_HEIGHT } + function toMiddle () { + thisObject.container.frame.position.y = browserCanvas.height / 2 - COCKPIT_SPACE_HEIGHT + } + + function moveUp () { + thisObject.container.frame.position.y = thisObject.container.frame.position.y - browserCanvas.height / 10 + if (thisObject.container.frame.position.y < 0) { + thisObject.container.frame.position.y = 0 + } + } + + function moveDown () { + thisObject.container.frame.position.y = thisObject.container.frame.position.y + browserCanvas.height / 10 + if (thisObject.container.frame.position.y > browserCanvas.height - COCKPIT_SPACE_HEIGHT) { + thisObject.container.frame.position.y = browserCanvas.height - COCKPIT_SPACE_HEIGHT + } + } + function physics () { thisObjectPhysics() childrenPhysics() From 4206b65160290bb8421dbde5c3a94891feb3125e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 2 Dec 2019 09:22:21 +0100 Subject: [PATCH 16/41] just ALT --- Canvas.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Canvas.js b/Canvas.js index 2b3e8f95f..3e01f45c9 100644 --- a/Canvas.js +++ b/Canvas.js @@ -216,17 +216,17 @@ function newCanvas () { } } - if (event.shiftKey === true && event.altKey === true && event.ctrlKey === true && event.code === 'ArrowUp') { + if (event.altKey === true && event.code === 'ArrowUp') { thisObject.cockpitSpace.toTop() return } - if (event.shiftKey === true && event.altKey === true && event.ctrlKey && event.code === 'ArrowDown') { + if (event.altKey === true && event.code === 'ArrowDown') { thisObject.cockpitSpace.toBottom() return } - if (event.shiftKey === true && event.altKey === true && event.ctrlKey && event.code === 'ArrowLeft' || event.altKey === true && event.code === 'ArrowRight') { + if (event.altKey === true && event.code === 'ArrowLeft' || event.altKey === true && event.code === 'ArrowRight') { thisObject.cockpitSpace.toMiddle() return } From b082a32902040a49d6330254b680906d8ce0091a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 2 Dec 2019 10:01:40 +0100 Subject: [PATCH 17/41] https://github.com/Superalgos/DesktopApp/issues/114 --- FloatingSpace/FloatingObject.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/FloatingSpace/FloatingObject.js b/FloatingSpace/FloatingObject.js index 01bda09bc..70d4bc0f1 100644 --- a/FloatingSpace/FloatingObject.js +++ b/FloatingSpace/FloatingObject.js @@ -207,6 +207,7 @@ function newFloatingObject () { function tensionPhysics () { /* Tension Effect */ + if (thisObject.isTensed === true) { let parent = thisObject.payload.chainParent if (parent === undefined) { return } @@ -244,6 +245,8 @@ function newFloatingObject () { thisObject.payload.angle = thisObject.payload.angle - 360 } + if (distanceToChainParent > 1000) { return } // this is introduced to avoid edges cases when importing workspaces. + newPosition = { x: parent.payload.position.x + distanceToChainParent * Math.cos(toRadians(thisObject.payload.angle)), y: parent.payload.position.y + distanceToChainParent * Math.sin(toRadians(thisObject.payload.angle)) From 69918eff2bfc28e2562ff1b9b0cac25150e6b36e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 2 Dec 2019 19:16:57 +0100 Subject: [PATCH 18/41] Warm up Floating Layer when a workspace is dropped --- DesignerSpace/Workspace/Workspace.js | 1 + FloatingSpace/UiObjectConstructor.js | 3 --- Spaces/FloatingSpace.js | 17 ++++++++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/DesignerSpace/Workspace/Workspace.js b/DesignerSpace/Workspace/Workspace.js index f900426ef..98a2beb12 100644 --- a/DesignerSpace/Workspace/Workspace.js +++ b/DesignerSpace/Workspace/Workspace.js @@ -205,6 +205,7 @@ function newWorkspace () { if (droppedNode.type === 'Workspace') { stopAllRunningTasks() functionLibraryNodeDeleter.deleteWorkspace(thisObject.workspaceNode, thisObject.workspaceNode.rootNodes) + canvas.floatingSpace.warmUp() thisObject.workspaceNode = droppedNode functionLibraryUiObjectsFromNodes.recreateWorkspace(thisObject.workspaceNode) return diff --git a/FloatingSpace/UiObjectConstructor.js b/FloatingSpace/UiObjectConstructor.js index ca6fbd99b..80e74b7ed 100644 --- a/FloatingSpace/UiObjectConstructor.js +++ b/FloatingSpace/UiObjectConstructor.js @@ -18,9 +18,6 @@ function newUiObjectConstructor () { function finalize () { floatingLayer = undefined - - payload.uiObject.finalize() - payload.uiObject = undefined } function initialize (pFloatingLayer) { diff --git a/Spaces/FloatingSpace.js b/Spaces/FloatingSpace.js index d3798cee8..b5dbad099 100644 --- a/Spaces/FloatingSpace.js +++ b/Spaces/FloatingSpace.js @@ -21,6 +21,7 @@ function newFloatingSpace () { fitIntoVisibleArea: fitIntoVisibleArea, isThisPointVisible: isThisPointVisible, isItFar: isItFar, + warmUp: warmUp, makeVisible: makeVisible, makeInvisible: makeInvisible, draw: draw, @@ -50,14 +51,24 @@ function newFloatingSpace () { let warmingUpCounter = 0 const PERCENTAGE_OF_SCREEN_FOR_DISPLACEMENT = 25 + let eventSubscriptionId return thisObject function finalize () { + thisObject.container.eventHandler.stopListening(eventSubscriptionId) + thisObject.floatingLayer.finalize() thisObject.profileBalls.finalize() thisObject.uiObjectConstructor.finalize() thisObject.noteSets.finalize() + thisObject.container.finalize() + + thisObject.floatingLayer = undefined + thisObject.profileBalls = undefined + thisObject.uiObjectConstructor = undefined + thisObject.noteSets = undefined + thisObject.container = undefined } function initialize (callBackFunction) { @@ -73,7 +84,11 @@ function newFloatingSpace () { thisObject.uiObjectConstructor = newUiObjectConstructor() thisObject.uiObjectConstructor.initialize(thisObject.floatingLayer) - thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel) + eventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel) + } + + function warmUp () { + warmingUpCounter = 0 } function isItFar (payload, dontCheckParent) { From e1c6eb0ce13fbac3c007848395234dd4028d0995 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 3 Dec 2019 09:46:48 +0100 Subject: [PATCH 19/41] Product definition references Plotter module --- .../FunctionLibraries/ProtocolNode.js | 8 +++++ .../ReferenceAttachDetach.js | 8 +++++ .../FunctionLibraries/UiObjectsFromNodes.js | 29 +++++++++++++++++++ FloatingSpace/UiObject.js | 4 +++ 4 files changed, 49 insertions(+) diff --git a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js index 2fdb0ae82..f771ddd94 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js +++ b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js @@ -1518,6 +1518,9 @@ function newProtocolNode () { if (includePayload) { object.savedPayload = getSavedPayload(node, includeReferences) } + if (followReferenceParent) { + object.referenceParent = getProtocolNode(node.payload.referenceParent, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) + } return object } case 'Record Definition': { @@ -1616,6 +1619,11 @@ function newProtocolNode () { code: getProtocolNode(node.code, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType), panels: [] } + if (includeParent) { + followAncestors = true + excludeChildren = true + object.parentNode = getProtocolNode(node.payload.parentNode, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) + } if (node.panels !== undefined) { for (let m = 0; m < node.panels.length; m++) { let panel = getProtocolNode(node.panels[m], removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) diff --git a/DesignerSpace/Workspace/FunctionLibraries/ReferenceAttachDetach.js b/DesignerSpace/Workspace/FunctionLibraries/ReferenceAttachDetach.js index 0b5099aff..ad9ed3e4f 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/ReferenceAttachDetach.js +++ b/DesignerSpace/Workspace/FunctionLibraries/ReferenceAttachDetach.js @@ -44,6 +44,10 @@ function newReferenceAttachDetach () { completeDetachment(node) return } + case 'Product Definition': { + completeDetachment(node) + return + } } } @@ -85,6 +89,10 @@ function newReferenceAttachDetach () { completeAttachment(node, attachToNode) } break + case 'Product Definition': { + completeAttachment(node, attachToNode) + } + break } } diff --git a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js index 783f7253f..5ead376f1 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js +++ b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js @@ -965,6 +965,15 @@ function newUiObjectsFromNodes () { return } case 'Product Definition': { + let referenceParent + if (mapOfReferenceChildren !== undefined) { + if (node.savedPayload.referenceParent !== undefined) { + if (node.savedPayload.referenceParent.id !== undefined) { + mapOfReferenceChildren.set(node.id, node) + referenceParent = node.savedPayload.referenceParent + } + } + } createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (node.record !== undefined) { createUiObjectFromNode(node.record, node, node, positionOffset) @@ -979,6 +988,11 @@ function newUiObjectsFromNodes () { if (node.dataBuilding !== undefined) { createUiObjectFromNode(node.dataBuilding, node, node, positionOffset) } + if (referenceParent !== undefined) { + node.savedPayload = { + referenceParent: referenceParent + } + } return } case 'Record Definition': { @@ -1024,6 +1038,14 @@ function newUiObjectsFromNodes () { return } case 'Plotter Module': { + let referenceChildren + if (mapOfReferenceParents !== undefined) { + if (node.savedPayload.referenceChildren !== undefined) { + referenceChildren = [] + mapOfReferenceParents.set(node.id, node) + referenceChildren = node.savedPayload.referenceChildren + } + } createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) if (node.code !== undefined) { createUiObjectFromNode(node.code, node, node, positionOffset) @@ -1032,6 +1054,13 @@ function newUiObjectsFromNodes () { let panel = node.panels[m] createUiObjectFromNode(panel, node, node, positionOffset) } + if (referenceChildren !== undefined) { + node.savedPayload = { + referenceChildren: referenceChildren + } + } else { + node.referenceChildren = [] + } return } case 'Plotter Panel': { diff --git a/FloatingSpace/UiObject.js b/FloatingSpace/UiObject.js index f702b5e60..73e350eb6 100644 --- a/FloatingSpace/UiObject.js +++ b/FloatingSpace/UiObject.js @@ -711,6 +711,10 @@ function newUiObject () { compatibleType = '->' + 'Process Definition' + '->' compatibleSubType = undefined break + case 'Product Definition': + compatibleType = '->' + 'Plotter Module' + '->' + compatibleSubType = undefined + break default: return } From 0b308b7e4bb620052e6493b7d5b22673436a0dbe Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 3 Dec 2019 12:18:23 +0100 Subject: [PATCH 20/41] Partial Implementation of getting plotters definition from UI --- .../FunctionLibraries/ProtocolNode.js | 1 + .../FunctionLibraries/UiObjectsFromNodes.js | 2 + FloatingSpace/UiObjectConstructor.js | 164 +++++++++++------- Panels/ProductsPanel.js | 87 ++++++++++ 4 files changed, 191 insertions(+), 63 deletions(-) diff --git a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js index f771ddd94..3ed3c191b 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js +++ b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js @@ -1593,6 +1593,7 @@ function newProtocolNode () { type: node.type, subType: node.subType, name: node.name, + code: node.code, modules: [] } if (node.modules !== undefined) { diff --git a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js index 5ead376f1..3552d6552 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js +++ b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js @@ -1382,6 +1382,7 @@ function newUiObjectsFromNodes () { let object = { type: 'Plotter', name: 'New Plotter', + code: '{}', modules: [] } if (node.plotters === undefined) { @@ -1397,6 +1398,7 @@ function newUiObjectsFromNodes () { let object = { type: 'Plotter Module', name: 'New Plotter Module', + code: '{}', panels: [] } if (node.modules === undefined) { diff --git a/FloatingSpace/UiObjectConstructor.js b/FloatingSpace/UiObjectConstructor.js index 80e74b7ed..8d96c837a 100644 --- a/FloatingSpace/UiObjectConstructor.js +++ b/FloatingSpace/UiObjectConstructor.js @@ -1539,7 +1539,26 @@ function newUiObjectConstructor () { break } case 'Plotter': { + uiObject.codeEditor = newCodeEditor() + uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.codeEditor.initialize() + uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) + menuItemsInitialValues.push( + { + action: 'Edit Plotter', + actionFunction: uiObject.codeEditor.activate, + label: 'Edit Plotter', + visible: true, + iconPathOn: 'html', + iconPathOff: 'html', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: -30, + dontShowAtFullscreen: true + } + ) menuItemsInitialValues.push( { action: 'Add Plotter Module', @@ -1550,7 +1569,7 @@ function newUiObjectConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: -20 + angle: -10 } ) menuItemsInitialValues.push( @@ -1566,68 +1585,6 @@ function newUiObjectConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: 0 - } - ) - menuItemsInitialValues.push( - { - action: 'Share', - actionFunction: payload.onMenuItemClick, - label: 'Share', - visible: true, - iconPathOn: 'menu-share', - iconPathOff: 'menu-share', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: 20 - } - ) - break - } - case 'Plotter Module': { - addLeftIcons(menuItemsInitialValues, floatingObject) - menuItemsInitialValues.push( - { - action: 'Add Code', - disableIfPropertyIsDefined: true, - propertyToCheckFor: 'code', - actionFunction: payload.onMenuItemClick, - label: 'Add Code', - visible: true, - relatedUiObject: 'Code', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: -30 - } - ) - menuItemsInitialValues.push( - { - action: 'Add Plotter Panel', - actionFunction: payload.onMenuItemClick, - label: 'Add Plotter Panel', - visible: true, - relatedUiObject: 'Plotter Panel', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: -10 - } - ) - menuItemsInitialValues.push( - { - action: 'Delete Plotter Module', - askConfirmation: true, - confirmationLabel: 'Confirm to Delete', - actionFunction: payload.onMenuItemClick, - label: 'Delete Plotter Module', - visible: true, - iconPathOn: 'delete', - iconPathOff: 'delete', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, angle: 10 } ) @@ -1647,6 +1604,87 @@ function newUiObjectConstructor () { ) break } + case 'Plotter Module': { + uiObject.codeEditor = newCodeEditor() + uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.codeEditor.initialize() + uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + addLeftIcons(menuItemsInitialValues, floatingObject) + menuItemsInitialValues.push( + { + action: 'Edit Plotter Module', + actionFunction: uiObject.codeEditor.activate, + label: 'Edit Plotter Module', + visible: true, + iconPathOn: 'html', + iconPathOff: 'html', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: -40, + dontShowAtFullscreen: true + } + ) + menuItemsInitialValues.push( + { + action: 'Add Code', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'code', + actionFunction: payload.onMenuItemClick, + label: 'Add Code', + visible: true, + relatedUiObject: 'Code', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: -20 + } + ) + menuItemsInitialValues.push( + { + action: 'Add Plotter Panel', + actionFunction: payload.onMenuItemClick, + label: 'Add Plotter Panel', + visible: true, + relatedUiObject: 'Plotter Panel', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 0 + } + ) + menuItemsInitialValues.push( + { + action: 'Delete Plotter Module', + askConfirmation: true, + confirmationLabel: 'Confirm to Delete', + actionFunction: payload.onMenuItemClick, + label: 'Delete Plotter Module', + visible: true, + iconPathOn: 'delete', + iconPathOff: 'delete', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 20 + } + ) + menuItemsInitialValues.push( + { + action: 'Share', + actionFunction: payload.onMenuItemClick, + label: 'Share', + visible: true, + iconPathOn: 'menu-share', + iconPathOff: 'menu-share', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 40 + } + ) + break + } case 'Plotter Panel': { addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( diff --git a/Panels/ProductsPanel.js b/Panels/ProductsPanel.js index a8a0339d8..c5a150fae 100644 --- a/Panels/ProductsPanel.js +++ b/Panels/ProductsPanel.js @@ -66,6 +66,7 @@ function newProductsPanel () { ecosystem = getUserEcosystem() } + /* For legacy plotters, we will add product cards based on the old ecosystem file */ for (let i = 0; i < ecosystem.devTeams.length; i++) { let devTeam = ecosystem.devTeams[i] @@ -83,6 +84,92 @@ function newProductsPanel () { } } + /* For new plotters defined at the UI, we will add product cards based on what we find at the workspace */ + let workspaceNode = canvas.designerSpace.workspace.workspaceNode + for (let i = 0; i < workspaceNode.rootNodes.length; i++) { + let rootNode = workspaceNode.rootNodes[i] + if (rootNode.type === 'Team') { + let teamNode = rootNode + + let team = {} + if (teamNode.code === undefined) { continue } + try { + let code = JSON.parse(teamNode.code) + team.codeName = code.codeName + } catch (err) { + continue + } + for (let j = 0; j < teamNode.indicatorBots.length; j++) { + let botNode = teamNode.indicatorBots[j] + + let bot = {} + if (botNode.code === undefined) { continue } + try { + let code = JSON.parse(botNode.code) + bot.codeName = code.codeName + } catch (err) { + continue + } + + for (let k = 0; k < botNode.products; k++) { + let productNode = botNode.products[k] + + let product = {} + if (productNode.code === undefined) { continue } + try { + let code = JSON.parse(productNode.code) + product.codeName = code.codeName + } catch (err) { + continue + } + + if (productNode.referenceParent === undefined) { continue } + let plotterModuleNode = productNode.referenceParent + + let plotterModule = {} + if (plotterModuleNode.code === undefined) { continue } + try { + let code = JSON.parse(plotterModuleNode.code) + plotterModule.codeName = code.codeName + } catch (err) { + continue + } + + if (plotterModuleNode.payload.parentNode === undefined) { continue } + let plotterNode = plotterModuleNode.payload.parentNode + + let plotter = {} + if (plotterNode.code === undefined) { continue } + try { + let code = JSON.parse(plotterNode.code) + plotter.codeName = code.codeName + } catch (err) { + continue + } + + if (plotterNode.payload.parentNode === undefined) { continue } + let plotterTeamNode = plotterNode.payload.parentNode + + let plotterTeam = {} + if (plotterTeamNode.code === undefined) { continue } + try { + let code = JSON.parse(plotterTeamNode.code) + plotterTeam.codeName = code.codeName + } catch (err) { + continue + } + + /* Conversion to fit old format */ + prduct.plotter = plotter + prduct.plotter.devTeam = plotterTeam.codeName + product.plotter.moduleName = plotterModule.codeName + + addProductCard(team, bot, product) + } + } + } + } + thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel) isInitialized = true } From d85b723d4b8a753f1f1eb7332531891ccdb87a82 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 3 Dec 2019 15:43:34 +0100 Subject: [PATCH 21/41] Product Card Displayed Properly --- Panels/ProductCard.js | 9 ++++++--- Panels/ProductsPanel.js | 42 ++++++++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/Panels/ProductCard.js b/Panels/ProductCard.js index 990f6a76e..49eba7250 100644 --- a/Panels/ProductCard.js +++ b/Panels/ProductCard.js @@ -152,10 +152,13 @@ function newProductCard () { let team = ecosystem.getTeam(thisObject.product.plotter.devTeam) let plotter = ecosystem.getPlotter(team, thisObject.product.plotter.codeName) - let plotterModule = ecosystem.getPlotterModule(plotter, thisObject.product.plotter.moduleName) - thisObject.product.plotter.profilePicture = plotterModule.profilePicture - thisObject.product.plotter.module = plotterModule + if (plotter !== undefined) { + let plotterModule = ecosystem.getPlotterModule(plotter, thisObject.product.plotter.moduleName) + + thisObject.product.plotter.profilePicture = plotterModule.profilePicture + thisObject.product.plotter.module = plotterModule + } /* Lets set the basic dimensions of this thisObject. */ diff --git a/Panels/ProductsPanel.js b/Panels/ProductsPanel.js index c5a150fae..7593570f0 100644 --- a/Panels/ProductsPanel.js +++ b/Panels/ProductsPanel.js @@ -111,7 +111,7 @@ function newProductsPanel () { continue } - for (let k = 0; k < botNode.products; k++) { + for (let k = 0; k < botNode.products.length; k++) { let productNode = botNode.products[k] let product = {} @@ -123,17 +123,17 @@ function newProductsPanel () { continue } - if (productNode.referenceParent === undefined) { continue } - let plotterModuleNode = productNode.referenceParent + if (productNode.payload.referenceParent === undefined) { continue } + let plotterModuleNode = productNode.payload.referenceParent - let plotterModule = {} - if (plotterModuleNode.code === undefined) { continue } - try { - let code = JSON.parse(plotterModuleNode.code) - plotterModule.codeName = code.codeName - } catch (err) { - continue - } + let plotterModule = {}// Provitional code until CODE desambiguation is done. + // if (plotterModuleNode.code === undefined) { continue } + // try { + // let code = JSON.parse(plotterModuleNode.code) + plotterModule.codeName = plotterModuleNode.name // code.codeName + // } catch (err) { + // continue + // } if (plotterModuleNode.payload.parentNode === undefined) { continue } let plotterNode = plotterModuleNode.payload.parentNode @@ -160,9 +160,25 @@ function newProductsPanel () { } /* Conversion to fit old format */ - prduct.plotter = plotter - prduct.plotter.devTeam = plotterTeam.codeName + product.plotter = plotter + product.plotter.devTeam = plotterTeam.codeName product.plotter.moduleName = plotterModule.codeName + product.displayName = productNode.name + product.dataSets = [] + team.displayName = teamNode.name + bot.displayName = botNode.name + + for (let m = 0; m < productNode.datasets.length; m++) { + let dataset = productNode.datasets[m] + + if (dataset.code === undefined) { continue } + try { + let code = JSON.parse(dataset.code) + product.dataSets.push(code) + } catch (err) { + continue + } + } addProductCard(team, bot, product) } From 4e32c72c1bb813d1fdb01a63fb09c3c872a728c3 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 3 Dec 2019 16:22:19 +0100 Subject: [PATCH 22/41] Plotter Running From within Canvas App --- ChartsSpace/PlottersManager.js | 8 +- Panels/ProductsPanel.js | 4 + Plotter.js | 548 +++++++++++++++++++++++++++++++++ 3 files changed, 559 insertions(+), 1 deletion(-) create mode 100644 Plotter.js diff --git a/ChartsSpace/PlottersManager.js b/ChartsSpace/PlottersManager.js index 8b9fb6a7c..87729e683 100644 --- a/ChartsSpace/PlottersManager.js +++ b/ChartsSpace/PlottersManager.js @@ -168,7 +168,13 @@ function newPlottersManager () { } } /* Now we have all the initial data loaded and ready to be delivered to the new instance of the plotter. */ - let plotter = getNewPlotter(pProductCard.product.plotter.devTeam, pProductCard.product.plotter.codeName, pProductCard.product.plotter.moduleName) + let plotter + + if (pProductCard.product.plotter.legacy === false) { + plotter = newPlotter() + } else { + plotter = getNewPlotter(pProductCard.product.plotter.devTeam, pProductCard.product.plotter.codeName, pProductCard.product.plotter.moduleName) + } plotter.container.connectToParent(thisObject.container, true, true, false, true, true, true) plotter.container.frame.position.x = thisObject.container.frame.width / 2 - plotter.container.frame.width / 2 diff --git a/Panels/ProductsPanel.js b/Panels/ProductsPanel.js index 7593570f0..cee373ade 100644 --- a/Panels/ProductsPanel.js +++ b/Panels/ProductsPanel.js @@ -163,10 +163,14 @@ function newProductsPanel () { product.plotter = plotter product.plotter.devTeam = plotterTeam.codeName product.plotter.moduleName = plotterModule.codeName + product.plotter.legacy = false + product.plotter.module = { panels: [] } product.displayName = productNode.name product.dataSets = [] team.displayName = teamNode.name + team.host = {'url': 'localhost'} bot.displayName = botNode.name + product.exchangeList = [{'name': 'Poloniex'}] for (let m = 0; m < productNode.datasets.length; m++) { let dataset = productNode.datasets[m] diff --git a/Plotter.js b/Plotter.js new file mode 100644 index 000000000..7759dc99a --- /dev/null +++ b/Plotter.js @@ -0,0 +1,548 @@ +function newPlotter () { + const MODULE_NAME = 'AAMasters Plotters Bollinger Channels' + const ERROR_LOG = true + const INTENSIVE_LOG = false + const logger = newWebDebugLog() + logger.fileName = MODULE_NAME + + let thisObject = { + + /* Events declared outside the plotter. */ + + onDailyFileLoaded: onDailyFileLoaded, + + // Main functions and properties. + + initialize: initialize, + finalize: finalize, + container: undefined, + getContainer: getContainer, + setTimePeriod: setTimePeriod, + setDatetime: setDatetime, + recalculateScale: recalculateScale, + draw: draw, + + // Secondary functions and properties. + + currentChannel: undefined + } + + /* this is part of the module template */ + + let container = newContainer() // Do not touch this 3 lines, they are just needed. + container.initialize() + thisObject.container = container + + let timeLineCoordinateSystem = newTimeLineCoordinateSystem() // Needed to be able to plot on the timeline, otherwise not. + + let timePeriod // This will hold the current Time Period the user is at. + let datetime // This will hold the current Datetime the user is at. + + let marketFile // This is the current Market File being plotted. + let fileCursor // This is the current File Cursor being used to retrieve Daily Files. + + let marketFiles // This object will provide the different Market Files at different Time Periods. + let dailyFiles // This object will provide the different File Cursors at different Time Periods. + + /* these are module specific variables: */ + + let channels = [] + + let zoomChangedEventSubscriptionId + let offsetChangedEventSubscriptionId + let dragFinishedEventSubscriptionId + let dimmensionsChangedEventSubscriptionId + let marketFilesUpdatedEventSubscriptionId + let dailyFilesUpdatedEventSubscriptionId + + return thisObject + + function finalize () { + try { + /* Stop listening to the necesary events. */ + + viewPort.eventHandler.stopListening(zoomChangedEventSubscriptionId) + viewPort.eventHandler.stopListening(offsetChangedEventSubscriptionId) + canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId) + thisObject.container.eventHandler.stopListening(dimmensionsChangedEventSubscriptionId) + marketFiles.eventHandler.stopListening(marketFilesUpdatedEventSubscriptionId) + dailyFiles.eventHandler.stopListening(dailyFilesUpdatedEventSubscriptionId) + + /* Destroyd References */ + + marketFiles = undefined + dailyFiles = undefined + + datetime = undefined + timePeriod = undefined + + marketFile = undefined + fileCursor = undefined + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err.stack) } + } + } + + function initialize (pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + try { + /* Store the information received. */ + + marketFiles = pStorage.marketFiles[0] + dailyFiles = pStorage.dailyFiles[0] + + datetime = pDatetime + timePeriod = pTimePeriod + + /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ + + marketFile = marketFiles.getFile(ONE_DAY_IN_MILISECONDS) // This file is the one processed faster. + + recalculateScale() + + /* Now we set the right files according to current Period. */ + + marketFile = marketFiles.getFile(pTimePeriod) + fileCursor = dailyFiles.getFileCursor(pTimePeriod) + + /* Listen to the necesary events. */ + + zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent('Zoom Changed', onZoomChanged) + offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent('Offset Changed', onOffsetChanged) + dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent('Drag Finished', onDragFinished) + marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent('Files Updated', onMarketFilesUpdated) + dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent('Files Updated', onDailyFilesUpdated) + + /* Get ready for plotting. */ + + recalculate() + + dimmensionsChangedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { + recalculateScale() + recalculate() + }) + + callBackFunction() + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err) } + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + } + } + + function onMarketFilesUpdated () { + try { + let newMarketFile = marketFiles.getFile(timePeriod) + if (newMarketFile !== undefined) { + marketFile = newMarketFile + recalculate() + } + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] onMarketFilesUpdated -> err = ' + err.stack) } + } + } + + function onDailyFilesUpdated () { + try { + let newFileCursor = dailyFiles.getFileCursor(timePeriod) + if (newFileCursor !== undefined) { + fileCursor = newFileCursor + recalculate() + } + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] onDailyFilesUpdated -> err = ' + err.stack) } + } + } + + function getContainer (point) { + try { + let container + + /* First we check if this point is inside this space. */ + + if (this.container.frame.isThisPointHere(point) === true) { + return this.container + } else { + /* This point does not belong to this space. */ + + return undefined + } + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] getContainer -> err = ' + err) } + } + } + + function setTimePeriod (pTimePeriod) { + try { + if (timePeriod !== pTimePeriod) { + timePeriod = pTimePeriod + + if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + let newMarketFile = marketFiles.getFile(pTimePeriod) + + if (newMarketFile !== undefined) { + marketFile = newMarketFile + recalculate() + } + } else { + let newFileCursor = dailyFiles.getFileCursor(pTimePeriod) + + if (newFileCursor !== undefined) { + fileCursor = newFileCursor + recalculate() + } + } + } + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] setTimePeriod -> err = ' + err) } + } + } + + function setDatetime (pDatetime) { + datetime = pDatetime + } + + function onDailyFileLoaded (event) { + try { + if (event.currentValue === event.totalValue) { + /* This happens only when all of the files in the cursor have been loaded. */ + + recalculate() + } + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] onDailyFileLoaded -> err = ' + err) } + } + } + + function draw () { + try { + this.container.frame.draw() + + plotChart() + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] draw -> err = ' + err) } + } + } + + function recalculate () { + try { + if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + recalculateUsingMarketFiles() + } else { + recalculateUsingDailyFiles() + } + + thisObject.container.eventHandler.raiseEvent('CandleStairs Changed', channels) + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] recalculate -> err = ' + err) } + } + } + + function recalculateUsingDailyFiles () { + try { + if (fileCursor === undefined) { return } // We need to wait + + if (fileCursor.files.size === 0) { return } // We need to wait until there are files in the cursor + + let daysOnSides = getSideDays(timePeriod) + + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem) + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem) + + let dateDiff = rightDate.valueOf() - leftDate.valueOf() + + let farLeftDate = new Date(leftDate.valueOf() - dateDiff * 1.5) + let farRightDate = new Date(rightDate.valueOf() + dateDiff * 1.5) + + let currentDate = new Date(farLeftDate.valueOf()) + + channels = [] + + while (currentDate.valueOf() <= farRightDate.valueOf() + ONE_DAY_IN_MILISECONDS) { + let stringDate = currentDate.getFullYear() + '-' + pad(currentDate.getMonth() + 1, 2) + '-' + pad(currentDate.getDate(), 2) + + let dailyFile = fileCursor.files.get(stringDate) + + if (dailyFile !== undefined) { + for (let i = 0; i < dailyFile.length; i++) { + let channel = { + begin: undefined, + end: undefined, + direction: undefined, + period: 0, + firstMovingAverage: 0, + lastMovingAverage: 0, + firstDeviation: 0, + lastDeviation: 0 + } + + channel.begin = dailyFile[i][0] + channel.end = dailyFile[i][1] + + channel.direction = dailyFile[i][2] + + channel.period = dailyFile[i][3] + + channel.firstMovingAverage = dailyFile[i][4] + channel.lastMovingAverage = dailyFile[i][5] + + channel.firstDeviation = dailyFile[i][6] + channel.lastDeviation = dailyFile[i][7] + + if (channel.begin >= farLeftDate.valueOf() && channel.end <= farRightDate.valueOf()) { + channels.push(channel) + + if (datetime.valueOf() >= channel.begin && datetime.valueOf() <= channel.end) { + thisObject.currentChannel = channel + thisObject.container.eventHandler.raiseEvent('Current Channel Changed', thisObject.currentChannel) + } + } + } + } + + currentDate = new Date(currentDate.valueOf() + ONE_DAY_IN_MILISECONDS) + } + + /* Lests check if all the visible screen is going to be covered by candle-channel. */ + + let lowerEnd = leftDate.valueOf() + let upperEnd = rightDate.valueOf() + + if (channels.length > 0) { + if (channels[0].begin > lowerEnd || channels[channels.length - 1].end < upperEnd) { + setTimeout(recalculate, 2000) + + // console.log("File missing while calculating candle-channel, scheduling a recalculation in 2 seconds."); + } + } + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] recalculateUsingDailyFiles -> err = ' + err) } + } + } + + function recalculateUsingMarketFiles () { + try { + if (marketFile === undefined) { return } // Initialization not complete yet. + + let daysOnSides = getSideDays(timePeriod) + + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem) + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem) + + let dateDiff = rightDate.valueOf() - leftDate.valueOf() + + leftDate = new Date(leftDate.valueOf() - dateDiff * 1.5) + rightDate = new Date(rightDate.valueOf() + dateDiff * 1.5) + + channels = [] + + for (let i = 0; i < marketFile.length; i++) { + let channel = { + begin: undefined, + end: undefined, + direction: undefined, + period: 0, + firstMovingAverage: 0, + lastMovingAverage: 0, + firstDeviation: 0, + lastDeviation: 0 + } + + channel.begin = marketFile[i][0] + channel.end = marketFile[i][1] + + channel.direction = marketFile[i][2] + + channel.period = marketFile[i][3] + + channel.firstMovingAverage = marketFile[i][4] + channel.lastMovingAverage = marketFile[i][5] + + channel.firstDeviation = marketFile[i][6] + channel.lastDeviation = marketFile[i][7] + + if (channel.begin >= leftDate.valueOf() && channel.end <= rightDate.valueOf()) { + channels.push(channel) + + if (datetime.valueOf() >= channel.begin && datetime.valueOf() <= channel.end) { + thisObject.currentChannel = channel + thisObject.container.eventHandler.raiseEvent('Current Channel Changed', thisObject.currentChannel) + } + } + } + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] recalculateUsingMarketFiles -> err = ' + err) } + } + } + + function recalculateScale () { + try { + if (timeLineCoordinateSystem.maxValue > 0) { return } // Already calculated. + + let minValue = { + x: MIN_PLOTABLE_DATE.valueOf(), + y: 0 + } + + let maxValue = { + x: MAX_PLOTABLE_DATE.valueOf(), + y: nextPorwerOf10(USDT_BTC_HTH) / 4 // TODO: This 4 is temporary + } + + timeLineCoordinateSystem.initialize( + minValue, + maxValue, + thisObject.container.frame.width, + thisObject.container.frame.height + ) + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] recalculateScale -> err = ' + err) } + } + } + + function plotChart () { + try { + let userPosition = getUserPosition() + let userPositionDate = userPosition.point.x + + /* Clean the pannel at places where there is no channel. */ + + let channel = { + direction: '', + period: '' + } + + let currentChannel = { + innerChannel: channel + } + + thisObject.container.eventHandler.raiseEvent('Current Channel Changed', currentChannel) + + if (channels.length > 0) { + for (let i = 0; i < channels.length; i++) { + channel = channels[i] + + let channelPoint1 + let channelPoint2 + let channelPoint3 + let channelPoint4 + + channelPoint1 = { + x: channel.begin, + y: channel.firstMovingAverage - channel.firstDeviation + } + + channelPoint2 = { + x: channel.end, + y: channel.lastMovingAverage - channel.lastDeviation + } + + channelPoint3 = { + x: channel.end, + y: channel.lastMovingAverage + channel.lastDeviation + } + + channelPoint4 = { + x: channel.begin, + y: channel.firstMovingAverage + channel.firstDeviation + } + + channelPoint1 = timeLineCoordinateSystem.transformThisPoint(channelPoint1) + channelPoint2 = timeLineCoordinateSystem.transformThisPoint(channelPoint2) + channelPoint3 = timeLineCoordinateSystem.transformThisPoint(channelPoint3) + channelPoint4 = timeLineCoordinateSystem.transformThisPoint(channelPoint4) + + channelPoint1 = transformThisPoint(channelPoint1, thisObject.container) + channelPoint2 = transformThisPoint(channelPoint2, thisObject.container) + channelPoint3 = transformThisPoint(channelPoint3, thisObject.container) + channelPoint4 = transformThisPoint(channelPoint4, thisObject.container) + + if (channelPoint2.x < viewPort.visibleArea.bottomLeft.x || channelPoint1.x > viewPort.visibleArea.bottomRight.x) { + continue + } + + channelPoint1 = viewPort.fitIntoVisibleArea(channelPoint1) + channelPoint2 = viewPort.fitIntoVisibleArea(channelPoint2) + channelPoint3 = viewPort.fitIntoVisibleArea(channelPoint3) + channelPoint4 = viewPort.fitIntoVisibleArea(channelPoint4) + + browserCanvasContext.beginPath() + + browserCanvasContext.moveTo(channelPoint1.x, channelPoint1.y) + browserCanvasContext.lineTo(channelPoint2.x, channelPoint2.y) + browserCanvasContext.lineTo(channelPoint3.x, channelPoint3.y) + browserCanvasContext.lineTo(channelPoint4.x, channelPoint4.y) + + browserCanvasContext.closePath() + + let opacity = '0.25' + + if (channel.direction === 'Side') { browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.LIGHT + ', ' + opacity + ')' } + if (channel.direction === 'Up') { browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ')' } + if (channel.direction === 'Down') { browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')' } + + if (userPositionDate >= channel.begin && userPositionDate <= channel.end) { + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 0.1)' // Current channel accroding to time + + let currentChannel = { + innerChannel: channel + } + thisObject.container.eventHandler.raiseEvent('Current Channel Changed', currentChannel) + } + + browserCanvasContext.fill() + + browserCanvasContext.beginPath() + + browserCanvasContext.moveTo(channelPoint1.x, channelPoint1.y) + browserCanvasContext.lineTo(channelPoint2.x, channelPoint2.y) + browserCanvasContext.moveTo(channelPoint3.x, channelPoint3.y) + browserCanvasContext.lineTo(channelPoint4.x, channelPoint4.y) + + browserCanvasContext.closePath() + + if (channel.direction === 'Side') { browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')' } + if (channel.direction === 'Up') { browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')' } + if (channel.direction === 'Down') { browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + opacity + ')' } + + browserCanvasContext.lineWidth = 1 + browserCanvasContext.setLineDash([0, 0]) + browserCanvasContext.stroke() + } + } + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] plotChart -> err = ' + err) } + } + } + + function onZoomChanged (event) { + try { + recalculate() + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] onZoomChanged -> err = ' + err) } + } + } + + function onDragFinished () { + try { + recalculate() + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] onDragFinished -> err = ' + err) } + } + } + + function onOffsetChanged (event) { + try { + if (event !== undefined) { + if (event.recalculate === true) { + recalculate() + return + } + } + if (Math.random() * 100 > 95) { + recalculate() + }; + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] onOffsetChanged -> err = ' + err) } + } + } +} + From 4f2e5e4d47461f1f8075d8d636dc522cc51afc66 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 4 Dec 2019 12:12:54 +0100 Subject: [PATCH 23/41] Plotter daily Files using the Record Definition to inflate data --- ChartsSpace/PlottersManager.js | 2 +- Panels/ProductsPanel.js | 5 + Plotter.js | 314 +++++++++++++++++++-------------- 3 files changed, 191 insertions(+), 130 deletions(-) diff --git a/ChartsSpace/PlottersManager.js b/ChartsSpace/PlottersManager.js index 87729e683..e9becd625 100644 --- a/ChartsSpace/PlottersManager.js +++ b/ChartsSpace/PlottersManager.js @@ -180,7 +180,7 @@ function newPlottersManager () { plotter.container.frame.position.x = thisObject.container.frame.width / 2 - plotter.container.frame.width / 2 plotter.container.frame.position.y = thisObject.container.frame.height / 2 - plotter.container.frame.height / 2 plotter.fitFunction = thisObject.fitFunction - plotter.initialize(storage, exchange, market, datetime, timePeriod, onPlotterInizialized) + plotter.initialize(storage, exchange, market, datetime, timePeriod, onPlotterInizialized, pProductCard.product.definition) function onPlotterInizialized () { try { diff --git a/Panels/ProductsPanel.js b/Panels/ProductsPanel.js index cee373ade..9465e5a5a 100644 --- a/Panels/ProductsPanel.js +++ b/Panels/ProductsPanel.js @@ -167,11 +167,16 @@ function newProductsPanel () { product.plotter.module = { panels: [] } product.displayName = productNode.name product.dataSets = [] + team.displayName = teamNode.name team.host = {'url': 'localhost'} bot.displayName = botNode.name product.exchangeList = [{'name': 'Poloniex'}] + /* We take a snapwhot of the current product definition to be used by the plotter. */ + let functionLibraryProtocolNode = newProtocolNode() + product.definition = functionLibraryProtocolNode.getProtocolNode(productNode, false, true, true) + for (let m = 0; m < productNode.datasets.length; m++) { let dataset = productNode.datasets[m] diff --git a/Plotter.js b/Plotter.js index 7759dc99a..d899959fb 100644 --- a/Plotter.js +++ b/Plotter.js @@ -1,5 +1,5 @@ function newPlotter () { - const MODULE_NAME = 'AAMasters Plotters Bollinger Channels' + const MODULE_NAME = 'Plotter' const ERROR_LOG = true const INTENSIVE_LOG = false const logger = newWebDebugLog() @@ -24,29 +24,27 @@ function newPlotter () { // Secondary functions and properties. - currentChannel: undefined + currentRecord: undefined // ---> Check Here } - /* this is part of the module template */ - - let container = newContainer() // Do not touch this 3 lines, they are just needed. + let container = newContainer() container.initialize() thisObject.container = container - let timeLineCoordinateSystem = newTimeLineCoordinateSystem() // Needed to be able to plot on the timeline, otherwise not. + let timeLineCoordinateSystem = newTimeLineCoordinateSystem() // Needed to be able to plot on the timeline, otherwise not. - let timePeriod // This will hold the current Time Period the user is at. - let datetime // This will hold the current Datetime the user is at. + let timePeriod // This will hold the current Time Period the user is at. + let datetime // This will hold the current Datetime the user is at. - let marketFile // This is the current Market File being plotted. - let fileCursor // This is the current File Cursor being used to retrieve Daily Files. + let marketFile // This is the current Market File being plotted. + let fileCursor // This is the current File Cursor being used to retrieve Daily Files. - let marketFiles // This object will provide the different Market Files at different Time Periods. - let dailyFiles // This object will provide the different File Cursors at different Time Periods. + let marketFiles // This object will provide the different Market Files at different Time Periods. + let dailyFiles // This object will provide the different File Cursors at different Time Periods. - /* these are module specific variables: */ + let productDefinition // Here we store a snapshot of the product definition which references this plotter. - let channels = [] + let records = [] // We will have the information to be plotted here. let zoomChangedEventSubscriptionId let offsetChangedEventSubscriptionId @@ -59,8 +57,7 @@ function newPlotter () { function finalize () { try { - /* Stop listening to the necesary events. */ - + /* Stop listening to the necesary events. */ viewPort.eventHandler.stopListening(zoomChangedEventSubscriptionId) viewPort.eventHandler.stopListening(offsetChangedEventSubscriptionId) canvas.eventHandler.stopListening(dragFinishedEventSubscriptionId) @@ -68,8 +65,7 @@ function newPlotter () { marketFiles.eventHandler.stopListening(marketFilesUpdatedEventSubscriptionId) dailyFiles.eventHandler.stopListening(dailyFilesUpdatedEventSubscriptionId) - /* Destroyd References */ - + /* Clear References */ marketFiles = undefined dailyFiles = undefined @@ -83,39 +79,35 @@ function newPlotter () { } } - function initialize (pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + function initialize (pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction, pProductDefinition) { try { - /* Store the information received. */ - + /* Store the information received. */ marketFiles = pStorage.marketFiles[0] dailyFiles = pStorage.dailyFiles[0] datetime = pDatetime timePeriod = pTimePeriod - /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ + productDefinition = pProductDefinition + /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ marketFile = marketFiles.getFile(ONE_DAY_IN_MILISECONDS) // This file is the one processed faster. recalculateScale() - /* Now we set the right files according to current Period. */ - + /* Now we set the right files according to current Period. */ marketFile = marketFiles.getFile(pTimePeriod) fileCursor = dailyFiles.getFileCursor(pTimePeriod) - /* Listen to the necesary events. */ - + /* Listen to the necesary events. */ zoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent('Zoom Changed', onZoomChanged) offsetChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent('Offset Changed', onOffsetChanged) dragFinishedEventSubscriptionId = canvas.eventHandler.listenToEvent('Drag Finished', onDragFinished) marketFilesUpdatedEventSubscriptionId = marketFiles.eventHandler.listenToEvent('Files Updated', onMarketFilesUpdated) dailyFilesUpdatedEventSubscriptionId = dailyFiles.eventHandler.listenToEvent('Files Updated', onDailyFilesUpdated) - /* Get ready for plotting. */ - + /* Get ready for plotting. */ recalculate() - dimmensionsChangedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { recalculateScale() recalculate() @@ -155,14 +147,11 @@ function newPlotter () { function getContainer (point) { try { let container - - /* First we check if this point is inside this space. */ - + /* First we check if this point is inside this space. */ if (this.container.frame.isThisPointHere(point) === true) { return this.container } else { - /* This point does not belong to this space. */ - + /* This point does not belong to this space. */ return undefined } } catch (err) { @@ -203,8 +192,7 @@ function newPlotter () { function onDailyFileLoaded (event) { try { if (event.currentValue === event.totalValue) { - /* This happens only when all of the files in the cursor have been loaded. */ - + /* This happens only when all of the files in the cursor have been loaded. */ recalculate() } } catch (err) { @@ -215,7 +203,6 @@ function newPlotter () { function draw () { try { this.container.frame.draw() - plotChart() } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] draw -> err = ' + err) } @@ -229,17 +216,119 @@ function newPlotter () { } else { recalculateUsingDailyFiles() } - - thisObject.container.eventHandler.raiseEvent('CandleStairs Changed', channels) + thisObject.container.eventHandler.raiseEvent('CandleStairs Changed', records) // --> Check This } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] recalculate -> err = ' + err) } } } + function jsonifyDataFile (dataFile, recordDefinition, farLeftDate, farRightDate) { + /* + This function has as an input the raw data on files and creates with it an array of JSON objects + with not calculated properties for later being consumed by Formulas + */ + + let jsonifiedArray = [] + let previous + + for (let i = 0; i < dataFile.length; i++) { + let record = {} + for (let j = 0; j < recordDefinition.properties.length; j++) { + let property = recordDefinition.properties[j] + if (property.code.isCalculated !== true) { + record[property.code.codeName] = dataFile[i][j] + } + } + + if (record.begin >= farLeftDate.valueOf() && record.end <= farRightDate.valueOf()) { + record.previous = previous + jsonifiedArray.push(record) + previous = record + + if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { + thisObject.currentRecord = record + thisObject.container.eventHandler.raiseEvent('Current Record Changed', thisObject.currentRecord) + } + } + } + + return jsonifiedArray + } + + function calculationsProcedure (jsonArray, recordDefinition, calculationsProcedure, timePeriod) { + /* + This function has as an input an array of JSON objects, and it adds calculated properties to + complete the set of properties that will be available. + */ + + let system = { // These are the available system variables to be used in User Code and Formulas + timePeriod: timePeriod, + ONE_DAY_IN_MILISECONDS: ONE_DAY_IN_MILISECONDS + } + let variable = {} // This is the structure where the user will define its own variables that will be shared across different code blocks and formulas. + let results = [] + + /* This is Initialization Code */ + if (calculationsProcedure.initialization !== undefined) { + if (calculationsProcedure.initialization.code !== undefined) { + try { + eval(calculationsProcedure.initialization.code.code) + } catch (err) { + logger.write('[ERROR] calculationsProcedure -> initialization -> Error executing User Code. Error = ' + err.stack) + logger.write('[ERROR] calculationsProcedure -> initialization -> Error executing User Code. Code = ' + calculationsProcedure.initialization.code.code) + throw ('Error Executing User Code.') + } + } + } + + /* This is Initialization Code */ + if (calculationsProcedure.loop !== undefined) { + if (calculationsProcedure.loop.code !== undefined) { + for (let index = 0; index < jsonArray.length; index++) { + let product = jsonArray[index] + + /* This is Loop Code */ + try { + eval(calculationsProcedure.loop.code.code) + } catch (err) { + logger.write('[ERROR] calculationsProcedure -> loop -> Error executing User Code. Error = ' + err.stack) + logger.write('[ERROR] calculationsProcedure -> loop -> Error executing User Code. product = ' + JSON.stringify(product)) + logger.write('[ERROR] calculationsProcedure -> loop -> Error executing User Code. Code = ' + calculationsProcedure.loop.code.code) + throw ('Error Executing User Code.') + } + + /* For each calculated property we apply its formula */ + for (let j = 0; j < recordDefinition.properties.length; j++) { + let property = recordDefinition.properties[j] + if (property.code.isCalculated === true) { + if (property.formula !== undefined) { + if (property.formula.code !== undefined) { + try { + let newValue = eval(property.formula.code) + let currentRecord = product + currentRecord[property.code.codeName] = newValue + } catch (err) { + logger.write('[ERROR] calculationsProcedure -> loop -> formula -> Error executing User Code. Error = ' + err.stack) + logger.write('[ERROR] calculationsProcedure -> loop -> formula -> Error executing User Code. product = ' + JSON.stringify(product)) + logger.write('[ERROR] calculationsProcedure -> loop -> formula -> Error executing User Code. Code = ' + property.formula.code) + throw ('Error Executing User Code.') + } + } + } + } + } + + /* Adding the new element to the resulting array */ + results.push(product) + } + } + } + return results + } + function recalculateUsingDailyFiles () { try { - if (fileCursor === undefined) { return } // We need to wait - + if (fileCursor === undefined) { return } // We need to wait until there is a fileCursor if (fileCursor.files.size === 0) { return } // We need to wait until there are files in the cursor let daysOnSides = getSideDays(timePeriod) @@ -254,7 +343,7 @@ function newPlotter () { let currentDate = new Date(farLeftDate.valueOf()) - channels = [] + records = [] while (currentDate.valueOf() <= farRightDate.valueOf() + ONE_DAY_IN_MILISECONDS) { let stringDate = currentDate.getFullYear() + '-' + pad(currentDate.getMonth() + 1, 2) + '-' + pad(currentDate.getDate(), 2) @@ -262,55 +351,28 @@ function newPlotter () { let dailyFile = fileCursor.files.get(stringDate) if (dailyFile !== undefined) { - for (let i = 0; i < dailyFile.length; i++) { - let channel = { - begin: undefined, - end: undefined, - direction: undefined, - period: 0, - firstMovingAverage: 0, - lastMovingAverage: 0, - firstDeviation: 0, - lastDeviation: 0 - } + /* Transform the current file content into an array of JSON objects */ + let jsonData = jsonifyDataFile(dailyFile, productDefinition.record, farLeftDate, farRightDate) - channel.begin = dailyFile[i][0] - channel.end = dailyFile[i][1] - - channel.direction = dailyFile[i][2] - - channel.period = dailyFile[i][3] - - channel.firstMovingAverage = dailyFile[i][4] - channel.lastMovingAverage = dailyFile[i][5] - - channel.firstDeviation = dailyFile[i][6] - channel.lastDeviation = dailyFile[i][7] - - if (channel.begin >= farLeftDate.valueOf() && channel.end <= farRightDate.valueOf()) { - channels.push(channel) - - if (datetime.valueOf() >= channel.begin && datetime.valueOf() <= channel.end) { - thisObject.currentChannel = channel - thisObject.container.eventHandler.raiseEvent('Current Channel Changed', thisObject.currentChannel) - } - } + /* Add the calculated properties */ + if (productDefinition.calculations !== undefined) { + let calculationsResult = calculationsProcedure(jsonData, productDefinition.record, productDefinition.calculations, timePeriod) + records.push(...calculationsResult) // This adds records to the current array. + } else { + records.push(...jsonData)// This adds records to the current array. } } currentDate = new Date(currentDate.valueOf() + ONE_DAY_IN_MILISECONDS) } - /* Lests check if all the visible screen is going to be covered by candle-channel. */ - + /* Lests check if all the visible screen is going to be covered by candle-record. */ let lowerEnd = leftDate.valueOf() let upperEnd = rightDate.valueOf() - if (channels.length > 0) { - if (channels[0].begin > lowerEnd || channels[channels.length - 1].end < upperEnd) { + if (records.length > 0) { + if (records[0].begin > lowerEnd || records[records.length - 1].end < upperEnd) { setTimeout(recalculate, 2000) - - // console.log("File missing while calculating candle-channel, scheduling a recalculation in 2 seconds."); } } } catch (err) { @@ -320,7 +382,7 @@ function newPlotter () { function recalculateUsingMarketFiles () { try { - if (marketFile === undefined) { return } // Initialization not complete yet. + if (marketFile === undefined) { return } // Initialization not complete yet. let daysOnSides = getSideDays(timePeriod) @@ -332,10 +394,10 @@ function newPlotter () { leftDate = new Date(leftDate.valueOf() - dateDiff * 1.5) rightDate = new Date(rightDate.valueOf() + dateDiff * 1.5) - channels = [] + records = [] for (let i = 0; i < marketFile.length; i++) { - let channel = { + let record = { begin: undefined, end: undefined, direction: undefined, @@ -346,25 +408,21 @@ function newPlotter () { lastDeviation: 0 } - channel.begin = marketFile[i][0] - channel.end = marketFile[i][1] + record.begin = marketFile[i][0] + record.end = marketFile[i][1] + record.direction = marketFile[i][2] + record.period = marketFile[i][3] + record.firstMovingAverage = marketFile[i][4] + record.lastMovingAverage = marketFile[i][5] + record.firstDeviation = marketFile[i][6] + record.lastDeviation = marketFile[i][7] - channel.direction = marketFile[i][2] + if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { + records.push(record) - channel.period = marketFile[i][3] - - channel.firstMovingAverage = marketFile[i][4] - channel.lastMovingAverage = marketFile[i][5] - - channel.firstDeviation = marketFile[i][6] - channel.lastDeviation = marketFile[i][7] - - if (channel.begin >= leftDate.valueOf() && channel.end <= rightDate.valueOf()) { - channels.push(channel) - - if (datetime.valueOf() >= channel.begin && datetime.valueOf() <= channel.end) { - thisObject.currentChannel = channel - thisObject.container.eventHandler.raiseEvent('Current Channel Changed', thisObject.currentChannel) + if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { + thisObject.currentRecord = record + thisObject.container.eventHandler.raiseEvent('Current Record Changed', thisObject.currentRecord) } } } @@ -403,22 +461,21 @@ function newPlotter () { let userPosition = getUserPosition() let userPositionDate = userPosition.point.x - /* Clean the pannel at places where there is no channel. */ - - let channel = { + /* Clean the pannel at places where there is no record. */ + let record = { direction: '', period: '' } - let currentChannel = { - innerChannel: channel + let currentRecord = { + innerChannel: record } - thisObject.container.eventHandler.raiseEvent('Current Channel Changed', currentChannel) + thisObject.container.eventHandler.raiseEvent('Current Record Changed', currentRecord) - if (channels.length > 0) { - for (let i = 0; i < channels.length; i++) { - channel = channels[i] + if (records.length > 0) { + for (let i = 0; i < records.length; i++) { + record = records[i] let channelPoint1 let channelPoint2 @@ -426,23 +483,23 @@ function newPlotter () { let channelPoint4 channelPoint1 = { - x: channel.begin, - y: channel.firstMovingAverage - channel.firstDeviation + x: record.begin, + y: record.firstMovingAverage - record.firstDeviation } channelPoint2 = { - x: channel.end, - y: channel.lastMovingAverage - channel.lastDeviation + x: record.end, + y: record.lastMovingAverage - record.lastDeviation } channelPoint3 = { - x: channel.end, - y: channel.lastMovingAverage + channel.lastDeviation + x: record.end, + y: record.lastMovingAverage + record.lastDeviation } channelPoint4 = { - x: channel.begin, - y: channel.firstMovingAverage + channel.firstDeviation + x: record.begin, + y: record.firstMovingAverage + record.firstDeviation } channelPoint1 = timeLineCoordinateSystem.transformThisPoint(channelPoint1) @@ -475,17 +532,17 @@ function newPlotter () { let opacity = '0.25' - if (channel.direction === 'Side') { browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.LIGHT + ', ' + opacity + ')' } - if (channel.direction === 'Up') { browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ')' } - if (channel.direction === 'Down') { browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')' } + if (record.direction === 'Side') { browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.LIGHT + ', ' + opacity + ')' } + if (record.direction === 'Up') { browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ')' } + if (record.direction === 'Down') { browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')' } - if (userPositionDate >= channel.begin && userPositionDate <= channel.end) { - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 0.1)' // Current channel accroding to time + if (userPositionDate >= record.begin && userPositionDate <= record.end) { + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 0.1)' // Current record accroding to time - let currentChannel = { - innerChannel: channel + let currentRecord = { + innerChannel: record } - thisObject.container.eventHandler.raiseEvent('Current Channel Changed', currentChannel) + thisObject.container.eventHandler.raiseEvent('Current Record Changed', currentRecord) } browserCanvasContext.fill() @@ -499,9 +556,9 @@ function newPlotter () { browserCanvasContext.closePath() - if (channel.direction === 'Side') { browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')' } - if (channel.direction === 'Up') { browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')' } - if (channel.direction === 'Down') { browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + opacity + ')' } + if (record.direction === 'Side') { browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')' } + if (record.direction === 'Up') { browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')' } + if (record.direction === 'Down') { browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + opacity + ')' } browserCanvasContext.lineWidth = 1 browserCanvasContext.setLineDash([0, 0]) @@ -545,4 +602,3 @@ function newPlotter () { } } } - From 04d54163e2c30b1960100655b6cb7820d9df894c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 4 Dec 2019 16:33:11 +0100 Subject: [PATCH 24/41] unnecesary margin --- ChartsSpace/ViewPort.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ChartsSpace/ViewPort.js b/ChartsSpace/ViewPort.js index 55146cbd0..b96904c80 100644 --- a/ChartsSpace/ViewPort.js +++ b/ChartsSpace/ViewPort.js @@ -85,8 +85,8 @@ function newViewPort () { function resize () { TOP_MARGIN = 30 + TOP_SPACE_HEIGHT BOTTOM_MARGIN = 30 + browserCanvas.height - COCKPIT_SPACE_POSITION - LEFT_MARGIN = 50 - RIGHT_MARGIN = 50 + LEFT_MARGIN = 0 + RIGHT_MARGIN = 0 MARGINS = { TOP: TOP_MARGIN, BOTTOM: BOTTOM_MARGIN, From 2d8d38f76d36449106dc922e39eb735e946d1d24 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 4 Dec 2019 16:41:44 +0100 Subject: [PATCH 25/41] Market Files using record definition --- Plotter.js | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/Plotter.js b/Plotter.js index d899959fb..957744b3d 100644 --- a/Plotter.js +++ b/Plotter.js @@ -396,35 +396,15 @@ function newPlotter () { records = [] - for (let i = 0; i < marketFile.length; i++) { - let record = { - begin: undefined, - end: undefined, - direction: undefined, - period: 0, - firstMovingAverage: 0, - lastMovingAverage: 0, - firstDeviation: 0, - lastDeviation: 0 - } + /* Transform the current file content into an array of JSON objects */ + let jsonData = jsonifyDataFile(marketFile, productDefinition.record, leftDate, rightDate) - record.begin = marketFile[i][0] - record.end = marketFile[i][1] - record.direction = marketFile[i][2] - record.period = marketFile[i][3] - record.firstMovingAverage = marketFile[i][4] - record.lastMovingAverage = marketFile[i][5] - record.firstDeviation = marketFile[i][6] - record.lastDeviation = marketFile[i][7] - - if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { - records.push(record) - - if (datetime.valueOf() >= record.begin && datetime.valueOf() <= record.end) { - thisObject.currentRecord = record - thisObject.container.eventHandler.raiseEvent('Current Record Changed', thisObject.currentRecord) - } - } + /* Add the calculated properties */ + if (productDefinition.calculations !== undefined) { + let calculationsResult = calculationsProcedure(jsonData, productDefinition.record, productDefinition.calculations, timePeriod) + records.push(...calculationsResult) // This adds records to the current array. + } else { + records.push(...jsonData)// This adds records to the current array. } } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] recalculateUsingMarketFiles -> err = ' + err) } From 7fb1a1ff35a42977ced29c7b16b745c3ae928823 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 4 Dec 2019 17:47:45 +0100 Subject: [PATCH 26/41] Plotter working from code object --- Panels/ProductsPanel.js | 5 +- Plotter.js | 129 ++++++++++------------------------------ 2 files changed, 37 insertions(+), 97 deletions(-) diff --git a/Panels/ProductsPanel.js b/Panels/ProductsPanel.js index 9465e5a5a..f49910b91 100644 --- a/Panels/ProductsPanel.js +++ b/Panels/ProductsPanel.js @@ -159,6 +159,9 @@ function newProductsPanel () { continue } + if (plotterModuleNode.code === undefined) { continue } + if (plotterModuleNode.code.code === undefined) { continue } + /* Conversion to fit old format */ product.plotter = plotter product.plotter.devTeam = plotterTeam.codeName @@ -175,7 +178,7 @@ function newProductsPanel () { /* We take a snapwhot of the current product definition to be used by the plotter. */ let functionLibraryProtocolNode = newProtocolNode() - product.definition = functionLibraryProtocolNode.getProtocolNode(productNode, false, true, true) + product.definition = functionLibraryProtocolNode.getProtocolNode(productNode, false, true, true, false, false, true) for (let m = 0; m < productNode.datasets.length; m++) { let dataset = productNode.datasets[m] diff --git a/Plotter.js b/Plotter.js index 957744b3d..6259c3d3d 100644 --- a/Plotter.js +++ b/Plotter.js @@ -442,108 +442,45 @@ function newPlotter () { let userPositionDate = userPosition.point.x /* Clean the pannel at places where there is no record. */ - let record = { - direction: '', - period: '' - } - let currentRecord = { - innerChannel: record + innerChannel: undefined } - thisObject.container.eventHandler.raiseEvent('Current Record Changed', currentRecord) - if (records.length > 0) { - for (let i = 0; i < records.length; i++) { - record = records[i] + for (let i = 0; i < records.length; i++) { + let record = records[i] - let channelPoint1 - let channelPoint2 - let channelPoint3 - let channelPoint4 - - channelPoint1 = { - x: record.begin, - y: record.firstMovingAverage - record.firstDeviation - } - - channelPoint2 = { - x: record.end, - y: record.lastMovingAverage - record.lastDeviation - } - - channelPoint3 = { - x: record.end, - y: record.lastMovingAverage + record.lastDeviation - } - - channelPoint4 = { - x: record.begin, - y: record.firstMovingAverage + record.firstDeviation - } - - channelPoint1 = timeLineCoordinateSystem.transformThisPoint(channelPoint1) - channelPoint2 = timeLineCoordinateSystem.transformThisPoint(channelPoint2) - channelPoint3 = timeLineCoordinateSystem.transformThisPoint(channelPoint3) - channelPoint4 = timeLineCoordinateSystem.transformThisPoint(channelPoint4) - - channelPoint1 = transformThisPoint(channelPoint1, thisObject.container) - channelPoint2 = transformThisPoint(channelPoint2, thisObject.container) - channelPoint3 = transformThisPoint(channelPoint3, thisObject.container) - channelPoint4 = transformThisPoint(channelPoint4, thisObject.container) - - if (channelPoint2.x < viewPort.visibleArea.bottomLeft.x || channelPoint1.x > viewPort.visibleArea.bottomRight.x) { - continue - } - - channelPoint1 = viewPort.fitIntoVisibleArea(channelPoint1) - channelPoint2 = viewPort.fitIntoVisibleArea(channelPoint2) - channelPoint3 = viewPort.fitIntoVisibleArea(channelPoint3) - channelPoint4 = viewPort.fitIntoVisibleArea(channelPoint4) - - browserCanvasContext.beginPath() - - browserCanvasContext.moveTo(channelPoint1.x, channelPoint1.y) - browserCanvasContext.lineTo(channelPoint2.x, channelPoint2.y) - browserCanvasContext.lineTo(channelPoint3.x, channelPoint3.y) - browserCanvasContext.lineTo(channelPoint4.x, channelPoint4.y) - - browserCanvasContext.closePath() - - let opacity = '0.25' - - if (record.direction === 'Side') { browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.LIGHT + ', ' + opacity + ')' } - if (record.direction === 'Up') { browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ')' } - if (record.direction === 'Down') { browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')' } - - if (userPositionDate >= record.begin && userPositionDate <= record.end) { - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 0.1)' // Current record accroding to time - - let currentRecord = { - innerChannel: record - } - thisObject.container.eventHandler.raiseEvent('Current Record Changed', currentRecord) - } - - browserCanvasContext.fill() - - browserCanvasContext.beginPath() - - browserCanvasContext.moveTo(channelPoint1.x, channelPoint1.y) - browserCanvasContext.lineTo(channelPoint2.x, channelPoint2.y) - browserCanvasContext.moveTo(channelPoint3.x, channelPoint3.y) - browserCanvasContext.lineTo(channelPoint4.x, channelPoint4.y) - - browserCanvasContext.closePath() - - if (record.direction === 'Side') { browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')' } - if (record.direction === 'Up') { browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', ' + opacity + ')' } - if (record.direction === 'Down') { browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', ' + opacity + ')' } - - browserCanvasContext.lineWidth = 1 - browserCanvasContext.setLineDash([0, 0]) - browserCanvasContext.stroke() + let beginPoint = { + x: record.begin, + y: 0 } + + let endPoint = { + x: record.end, + y: 0 + } + + beginPoint = timeLineCoordinateSystem.transformThisPoint(beginPoint) + endPoint = timeLineCoordinateSystem.transformThisPoint(endPoint) + + beginPoint = transformThisPoint(beginPoint, thisObject.container) + endPoint = transformThisPoint(endPoint, thisObject.container) + + if (endPoint.x < viewPort.visibleArea.bottomLeft.x || beginPoint.x > viewPort.visibleArea.bottomRight.x) { + continue + } + + let atMousePosition = false + if (userPositionDate >= record.begin && userPositionDate <= record.end) { + atMousePosition = true + + let currentRecord = { + innerChannel: record + } + thisObject.container.eventHandler.raiseEvent('Current Record Changed', currentRecord) + } + + eval(productDefinition.referenceParent.code.code) } } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] plotChart -> err = ' + err) } From 1b57aab9e234770416ccf10df6a90b8eb2f84661 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 4 Dec 2019 19:49:11 +0100 Subject: [PATCH 27/41] taking the snapshot at the Protter Manager --- ChartsSpace/PlottersManager.js | 7 ++++++- Panels/ProductsPanel.js | 8 ++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ChartsSpace/PlottersManager.js b/ChartsSpace/PlottersManager.js index e9becd625..bd50cd28f 100644 --- a/ChartsSpace/PlottersManager.js +++ b/ChartsSpace/PlottersManager.js @@ -169,9 +169,14 @@ function newPlottersManager () { } /* Now we have all the initial data loaded and ready to be delivered to the new instance of the plotter. */ let plotter + let productDefinition if (pProductCard.product.plotter.legacy === false) { plotter = newPlotter() + + /* We take a snapwhot of the current product definition to be used by the plotter. */ + let functionLibraryProtocolNode = newProtocolNode() + productDefinition = functionLibraryProtocolNode.getProtocolNode(pProductCard.product.node, false, true, true, false, false, true) } else { plotter = getNewPlotter(pProductCard.product.plotter.devTeam, pProductCard.product.plotter.codeName, pProductCard.product.plotter.moduleName) } @@ -180,7 +185,7 @@ function newPlottersManager () { plotter.container.frame.position.x = thisObject.container.frame.width / 2 - plotter.container.frame.width / 2 plotter.container.frame.position.y = thisObject.container.frame.height / 2 - plotter.container.frame.height / 2 plotter.fitFunction = thisObject.fitFunction - plotter.initialize(storage, exchange, market, datetime, timePeriod, onPlotterInizialized, pProductCard.product.definition) + plotter.initialize(storage, exchange, market, datetime, timePeriod, onPlotterInizialized, productDefinition) function onPlotterInizialized () { try { diff --git a/Panels/ProductsPanel.js b/Panels/ProductsPanel.js index f49910b91..c38f46096 100644 --- a/Panels/ProductsPanel.js +++ b/Panels/ProductsPanel.js @@ -170,15 +170,11 @@ function newProductsPanel () { product.plotter.module = { panels: [] } product.displayName = productNode.name product.dataSets = [] - + product.exchangeList = [{'name': 'Poloniex'}] + product.node = productNode team.displayName = teamNode.name team.host = {'url': 'localhost'} bot.displayName = botNode.name - product.exchangeList = [{'name': 'Poloniex'}] - - /* We take a snapwhot of the current product definition to be used by the plotter. */ - let functionLibraryProtocolNode = newProtocolNode() - product.definition = functionLibraryProtocolNode.getProtocolNode(productNode, false, true, true, false, false, true) for (let m = 0; m < productNode.datasets.length; m++) { let dataset = productNode.datasets[m] From be8b12a19cf331c41d2c3f39cf1c2c893469be74 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 4 Dec 2019 21:12:00 +0100 Subject: [PATCH 28/41] Panels are working! --- ChartsSpace/PlottersManager.js | 22 ++++++ Panels/PlotterPanel.js | 122 +++++++++++++++++++++++++++++++++ Plotter.js | 4 +- Spaces/PanelsSpace.js | 21 ++++-- 4 files changed, 161 insertions(+), 8 deletions(-) create mode 100644 Panels/PlotterPanel.js diff --git a/ChartsSpace/PlottersManager.js b/ChartsSpace/PlottersManager.js index bd50cd28f..3443832e1 100644 --- a/ChartsSpace/PlottersManager.js +++ b/ChartsSpace/PlottersManager.js @@ -201,6 +201,7 @@ function newPlottersManager () { /* Lets load now this plotter panels. */ productPlotter.panels = [] + /* Here is where we instantiate the legacy panels */ for (let i = 0; i < pProductCard.product.plotter.module.panels.length; i++) { let panelConfig = pProductCard.product.plotter.module.panels[i] @@ -220,6 +221,27 @@ function newPlottersManager () { productPlotter.panels.push(plotterPanelHandle) } + /* Here we instantiate the UI Defined Panels. */ + if (productDefinition !== undefined) { + for (let i = 0; i < productDefinition.referenceParent.panels.length; i++) { + let panel = productDefinition.referenceParent.panels[i] + + let parameters = { + devTeam: pProductCard.product.plotter.devTeam, + plotterCodeName: pProductCard.product.plotter.codeName, + moduleCodeName: pProductCard.product.plotter.moduleName, + panelCodeName: panel.id + } + let panelOwner = exchange + ' ' + market.assetB + '/' + market.assetA + let plotterPanelHandle = canvas.panelsSpace.createNewPanel('Plotter Panel', parameters, panelOwner, pProductCard.session, panel) + let plotterPanel = canvas.panelsSpace.getPanel(plotterPanelHandle, panelOwner) + + /* Connect Panel to the Plotter via an Event. */ + productPlotter.plotter.container.eventHandler.listenToEvent('Current Record Changed', plotterPanel.onRecordChange) + productPlotter.panels.push(plotterPanelHandle) + } + } + productPlotters.push(productPlotter) callBack(GLOBAL.DEFAULT_OK_RESPONSE) } catch (err) { diff --git a/Panels/PlotterPanel.js b/Panels/PlotterPanel.js new file mode 100644 index 000000000..abe7f0dee --- /dev/null +++ b/Panels/PlotterPanel.js @@ -0,0 +1,122 @@ + +function newPlotterPanel () { + const MODULE_NAME = 'Plotter Panel' + const ERROR_LOG = true + const INTENSIVE_LOG = false + const logger = newWebDebugLog() + logger.fileName = MODULE_NAME + + let thisObject = { + fitFunction: undefined, + onRecordChange: onRecordChange, + container: undefined, + draw: draw, + getContainer: getContainer, + initialize: initialize + } + + let container = newContainer() + container.initialize() + thisObject.container = container + + container.frame.containerName = 'Plotter Panel' + + let currentRecord + let panelTabButton + let panelNode + + return thisObject + + function initialize (pPanelNode) { + panelNode = pPanelNode + container.frame.containerName = panelNode.name + + thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL + thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL + + thisObject.container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width * 5 + thisObject.container.frame.position.y = viewPort.visibleArea.bottomLeft.y - thisObject.container.frame.height + + panelTabButton = newPanelTabButton() + panelTabButton.parentContainer = thisObject.container + panelTabButton.container.frame.parentFrame = thisObject.container.frame + panelTabButton.fitFunction = thisObject.fitFunction + panelTabButton.initialize() + } + + function getContainer (point) { + let container + + container = panelTabButton.getContainer(point) + if (container !== undefined) { return container } + + if (thisObject.container.frame.isThisPointHere(point, true) === true) { + let checkPoint = { + x: point.x, + y: point.y + } + + checkPoint = thisObject.fitFunction(checkPoint) + + if (point.x === checkPoint.x && point.y === checkPoint.y) { + return thisObject.container + } + } + } + + function onRecordChange (pCurrentRecord) { + currentRecord = pCurrentRecord + } + + function draw () { + thisObject.container.frame.draw(false, false, true, thisObject.fitFunction) + + plotCurrentRecordData() + + panelTabButton.draw() + } + + function plotCurrentRecordData () { + const frameBodyHeight = thisObject.container.frame.getBodyHeight() + const frameTitleHeight = thisObject.container.frame.height - frameBodyHeight + + const X_AXIS = thisObject.container.frame.width / 2 + const Y_AXIS = frameTitleHeight + frameBodyHeight / 2 + const PANEL_HEIGHT = frameTitleHeight + frameBodyHeight + + if (currentRecord === undefined) { return } + if (currentRecord.data === undefined) { return } + + try { + eval(panelNode.code.code) + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err.stack) } + } + + function printLabel (labelToPrint, x, y, opacity) { + let labelPoint + let fontSize = 10 + + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + + let label = '' + labelToPrint + + let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO + + labelPoint = { + x: x - xOffset, + y: y + } + + labelPoint = thisObject.container.frame.frameThisPoint(labelPoint) + labelPoint = thisObject.fitFunction(labelPoint) + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')' + browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y) + } + + browserCanvasContext.closePath() + browserCanvasContext.fill() + } +} + diff --git a/Plotter.js b/Plotter.js index 6259c3d3d..28dd82efd 100644 --- a/Plotter.js +++ b/Plotter.js @@ -443,7 +443,7 @@ function newPlotter () { /* Clean the pannel at places where there is no record. */ let currentRecord = { - innerChannel: undefined + data: undefined } thisObject.container.eventHandler.raiseEvent('Current Record Changed', currentRecord) @@ -475,7 +475,7 @@ function newPlotter () { atMousePosition = true let currentRecord = { - innerChannel: record + data: record } thisObject.container.eventHandler.raiseEvent('Current Record Changed', currentRecord) } diff --git a/Spaces/PanelsSpace.js b/Spaces/PanelsSpace.js index 34f3d6c13..b67add293 100644 --- a/Spaces/PanelsSpace.js +++ b/Spaces/PanelsSpace.js @@ -35,7 +35,7 @@ function newPanelsSpace () { } - function createNewPanel (pType, pParameters, pOwner, pSession) { + function createNewPanel (pType, pParameters, pOwner, pSession, pPanelCode) { let panel switch (pType) { @@ -56,11 +56,20 @@ function newPanelsSpace () { } case 'Plotter Panel': { - panel = getNewPlotterPanel(pParameters.devTeam, pParameters.plotterCodeName, pParameters.moduleCodeName, pParameters.panelCodeName) - panel.fitFunction = canvas.chartSpace.fitIntoVisibleArea - panel.container.isVisibleFunction = canvas.chartSpace.isThisPointVisible - panel.session = pSession - panel.initialize() + if (pPanelCode !== undefined) { + panel = newPlotterPanel() + panel.fitFunction = canvas.chartSpace.fitIntoVisibleArea + panel.container.isVisibleFunction = canvas.chartSpace.isThisPointVisible + panel.session = pSession + panel.initialize(pPanelCode) + } else { + panel = getNewPlotterPanel(pParameters.devTeam, pParameters.plotterCodeName, pParameters.moduleCodeName, pParameters.panelCodeName) + panel.fitFunction = canvas.chartSpace.fitIntoVisibleArea + panel.container.isVisibleFunction = canvas.chartSpace.isThisPointVisible + panel.session = pSession + panel.initialize() + } + break } } From fafe5b8d026c686c972426d04414dd3dad9922ca Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 5 Dec 2019 12:51:01 +0100 Subject: [PATCH 29/41] Restarting Chart Spaace when new workspace is loaded --- Canvas.js | 15 ++------ ChartsSpace/PlottersManager.js | 56 ++++++++++++++++------------ ChartsSpace/TimeMachine.js | 35 ++++++++++------- ChartsSpace/TimelineChart.js | 27 ++++++++------ DesignerSpace/Workspace/Workspace.js | 2 + Scales/TimePeriodScale.js | 39 +++++++++++++------ Spaces/ChartSpace.js | 23 +++++++----- 7 files changed, 118 insertions(+), 79 deletions(-) diff --git a/Canvas.js b/Canvas.js index 3e01f45c9..113cd3047 100644 --- a/Canvas.js +++ b/Canvas.js @@ -81,7 +81,7 @@ function newCanvas () { } } - async function initialize () { + function initialize () { try { initializeBrowserCanvas() @@ -93,10 +93,10 @@ function newCanvas () { thisObject.floatingSpace.initialize() thisObject.topSpace = newTopSpace() - await thisObject.topSpace.initialize() + thisObject.topSpace.initialize() thisObject.designerSpace = newDesignerSpace() - await thisObject.designerSpace.initialize() + thisObject.designerSpace.initialize() thisObject.cockpitSpace = newCockpitSpace() thisObject.cockpitSpace.initialize() @@ -105,17 +105,10 @@ function newCanvas () { thisObject.panelsSpace.initialize() thisObject.chartSpace = newChartSpace() - thisObject.chartSpace.initialize(onCharSpaceInitialized) + thisObject.chartSpace.initialize() thisObject.bottomSpace = thisObject.cockpitSpace - function onCharSpaceInitialized (err) { - try { - viewPort.raiseEvents() // These events will impacts on objects just initialized. - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onCharSpaceInitialized -> err = ' + err.stack) } - } - } splashScreen = newSplashScreen() splashScreen.initialize() diff --git a/ChartsSpace/PlottersManager.js b/ChartsSpace/PlottersManager.js index 3443832e1..127d0ce6b 100644 --- a/ChartsSpace/PlottersManager.js +++ b/ChartsSpace/PlottersManager.js @@ -21,40 +21,48 @@ function newPlottersManager () { finalize: finalize } - thisObject.container = newContainer() - thisObject.container.initialize(MODULE_NAME) - let initializationReady = false let productsPanel let exchange let market + setupContainer() return thisObject - function finalize (callBackFunction) { - try { - for (let i = 0; i < productPlotters.length; i++) { - if (productPlotters[i].profile !== undefined) { - canvas.floatingSpace.profileBalls.destroyProfileBall(productPlotters[i].profile) - } - /* Destroyd the Note Set */ - canvas.floatingSpace.noteSets.destroyNoteSet(productPlotters[i].noteSet) - /* Then the panels. */ - for (let j = 0; j < productPlotters[i].panels.length; j++) { - canvas.panelsSpace.destroyPanel(productPlotters[i].panels[j]) - } - /* Finally the Storage Objects */ - productPlotters[i].storage.finalize() - if (productPlotters[i].plotter.finalize !== undefined) { - productPlotters[i].plotter.finalize() - } - productPlotters.splice(i, 1) // Delete item from array. + function setupContainer () { + thisObject.container = newContainer() + thisObject.container.initialize(MODULE_NAME) + } + + function finalize () { + for (let i = 0; i < productPlotters.length; i++) { + /* Then the panels. */ + for (let j = 0; j < productPlotters[i].panels.length; j++) { + canvas.panelsSpace.destroyPanel(productPlotters[i].panels[j]) + productPlotters[i].panels[j] = undefined } - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) + productPlotters[i].panels = undefined + + /* Finalize the plotters */ + if (productPlotters[i].plotter.finalize !== undefined) { + productPlotters[i].plotter.finalize() + } + productPlotters[i].plotter = undefined + + /* Finally the Storage Objects */ + productPlotters[i].storage.finalize() + productPlotters[i].storage = undefined + + productPlotters[i] = undefined } + productPlotters = [] + + productsPanel = undefined + + thisObject.container.finalize() + thisObject.container = undefined + setupContainer() } function initialize (pProductsPanel, pExchange, pMarket, callBackFunction) { diff --git a/ChartsSpace/TimeMachine.js b/ChartsSpace/TimeMachine.js index b56d543dd..9bcc527e9 100644 --- a/ChartsSpace/TimeMachine.js +++ b/ChartsSpace/TimeMachine.js @@ -28,17 +28,6 @@ function newTimeMachine () { finalize: finalize } - thisObject.container = newContainer() - thisObject.container.initialize(MODULE_NAME) - thisObject.container.isDraggeable = false - thisObject.container.detectMouseOver = true - - thisObject.container.frame.width = TIME_MACHINE_WIDTH - thisObject.container.frame.height = TIME_MACHINE_HEIGHT - - thisObject.container.frame.position.x = browserCanvas.width / 2 - TIME_MACHINE_WIDTH / 2 - thisObject.container.frame.position.y = browserCanvas.height / 2 - TIME_MACHINE_HEIGHT / 2 - let controlPanelHandle // We need this to destroy the Panel when this object is itself destroyed or no longer needs it... // ... also to request a reference to the object for the cases we need it. const SEPARATION_BETWEEN_TIMELINE_CHARTS = 1.5 @@ -52,21 +41,38 @@ function newTimeMachine () { } } + setupContainer() return thisObject + function setupContainer () { + thisObject.container = newContainer() + thisObject.container.initialize(MODULE_NAME) + thisObject.container.isDraggeable = false + thisObject.container.detectMouseOver = true + + thisObject.container.frame.width = TIME_MACHINE_WIDTH + thisObject.container.frame.height = TIME_MACHINE_HEIGHT + + thisObject.container.frame.position.x = browserCanvas.width / 2 - TIME_MACHINE_WIDTH / 2 + thisObject.container.frame.position.y = browserCanvas.height / 2 - TIME_MACHINE_HEIGHT / 2 + } + function finalize () { for (let i = 0; i < thisObject.charts.length; i++) { let chart = thisObject.charts[i] chart.finalize() } - thisObject.container.finalize() - thisObject.container = undefined + thisObject.charts = [] thisObject.timeScale.finalize() thisObject.timeScale = undefined thisObject.rateScale.finalize() thisObject.rateScale = undefined thisObject.fitFunction = undefined + + thisObject.container.finalize() + thisObject.container = undefined + setupContainer() } function initialize (callBackFunction) { @@ -261,6 +267,9 @@ function newTimeMachine () { } function childrenPhysics () { + if (thisObject.timeScale === undefined) { return } + if (thisObject.rateScale === undefined) { return } + thisObject.timeScale.physics() thisObject.rateScale.physics() diff --git a/ChartsSpace/TimelineChart.js b/ChartsSpace/TimelineChart.js index e06b51dee..1ade95cc3 100644 --- a/ChartsSpace/TimelineChart.js +++ b/ChartsSpace/TimelineChart.js @@ -23,10 +23,6 @@ function newTimelineChart () { finalize: finalize } - thisObject.container = newContainer() - thisObject.container.initialize(MODULE_NAME) - thisObject.container.detectMouseOver = true - thisObject.fitFunction = canvas.chartSpace.fitIntoVisibleArea let initializationReady = false @@ -50,16 +46,25 @@ function newTimelineChart () { let productsPanelHandle let timePeriodScale + setupContainer() return thisObject - function finalize () { - try { - if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') } + function setupContainer () { + thisObject.container = newContainer() + thisObject.container.initialize(MODULE_NAME) + thisObject.container.detectMouseOver = true + } - plotterManager.finalize() - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err.stack) } - } + function finalize () { + plotterManager.finalize() + plotterManager = undefined + timePeriodScale.finalize() + timePeriodScale = undefined + canvas.panelsSpace.destroyPanel(productsPanelHandle) + + thisObject.container.finalize() + thisObject.container = undefined + setupContainer() } function initialize (pExchange, pMarket, pTimeLineCoordinateSystem, callBackFunction) { diff --git a/DesignerSpace/Workspace/Workspace.js b/DesignerSpace/Workspace/Workspace.js index 98a2beb12..428952428 100644 --- a/DesignerSpace/Workspace/Workspace.js +++ b/DesignerSpace/Workspace/Workspace.js @@ -208,6 +208,8 @@ function newWorkspace () { canvas.floatingSpace.warmUp() thisObject.workspaceNode = droppedNode functionLibraryUiObjectsFromNodes.recreateWorkspace(thisObject.workspaceNode) + canvas.chartSpace.finalize() + canvas.chartSpace.initialize() return } else { if ( diff --git a/Scales/TimePeriodScale.js b/Scales/TimePeriodScale.js index 38ba997b4..93d2cb81b 100644 --- a/Scales/TimePeriodScale.js +++ b/Scales/TimePeriodScale.js @@ -14,13 +14,6 @@ function newTimePeriodScale () { const TIME_PERIOD_DEFAULT_VALUE = 0 const MIN_HEIGHT = 50 - thisObject.container = newContainer() - thisObject.container.initialize(MODULE_NAME) - - thisObject.container.isDraggeable = false - thisObject.container.isClickeable = false - thisObject.container.isWheelable = true - let mouse = { position: { x: 0, @@ -36,33 +29,57 @@ function newTimePeriodScale () { let timePeriodsMasterArray = [marketFilesPeriods, dailyFilePeriods] let timePeriodLabel = '' + let onMouseWheelEventSubscriptionId + let onMouseOverEventSubscriptionId + let onMouseNotOverEventSubscriptionId + let onZoomChangedEventSubscriptionId + + setupContainer() return thisObject + function setupContainer () { + thisObject.container = newContainer() + thisObject.container.initialize(MODULE_NAME) + + thisObject.container.isDraggeable = false + thisObject.container.isClickeable = false + thisObject.container.isWheelable = true + } + function finalize () { + thisObject.container.eventHandler.stopListening(onMouseWheelEventSubscriptionId) + thisObject.container.eventHandler.stopListening(onMouseOverEventSubscriptionId) + thisObject.container.eventHandler.stopListening(onMouseNotOverEventSubscriptionId) + thisObject.container.eventHandler.stopListening(onZoomChangedEventSubscriptionId) + + timeLineCoordinateSystem = undefined + objectStorage = undefined + thisObject.container.finalize() thisObject.container = undefined + setupContainer() } function initialize (pTimeLineCoordinateSystem) { timeLineCoordinateSystem = pTimeLineCoordinateSystem - thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel) + onMouseWheelEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel) readObjectState() newTimePeriod() - thisObject.container.eventHandler.listenToEvent('onMouseOver', function (event) { + onMouseOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', function (event) { mouse.position.x = event.x mouse.position.y = event.y visible = true }) - thisObject.container.eventHandler.listenToEvent('onMouseNotOver', function (event) { + onMouseWheelEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseNotOver', function (event) { visible = false }) - viewPort.eventHandler.listenToEvent('Zoom Changed', onZoomChanged) + onZoomChangedEventSubscriptionId = viewPort.eventHandler.listenToEvent('Zoom Changed', onZoomChanged) } function onZoomChanged (event) { diff --git a/Spaces/ChartSpace.js b/Spaces/ChartSpace.js index 226ce4795..d7bb2c624 100644 --- a/Spaces/ChartSpace.js +++ b/Spaces/ChartSpace.js @@ -30,17 +30,21 @@ function newChartSpace () { finalize: finalize } - thisObject.container = newContainer() - thisObject.container.initialize(MODULE_NAME) - - thisObject.container.isDraggeable = false - thisObject.container.isWheelable = false - let canvasBrowserResizedEventSubscriptionId const PERCENTAGE_OF_SCREEN_FOR_DISPLACEMENT = 25 + + setupContainer() return thisObject + function setupContainer () { + thisObject.container = newContainer() + thisObject.container.initialize(MODULE_NAME) + + thisObject.container.isDraggeable = false + thisObject.container.isWheelable = false + } + function finalize () { for (let i = 0; i < thisObject.timeMachines.length; i++) { let timeMachine = thisObject.timeMachines[i] @@ -51,9 +55,10 @@ function newChartSpace () { thisObject.container.finalize() thisObject.container = undefined + setupContainer() } - function initialize (callBackFunction) { + function initialize () { let initializedCounter = 0 let toInitialize = 1 @@ -75,14 +80,14 @@ function newChartSpace () { initializedCounter++ if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { - callBackFunction(err) + if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> Initialization Failed. -> Err ' + err.message) } return } thisObject.timeMachines.push(timeMachine) if (initializedCounter === toInitialize) { - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) + viewPort.raiseEvents() // These events will impacts on objects just initialized. } } } From b4f84105673d527669a3c17e6cef7c1315a6e9ef Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 5 Dec 2019 13:25:18 +0100 Subject: [PATCH 30/41] Final touches --- ChartsSpace/TimeMachine.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ChartsSpace/TimeMachine.js b/ChartsSpace/TimeMachine.js index 9bcc527e9..8b35c71fe 100644 --- a/ChartsSpace/TimeMachine.js +++ b/ChartsSpace/TimeMachine.js @@ -241,8 +241,12 @@ function newTimeMachine () { } else { if (purpose === GET_CONTAINER_PURPOSE.MOUSE_OVER) { thisObject.container.eventHandler.raiseEvent('onMouseNotOver') - thisObject.timeScale.visible = false - thisObject.rateScale.visible = false + if (thisObject.timeScale !== undefined) { + thisObject.timeScale.visible = false + } + if (thisObject.rateScale !== undefined) { + thisObject.rateScale.visible = false + } } return } From 849d6b8a510bdc216b632d1d5262bfa12552f5d1 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 6 Dec 2019 16:44:27 +0100 Subject: [PATCH 31/41] Code Editor Splitted in 4 --- FloatingSpace/CodeEditor.js | 4 +- FloatingSpace/ConditionEditor.js | 223 ++++++++++++++ FloatingSpace/ConfigEditor.js | 223 ++++++++++++++ FloatingSpace/FormulaEditor.js | 223 ++++++++++++++ FloatingSpace/UiObject.js | 104 ++++++- FloatingSpace/UiObjectConstructor.js | 434 ++++++++++++++------------- 6 files changed, 995 insertions(+), 216 deletions(-) create mode 100644 FloatingSpace/ConditionEditor.js create mode 100644 FloatingSpace/ConfigEditor.js create mode 100644 FloatingSpace/FormulaEditor.js diff --git a/FloatingSpace/CodeEditor.js b/FloatingSpace/CodeEditor.js index 62fcffdae..4c40de669 100644 --- a/FloatingSpace/CodeEditor.js +++ b/FloatingSpace/CodeEditor.js @@ -1,6 +1,6 @@ function newCodeEditor () { - const MODULE_NAME = 'Circular Menu Iem' + const MODULE_NAME = 'Code Editor' let thisObject = { isVisibleFunction: undefined, @@ -98,7 +98,7 @@ function newCodeEditor () { 'overflow:hidden;' + 'font-family: ' + UI_FONT.PRIMARY + ';' + 'font-size: 12px;' + - 'background-color: rgb(204, 88, 53);' + + 'background-color: rgb(' + UI_COLOR.RUSTED_RED + ');' + 'color:rgb(255, 255, 255);' + 'width: ' + thisObject.container.frame.width + 'px;' + 'height: ' + thisObject.container.frame.height + 'px' diff --git a/FloatingSpace/ConditionEditor.js b/FloatingSpace/ConditionEditor.js new file mode 100644 index 000000000..b9463357e --- /dev/null +++ b/FloatingSpace/ConditionEditor.js @@ -0,0 +1,223 @@ + +function newConditionEditor () { + const MODULE_NAME = 'Condition Editor' + + let thisObject = { + isVisibleFunction: undefined, + iconOK: undefined, + iconNOT_OK: undefined, + visible: false, + imagePathOK: undefined, + imagePathNOT_OK: undefined, + rawRadius: undefined, + targetRadius: undefined, + currentRadius: undefined, + container: undefined, + payload: undefined, + deactivate: deactivate, + activate: activate, + physics: physics, + drawBackground: drawBackground, + drawForeground: drawForeground, + getContainer: getContainer, + finalize: finalize, + initialize: initialize + } + + thisObject.container = newContainer() + thisObject.container.initialize(MODULE_NAME) + thisObject.container.isClickeable = false + thisObject.container.isDraggeable = false + thisObject.container.detectMouseOver = false + thisObject.container.frame.radius = 0 + thisObject.container.frame.position.x = 0 + thisObject.container.frame.position.y = 0 + + let isMouseOver = false + + return thisObject + + function finalize () { + thisObject.container.finalize() + thisObject.container = undefined + thisObject.iconOK = undefined + thisObject.iconNOT_OK = undefined + thisObject.payload = undefined + thisObject.isVisibleFunction = undefined + } + + function initialize () { + /* Load Images */ + + thisObject.iconOK = new Image() + thisObject.iconOK.onload = onImageLoad + + function onImageLoad () { + thisObject.iconNOT_OK = new Image() + thisObject.iconNOT_OK.onload = onImageLoad + + function onImageLoad () { + thisObject.canDrawIcon = true + } + thisObject.iconNOT_OK.src = window.canvasApp.urlPrefix + thisObject.imagePathNOT_OK + } + // thisObject.iconOK.src = window.canvasApp.urlPrefix + thisObject.imagePathOK + // thisObject.icon = thisObject.iconOK // The default value is ON. + } + + function deactivate () { + if (thisObject.visible === true) { + thisObject.visible = false + let textArea = document.getElementById('textArea') + textArea.style.display = 'none' + thisObject.payload.node.code = textArea.value + if (thisObject.payload.node.type !== 'Code' && thisObject.payload.node.type !== 'Formula') { + try { + let code = JSON.parse(thisObject.payload.node.code) + } catch (err) { + thisObject.payload.uiObject.setErrorMessage(err.message, 10) + } + } + } + } + + function activate (payload) { + thisObject.visible = true + thisObject.payload = payload + thisObject.rawRadius = 8 + thisObject.targetRadius = thisObject.container.frame.radius + thisObject.currentRadius = 0 + thisObject.payload.uiObject.setErrorMessage('', 0) + + let textArea = document.getElementById('textArea') + textArea.value = payload.node.code + textArea.style = 'resize: none;' + + ' border: none;' + + ' outline: none;' + + 'box-shadow: none;' + + 'overflow:hidden;' + + 'font-family: ' + UI_FONT.PRIMARY + ';' + + 'font-size: 12px;' + + 'background-color: rgb(' + UI_COLOR.GREEN + ');' + + 'color:rgb(255, 255, 255);' + + 'width: ' + thisObject.container.frame.width + 'px;' + + 'height: ' + thisObject.container.frame.height + 'px' + textArea.style.display = 'block' + textArea.focus() + } + + function getContainer (point) { + let container + if (thisObject.visible === true) { + if (point.x === VERY_LARGE_NUMBER) { + /* The the mouse leaves the canvas, and event of mouse over with a ridiculous coordinate is triggered so that + anyone can react. In our case, the code editor has a text area that is not part of the canvas, so the event is + triggered. We compensate recognizing this coordinate and returning our container. */ + return thisObject.container + } + + if (thisObject.container.frame.isThisPointHere(point, true, false) === true) { + return thisObject.container + } else { + return undefined + } + } + } + + function physics () { + if (Math.abs(thisObject.currentRadius - thisObject.targetRadius) >= 0.5) { + if (thisObject.currentRadius < thisObject.targetRadius) { + thisObject.currentRadius = thisObject.currentRadius + 0.5 + } else { + thisObject.currentRadius = thisObject.currentRadius - 0.5 + } + } + + thisObject.container.frame.position.x = 0 + thisObject.container.frame.position.y = 0 + + thisObject.container.frame.width = thisObject.container.frame.radius * 1.8 * 2 + thisObject.container.frame.height = thisObject.container.frame.radius * 1 * 2 + + let textAreaPosition = { + x: 0 - thisObject.container.frame.width / 2, + y: 0 - thisObject.container.frame.height * 3 / 7 + CURRENT_TOP_MARGIN + } + + textAreaPosition = thisObject.container.frame.frameThisPoint(textAreaPosition) + if (thisObject.visible === true) { + let checkPosition = { + x: textAreaPosition.x, + y: textAreaPosition.y - CURRENT_TOP_MARGIN + } + if (thisObject.isVisibleFunction(checkPosition) === false) { + deactivate() + } + } + if (thisObject.visible === true) { + let textAreaDiv = document.getElementById('textAreaDiv') + textAreaDiv.style = 'position:fixed; top:' + textAreaPosition.y + 'px; left:' + textAreaPosition.x + 'px; z-index:1; ' + } + } + + function drawBackground () { + if (thisObject.visible === true) { + let position = { + x: 0, + y: 0 + } + + position = thisObject.container.frame.frameThisPoint(position) + + let radius = thisObject.container.frame.radius * 2 + + if (radius > 0.5) { + browserCanvasContext.beginPath() + browserCanvasContext.arc(position.x, position.y, radius * 1.3 + 3, 0, Math.PI * 2, true) + browserCanvasContext.closePath() + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + 1 + ')' + browserCanvasContext.fill() + + browserCanvasContext.beginPath() + browserCanvasContext.arc(position.x, position.y, radius * 1.3, 0, Math.PI * 2, true) + browserCanvasContext.closePath() + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + 1 + ')' + browserCanvasContext.fill() + } + } + } + function drawForeground () { + let iconPosition = { + x: 0, + y: thisObject.currentRadius * 1.5 + } + + iconPosition = thisObject.container.frame.frameThisPoint(iconPosition) + + /* Menu Item */ + + if (thisObject.canDrawIcon === true && thisObject.currentRadius > 1) { + browserCanvasContext.drawImage(thisObject.icon, iconPosition.x - thisObject.currentRadius, iconPosition.y - thisObject.currentRadius, thisObject.currentRadius * 2, thisObject.currentRadius * 2) + + /* Menu Label */ + + let label = 'Code looks good!' + let labelPoint + let fontSize = 10 + + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY + + if (label !== undefined && thisObject.currentRadius >= thisObject.targetRadius) { + labelPoint = { + x: iconPosition.x + thisObject.currentRadius + 10, + y: iconPosition.y + fontSize * FONT_ASPECT_RATIO + } + + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)' + browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y) + } + } + } +} + diff --git a/FloatingSpace/ConfigEditor.js b/FloatingSpace/ConfigEditor.js new file mode 100644 index 000000000..0d5ce7bba --- /dev/null +++ b/FloatingSpace/ConfigEditor.js @@ -0,0 +1,223 @@ + +function newConfigEditor () { + const MODULE_NAME = 'Config Editor' + + let thisObject = { + isVisibleFunction: undefined, + iconOK: undefined, + iconNOT_OK: undefined, + visible: false, + imagePathOK: undefined, + imagePathNOT_OK: undefined, + rawRadius: undefined, + targetRadius: undefined, + currentRadius: undefined, + container: undefined, + payload: undefined, + deactivate: deactivate, + activate: activate, + physics: physics, + drawBackground: drawBackground, + drawForeground: drawForeground, + getContainer: getContainer, + finalize: finalize, + initialize: initialize + } + + thisObject.container = newContainer() + thisObject.container.initialize(MODULE_NAME) + thisObject.container.isClickeable = false + thisObject.container.isDraggeable = false + thisObject.container.detectMouseOver = false + thisObject.container.frame.radius = 0 + thisObject.container.frame.position.x = 0 + thisObject.container.frame.position.y = 0 + + let isMouseOver = false + + return thisObject + + function finalize () { + thisObject.container.finalize() + thisObject.container = undefined + thisObject.iconOK = undefined + thisObject.iconNOT_OK = undefined + thisObject.payload = undefined + thisObject.isVisibleFunction = undefined + } + + function initialize () { + /* Load Images */ + + thisObject.iconOK = new Image() + thisObject.iconOK.onload = onImageLoad + + function onImageLoad () { + thisObject.iconNOT_OK = new Image() + thisObject.iconNOT_OK.onload = onImageLoad + + function onImageLoad () { + thisObject.canDrawIcon = true + } + thisObject.iconNOT_OK.src = window.canvasApp.urlPrefix + thisObject.imagePathNOT_OK + } + // thisObject.iconOK.src = window.canvasApp.urlPrefix + thisObject.imagePathOK + // thisObject.icon = thisObject.iconOK // The default value is ON. + } + + function deactivate () { + if (thisObject.visible === true) { + thisObject.visible = false + let textArea = document.getElementById('textArea') + textArea.style.display = 'none' + thisObject.payload.node.code = textArea.value + if (thisObject.payload.node.type !== 'Code' && thisObject.payload.node.type !== 'Formula') { + try { + let code = JSON.parse(thisObject.payload.node.code) + } catch (err) { + thisObject.payload.uiObject.setErrorMessage(err.message, 10) + } + } + } + } + + function activate (payload) { + thisObject.visible = true + thisObject.payload = payload + thisObject.rawRadius = 8 + thisObject.targetRadius = thisObject.container.frame.radius + thisObject.currentRadius = 0 + thisObject.payload.uiObject.setErrorMessage('', 0) + + let textArea = document.getElementById('textArea') + textArea.value = payload.node.code + textArea.style = 'resize: none;' + + ' border: none;' + + ' outline: none;' + + 'box-shadow: none;' + + 'overflow:hidden;' + + 'font-family: ' + UI_FONT.PRIMARY + ';' + + 'font-size: 12px;' + + 'background-color: rgb(' + UI_COLOR.DARK_TURQUOISE + ');' + + 'color:rgb(255, 255, 255);' + + 'width: ' + thisObject.container.frame.width + 'px;' + + 'height: ' + thisObject.container.frame.height + 'px' + textArea.style.display = 'block' + textArea.focus() + } + + function getContainer (point) { + let container + if (thisObject.visible === true) { + if (point.x === VERY_LARGE_NUMBER) { + /* The the mouse leaves the canvas, and event of mouse over with a ridiculous coordinate is triggered so that + anyone can react. In our case, the code editor has a text area that is not part of the canvas, so the event is + triggered. We compensate recognizing this coordinate and returning our container. */ + return thisObject.container + } + + if (thisObject.container.frame.isThisPointHere(point, true, false) === true) { + return thisObject.container + } else { + return undefined + } + } + } + + function physics () { + if (Math.abs(thisObject.currentRadius - thisObject.targetRadius) >= 0.5) { + if (thisObject.currentRadius < thisObject.targetRadius) { + thisObject.currentRadius = thisObject.currentRadius + 0.5 + } else { + thisObject.currentRadius = thisObject.currentRadius - 0.5 + } + } + + thisObject.container.frame.position.x = 0 + thisObject.container.frame.position.y = 0 + + thisObject.container.frame.width = thisObject.container.frame.radius * 1.8 * 2 + thisObject.container.frame.height = thisObject.container.frame.radius * 1 * 2 + + let textAreaPosition = { + x: 0 - thisObject.container.frame.width / 2, + y: 0 - thisObject.container.frame.height * 3 / 7 + CURRENT_TOP_MARGIN + } + + textAreaPosition = thisObject.container.frame.frameThisPoint(textAreaPosition) + if (thisObject.visible === true) { + let checkPosition = { + x: textAreaPosition.x, + y: textAreaPosition.y - CURRENT_TOP_MARGIN + } + if (thisObject.isVisibleFunction(checkPosition) === false) { + deactivate() + } + } + if (thisObject.visible === true) { + let textAreaDiv = document.getElementById('textAreaDiv') + textAreaDiv.style = 'position:fixed; top:' + textAreaPosition.y + 'px; left:' + textAreaPosition.x + 'px; z-index:1; ' + } + } + + function drawBackground () { + if (thisObject.visible === true) { + let position = { + x: 0, + y: 0 + } + + position = thisObject.container.frame.frameThisPoint(position) + + let radius = thisObject.container.frame.radius * 2 + + if (radius > 0.5) { + browserCanvasContext.beginPath() + browserCanvasContext.arc(position.x, position.y, radius * 1.3 + 3, 0, Math.PI * 2, true) + browserCanvasContext.closePath() + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + 1 + ')' + browserCanvasContext.fill() + + browserCanvasContext.beginPath() + browserCanvasContext.arc(position.x, position.y, radius * 1.3, 0, Math.PI * 2, true) + browserCanvasContext.closePath() + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK_TURQUOISE + ', ' + 1 + ')' + browserCanvasContext.fill() + } + } + } + function drawForeground () { + let iconPosition = { + x: 0, + y: thisObject.currentRadius * 1.5 + } + + iconPosition = thisObject.container.frame.frameThisPoint(iconPosition) + + /* Menu Item */ + + if (thisObject.canDrawIcon === true && thisObject.currentRadius > 1) { + browserCanvasContext.drawImage(thisObject.icon, iconPosition.x - thisObject.currentRadius, iconPosition.y - thisObject.currentRadius, thisObject.currentRadius * 2, thisObject.currentRadius * 2) + + /* Menu Label */ + + let label = 'Code looks good!' + let labelPoint + let fontSize = 10 + + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY + + if (label !== undefined && thisObject.currentRadius >= thisObject.targetRadius) { + labelPoint = { + x: iconPosition.x + thisObject.currentRadius + 10, + y: iconPosition.y + fontSize * FONT_ASPECT_RATIO + } + + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)' + browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y) + } + } + } +} + diff --git a/FloatingSpace/FormulaEditor.js b/FloatingSpace/FormulaEditor.js new file mode 100644 index 000000000..6eeb20f92 --- /dev/null +++ b/FloatingSpace/FormulaEditor.js @@ -0,0 +1,223 @@ + +function newFormulaEditor () { + const MODULE_NAME = 'Formula Editor' + + let thisObject = { + isVisibleFunction: undefined, + iconOK: undefined, + iconNOT_OK: undefined, + visible: false, + imagePathOK: undefined, + imagePathNOT_OK: undefined, + rawRadius: undefined, + targetRadius: undefined, + currentRadius: undefined, + container: undefined, + payload: undefined, + deactivate: deactivate, + activate: activate, + physics: physics, + drawBackground: drawBackground, + drawForeground: drawForeground, + getContainer: getContainer, + finalize: finalize, + initialize: initialize + } + + thisObject.container = newContainer() + thisObject.container.initialize(MODULE_NAME) + thisObject.container.isClickeable = false + thisObject.container.isDraggeable = false + thisObject.container.detectMouseOver = false + thisObject.container.frame.radius = 0 + thisObject.container.frame.position.x = 0 + thisObject.container.frame.position.y = 0 + + let isMouseOver = false + + return thisObject + + function finalize () { + thisObject.container.finalize() + thisObject.container = undefined + thisObject.iconOK = undefined + thisObject.iconNOT_OK = undefined + thisObject.payload = undefined + thisObject.isVisibleFunction = undefined + } + + function initialize () { + /* Load Images */ + + thisObject.iconOK = new Image() + thisObject.iconOK.onload = onImageLoad + + function onImageLoad () { + thisObject.iconNOT_OK = new Image() + thisObject.iconNOT_OK.onload = onImageLoad + + function onImageLoad () { + thisObject.canDrawIcon = true + } + thisObject.iconNOT_OK.src = window.canvasApp.urlPrefix + thisObject.imagePathNOT_OK + } + // thisObject.iconOK.src = window.canvasApp.urlPrefix + thisObject.imagePathOK + // thisObject.icon = thisObject.iconOK // The default value is ON. + } + + function deactivate () { + if (thisObject.visible === true) { + thisObject.visible = false + let textArea = document.getElementById('textArea') + textArea.style.display = 'none' + thisObject.payload.node.code = textArea.value + if (thisObject.payload.node.type !== 'Code' && thisObject.payload.node.type !== 'Formula') { + try { + let code = JSON.parse(thisObject.payload.node.code) + } catch (err) { + thisObject.payload.uiObject.setErrorMessage(err.message, 10) + } + } + } + } + + function activate (payload) { + thisObject.visible = true + thisObject.payload = payload + thisObject.rawRadius = 8 + thisObject.targetRadius = thisObject.container.frame.radius + thisObject.currentRadius = 0 + thisObject.payload.uiObject.setErrorMessage('', 0) + + let textArea = document.getElementById('textArea') + textArea.value = payload.node.code + textArea.style = 'resize: none;' + + ' border: none;' + + ' outline: none;' + + 'box-shadow: none;' + + 'overflow:hidden;' + + 'font-family: ' + UI_FONT.PRIMARY + ';' + + 'font-size: 12px;' + + 'background-color: rgb(' + UI_COLOR.MANGANESE_PURPLE + ');' + + 'color:rgb(255, 255, 255);' + + 'width: ' + thisObject.container.frame.width + 'px;' + + 'height: ' + thisObject.container.frame.height + 'px' + textArea.style.display = 'block' + textArea.focus() + } + + function getContainer (point) { + let container + if (thisObject.visible === true) { + if (point.x === VERY_LARGE_NUMBER) { + /* The the mouse leaves the canvas, and event of mouse over with a ridiculous coordinate is triggered so that + anyone can react. In our case, the code editor has a text area that is not part of the canvas, so the event is + triggered. We compensate recognizing this coordinate and returning our container. */ + return thisObject.container + } + + if (thisObject.container.frame.isThisPointHere(point, true, false) === true) { + return thisObject.container + } else { + return undefined + } + } + } + + function physics () { + if (Math.abs(thisObject.currentRadius - thisObject.targetRadius) >= 0.5) { + if (thisObject.currentRadius < thisObject.targetRadius) { + thisObject.currentRadius = thisObject.currentRadius + 0.5 + } else { + thisObject.currentRadius = thisObject.currentRadius - 0.5 + } + } + + thisObject.container.frame.position.x = 0 + thisObject.container.frame.position.y = 0 + + thisObject.container.frame.width = thisObject.container.frame.radius * 1.8 * 2 + thisObject.container.frame.height = thisObject.container.frame.radius * 1 * 2 + + let textAreaPosition = { + x: 0 - thisObject.container.frame.width / 2, + y: 0 - thisObject.container.frame.height * 3 / 7 + CURRENT_TOP_MARGIN + } + + textAreaPosition = thisObject.container.frame.frameThisPoint(textAreaPosition) + if (thisObject.visible === true) { + let checkPosition = { + x: textAreaPosition.x, + y: textAreaPosition.y - CURRENT_TOP_MARGIN + } + if (thisObject.isVisibleFunction(checkPosition) === false) { + deactivate() + } + } + if (thisObject.visible === true) { + let textAreaDiv = document.getElementById('textAreaDiv') + textAreaDiv.style = 'position:fixed; top:' + textAreaPosition.y + 'px; left:' + textAreaPosition.x + 'px; z-index:1; ' + } + } + + function drawBackground () { + if (thisObject.visible === true) { + let position = { + x: 0, + y: 0 + } + + position = thisObject.container.frame.frameThisPoint(position) + + let radius = thisObject.container.frame.radius * 2 + + if (radius > 0.5) { + browserCanvasContext.beginPath() + browserCanvasContext.arc(position.x, position.y, radius * 1.3 + 3, 0, Math.PI * 2, true) + browserCanvasContext.closePath() + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + 1 + ')' + browserCanvasContext.fill() + + browserCanvasContext.beginPath() + browserCanvasContext.arc(position.x, position.y, radius * 1.3, 0, Math.PI * 2, true) + browserCanvasContext.closePath() + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.MANGANESE_PURPLE + ', ' + 1 + ')' + browserCanvasContext.fill() + } + } + } + function drawForeground () { + let iconPosition = { + x: 0, + y: thisObject.currentRadius * 1.5 + } + + iconPosition = thisObject.container.frame.frameThisPoint(iconPosition) + + /* Menu Item */ + + if (thisObject.canDrawIcon === true && thisObject.currentRadius > 1) { + browserCanvasContext.drawImage(thisObject.icon, iconPosition.x - thisObject.currentRadius, iconPosition.y - thisObject.currentRadius, thisObject.currentRadius * 2, thisObject.currentRadius * 2) + + /* Menu Label */ + + let label = 'Code looks good!' + let labelPoint + let fontSize = 10 + + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY + + if (label !== undefined && thisObject.currentRadius >= thisObject.targetRadius) { + labelPoint = { + x: iconPosition.x + thisObject.currentRadius + 10, + y: iconPosition.y + fontSize * FONT_ASPECT_RATIO + } + + browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)' + browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y) + } + } + } +} + diff --git a/FloatingSpace/UiObject.js b/FloatingSpace/UiObject.js index 73e350eb6..677af7a48 100644 --- a/FloatingSpace/UiObject.js +++ b/FloatingSpace/UiObject.js @@ -15,6 +15,9 @@ function newUiObject () { container: undefined, payload: undefined, codeEditor: undefined, + configEditor: undefined, + conditionEditor: undefined, + formulaEditor: undefined, uiObjectTitle: undefined, circularProgressBar: undefined, isExecuting: undefined, @@ -115,6 +118,21 @@ function newUiObject () { thisObject.codeEditor = undefined } + if (thisObject.configEditor !== undefined) { + thisObject.configEditor.finalize() + thisObject.configEditor = undefined + } + + if (thisObject.conditionEditor !== undefined) { + thisObject.conditionEditor.finalize() + thisObject.conditionEditor = undefined + } + + if (thisObject.formulaEditor !== undefined) { + thisObject.formulaEditor.finalize() + thisObject.formulaEditor = undefined + } + icon = undefined chainAttachToNode = undefined referenceAttachToNode = undefined @@ -156,6 +174,21 @@ function newUiObject () { if (container !== undefined) { return container } } + if (thisObject.configEditor !== undefined) { + container = thisObject.configEditor.getContainer(point) + if (container !== undefined) { return container } + } + + if (thisObject.conditionEditor !== undefined) { + container = thisObject.conditionEditor.getContainer(point) + if (container !== undefined) { return container } + } + + if (thisObject.formulaEditor !== undefined) { + container = thisObject.formulaEditor.getContainer(point) + if (container !== undefined) { return container } + } + container = thisObject.uiObjectTitle.getContainer(point) if (container !== undefined) { return container } @@ -178,6 +211,18 @@ function newUiObject () { thisObject.codeEditor.physics() } + if (thisObject.configEditor !== undefined) { + thisObject.configEditor.physics() + } + + if (thisObject.conditionEditor !== undefined) { + thisObject.conditionEditor.physics() + } + + if (thisObject.formulaEditor !== undefined) { + thisObject.formulaEditor.physics() + } + if (thisObject.payload.chainParent === undefined || thisObject.payload.chainParent.payload === undefined) { thisObject.payload.targetPosition.x = thisObject.payload.position.x, thisObject.payload.targetPosition.y = thisObject.payload.position.y @@ -928,6 +973,15 @@ function newUiObject () { if (thisObject.codeEditor !== undefined) { thisObject.codeEditor.deactivate() } + if (thisObject.configEditor !== undefined) { + thisObject.configEditor.deactivate() + } + if (thisObject.conditionEditor !== undefined) { + thisObject.conditionEditor.deactivate() + } + if (thisObject.formulaEditor !== undefined) { + thisObject.formulaEditor.deactivate() + } } function onDisplace (event) { @@ -939,6 +993,15 @@ function newUiObject () { if (thisObject.codeEditor !== undefined) { thisObject.codeEditor.deactivate() } + if (thisObject.configEditor !== undefined) { + thisObject.configEditor.deactivate() + } + if (thisObject.conditionEditor !== undefined) { + thisObject.conditionEditor.deactivate() + } + if (thisObject.formulaEditor !== undefined) { + thisObject.formulaEditor.deactivate() + } isDragging = true if (event.button === 2) { rightDragging = true @@ -1009,16 +1072,43 @@ function newUiObject () { thisObject.codeEditor.drawBackground() thisObject.codeEditor.drawForeground() } + if (thisObject.configEditor !== undefined) { + thisObject.configEditor.drawBackground() + thisObject.configEditor.drawForeground() + } + if (thisObject.conditionEditor !== undefined) { + thisObject.conditionEditor.drawBackground() + thisObject.conditionEditor.drawForeground() + } + if (thisObject.formulaEditor !== undefined) { + thisObject.formulaEditor.drawBackground() + thisObject.formulaEditor.drawForeground() + } + + let drawMenu = true if (thisObject.codeEditor !== undefined) { - if (thisObject.codeEditor.visible === false) { - drawBodyAndPicture() - if (isDragging === false) { - thisObject.menu.drawBackground() - thisObject.menu.drawForeground() - } + if (thisObject.codeEditor.visible === true) { + drawMenu = false } - } else { + } + if (thisObject.configEditor !== undefined) { + if (thisObject.configEditor.visible === true) { + drawMenu = false + } + } + if (thisObject.conditionEditor !== undefined) { + if (thisObject.conditionEditor.visible === true) { + drawMenu = false + } + } + if (thisObject.formulaEditor !== undefined) { + if (thisObject.formulaEditor.visible === true) { + drawMenu = false + } + } + + if (drawMenu === true) { drawBodyAndPicture() if (isDragging === false) { thisObject.menu.drawBackground() diff --git a/FloatingSpace/UiObjectConstructor.js b/FloatingSpace/UiObjectConstructor.js index 8d96c837a..8b86dfbc8 100644 --- a/FloatingSpace/UiObjectConstructor.js +++ b/FloatingSpace/UiObjectConstructor.js @@ -313,16 +313,16 @@ function newUiObjectConstructor () { break } case 'Team': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Team', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Bot', + action: 'Configure Team', + actionFunction: uiObject.configEditor.activate, + label: 'Configigure Team', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -418,16 +418,16 @@ function newUiObjectConstructor () { break } case 'Sensor Bot': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Bot', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Bot', + action: 'Configure Bot', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Bot', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -497,16 +497,16 @@ function newUiObjectConstructor () { break } case 'Indicator Bot': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Bot', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Bot', + action: 'Configure Bot', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Bot', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -576,16 +576,16 @@ function newUiObjectConstructor () { break } case 'Trading Bot': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Bot', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Bot', + action: 'Configure Bot', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Bot', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -655,16 +655,16 @@ function newUiObjectConstructor () { break } case 'Process Definition': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Process', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Process', + action: 'Configure Process', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Process', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -1190,16 +1190,16 @@ function newUiObjectConstructor () { break } case 'Status Dependency': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Status Dependency', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Status Dependency', + action: 'Configure Status Dependency', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Status Dependency', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -1277,16 +1277,16 @@ function newUiObjectConstructor () { break } case 'Product Definition': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Product', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Product', + action: 'Configure Product', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Product', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -1418,16 +1418,16 @@ function newUiObjectConstructor () { break } case 'Record Property': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Property', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Property', + action: 'Configure Property', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Property', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -1486,16 +1486,16 @@ function newUiObjectConstructor () { break } case 'Dataset Definition': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Definition', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Definition', + action: 'Configure Definition', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Definition', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -1539,16 +1539,16 @@ function newUiObjectConstructor () { break } case 'Plotter': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Plotter', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Plotter', + action: 'Configure Plotter', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Plotter', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -1605,16 +1605,16 @@ function newUiObjectConstructor () { break } case 'Plotter Module': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Plotter Module', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Plotter Module', + action: 'Configure Plotter Module', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Plotter Module', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -1876,10 +1876,10 @@ function newUiObjectConstructor () { break } case 'Telegram Bot': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { @@ -1896,9 +1896,9 @@ function newUiObjectConstructor () { ) menuItemsInitialValues.push( { - action: 'Edit Telegram Bot', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Telegram Bot', + action: 'Configure Telegram Bot', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Telegram Bot', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -1942,10 +1942,10 @@ function newUiObjectConstructor () { break } case 'Announcement': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { @@ -1965,9 +1965,9 @@ function newUiObjectConstructor () { addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Announcement', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Announcement', + action: 'Configure Announcement', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Announcement', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -2058,16 +2058,16 @@ function newUiObjectConstructor () { break } case 'Layer': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Layer', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Layer', + action: 'Configure Layer', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Layer', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -2288,17 +2288,17 @@ function newUiObjectConstructor () { break } case 'Sensor Bot Instance': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Sensor Bot Instance', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Sensor Bot Instance', + action: 'Configure Sensor Bot Instance', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Sensor Bot Instance', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -2355,17 +2355,17 @@ function newUiObjectConstructor () { break } case 'Indicator Bot Instance': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Indicator Bot Instance', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Indicator Bot Instance', + action: 'Configure Indicator Bot Instance', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Indicator Bot Instance', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -2422,17 +2422,17 @@ function newUiObjectConstructor () { break } case 'Trading Bot Instance': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Trading Bot Instance', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Trading Bot Instance', + action: 'Configure Trading Bot Instance', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Trading Bot Instance', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -2489,10 +2489,10 @@ function newUiObjectConstructor () { break } case 'Process Instance': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) @@ -2560,9 +2560,9 @@ function newUiObjectConstructor () { ) menuItemsInitialValues.push( { - action: 'Edit Process Instance', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Process Instance', + action: 'Configure Process Instance', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Process Instance', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -2608,9 +2608,9 @@ function newUiObjectConstructor () { default: { menuItemsInitialValues.push( { - action: 'Edit Process Instance', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Process Instance', + action: 'Configure Process Instance', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Process Instance', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -2657,10 +2657,10 @@ function newUiObjectConstructor () { break } case 'Backtesting Session': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( @@ -2733,9 +2733,9 @@ function newUiObjectConstructor () { ) menuItemsInitialValues.push( { - action: 'Edit Session', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Session', + action: 'Configure Session', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Session', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -2779,10 +2779,10 @@ function newUiObjectConstructor () { break } case 'Live Trading Session': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( @@ -2855,9 +2855,9 @@ function newUiObjectConstructor () { ) menuItemsInitialValues.push( { - action: 'Edit Session', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Session', + action: 'Configure Session', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Session', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -2901,10 +2901,10 @@ function newUiObjectConstructor () { break } case 'Fordward Testing Session': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( @@ -2977,9 +2977,9 @@ function newUiObjectConstructor () { ) menuItemsInitialValues.push( { - action: 'Edit Session', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Session', + action: 'Configure Session', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Session', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -3023,10 +3023,10 @@ function newUiObjectConstructor () { break } case 'Paper Trading Session': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( @@ -3099,9 +3099,9 @@ function newUiObjectConstructor () { ) menuItemsInitialValues.push( { - action: 'Edit Session', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Session', + action: 'Configure Session', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Session', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -3244,17 +3244,17 @@ function newUiObjectConstructor () { break } case 'Exchange Account Key': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Key Value', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Key Value', + action: 'Configure Key Value', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Key Value', visible: true, iconPathOn: 'html', iconPathOff: 'html', @@ -3393,17 +3393,17 @@ function newUiObjectConstructor () { break } case 'Base Asset': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Base Asset', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Base Asset', + action: 'Configure Base Asset', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Base Asset', visible: true, iconPathOn: 'settings', iconPathOff: 'settings', @@ -3446,17 +3446,17 @@ function newUiObjectConstructor () { break } case 'Time Range': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Time Range', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Time Range', + action: 'Configure Time Range', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Time Range', visible: true, iconPathOn: 'settings', iconPathOff: 'settings', @@ -3499,17 +3499,17 @@ function newUiObjectConstructor () { break } case 'Time Period': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Time Period', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Time Period', + action: 'Configure Time Period', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Time Period', visible: true, iconPathOn: 'settings', iconPathOff: 'settings', @@ -3552,17 +3552,17 @@ function newUiObjectConstructor () { break } case 'Slippage': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Slippage', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Slippage', + action: 'Configure Slippage', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Slippage', visible: true, iconPathOn: 'settings', iconPathOff: 'settings', @@ -3605,17 +3605,17 @@ function newUiObjectConstructor () { break } case 'Fee Structure': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.configEditor = newConfigEditor() + uiObject.configEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.configEditor.initialize() + uiObject.configEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { - action: 'Edit Fee Structure', - actionFunction: uiObject.codeEditor.activate, - label: 'Edit Fee Structure', + action: 'Configure Fee Structure', + actionFunction: uiObject.configEditor.activate, + label: 'Configure Fee Structure', visible: true, iconPathOn: 'settings', iconPathOff: 'settings', @@ -4424,16 +4424,16 @@ function newUiObjectConstructor () { break } case 'Formula': { - uiObject.codeEditor = newCodeEditor() - uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction - uiObject.codeEditor.initialize() - uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + uiObject.formulaEditor = newFormulaEditor() + uiObject.formulaEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.formulaEditor.initialize() + uiObject.formulaEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( { action: 'Edit Formula', - actionFunction: uiObject.codeEditor.activate, + actionFunction: uiObject.formulaEditor.activate, label: 'Edit Formula', visible: true, iconPathOn: 'html', @@ -4572,7 +4572,27 @@ function newUiObjectConstructor () { break } case 'Condition': { + uiObject.conditionEditor = newConditionEditor() + uiObject.conditionEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.conditionEditor.initialize() + uiObject.conditionEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + addLeftIcons(menuItemsInitialValues, floatingObject) + menuItemsInitialValues.push( + { + action: 'Edit Condition', + actionFunction: uiObject.conditionEditor.activate, + label: 'Edit Condition', + visible: true, + iconPathOn: 'html', + iconPathOff: 'html', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: -60, + dontShowAtFullscreen: true + } + ) menuItemsInitialValues.push( { action: 'Add Code', @@ -4585,7 +4605,7 @@ function newUiObjectConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: -40 + angle: -20 } ) menuItemsInitialValues.push( @@ -4601,7 +4621,7 @@ function newUiObjectConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: 0 + angle: 20 } ) menuItemsInitialValues.push( @@ -4615,7 +4635,7 @@ function newUiObjectConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: 40 + angle: 60 } ) break From 58d48edfa6ee30f3e9d174440787ee1f21bc2b6b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 6 Dec 2019 18:06:56 +0100 Subject: [PATCH 32/41] Refactoring Code for Javascript Code --- .../FunctionLibraries/ChainAttachDetach.js | 4 ++-- .../Workspace/FunctionLibraries/NodeChildren.js | 2 +- .../Workspace/FunctionLibraries/NodeDeleter.js | 2 +- .../Workspace/FunctionLibraries/OnFocus.js | 2 +- .../Workspace/FunctionLibraries/ProtocolNode.js | 2 +- .../Workspace/FunctionLibraries/ShortcutKeys.js | 2 +- .../FunctionLibraries/UiObjectsFromNodes.js | 8 ++++---- FloatingSpace/CodeEditor.js | 3 +-- FloatingSpace/ConditionEditor.js | 3 +-- FloatingSpace/ConfigEditor.js | 3 +-- FloatingSpace/FormulaEditor.js | 3 +-- FloatingSpace/UiObject.js | 4 ++-- FloatingSpace/UiObjectConstructor.js | 14 +++++++------- Spaces/DesignerSpace.js | 2 +- 14 files changed, 25 insertions(+), 29 deletions(-) diff --git a/DesignerSpace/Workspace/FunctionLibraries/ChainAttachDetach.js b/DesignerSpace/Workspace/FunctionLibraries/ChainAttachDetach.js index 768153f6a..37a3b8baf 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/ChainAttachDetach.js +++ b/DesignerSpace/Workspace/FunctionLibraries/ChainAttachDetach.js @@ -501,7 +501,7 @@ function newChainAttachDetach () { completeDetachment(node, rootNodes) return } - case 'Code': { + case 'Javascript Code': { node.payload.parentNode.code = undefined completeDetachment(node, rootNodes) return @@ -1100,7 +1100,7 @@ function newChainAttachDetach () { completeAttachment(node, rootNodes) } break - case 'Code': { + case 'Javascript Code': { node.payload.parentNode = attachToNode node.payload.chainParent = attachToNode node.payload.parentNode.code = node diff --git a/DesignerSpace/Workspace/FunctionLibraries/NodeChildren.js b/DesignerSpace/Workspace/FunctionLibraries/NodeChildren.js index f96277c64..e1e95e554 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/NodeChildren.js +++ b/DesignerSpace/Workspace/FunctionLibraries/NodeChildren.js @@ -227,7 +227,7 @@ function newNodeChildren () { case 'Condition': { return countChildrenCondition(parentNode, childNode) } - case 'Code': { + case 'Javascript Code': { return countChildrenCode(parentNode, childNode) } default: { diff --git a/DesignerSpace/Workspace/FunctionLibraries/NodeDeleter.js b/DesignerSpace/Workspace/FunctionLibraries/NodeDeleter.js index 1435c1a90..c2a987ba3 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/NodeDeleter.js +++ b/DesignerSpace/Workspace/FunctionLibraries/NodeDeleter.js @@ -372,7 +372,7 @@ function newNodeDeleter () { deleteCondition(rootNode, rootNodes) break } - case 'Code': { + case 'Javascript Code': { deleteCode(rootNode, rootNodes) break } diff --git a/DesignerSpace/Workspace/FunctionLibraries/OnFocus.js b/DesignerSpace/Workspace/FunctionLibraries/OnFocus.js index d3633c3d7..353eb3723 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/OnFocus.js +++ b/DesignerSpace/Workspace/FunctionLibraries/OnFocus.js @@ -7,7 +7,7 @@ function newOnFocus () { function getNodeThatIsOnFocus (node) { if (node === undefined) { return } switch (node.type) { - case 'Code': + case 'Javascript Code': { if (node.payload.uiObject.isOnFocus === true) { return node diff --git a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js index 3ed3c191b..328100cc0 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js +++ b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js @@ -7,7 +7,7 @@ function newProtocolNode () { function getProtocolNode (node, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) { if (node === undefined) { return } switch (node.type) { - case 'Code': + case 'Javascript Code': { let object = { type: node.type, diff --git a/DesignerSpace/Workspace/FunctionLibraries/ShortcutKeys.js b/DesignerSpace/Workspace/FunctionLibraries/ShortcutKeys.js index 874f93f29..31e3c7070 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/ShortcutKeys.js +++ b/DesignerSpace/Workspace/FunctionLibraries/ShortcutKeys.js @@ -7,7 +7,7 @@ function newShortcutKeys () { function getNodeByShortcutKey (node, searchingKey) { if (node === undefined) { return } switch (node.type) { - case 'Code': + case 'Javascript Code': { if (node.payload.uiObject.shortcutKey === searchingKey) { return node diff --git a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js index 3552d6552..356cdfa59 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js +++ b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js @@ -110,9 +110,9 @@ function newUiObjectsFromNodes () { function createUiObjectFromNode (node, parentNode, chainParent, positionOffset) { switch (node.type) { - case 'Code': + case 'Javascript Code': { - createUiObject(false, 'Code', node.name, node, parentNode, chainParent, 'Code', positionOffset) + createUiObject(false, 'Javascript Code', node.name, node, parentNode, chainParent, 'Javascript Code', positionOffset) return } case 'Condition': @@ -2033,7 +2033,7 @@ function newUiObjectsFromNodes () { node.code = { code: DEFAULT_CODE_TEXT } - createUiObject(true, 'Code', '', node.code, node, node) + createUiObject(true, 'Javascript Code', '', node.code, node, node) } return node.code @@ -2099,7 +2099,7 @@ function newUiObjectsFromNodes () { } situation.conditions.push(condition) createUiObject(true, 'Condition', condition.name, condition, situation, situation, 'Condition') - createUiObject(true, 'Code', '', condition.code, condition, condition, 'Code') + createUiObject(true, 'Javascript Code', '', condition.code, condition, condition, 'Javascript Code') return condition } diff --git a/FloatingSpace/CodeEditor.js b/FloatingSpace/CodeEditor.js index 4c40de669..2770294ce 100644 --- a/FloatingSpace/CodeEditor.js +++ b/FloatingSpace/CodeEditor.js @@ -71,7 +71,7 @@ function newCodeEditor () { let textArea = document.getElementById('textArea') textArea.style.display = 'none' thisObject.payload.node.code = textArea.value - if (thisObject.payload.node.type !== 'Code' && thisObject.payload.node.type !== 'Formula') { + if (thisObject.payload.node.type !== 'Javascript Code' && thisObject.payload.node.type !== 'Formula') { try { let code = JSON.parse(thisObject.payload.node.code) } catch (err) { @@ -220,4 +220,3 @@ function newCodeEditor () { } } } - diff --git a/FloatingSpace/ConditionEditor.js b/FloatingSpace/ConditionEditor.js index b9463357e..859c58b6f 100644 --- a/FloatingSpace/ConditionEditor.js +++ b/FloatingSpace/ConditionEditor.js @@ -71,7 +71,7 @@ function newConditionEditor () { let textArea = document.getElementById('textArea') textArea.style.display = 'none' thisObject.payload.node.code = textArea.value - if (thisObject.payload.node.type !== 'Code' && thisObject.payload.node.type !== 'Formula') { + if (thisObject.payload.node.type !== 'Javascript Code' && thisObject.payload.node.type !== 'Formula') { try { let code = JSON.parse(thisObject.payload.node.code) } catch (err) { @@ -220,4 +220,3 @@ function newConditionEditor () { } } } - diff --git a/FloatingSpace/ConfigEditor.js b/FloatingSpace/ConfigEditor.js index 0d5ce7bba..34ba77931 100644 --- a/FloatingSpace/ConfigEditor.js +++ b/FloatingSpace/ConfigEditor.js @@ -71,7 +71,7 @@ function newConfigEditor () { let textArea = document.getElementById('textArea') textArea.style.display = 'none' thisObject.payload.node.code = textArea.value - if (thisObject.payload.node.type !== 'Code' && thisObject.payload.node.type !== 'Formula') { + if (thisObject.payload.node.type !== 'Javascript Code' && thisObject.payload.node.type !== 'Formula') { try { let code = JSON.parse(thisObject.payload.node.code) } catch (err) { @@ -220,4 +220,3 @@ function newConfigEditor () { } } } - diff --git a/FloatingSpace/FormulaEditor.js b/FloatingSpace/FormulaEditor.js index 6eeb20f92..18bbdbde8 100644 --- a/FloatingSpace/FormulaEditor.js +++ b/FloatingSpace/FormulaEditor.js @@ -71,7 +71,7 @@ function newFormulaEditor () { let textArea = document.getElementById('textArea') textArea.style.display = 'none' thisObject.payload.node.code = textArea.value - if (thisObject.payload.node.type !== 'Code' && thisObject.payload.node.type !== 'Formula') { + if (thisObject.payload.node.type !== 'Javascript Code' && thisObject.payload.node.type !== 'Formula') { try { let code = JSON.parse(thisObject.payload.node.code) } catch (err) { @@ -220,4 +220,3 @@ function newFormulaEditor () { } } } - diff --git a/FloatingSpace/UiObject.js b/FloatingSpace/UiObject.js index 677af7a48..402248e41 100644 --- a/FloatingSpace/UiObject.js +++ b/FloatingSpace/UiObject.js @@ -550,7 +550,7 @@ function newUiObject () { compatibleType = '->' + 'Situation' + '->' compatibleSubType = undefined break - case 'Code': + case 'Javascript Code': compatibleType = '->' + 'Condition' + '->' + 'Procedure Initialization' + '->' + 'Procedure Loop' + '->' + 'Plotter Module' + '->' + 'Plotter Panel' + '->' compatibleSubType = undefined break @@ -609,7 +609,7 @@ function newUiObject () { if (thisObject.payload.node.type === 'Take Profit' && nearbyNode.takeProfit !== undefined) { continue } if (thisObject.payload.node.type === 'Formula' && nearbyNode.formula !== undefined) { continue } if (thisObject.payload.node.type === 'Next Phase Event' && nearbyNode.nextPhaseEvent !== undefined) { continue } - if (thisObject.payload.node.type === 'Code' && nearbyNode.code !== undefined) { continue } + if (thisObject.payload.node.type === 'Javascript Code' && nearbyNode.code !== undefined) { continue } /* Here we check if the subtypes are compatible. */ if (nearbyNode.subType !== undefined && compatibleSubType !== undefined) { if (compatibleSubType.indexOf('->' + nearbyNode.subType + '->') < 0) { diff --git a/FloatingSpace/UiObjectConstructor.js b/FloatingSpace/UiObjectConstructor.js index 8b86dfbc8..99dec544b 100644 --- a/FloatingSpace/UiObjectConstructor.js +++ b/FloatingSpace/UiObjectConstructor.js @@ -1067,7 +1067,7 @@ function newUiObjectConstructor () { actionFunction: payload.onMenuItemClick, label: 'Add Code', visible: true, - relatedUiObject: 'Code', + relatedUiObject: 'Javascript Code', rawRadius: 8, targetRadius: 0, currentRadius: 0, @@ -1116,7 +1116,7 @@ function newUiObjectConstructor () { actionFunction: payload.onMenuItemClick, label: 'Add Code', visible: true, - relatedUiObject: 'Code', + relatedUiObject: 'Javascript Code', rawRadius: 8, targetRadius: 0, currentRadius: 0, @@ -1633,7 +1633,7 @@ function newUiObjectConstructor () { actionFunction: payload.onMenuItemClick, label: 'Add Code', visible: true, - relatedUiObject: 'Code', + relatedUiObject: 'Javascript Code', rawRadius: 8, targetRadius: 0, currentRadius: 0, @@ -1695,7 +1695,7 @@ function newUiObjectConstructor () { actionFunction: payload.onMenuItemClick, label: 'Add Code', visible: true, - relatedUiObject: 'Code', + relatedUiObject: 'Javascript Code', rawRadius: 8, targetRadius: 0, currentRadius: 0, @@ -4601,7 +4601,7 @@ function newUiObjectConstructor () { actionFunction: payload.onMenuItemClick, label: 'Add Code', visible: true, - relatedUiObject: 'Code', + relatedUiObject: 'Javascript Code', rawRadius: 8, targetRadius: 0, currentRadius: 0, @@ -4640,7 +4640,7 @@ function newUiObjectConstructor () { ) break } - case 'Code': { + case 'Javascript Code': { uiObject.codeEditor = newCodeEditor() uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction uiObject.codeEditor.initialize() @@ -5003,7 +5003,7 @@ function newUiObjectConstructor () { level_5() break } - case 'Code': { + case 'Javascript Code': { level_5() break } diff --git a/Spaces/DesignerSpace.js b/Spaces/DesignerSpace.js index ba1413c04..4d2c4764c 100644 --- a/Spaces/DesignerSpace.js +++ b/Spaces/DesignerSpace.js @@ -86,7 +86,7 @@ function newDesignerSpace () { ['Next Phase Event', 'pantone'], ['Situation', 'pyramid'], ['Condition', 'testing'], - ['Code', 'html'], + ['Javascript Code', 'html'], ['Team', 'team'], ['Sensor Bot', 'bot-sensor'], ['Indicator Bot', 'bot-indicator'], From a499dc24773373458cb26c29b40acf5d482097fc Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 6 Dec 2019 20:33:16 +0100 Subject: [PATCH 33/41] Javascript Code with its own property javascriptCode --- .../FunctionLibraries/ChainAttachDetach.js | 4 +-- .../FunctionLibraries/NodeChildren.js | 4 +-- .../FunctionLibraries/NodeDeleter.js | 24 ++++++------- .../FunctionLibraries/ProtocolNode.js | 10 +++--- .../FunctionLibraries/UiObjectsFromNodes.js | 35 +++++++++++-------- DesignerSpace/Workspace/Workspace.js | 4 +-- FloatingSpace/CodeEditor.js | 7 ---- FloatingSpace/ConditionEditor.js | 7 ---- FloatingSpace/ConfigEditor.js | 11 +++--- FloatingSpace/FormulaEditor.js | 7 ---- FloatingSpace/UiObject.js | 2 +- Panels/PlotterPanel.js | 2 +- Panels/ProductsPanel.js | 4 +-- Plotter.js | 14 ++++---- 14 files changed, 59 insertions(+), 76 deletions(-) diff --git a/DesignerSpace/Workspace/FunctionLibraries/ChainAttachDetach.js b/DesignerSpace/Workspace/FunctionLibraries/ChainAttachDetach.js index 37a3b8baf..e4c5e9e04 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/ChainAttachDetach.js +++ b/DesignerSpace/Workspace/FunctionLibraries/ChainAttachDetach.js @@ -502,7 +502,7 @@ function newChainAttachDetach () { return } case 'Javascript Code': { - node.payload.parentNode.code = undefined + node.payload.parentNode.javascriptCode = undefined completeDetachment(node, rootNodes) return } @@ -1103,7 +1103,7 @@ function newChainAttachDetach () { case 'Javascript Code': { node.payload.parentNode = attachToNode node.payload.chainParent = attachToNode - node.payload.parentNode.code = node + node.payload.parentNode.javascriptCode = node completeAttachment(node, rootNodes) } break diff --git a/DesignerSpace/Workspace/FunctionLibraries/NodeChildren.js b/DesignerSpace/Workspace/FunctionLibraries/NodeChildren.js index e1e95e554..1eb525cd0 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/NodeChildren.js +++ b/DesignerSpace/Workspace/FunctionLibraries/NodeChildren.js @@ -228,7 +228,7 @@ function newNodeChildren () { return countChildrenCondition(parentNode, childNode) } case 'Javascript Code': { - return countChildrenCode(parentNode, childNode) + return countChildrenJavascriptCode(parentNode, childNode) } default: { console.log('WARNING this parentNode type is not listed at NodeChildren: ' + parentNode.type) @@ -1483,7 +1483,7 @@ function newNodeChildren () { return response } - function countChildrenCode (parentNode, childNode) { + function countChildrenJavascriptCode (parentNode, childNode) { let response = { childrenCount: 0, childIndex: undefined diff --git a/DesignerSpace/Workspace/FunctionLibraries/NodeDeleter.js b/DesignerSpace/Workspace/FunctionLibraries/NodeDeleter.js index c2a987ba3..da06b462f 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/NodeDeleter.js +++ b/DesignerSpace/Workspace/FunctionLibraries/NodeDeleter.js @@ -69,7 +69,7 @@ function newNodeDeleter () { deleteFormula: deleteFormula, deleteSituation: deleteSituation, deleteCondition: deleteCondition, - deleteCode: deleteCode + deleteJavascriptCode: deleteJavascriptCode } return thisObject @@ -373,7 +373,7 @@ function newNodeDeleter () { break } case 'Javascript Code': { - deleteCode(rootNode, rootNodes) + deleteJavascriptCode(rootNode, rootNodes) break } @@ -733,8 +733,8 @@ function newNodeDeleter () { payload.parentNode.loop = undefined } - if (node.code !== undefined) { - deleteCode(node.code, rootNodes) + if (node.javascriptCode !== undefined) { + deleteJavascriptCode(node.javascriptCode, rootNodes) } completeDeletion(node, rootNodes) @@ -919,8 +919,8 @@ function newNodeDeleter () { } } - if (node.code !== undefined) { - deleteCode(node.code, rootNodes) + if (node.javascriptCode !== undefined) { + deleteJavascriptCode(node.javascriptCode, rootNodes) } if (node.panels !== undefined) { @@ -946,8 +946,8 @@ function newNodeDeleter () { } } - if (node.code !== undefined) { - deleteCode(node.code, rootNodes) + if (node.javascriptCode !== undefined) { + deleteJavascriptCode(node.javascriptCode, rootNodes) } completeDeletion(node, rootNodes) @@ -1697,17 +1697,17 @@ function newNodeDeleter () { } else { completeDeletion(node, rootNodes) } - if (node.code !== undefined) { - deleteCode(node.code, rootNodes) + if (node.javascriptCode !== undefined) { + deleteJavascriptCode(node.javascriptCode, rootNodes) } destroyUiObject(node) cleanNode(node) } - function deleteCode (node, rootNodes) { + function deleteJavascriptCode (node, rootNodes) { let payload = node.payload if (payload.parentNode !== undefined) { - payload.parentNode.code = undefined + payload.parentNode.javascriptCode = undefined } else { completeDeletion(node, rootNodes) } diff --git a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js index 328100cc0..72d5389f0 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js +++ b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js @@ -29,7 +29,7 @@ function newProtocolNode () { type: node.type, subType: node.subType, name: node.name, - code: getProtocolNode(node.code, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) + javascriptCode: getProtocolNode(node.javascriptCode, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) } if (includeIds) { object.id = node.id @@ -1402,7 +1402,7 @@ function newProtocolNode () { type: node.type, subType: node.subType, name: node.name, - code: getProtocolNode(node.code, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) + javascriptCode: getProtocolNode(node.javascriptCode, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) } if (includeIds) { object.id = node.id @@ -1417,7 +1417,7 @@ function newProtocolNode () { type: node.type, subType: node.subType, name: node.name, - code: getProtocolNode(node.code, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) + javascriptCode: getProtocolNode(node.javascriptCode, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) } if (includeIds) { object.id = node.id @@ -1617,7 +1617,7 @@ function newProtocolNode () { type: node.type, subType: node.subType, name: node.name, - code: getProtocolNode(node.code, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType), + javascriptCode: getProtocolNode(node.javascriptCode, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType), panels: [] } if (includeParent) { @@ -1646,7 +1646,7 @@ function newProtocolNode () { type: node.type, subType: node.subType, name: node.name, - code: getProtocolNode(node.code, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) + javascriptCode: getProtocolNode(node.javascriptCode, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) } if (includeIds) { object.id = node.id diff --git a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js index 356cdfa59..9617118a6 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js +++ b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js @@ -65,7 +65,7 @@ function newUiObjectsFromNodes () { addNextPhaseEvent: addNextPhaseEvent, addSituation: addSituation, addCondition: addCondition, - addCode: addCode + addJavascriptCode: addJavascriptCode } let mapOfReferenceParents @@ -118,8 +118,9 @@ function newUiObjectsFromNodes () { case 'Condition': { createUiObject(false, 'Condition', node.name, node, parentNode, chainParent, 'Condition', positionOffset) - if (node.code !== undefined) { - createUiObjectFromNode(node.code, node, node, positionOffset) + + if (node.javascriptCode !== undefined) { + createUiObjectFromNode(node.javascriptCode, node, node, positionOffset) } return } @@ -898,15 +899,17 @@ function newUiObjectsFromNodes () { } case 'Procedure Initialization': { createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) - if (node.code !== undefined) { - createUiObjectFromNode(node.code, node, node, positionOffset) + + if (node.javascriptCode !== undefined) { + createUiObjectFromNode(node.javascriptCode, node, node, positionOffset) } return } case 'Procedure Loop': { createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) - if (node.code !== undefined) { - createUiObjectFromNode(node.code, node, node, positionOffset) + + if (node.javascriptCode !== undefined) { + createUiObjectFromNode(node.javascriptCode, node, node, positionOffset) } return } @@ -1047,8 +1050,9 @@ function newUiObjectsFromNodes () { } } createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) - if (node.code !== undefined) { - createUiObjectFromNode(node.code, node, node, positionOffset) + + if (node.javascriptCode !== undefined) { + createUiObjectFromNode(node.javascriptCode, node, node, positionOffset) } for (let m = 0; m < node.panels.length; m++) { let panel = node.panels[m] @@ -1065,8 +1069,9 @@ function newUiObjectsFromNodes () { } case 'Plotter Panel': { createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) - if (node.code !== undefined) { - createUiObjectFromNode(node.code, node, node, positionOffset) + + if (node.javascriptCode !== undefined) { + createUiObjectFromNode(node.javascriptCode, node, node, positionOffset) } return } @@ -2028,15 +2033,15 @@ function newUiObjectsFromNodes () { return node.nextPhaseEvent } - function addCode (node) { - if (node.code === undefined) { - node.code = { + function addJavascriptCode (node) { + if (node.javascriptCode === undefined) { + node.javascriptCode = { code: DEFAULT_CODE_TEXT } createUiObject(true, 'Javascript Code', '', node.code, node, node) } - return node.code + return node.javascriptCode } function addPhase (parentNode) { diff --git a/DesignerSpace/Workspace/Workspace.js b/DesignerSpace/Workspace/Workspace.js index 428952428..f00e90f40 100644 --- a/DesignerSpace/Workspace/Workspace.js +++ b/DesignerSpace/Workspace/Workspace.js @@ -637,7 +637,7 @@ function newWorkspace () { break case 'Add Code': { - functionLibraryUiObjectsFromNodes.addCode(payload.node) + functionLibraryUiObjectsFromNodes.addJavascriptCode(payload.node) } break case 'Add Exchange Account': @@ -922,7 +922,7 @@ function newWorkspace () { break } case 'Delete Code': { - functionLibraryNodeDeleter.deleteCode(payload.node, thisObject.workspaceNode.rootNodes) + functionLibraryNodeDeleter.deleteJavascriptCode(payload.node, thisObject.workspaceNode.rootNodes) break } case 'Delete Exchange Account': { diff --git a/FloatingSpace/CodeEditor.js b/FloatingSpace/CodeEditor.js index 2770294ce..cffba932a 100644 --- a/FloatingSpace/CodeEditor.js +++ b/FloatingSpace/CodeEditor.js @@ -71,13 +71,6 @@ function newCodeEditor () { let textArea = document.getElementById('textArea') textArea.style.display = 'none' thisObject.payload.node.code = textArea.value - if (thisObject.payload.node.type !== 'Javascript Code' && thisObject.payload.node.type !== 'Formula') { - try { - let code = JSON.parse(thisObject.payload.node.code) - } catch (err) { - thisObject.payload.uiObject.setErrorMessage(err.message, 10) - } - } } } diff --git a/FloatingSpace/ConditionEditor.js b/FloatingSpace/ConditionEditor.js index 859c58b6f..373c5def7 100644 --- a/FloatingSpace/ConditionEditor.js +++ b/FloatingSpace/ConditionEditor.js @@ -71,13 +71,6 @@ function newConditionEditor () { let textArea = document.getElementById('textArea') textArea.style.display = 'none' thisObject.payload.node.code = textArea.value - if (thisObject.payload.node.type !== 'Javascript Code' && thisObject.payload.node.type !== 'Formula') { - try { - let code = JSON.parse(thisObject.payload.node.code) - } catch (err) { - thisObject.payload.uiObject.setErrorMessage(err.message, 10) - } - } } } diff --git a/FloatingSpace/ConfigEditor.js b/FloatingSpace/ConfigEditor.js index 34ba77931..17fbd8818 100644 --- a/FloatingSpace/ConfigEditor.js +++ b/FloatingSpace/ConfigEditor.js @@ -71,12 +71,11 @@ function newConfigEditor () { let textArea = document.getElementById('textArea') textArea.style.display = 'none' thisObject.payload.node.code = textArea.value - if (thisObject.payload.node.type !== 'Javascript Code' && thisObject.payload.node.type !== 'Formula') { - try { - let code = JSON.parse(thisObject.payload.node.code) - } catch (err) { - thisObject.payload.uiObject.setErrorMessage(err.message, 10) - } + + try { + let code = JSON.parse(thisObject.payload.node.code) + } catch (err) { + thisObject.payload.uiObject.setErrorMessage(err.message, 10) } } } diff --git a/FloatingSpace/FormulaEditor.js b/FloatingSpace/FormulaEditor.js index 18bbdbde8..f2e805485 100644 --- a/FloatingSpace/FormulaEditor.js +++ b/FloatingSpace/FormulaEditor.js @@ -71,13 +71,6 @@ function newFormulaEditor () { let textArea = document.getElementById('textArea') textArea.style.display = 'none' thisObject.payload.node.code = textArea.value - if (thisObject.payload.node.type !== 'Javascript Code' && thisObject.payload.node.type !== 'Formula') { - try { - let code = JSON.parse(thisObject.payload.node.code) - } catch (err) { - thisObject.payload.uiObject.setErrorMessage(err.message, 10) - } - } } } diff --git a/FloatingSpace/UiObject.js b/FloatingSpace/UiObject.js index 402248e41..50eb1d391 100644 --- a/FloatingSpace/UiObject.js +++ b/FloatingSpace/UiObject.js @@ -609,7 +609,7 @@ function newUiObject () { if (thisObject.payload.node.type === 'Take Profit' && nearbyNode.takeProfit !== undefined) { continue } if (thisObject.payload.node.type === 'Formula' && nearbyNode.formula !== undefined) { continue } if (thisObject.payload.node.type === 'Next Phase Event' && nearbyNode.nextPhaseEvent !== undefined) { continue } - if (thisObject.payload.node.type === 'Javascript Code' && nearbyNode.code !== undefined) { continue } + if (thisObject.payload.node.type === 'Javascript Code' && nearbyNode.javascriptCode !== undefined) { continue } /* Here we check if the subtypes are compatible. */ if (nearbyNode.subType !== undefined && compatibleSubType !== undefined) { if (compatibleSubType.indexOf('->' + nearbyNode.subType + '->') < 0) { diff --git a/Panels/PlotterPanel.js b/Panels/PlotterPanel.js index abe7f0dee..493c41a05 100644 --- a/Panels/PlotterPanel.js +++ b/Panels/PlotterPanel.js @@ -88,7 +88,7 @@ function newPlotterPanel () { if (currentRecord.data === undefined) { return } try { - eval(panelNode.code.code) + eval(panelNode.javascriptCode.code) } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err.stack) } } diff --git a/Panels/ProductsPanel.js b/Panels/ProductsPanel.js index c38f46096..a7f3f5213 100644 --- a/Panels/ProductsPanel.js +++ b/Panels/ProductsPanel.js @@ -159,8 +159,8 @@ function newProductsPanel () { continue } - if (plotterModuleNode.code === undefined) { continue } - if (plotterModuleNode.code.code === undefined) { continue } + if (plotterModuleNode.javascriptCode === undefined) { continue } + if (plotterModuleNode.javascriptCode.code === undefined) { continue } /* Conversion to fit old format */ product.plotter = plotter diff --git a/Plotter.js b/Plotter.js index 28dd82efd..de33a8f26 100644 --- a/Plotter.js +++ b/Plotter.js @@ -270,12 +270,12 @@ function newPlotter () { /* This is Initialization Code */ if (calculationsProcedure.initialization !== undefined) { - if (calculationsProcedure.initialization.code !== undefined) { + if (calculationsProcedure.initialization.javascriptCode !== undefined) { try { - eval(calculationsProcedure.initialization.code.code) + eval(calculationsProcedure.initialization.javascriptCode.code) } catch (err) { logger.write('[ERROR] calculationsProcedure -> initialization -> Error executing User Code. Error = ' + err.stack) - logger.write('[ERROR] calculationsProcedure -> initialization -> Error executing User Code. Code = ' + calculationsProcedure.initialization.code.code) + logger.write('[ERROR] calculationsProcedure -> initialization -> Error executing User Code. Code = ' + calculationsProcedure.initialization.javascriptCode.code) throw ('Error Executing User Code.') } } @@ -283,17 +283,17 @@ function newPlotter () { /* This is Initialization Code */ if (calculationsProcedure.loop !== undefined) { - if (calculationsProcedure.loop.code !== undefined) { + if (calculationsProcedure.loop.javascriptCode !== undefined) { for (let index = 0; index < jsonArray.length; index++) { let product = jsonArray[index] /* This is Loop Code */ try { - eval(calculationsProcedure.loop.code.code) + eval(calculationsProcedure.loop.javascriptCode.code) } catch (err) { logger.write('[ERROR] calculationsProcedure -> loop -> Error executing User Code. Error = ' + err.stack) logger.write('[ERROR] calculationsProcedure -> loop -> Error executing User Code. product = ' + JSON.stringify(product)) - logger.write('[ERROR] calculationsProcedure -> loop -> Error executing User Code. Code = ' + calculationsProcedure.loop.code.code) + logger.write('[ERROR] calculationsProcedure -> loop -> Error executing User Code. Code = ' + calculationsProcedure.loop.javascriptCode.code) throw ('Error Executing User Code.') } @@ -480,7 +480,7 @@ function newPlotter () { thisObject.container.eventHandler.raiseEvent('Current Record Changed', currentRecord) } - eval(productDefinition.referenceParent.code.code) + eval(productDefinition.referenceParent.javascriptCode.code) } } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] plotChart -> err = ' + err) } From 70b226456cf249c268715cc97987bc54724bb43c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 7 Dec 2019 08:00:14 +0100 Subject: [PATCH 34/41] Bug fixed with frozen objects on focus --- FloatingSpace/FloatingLayer.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/FloatingSpace/FloatingLayer.js b/FloatingSpace/FloatingLayer.js index dd8d078ee..3d2bef34f 100644 --- a/FloatingSpace/FloatingLayer.js +++ b/FloatingSpace/FloatingLayer.js @@ -170,11 +170,6 @@ function newFloatingLayer () { let floatingObject = invisibleFloatingObjects[invisibleFloatingObjects.length - i - 1] floatingObject.drawForeground() } - - for (let i = 0; i < invisibleFloatingObjects.length; i++) { - let floatingObject = invisibleFloatingObjects[i] - floatingObject.drawOnFocus() - } } function drawVisibleObjects () { @@ -193,6 +188,12 @@ function newFloatingLayer () { floatingObject.drawForeground() } + /* Invisible objects on focus (freezed) should still have some priority */ + for (let i = 0; i < invisibleFloatingObjects.length; i++) { + let floatingObject = invisibleFloatingObjects[i] + floatingObject.drawOnFocus() + } + for (let i = 0; i < visibleFloatingObjects.length; i++) { let floatingObject = visibleFloatingObjects[i] floatingObject.drawOnFocus() From 3f6afde7ea97bcd64a9fb9394797c7556243eef5 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 7 Dec 2019 10:45:51 +0100 Subject: [PATCH 35/41] Bug Fixed --- .../Workspace/FunctionLibraries/ProtocolNode.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js index 72d5389f0..61af86981 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js +++ b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js @@ -1596,14 +1596,17 @@ function newProtocolNode () { code: node.code, modules: [] } - if (node.modules !== undefined) { - for (let m = 0; m < node.modules.length; m++) { - let module = getProtocolNode(node.modules[m], removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) - if (module !== undefined) { - object.modules.push(module) + if (excludeChildren !== true) { + if (node.modules !== undefined) { + for (let m = 0; m < node.modules.length; m++) { + let module = getProtocolNode(node.modules[m], removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) + if (module !== undefined) { + object.modules.push(module) + } } } } + if (includeIds) { object.id = node.id } From 128d03d25af4380a0a40639f8fdd1d98def7e577 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 7 Dec 2019 11:11:36 +0100 Subject: [PATCH 36/41] Getting info from the config of the plotter module --- .../Workspace/FunctionLibraries/ProtocolNode.js | 1 + Panels/ProductsPanel.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js index 61af86981..504d5388e 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js +++ b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js @@ -1620,6 +1620,7 @@ function newProtocolNode () { type: node.type, subType: node.subType, name: node.name, + code: node.code, javascriptCode: getProtocolNode(node.javascriptCode, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType), panels: [] } diff --git a/Panels/ProductsPanel.js b/Panels/ProductsPanel.js index a7f3f5213..042560c73 100644 --- a/Panels/ProductsPanel.js +++ b/Panels/ProductsPanel.js @@ -126,14 +126,14 @@ function newProductsPanel () { if (productNode.payload.referenceParent === undefined) { continue } let plotterModuleNode = productNode.payload.referenceParent - let plotterModule = {}// Provitional code until CODE desambiguation is done. - // if (plotterModuleNode.code === undefined) { continue } - // try { - // let code = JSON.parse(plotterModuleNode.code) - plotterModule.codeName = plotterModuleNode.name // code.codeName - // } catch (err) { - // continue - // } + let plotterModule = {} + if (plotterModuleNode.code === undefined) { continue } + try { + let code = JSON.parse(plotterModuleNode.code) + plotterModule.codeName = code.codeName + } catch (err) { + continue + } if (plotterModuleNode.payload.parentNode === undefined) { continue } let plotterNode = plotterModuleNode.payload.parentNode From 9eacd5ab0a27afb03b8ebc60b90dc34b7f869482 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 7 Dec 2019 12:09:56 +0100 Subject: [PATCH 37/41] App Schema Map done --- Dashboard.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Dashboard.js b/Dashboard.js index 5e0d85852..928c876ef 100644 --- a/Dashboard.js +++ b/Dashboard.js @@ -3,6 +3,7 @@ let markets let ecosystem = newEcosystem() let systemEventHandler let viewPort +let APP_SCHEMA = new Map() function newDashboard () { const MODULE_NAME = 'Dashboard' @@ -29,7 +30,23 @@ function newDashboard () { viewPort = newViewPort() systemEventHandler = newSystemEventHandler() - systemEventHandler.initialize(startCanvas) + systemEventHandler.initialize(setUpAppSchema) + + function setUpAppSchema () { + let schemaArray = getAppSchema() + for (let i = 0; i < schemaArray.length; i++) { + let nodeDefinition = schemaArray[i] + let key + if (nodeDefinition.subType !== undefined) { + key = nodeDefinition.type + '-' + nodeDefinition.subType + } else { + key = nodeDefinition.type + } + APP_SCHEMA.set(key, nodeDefinition) + } + console.log(APP_SCHEMA) + startCanvas() + } function startCanvas () { /* If this method is executed for a second time, it should finalize the current execution structure */ From 09416fc474c6096326fa523f25d988a331c7e379 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 7 Dec 2019 12:47:53 +0100 Subject: [PATCH 38/41] Icon definition at schema implemented --- Dashboard.js | 14 +++++++------- FloatingSpace/CircularMenuItem.js | 1 + FloatingSpace/UiObjectConstructor.js | 23 ++++++++++++++++++----- Spaces/DesignerSpace.js | 7 +++++++ 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Dashboard.js b/Dashboard.js index 928c876ef..ff9e3d493 100644 --- a/Dashboard.js +++ b/Dashboard.js @@ -3,7 +3,8 @@ let markets let ecosystem = newEcosystem() let systemEventHandler let viewPort -let APP_SCHEMA = new Map() +let APP_SCHEMA_MAP = new Map() +let APP_SCHEMA_ARRAY = [] function newDashboard () { const MODULE_NAME = 'Dashboard' @@ -33,18 +34,18 @@ function newDashboard () { systemEventHandler.initialize(setUpAppSchema) function setUpAppSchema () { - let schemaArray = getAppSchema() - for (let i = 0; i < schemaArray.length; i++) { - let nodeDefinition = schemaArray[i] + APP_SCHEMA_ARRAY = getAppSchema() + for (let i = 0; i < APP_SCHEMA_ARRAY.length; i++) { + let nodeDefinition = APP_SCHEMA_ARRAY[i] let key if (nodeDefinition.subType !== undefined) { key = nodeDefinition.type + '-' + nodeDefinition.subType } else { key = nodeDefinition.type } - APP_SCHEMA.set(key, nodeDefinition) + APP_SCHEMA_MAP.set(key, nodeDefinition) } - console.log(APP_SCHEMA) + console.log(APP_SCHEMA_MAP) startCanvas() } @@ -127,4 +128,3 @@ function newDashboard () { } } } - diff --git a/FloatingSpace/CircularMenuItem.js b/FloatingSpace/CircularMenuItem.js index 7f9c93cbd..a473124d7 100644 --- a/FloatingSpace/CircularMenuItem.js +++ b/FloatingSpace/CircularMenuItem.js @@ -382,6 +382,7 @@ function newCircularMenuItem () { iconSize = thisObject.currentRadius } + if (thisObject.icon === undefined) { return } if (thisObject.icon.canDrawIcon === true && thisObject.currentRadius > 1 && thisObject.isDeployed === true) { browserCanvasContext.drawImage(thisObject.icon, menuPosition.x - iconSize, menuPosition.y - iconSize, iconSize * 2, iconSize * 2) diff --git a/FloatingSpace/UiObjectConstructor.js b/FloatingSpace/UiObjectConstructor.js index 99dec544b..d0dff925c 100644 --- a/FloatingSpace/UiObjectConstructor.js +++ b/FloatingSpace/UiObjectConstructor.js @@ -1621,7 +1621,7 @@ function newUiObjectConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: -40, + angle: -50, dontShowAtFullscreen: true } ) @@ -1637,9 +1637,22 @@ function newUiObjectConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: -20 + angle: -30 } ) + menuItemsInitialValues.push( + { + action: 'Add Shapes', + actionFunction: payload.onMenuItemClick, + label: 'Add Shapes', + visible: true, + relatedUiObject: 'Shapes', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: -10 + } + ) menuItemsInitialValues.push( { action: 'Add Plotter Panel', @@ -1650,7 +1663,7 @@ function newUiObjectConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: 0 + angle: 10 } ) menuItemsInitialValues.push( @@ -1666,7 +1679,7 @@ function newUiObjectConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: 20 + angle: 30 } ) menuItemsInitialValues.push( @@ -1680,7 +1693,7 @@ function newUiObjectConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: 40 + angle: 50 } ) break diff --git a/Spaces/DesignerSpace.js b/Spaces/DesignerSpace.js index 4d2c4764c..b06dec154 100644 --- a/Spaces/DesignerSpace.js +++ b/Spaces/DesignerSpace.js @@ -118,6 +118,13 @@ function newDesignerSpace () { let icon = thisObject.iconCollection.get(record[1]) thisObject.iconByUiObjectType.set(record[0], icon) } + + /* Take types-icons relationships defined at the schema */ + for (let i = 0; i < APP_SCHEMA_ARRAY.length; i++) { + let nodeDefinition = APP_SCHEMA_ARRAY[i] + let icon = thisObject.iconCollection.get(nodeDefinition.icon) + thisObject.iconByUiObjectType.set(nodeDefinition.type, icon) + } } function loadIconCollection () { From c65545e879091ce93a903707284f11deb4e13271 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 7 Dec 2019 16:42:26 +0100 Subject: [PATCH 39/41] Can add an UI object defined at the App Schema --- .../FunctionLibraries/UiObjectsFromNodes.js | 29 ++++++++++ DesignerSpace/Workspace/Workspace.js | 7 ++- FloatingSpace/CircularMenuItem.js | 6 +-- FloatingSpace/UiObjectConstructor.js | 53 +++++++++++++++++-- Spaces/DesignerSpace.js | 7 ++- 5 files changed, 92 insertions(+), 10 deletions(-) diff --git a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js index 9617118a6..0c009e1fc 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js +++ b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js @@ -2,6 +2,7 @@ function newUiObjectsFromNodes () { thisObject = { recreateWorkspace: recreateWorkspace, createUiObjectFromNode: createUiObjectFromNode, + addUIObject: addUIObject, addTeam: addTeam, addSensorBot: addSensorBot, addIndicatorBot: addIndicatorBot, @@ -1078,6 +1079,34 @@ function newUiObjectsFromNodes () { } } + function addUIObject (parent, type) { + let object = { + name: 'New ' + type, + type: type + } + createUiObject(true, object.type, object.name, object, parent, parent) + + let nodeDefinition = APP_SCHEMA_MAP.get(parent.type) + if (nodeDefinition !== undefined) { + for (i = 0; i < nodeDefinition.properties.length; i++) { + let property = nodeDefinition.properties[i] + if (property.childType === type) { + switch (property.type) { + case 'node': { + parent[property.name] = object + } + break + case 'array': { + parent[property.name].push(object) + } + break + } + } + } + } + return object + } + function addTeam (node) { let team = { name: 'New Team', diff --git a/DesignerSpace/Workspace/Workspace.js b/DesignerSpace/Workspace/Workspace.js index f00e90f40..ed8f1f339 100644 --- a/DesignerSpace/Workspace/Workspace.js +++ b/DesignerSpace/Workspace/Workspace.js @@ -248,8 +248,13 @@ function newWorkspace () { } } - async function onMenuItemClick (payload, action, callBackFunction) { + async function onMenuItemClick (payload, action, relatedUiObject, callBackFunction) { switch (action) { + case 'Add UI Object': + { + functionLibraryUiObjectsFromNodes.addUIObject(payload.node, relatedUiObject) + } + break case 'Share Workspace': { let text = stringifyWorkspace(true) diff --git a/FloatingSpace/CircularMenuItem.js b/FloatingSpace/CircularMenuItem.js index a473124d7..92ff2d7c5 100644 --- a/FloatingSpace/CircularMenuItem.js +++ b/FloatingSpace/CircularMenuItem.js @@ -229,7 +229,7 @@ function newCircularMenuItem () { if (thisObject.label === undefined) { /* This is what we have in the case of menu items that are only Icons. In this situation there is no complex logic, just execute the specified action. */ - thisObject.actionFunction(thisObject.payload, thisObject.action) + thisObject.actionFunction(thisObject.payload, thisObject.action, thisObject.relatedUiObject) return } @@ -261,7 +261,7 @@ function newCircularMenuItem () { } /* Execute the action and wait for callbacks to update our statuus. */ - thisObject.actionFunction(thisObject.payload, thisObject.action, onPrimaryCallBack) + thisObject.actionFunction(thisObject.payload, thisObject.action, thisObject.relatedUiObject, onPrimaryCallBack) return } if (temporaryStatus === STATUS_PRIMARY_WORK_DONE && thisObject.secondaryAction !== undefined) { @@ -271,7 +271,7 @@ function newCircularMenuItem () { } /* Execute the action and wait for callbacks to update our statuus. */ - thisObject.actionFunction(thisObject.payload, thisObject.secondaryAction, onSecondaryCallBack) + thisObject.actionFunction(thisObject.payload, thisObject.secondaryAction, thisObject.relatedUiObject, onSecondaryCallBack) return } diff --git a/FloatingSpace/UiObjectConstructor.js b/FloatingSpace/UiObjectConstructor.js index d0dff925c..b05162849 100644 --- a/FloatingSpace/UiObjectConstructor.js +++ b/FloatingSpace/UiObjectConstructor.js @@ -1621,7 +1621,7 @@ function newUiObjectConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: -50, + angle: -60, dontShowAtFullscreen: true } ) @@ -1642,7 +1642,9 @@ function newUiObjectConstructor () { ) menuItemsInitialValues.push( { - action: 'Add Shapes', + action: 'Add UI Object', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'shapes', actionFunction: payload.onMenuItemClick, label: 'Add Shapes', visible: true, @@ -1693,7 +1695,7 @@ function newUiObjectConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: 50 + angle: 60 } ) break @@ -4708,7 +4710,21 @@ function newUiObjectConstructor () { break } default: { - if (ERROR_LOG === true) { logger.write('[ERROR] getMenuItemsInitialValues -> UI Object Type not Recognized -> type = ' + payload.node.type) } + let nodeDefinition = APP_SCHEMA_MAP.get(payload.node.type) + if (nodeDefinition !== undefined) { + for (i = 0; i < nodeDefinition.menuItems.length; i++) { + let menutItemDefinition = nodeDefinition.menuItems[i] + let newMenuItem = JSON.parse(JSON.stringify(menutItemDefinition)) + + /* We need to reference the real function based on its name */ + if (menutItemDefinition.actionFunction !== undefined) { + newMenuItem.actionFunction = eval(menutItemDefinition.actionFunction) + } + menuItemsInitialValues.push(newMenuItem) + } + } else { + if (ERROR_LOG === true) { logger.write('[ERROR] getMenuItemsInitialValues -> UI Object Type not Recognized -> type = ' + payload.node.type) } + } } } @@ -5021,6 +5037,35 @@ function newUiObjectConstructor () { break } default: { + let nodeDefinition = APP_SCHEMA_MAP.get(payload.node.type) + if (nodeDefinition !== undefined) { + switch (nodeDefinition.level) { + case 0: { + level_0() + return + } + case 1: { + level_1() + return + } + case 2: { + level_2() + return + } + case 3: { + level_3() + return + } + case 4: { + level_4() + return + } + case 5: { + level_5() + return + } + } + } if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> UI Object Type not Recognized -> type = ' + payload.node.type) } return } diff --git a/Spaces/DesignerSpace.js b/Spaces/DesignerSpace.js index b06dec154..8cde058e0 100644 --- a/Spaces/DesignerSpace.js +++ b/Spaces/DesignerSpace.js @@ -122,8 +122,11 @@ function newDesignerSpace () { /* Take types-icons relationships defined at the schema */ for (let i = 0; i < APP_SCHEMA_ARRAY.length; i++) { let nodeDefinition = APP_SCHEMA_ARRAY[i] - let icon = thisObject.iconCollection.get(nodeDefinition.icon) - thisObject.iconByUiObjectType.set(nodeDefinition.type, icon) + let iconName = nodeDefinition.icon + if (iconName !== undefined) { + let icon = thisObject.iconCollection.get(iconName) + thisObject.iconByUiObjectType.set(nodeDefinition.type, icon) + } } } From b62225c53d682a118a2352ac1bb0dceaac98f2ca Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 7 Dec 2019 19:41:29 +0100 Subject: [PATCH 40/41] Protocol Node first interation with APP SCHEMA --- .../FunctionLibraries/ProtocolNode.js | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js index 504d5388e..fe6ca3354 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js +++ b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js @@ -1661,6 +1661,90 @@ function newProtocolNode () { return object } + default: { + let nodeDefinition = APP_SCHEMA_MAP.get(node.type) + if (nodeDefinition !== undefined) { + if (removePersonalData === true && nodeDefinition.isPersonalData === true) { return } + let object = { + type: node.type, + subType: node.subType, + name: node.name, + code: node.code + } + + if (excludeChildren !== true) { + /* Children Nodes */ + if (nodeDefinition.properties !== undefined) { + for (i = 0; i < nodeDefinition.properties.length; i++) { + let property = nodeDefinition.properties[i] + + switch (property.type) { + case 'node': { + if (node[property.name] !== undefined) { + if (excludeType !== property.childType) { + object[property.name] = getProtocolNode(node.payload.parentNode, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) + } + } + break + } + case 'array': { + if (node[property.name] !== undefined) { + if (excludeType !== property.childType) { + let nodePropertyArray = node[property.name] + object[property.name] = [] + for (let m = 0; m < nodePropertyArray.length; m++) { + let protocolNode = getProtocolNode(nodePropertyArray[m], removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) + if (protocolNode !== undefined) { + object[property.name].push(protocolNode) + } + } + } + } + break + } + } + } + } + } + + /* Ancestors Nodes */ + if (includeParent) { + if (nodeDefinition.followAncestors !== undefined) { + followAncestors = nodeDefinition.followAncestors + } + if (nodeDefinition.excludeChildren !== undefined) { + excludeChildren = nodeDefinition.excludeChildren + } + if (nodeDefinition.excludeType !== undefined) { + excludeType = nodeDefinition.excludeType + } + object.parentNode = getProtocolNode(node.payload.parentNode, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) + } + + /* Ancestors Nodes */ + if (followAncestors) { + if (nodeDefinition.excludeChildren !== undefined) { + excludeChildren = nodeDefinition.excludeChildren + } + object.parentNode = getProtocolNode(node.payload.parentNode, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) + } + + if (parseCode) { + object.code = JSON.parse(node.code) + } + + if (includeIds) { + object.id = node.id + } + if (includePayload) { + object.savedPayload = getSavedPayload(node, includeReferences) + } + if (followReferenceParent) { + object.referenceParent = getProtocolNode(node.payload.referenceParent, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType) + } + return object + } + } } } From 1d891d193a2651fa9430cab40f5774075628aec4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 7 Dec 2019 20:12:47 +0100 Subject: [PATCH 41/41] Ui Object From nodes from SCHEMA --- .../FunctionLibraries/ProtocolNode.js | 1 + .../FunctionLibraries/UiObjectsFromNodes.js | 58 +++++++++++++++---- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js index fe6ca3354..68482972f 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js +++ b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js @@ -1622,6 +1622,7 @@ function newProtocolNode () { name: node.name, code: node.code, javascriptCode: getProtocolNode(node.javascriptCode, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType), + shapes: getProtocolNode(node.shapes, removePersonalData, parseCode, includeIds, includePayload, includeReferences, followReferenceParent, includeParent, followAncestors, excludeChildren, excludeType), panels: [] } if (includeParent) { diff --git a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js index 0c009e1fc..e2a05c867 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js +++ b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js @@ -1055,6 +1055,11 @@ function newUiObjectsFromNodes () { if (node.javascriptCode !== undefined) { createUiObjectFromNode(node.javascriptCode, node, node, positionOffset) } + + if (node.shapes !== undefined) { + createUiObjectFromNode(node.shapes, node, node, positionOffset) + } + for (let m = 0; m < node.panels.length; m++) { let panel = node.panels[m] createUiObjectFromNode(panel, node, node, positionOffset) @@ -1076,6 +1081,35 @@ function newUiObjectsFromNodes () { } return } + default: { + let nodeDefinition = APP_SCHEMA_MAP.get(node.type) + if (nodeDefinition !== undefined) { + createUiObject(false, node.type, node.name, node, parentNode, chainParent, node.type, positionOffset) + + if (nodeDefinition.properties !== undefined) { + for (i = 0; i < nodeDefinition.properties.length; i++) { + let property = nodeDefinition.properties[i] + if (node[property.name] !== undefined) { + switch (property.type) { + case 'node': { + createUiObjectFromNode(node[property.name], node, node, positionOffset) + } + break + case 'array': { + let nodePropertyArray = node[property.name] + for (let m = 0; m < nodePropertyArray.length; m++) { + let arrayItem = nodePropertyArray[m] + createUiObjectFromNode(arrayItem, node, node, positionOffset) + } + } + break + } + } + } + } + } + return + } } } @@ -1088,18 +1122,20 @@ function newUiObjectsFromNodes () { let nodeDefinition = APP_SCHEMA_MAP.get(parent.type) if (nodeDefinition !== undefined) { - for (i = 0; i < nodeDefinition.properties.length; i++) { - let property = nodeDefinition.properties[i] - if (property.childType === type) { - switch (property.type) { - case 'node': { - parent[property.name] = object + if (nodeDefinition.properties !== undefined) { + for (i = 0; i < nodeDefinition.properties.length; i++) { + let property = nodeDefinition.properties[i] + if (property.childType === type) { + switch (property.type) { + case 'node': { + parent[property.name] = object + } + break + case 'array': { + parent[property.name].push(object) + } + break } - break - case 'array': { - parent[property.name].push(object) - } - break } } }