diff --git a/ChartsSpace/PlottersManager.js b/ChartsSpace/PlottersManager.js index 740a59a34..91bf7b67b 100644 --- a/ChartsSpace/PlottersManager.js +++ b/ChartsSpace/PlottersManager.js @@ -72,25 +72,25 @@ function newPlottersManager () { exchange = pExchange market = pMarket /* Listen to the event of change of status */ - layersPanel.container.eventHandler.listenToEvent('Product Card Status Changed', onProductCardStatusChanged) + layersPanel.container.eventHandler.listenToEvent('Product Card Status Changed', onLayerStatusChanged) /* Lets get all the cards that needs to be loaded. */ - let loadingProductCards = layersPanel.getLoadingProductCards() + let loadingLayers = layersPanel.getLoadingLayers() - for (let i = 0; i < loadingProductCards.length; i++) { + for (let i = 0; i < loadingLayers.length; i++) { /* For each one, we will initialize the associated plotter. */ - initializeProductPlotter(loadingProductCards[i]) + initializeProductPlotter(loadingLayers[i]) } } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err.stack) } } } - function initializeProductPlotter (pProductCard, callBack) { + function initializeProductPlotter (pLayer, callBack) { try { /* Before Initializing a Plotter, we need the Storage it will use, loaded with the files it will initially need. */ - let objName = pProductCard.dataMine.codeName + '-' + pProductCard.bot.codeName + '-' + pProductCard.product.codeName + let objName = pLayer.dataMine.codeName + '-' + pLayer.bot.codeName + '-' + pLayer.product.codeName let storage = newProductStorage(objName) /* @@ -98,30 +98,30 @@ function newPlottersManager () { so that the UI can somehow show this. There are different types of events. */ - for (let i = 0; i < pProductCard.product.dataSets.length; i++) { - let thisSet = pProductCard.product.dataSets[i] + for (let i = 0; i < pLayer.product.dataSets.length; i++) { + let thisSet = pLayer.product.dataSets[i] switch (thisSet.type) { case 'Market Files': { - storage.eventHandler.listenToEvent('Market File Loaded', pProductCard.onMarketFileLoaded) + storage.eventHandler.listenToEvent('Market File Loaded', pLayer.onMarketFileLoaded) } break case 'Daily Files': { - storage.eventHandler.listenToEvent('Daily File Loaded', pProductCard.onDailyFileLoaded) + storage.eventHandler.listenToEvent('Daily File Loaded', pLayer.onDailyFileLoaded) } break case 'Single File': { - storage.eventHandler.listenToEvent('Single File Loaded', pProductCard.onSingleFileLoaded) + storage.eventHandler.listenToEvent('Single File Loaded', pLayer.onSingleFileLoaded) } break case 'File Sequence': { - storage.eventHandler.listenToEvent('File Sequence Loaded', pProductCard.onFileSequenceLoaded) + storage.eventHandler.listenToEvent('File Sequence Loaded', pLayer.onFileSequenceLoaded) } break } } - storage.initialize(pProductCard.dataMine, pProductCard.bot, pProductCard.session, pProductCard.product, exchange, market, datetime, timeFrame, onProductStorageInitialized) + storage.initialize(pLayer.dataMine, pLayer.bot, pLayer.session, pLayer.product, exchange, market, datetime, timeFrame, onProductStorageInitialized) function onProductStorageInitialized (err) { try { @@ -130,7 +130,7 @@ function newPlottersManager () { let plotter let productDefinition - if (pProductCard.product.plotter.legacy === false) { + if (pLayer.product.plotter.legacy === false) { plotter = newPlotter() /* We take a snapwhot of the current product definition to be used by the plotter. */ @@ -145,9 +145,9 @@ function newPlottersManager () { 'Polygon Border->Style->Style Condition->Style->' + 'Polygon Vertex->Point->' + 'Plotter Panel->Javascript Code->Panel Data->Data Formula->' - productDefinition = functionLibraryProtocolNode.getProtocolNode(pProductCard.product.node, false, true, true, false, false, lightingPath) + productDefinition = functionLibraryProtocolNode.getProtocolNode(pLayer.product.node, false, true, true, false, false, lightingPath) } else { - plotter = getNewPlotter(pProductCard.product.plotter.dataMine, pProductCard.product.plotter.codeName, pProductCard.product.plotter.moduleName) + plotter = getNewPlotter(pLayer.product.plotter.dataMine, pLayer.product.plotter.codeName, pLayer.product.plotter.moduleName) } plotter.container.connectToParent(thisObject.container, true, true, false, true, true, true, false, false, true) @@ -159,7 +159,7 @@ function newPlottersManager () { function onPlotterInizialized () { try { let productPlotter = { - productCard: pProductCard, + layer: pLayer, plotter: plotter, storage: storage, profile: undefined, @@ -171,17 +171,17 @@ function newPlottersManager () { 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] + for (let i = 0; i < pLayer.product.plotter.module.panels.length; i++) { + let panelConfig = pLayer.product.plotter.module.panels[i] let parameters = { - dataMine: pProductCard.product.plotter.dataMine, - plotterCodeName: pProductCard.product.plotter.codeName, - moduleCodeName: pProductCard.product.plotter.moduleName, + dataMine: pLayer.product.plotter.dataMine, + plotterCodeName: pLayer.product.plotter.codeName, + moduleCodeName: pLayer.product.plotter.moduleName, panelCodeName: panelConfig.codeName } let panelOwner = exchange + ' ' + market.quotedAsset + '/' + market.baseAsset - let plotterPanelHandle = canvas.panelsSpace.createNewPanel('Plotter Panel', parameters, panelOwner, pProductCard.session) + let plotterPanelHandle = canvas.panelsSpace.createNewPanel('Plotter Panel', parameters, panelOwner, pLayer.session) let plotterPanel = canvas.panelsSpace.getPanel(plotterPanelHandle, panelOwner) /* Connect Panel to the Plotter via an Event. */ if (panelConfig.event !== undefined) { @@ -196,13 +196,13 @@ function newPlottersManager () { let panel = productDefinition.referenceParent.panels[i] let parameters = { - dataMine: pProductCard.product.plotter.dataMine, - plotterCodeName: pProductCard.product.plotter.codeName, - moduleCodeName: pProductCard.product.plotter.moduleName, + dataMine: pLayer.product.plotter.dataMine, + plotterCodeName: pLayer.product.plotter.codeName, + moduleCodeName: pLayer.product.plotter.moduleName, panelCodeName: panel.id } let panelOwner = exchange + ' ' + market.quotedAsset + '/' + market.baseAsset - let plotterPanelHandle = canvas.panelsSpace.createNewPanel('Plotter Panel', parameters, panelOwner, pProductCard.session, panel) + let plotterPanelHandle = canvas.panelsSpace.createNewPanel('Plotter Panel', parameters, panelOwner, pLayer.session, panel) let plotterPanel = canvas.panelsSpace.getPanel(plotterPanelHandle, panelOwner) /* Connect Panel to the Plotter via an Event. */ @@ -226,26 +226,26 @@ function newPlottersManager () { } } - function onProductCardStatusChanged (pProductCard) { - if (pProductCard.status === PRODUCT_CARD_STATUS.LOADING) { + function onLayerStatusChanged (pLayer) { + if (pLayer.status === PRODUCT_CARD_STATUS.LOADING) { /* Lets see if we can find the Plotter of this card on our Active Plotters list, other wise we will initialize it */ let found = false for (let i = 0; i < productPlotters.length; i++) { - if (productPlotters[i].productCard.code === pProductCard.code) { + if (productPlotters[i].layer.code === pLayer.code) { found = true } } if (found === false) { - initializeProductPlotter(pProductCard, onProductPlotterInitialized) + initializeProductPlotter(pLayer, onProductPlotterInitialized) function onProductPlotterInitialized (err) { /* There is no policy yet of what to do if this fails. */ } } } - if (pProductCard.status === PRODUCT_CARD_STATUS.OFF) { + if (pLayer.status === PRODUCT_CARD_STATUS.OFF) { /* If the plotter of this card is not on our Active Plotters list, then we remove it. */ for (let i = 0; i < productPlotters.length; i++) { - if (productPlotters[i].productCard.code === pProductCard.code) { + if (productPlotters[i].layer.code === pLayer.code) { /* Then the panels. */ for (let j = 0; j < productPlotters[i].panels.length; j++) { canvas.panelsSpace.destroyPanel(productPlotters[i].panels[j]) @@ -268,7 +268,7 @@ function newPlottersManager () { timeFrame = pTimeFrame for (let i = 0; i < productPlotters.length; i++) { let productPlotter = productPlotters[i] - productPlotter.productCard.setTimeFrame(timeFrame) + productPlotter.layer.setTimeFrame(timeFrame) productPlotter.storage.setTimeFrame(timeFrame) productPlotter.plotter.setTimeFrame(timeFrame) } @@ -278,7 +278,7 @@ function newPlottersManager () { datetime = pDatetime for (let i = 0; i < productPlotters.length; i++) { let productPlotter = productPlotters[i] - productPlotter.productCard.setDatetime(pDatetime) + productPlotter.layer.setDatetime(pDatetime) productPlotter.storage.setDatetime(pDatetime) productPlotter.plotter.setDatetime(pDatetime) } diff --git a/CockpitSpace/FullScreen.js b/CockpitSpace/FullScreen.js index 8f204e3b7..12951403f 100644 --- a/CockpitSpace/FullScreen.js +++ b/CockpitSpace/FullScreen.js @@ -28,7 +28,7 @@ function newFullScreen () { let isMouseOver = false let counterTillNextState = 0 - let productCardsToTurnOn = [] + let layersToTurnOn = [] return thisObject function finalize () { diff --git a/Panels/ProductCard.js b/Panels/Layer.js similarity index 99% rename from Panels/ProductCard.js rename to Panels/Layer.js index 45580da75..03c724f46 100644 --- a/Panels/ProductCard.js +++ b/Panels/Layer.js @@ -1,4 +1,4 @@ -function newProductCard () { +function newLayer () { const MODULE_NAME = 'Product Card' const ERROR_LOG = true const logger = newWebDebugLog() @@ -319,10 +319,10 @@ function newProductCard () { } function draw () { - drawProductCard() + drawLayer() } - function drawProductCard () { + function drawLayer () { switch (thisObject.status) { case PRODUCT_CARD_STATUS.ON: @@ -568,4 +568,3 @@ function newProductCard () { browserCanvasContext.lineWidth = 10 } } - diff --git a/Panels/LayersPanel.js b/Panels/LayersPanel.js index 0d8e657df..995688ca4 100644 --- a/Panels/LayersPanel.js +++ b/Panels/LayersPanel.js @@ -3,8 +3,8 @@ function newProductsPanel () { name: 'Layers Panel', fitFunction: undefined, container: undefined, - productCards: [], - getLoadingProductCards: getLoadingProductCards, + layers: [], + getLoadingLayers: getLoadingLayers, physics: physics, draw: draw, getContainer: getContainer, // returns the inner most container that holds the point received by parameter. @@ -24,8 +24,8 @@ function newProductsPanel () { let isInitialized = false - let cardsMap = new Map() - let visibleProductCards = [] + let layersMap = new Map() + let visibleLayers = [] let firstVisibleCard = 1 /* Needed Variables */ @@ -60,7 +60,7 @@ function newProductsPanel () { panelTabButton.fitFunction = thisObject.fitFunction panelTabButton.initialize() - /* First thing is to build the thisObject.productCards array */ + /* First thing is to build the thisObject.layers array */ let ecosystem = JSON.parse(window.localStorage.getItem('ecosystem')) if (ecosystem === null || ecosystem === undefined) { ecosystem = getUserEcosystem() @@ -78,7 +78,7 @@ function newProductsPanel () { for (let k = 0; k < bot.products.length; k++) { let product = bot.products[k] - addProductCard(dataMine, bot, product) + addLayer(dataMine, bot, product) } } } @@ -187,7 +187,7 @@ function newProductsPanel () { } } - addProductCard(dataMine, bot, product) + addLayer(dataMine, bot, product) } } } @@ -197,36 +197,36 @@ function newProductsPanel () { isInitialized = true } - function removeProductCard (code) { - let productCard = cardsMap.get(code) - cardsMap.delete(code) - productCard.turnOff() - productCard.finalize() + function removeLayer (code) { + let layer = layersMap.get(code) + layersMap.delete(code) + layer.turnOff() + layer.finalize() } - function addProductCard (dataMine, bot, product, session) { + function addLayer (dataMine, bot, product, session) { /* Now we create Product objects */ - let productCard = newProductCard() + let layer = newLayer() - productCard.dataMine = dataMine - productCard.bot = bot - productCard.product = product - productCard.fitFunction = thisObject.fitFunction - productCard.code = exchange + '-' + market.quotedAsset + '/' + market.baseAsset + '-' + dataMine.codeName + '-' + bot.codeName + '-' + product.codeName + layer.dataMine = dataMine + layer.bot = bot + layer.product = product + layer.fitFunction = thisObject.fitFunction + layer.code = exchange + '-' + market.quotedAsset + '/' + market.baseAsset + '-' + dataMine.codeName + '-' + bot.codeName + '-' + product.codeName if (session !== undefined) { - productCard.code = productCard.code + '-' + session.id + layer.code = layer.code + '-' + session.id } - productCard.session = session + layer.session = session /* Initialize it */ - productCard.initialize() - cardsMap.set(productCard.code, productCard) + layer.initialize() + layersMap.set(layer.code, layer) /* Container Stuff */ - productCard.container.frame.parentFrame = thisObject.container.frame - productCard.container.parentContainer = thisObject.container - productCard.container.isWheelable = true + layer.container.frame.parentFrame = thisObject.container.frame + layer.container.parentContainer = thisObject.container + layer.container.isWheelable = true /* Positioning within thisObject Panel */ let position = { @@ -234,22 +234,22 @@ function newProductsPanel () { y: thisObject.container.frame.height - thisObject.container.frame.getBodyHeight() } - productCard.container.frame.position.x = position.x - productCard.container.frame.position.y = position.y + productCard.container.frame.height * thisObject.productCards.length + CANRD_SEPARATION + layer.container.frame.position.x = position.x + layer.container.frame.position.y = position.y + layer.container.frame.height * thisObject.layers.length + CANRD_SEPARATION /* Add to the Product Array */ - thisObject.productCards.push(productCard) + thisObject.layers.push(layer) /* Add to Visible Product Array */ - if (productCard.container.frame.position.y + productCard.container.frame.height < thisObject.container.frame.height) { - visibleProductCards.push(productCard) + if (layer.container.frame.position.y + layer.container.frame.height < thisObject.container.frame.height) { + visibleLayers.push(layer) } /* Listen to Status Changes Events */ - productCard.container.eventHandler.listenToEvent('Status Changed', onProductCardStatusChanged) - productCard.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel) + layer.container.eventHandler.listenToEvent('Status Changed', onLayerStatusChanged) + layer.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel) - return productCard + return layer } function onMouseWheel (event) { @@ -262,20 +262,20 @@ function newProductsPanel () { firstVisibleCard = firstVisibleCard + delta - calculateVisbleProductCards() + calculateVisbleLayers() } - function calculateVisbleProductCards () { - let availableSlots = visibleProductCards.length + function calculateVisbleLayers () { + let availableSlots = visibleLayers.length if (firstVisibleCard < 1) { firstVisibleCard = 1 } - if (firstVisibleCard > (thisObject.productCards.length - availableSlots + 1)) { firstVisibleCard = thisObject.productCards.length - availableSlots + 1 } + if (firstVisibleCard > (thisObject.layers.length - availableSlots + 1)) { firstVisibleCard = thisObject.layers.length - availableSlots + 1 } - visibleProductCards = [] + visibleLayers = [] - for (let i = 0; i < thisObject.productCards.length; i++) { + for (let i = 0; i < thisObject.layers.length; i++) { if (i + 1 >= firstVisibleCard && i + 1 < firstVisibleCard + availableSlots) { - let productCard = thisObject.productCards[i] + let layer = thisObject.layers[i] /* Positioning within thisObject Panel */ @@ -283,28 +283,28 @@ function newProductsPanel () { x: 10, y: thisObject.container.frame.height - thisObject.container.frame.getBodyHeight() } - productCard.container.frame.position.x = position.x - productCard.container.frame.position.y = position.y + productCard.container.frame.height * visibleProductCards.length + CANRD_SEPARATION + layer.container.frame.position.x = position.x + layer.container.frame.position.y = position.y + layer.container.frame.height * visibleLayers.length + CANRD_SEPARATION /* Add to Visible Product Array */ - visibleProductCards.push(productCard) + visibleLayers.push(layer) } } } - function onProductCardStatusChanged (pProductCard) { - thisObject.container.eventHandler.raiseEvent('Product Card Status Changed', pProductCard) + function onLayerStatusChanged (pLayer) { + thisObject.container.eventHandler.raiseEvent('Product Card Status Changed', pLayer) } - function getLoadingProductCards () { - /* Returns all thisObject.productCards which status is LOADING */ + function getLoadingLayers () { + /* Returns all thisObject.layers which status is LOADING */ let onProducts = [] - for (let i = 0; i < thisObject.productCards.length; i++) { - if (thisObject.productCards[i].status === PRODUCT_CARD_STATUS.LOADING) { - onProducts.push(thisObject.productCards[i]) + for (let i = 0; i < thisObject.layers.length; i++) { + if (thisObject.layers[i].status === PRODUCT_CARD_STATUS.LOADING) { + onProducts.push(thisObject.layers[i]) } } @@ -322,8 +322,8 @@ function newProductsPanel () { if (thisObject.container.frame.isThisPointHere(point, true) === true) { /* Now we see which is the inner most container that has it */ - for (let i = 0; i < visibleProductCards.length; i++) { - container = visibleProductCards[i].getContainer(point) + for (let i = 0; i < visibleLayers.length; i++) { + container = visibleLayers[i].getContainer(point) if (container !== undefined) { let checkPoint = { @@ -371,15 +371,15 @@ function newProductsPanel () { local array after all the layers at the designer have been processed, are turned off and discarded. */ - let localProductCards = [] - moveToLocalProductCards() - synchronizeLayersAndProductCards() + let localLayers = [] + moveToLocalLayers() + synchronizeLayersAndLayers() /* At this poins all the cards still at the local array need to be removed from the panel. */ turnOffUnusedProducCards() - calculateVisbleProductCards() + calculateVisbleLayers() - function synchronizeLayersAndProductCards () { + function synchronizeLayersAndLayers () { /* We will look into the ecosystem to know which Trading bots are defined there. */ let ecosystem = JSON.parse(window.localStorage.getItem('ecosystem')) if (ecosystem === null || ecosystem === undefined) { @@ -439,10 +439,10 @@ function newProductsPanel () { if (product.codeName === layerCode.product) { /* We have a layer that is matching the current product */ let cardCode = exchange + '-' + market.quotedAsset + '/' + market.baseAsset + '-' + dataMine.codeName + '-' + bot.codeName + '-' + product.codeName + '-' + process.session.id - let cardFound = removeFromLocalProductCards(cardCode) + let cardFound = removeFromLocalLayers(cardCode) if (cardFound !== true) { - productCard = addProductCard(dataMine, bot, product, process.session) - onProductCardStatusChanged(productCard) + layer = addLayer(dataMine, bot, product, process.session) + onLayerStatusChanged(layer) } } } @@ -458,36 +458,36 @@ function newProductsPanel () { } } - function moveToLocalProductCards () { + function moveToLocalLayers () { removeNext() function removeNext () { - for (let i = 0; i < thisObject.productCards.length; i++) { - let productCard = thisObject.productCards[i] - if (productCard.session !== undefined) { - thisObject.productCards.splice(i, 1) - localProductCards.push(productCard) + for (let i = 0; i < thisObject.layers.length; i++) { + let layer = thisObject.layers[i] + if (layer.session !== undefined) { + thisObject.layers.splice(i, 1) + localLayers.push(layer) removeNext() } } } } - function removeFromLocalProductCards (code) { - for (let i = 0; i < localProductCards.length; i++) { - let productCard = localProductCards[i] - if (productCard.code === code) { - thisObject.productCards.push(productCard) - localProductCards.splice(i, 1) + function removeFromLocalLayers (code) { + for (let i = 0; i < localLayers.length; i++) { + let layer = localLayers[i] + if (layer.code === code) { + thisObject.layers.push(layer) + localLayers.splice(i, 1) return true } } } function turnOffUnusedProducCards () { - for (let i = 0; i < localProductCards.length; i++) { - let productCard = localProductCards[i] - removeProductCard(productCard.code) + for (let i = 0; i < localLayers.length; i++) { + let layer = localLayers[i] + removeLayer(layer.code) } } } @@ -496,8 +496,8 @@ function newProductsPanel () { thisObject.container.frame.draw(false, false, false, thisObject.fitFunction) - for (let i = 0; i < visibleProductCards.length; i++) { - visibleProductCards[i].draw() + for (let i = 0; i < visibleLayers.length; i++) { + visibleLayers[i].draw() } panelTabButton.draw() diff --git a/Project.njsproj b/Project.njsproj index 2023bf304..99fe110d0 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -127,7 +127,7 @@ Code - + Code