From 1ed6a48488e14b4e0aeda3a72e7e6df3a1aa2bdb Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 16 Jun 2020 12:16:40 +0200 Subject: [PATCH] Plotting Modules --- ChartingSpace/PlottersManager.js | 1 + FloatingSpace/UiObject.js | 9 ++++--- Plotting/NodesErrors.js | 36 +++++++++++++++++++++++++ Plotting/NodesHighlights.js | 33 +++++++++++++++++++++++ Plotting/NodesProgress.js | 32 ++++++++++++++++++++++ Plotting/NodesRunning.js | 36 +++++++++++++++++++++++++ Plotting/NodesStatus.js | 32 ++++++++++++++++++++++ Plotting/NodesValues.js | 32 ++++++++++++++++++++++ Plotter.js => Plotting/Plotter.js | 8 +++--- Utilities/RecursiveEvalNode.js | 45 +++++++++++++++++++++++++++++++ 10 files changed, 258 insertions(+), 6 deletions(-) create mode 100644 Plotting/NodesErrors.js create mode 100644 Plotting/NodesHighlights.js create mode 100644 Plotting/NodesProgress.js create mode 100644 Plotting/NodesRunning.js create mode 100644 Plotting/NodesStatus.js create mode 100644 Plotting/NodesValues.js rename Plotter.js => Plotting/Plotter.js (99%) create mode 100644 Utilities/RecursiveEvalNode.js diff --git a/ChartingSpace/PlottersManager.js b/ChartingSpace/PlottersManager.js index e660e48de..8348a4d7a 100644 --- a/ChartingSpace/PlottersManager.js +++ b/ChartingSpace/PlottersManager.js @@ -199,6 +199,7 @@ function newPlottersManager () { connector.panels = [] if (product !== undefined) { + /* Here we setup the panels associated with this plotter */ for (let i = 0; i < plotterModule.panels.length; i++) { let panel = plotterModule.panels[i] diff --git a/FloatingSpace/UiObject.js b/FloatingSpace/UiObject.js index 0e9f16202..412af7968 100644 --- a/FloatingSpace/UiObject.js +++ b/FloatingSpace/UiObject.js @@ -20,7 +20,7 @@ function newUiObject () { formulaEditor: undefined, uiObjectTitle: undefined, circularProgressBar: undefined, - isExecuting: undefined, + isRunningAtBackend: undefined, isRunning: undefined, shortcutKey: undefined, isShowing: undefined, @@ -35,8 +35,11 @@ function newUiObject () { setErrorMessage: setErrorMessage, resetErrorMessage: resetErrorMessage, setValue: setValue, + resetValue: resetValue, setPercentage: setPercentage, + resetPercentage: resetPercentage, setStatus: setStatus, + resetStatus: resetStatus, physics: physics, invisiblePhysics: invisiblePhysics, drawBackground: drawBackground, @@ -1817,7 +1820,7 @@ function newUiObject () { if (icon !== undefined) { if (icon.canDrawIcon === true) { let additionalImageSize = 0 - if (thisObject.isExecuting === true || isReadyToReferenceAttach === true || isReadyToChainAttach === true) { additionalImageSize = 20 } + if (thisObject.isRunningAtBackend === true || isReadyToReferenceAttach === true || isReadyToChainAttach === true) { additionalImageSize = 20 } let totalImageSize = additionalImageSize + thisObject.payload.floatingObject.currentImageSize if (canvas.floatingSpace.inMapMode === true) { totalImageSize = canvas.floatingSpace.transformImagesizeToMap(totalImageSize) @@ -1843,7 +1846,7 @@ function newUiObject () { if (executingIcon !== undefined) { if (executingIcon.canDrawIcon === true) { - if (thisObject.isExecuting === true) { + if (thisObject.isRunningAtBackend === true) { const DISTANCE_FROM_CENTER = thisObject.container.frame.radius / 3 + 50 const EXECUTING_ICON_SIZE = 20 + thisObject.container.frame.radius / 6 diff --git a/Plotting/NodesErrors.js b/Plotting/NodesErrors.js new file mode 100644 index 000000000..db636c80a --- /dev/null +++ b/Plotting/NodesErrors.js @@ -0,0 +1,36 @@ +function newNodesErrors () { + const MODULE_NAME = 'Nodes Errors' + const logger = newWebDebugLog() + logger.fileName = MODULE_NAME + + let thisObject = { + onRecordChange: onRecordChange, + initialize: initialize, + finalize: finalize + } + + let rootNode + return thisObject + + function finalize () { + rootNode = undefined + } + + function initialize (pRootNode) { + rootNode = pRootNode + } + + function onRecordChange (currentRecord) { + evalNode(rootNode, currentRecord.array, 0, applyError) + } + + function applyError (node, errorMessage) { + if (node.payload === undefined) { return } + if (node.payload.uiObject === undefined) { return } + if (errorMessage === '') { + node.payload.uiObject.resetErrorMessage(errorMessage) + } else { + node.payload.uiObject.setErrorMessage(errorMessage) + } + } +} diff --git a/Plotting/NodesHighlights.js b/Plotting/NodesHighlights.js new file mode 100644 index 000000000..d1dcca65b --- /dev/null +++ b/Plotting/NodesHighlights.js @@ -0,0 +1,33 @@ +function newNodesHighlights () { + const MODULE_NAME = 'Nodes Highlights' + const logger = newWebDebugLog() + logger.fileName = MODULE_NAME + + let thisObject = { + onRecordChange: onRecordChange, + initialize: initialize, + finalize: finalize + } + + let rootNode + return thisObject + + function finalize () { + rootNode = undefined + } + + function initialize (pRootNode) { + rootNode = pRootNode + } + + function onRecordChange (currentRecord) { + evalNode(rootNode, currentRecord.array, 0, applyHighlight) + } + + function applyHighlight (node, value) { + if (value !== 1) { return } + if (node.payload === undefined) { return } + if (node.payload.uiObject === undefined) { return } + node.payload.uiObject.highlight() + } +} diff --git a/Plotting/NodesProgress.js b/Plotting/NodesProgress.js new file mode 100644 index 000000000..03992cc11 --- /dev/null +++ b/Plotting/NodesProgress.js @@ -0,0 +1,32 @@ +function newNodesProgress () { + const MODULE_NAME = 'Nodes Progress' + const logger = newWebDebugLog() + logger.fileName = MODULE_NAME + + let thisObject = { + onRecordChange: onRecordChange, + initialize: initialize, + finalize: finalize + } + + let rootNode + return thisObject + + function finalize () { + rootNode = undefined + } + + function initialize (pRootNode) { + rootNode = pRootNode + } + + function onRecordChange (currentRecord) { + evalNode(rootNode, currentRecord.array, 0, applyProgress) + } + + function applyProgress (node, value) { + if (node.payload === undefined) { return } + if (node.payload.uiObject === undefined) { return } + node.payload.uiObject.setPercentage(node, value) + } +} diff --git a/Plotting/NodesRunning.js b/Plotting/NodesRunning.js new file mode 100644 index 000000000..630e372fe --- /dev/null +++ b/Plotting/NodesRunning.js @@ -0,0 +1,36 @@ +function newNodesRunning () { + const MODULE_NAME = 'Nodes Running' + const logger = newWebDebugLog() + logger.fileName = MODULE_NAME + + let thisObject = { + onRecordChange: onRecordChange, + initialize: initialize, + finalize: finalize + } + + let rootNode + return thisObject + + function finalize () { + rootNode = undefined + } + + function initialize (pRootNode) { + rootNode = pRootNode + } + + function onRecordChange (currentRecord) { + evalNode(rootNode, currentRecord.array, 0, applyExecution) + } + + function applyExecution (node, value) { + if (node.payload === undefined) { return } + if (node.payload.uiObject === undefined) { return } + if (value === 1) { + node.payload.uiObject.isRunningAtBackend = true + } else { + node.payload.uiObject.isRunningAtBackend = false + } + } +} diff --git a/Plotting/NodesStatus.js b/Plotting/NodesStatus.js new file mode 100644 index 000000000..cab163268 --- /dev/null +++ b/Plotting/NodesStatus.js @@ -0,0 +1,32 @@ +function newNodesStatus () { + const MODULE_NAME = 'Nodes Status' + const logger = newWebDebugLog() + logger.fileName = MODULE_NAME + + let thisObject = { + onRecordChange: onRecordChange, + initialize: initialize, + finalize: finalize + } + + let rootNode + return thisObject + + function finalize () { + rootNode = undefined + } + + function initialize (pRootNode) { + rootNode = pRootNode + } + + function onRecordChange (currentRecord) { + evalNode(rootNode, currentRecord.array, 0, applyStatus) + } + + function applyStatus (node, status) { + if (node.payload === undefined) { return } + if (node.payload.uiObject === undefined) { return } + node.payload.uiObject.setStatus(node, status) + } +} diff --git a/Plotting/NodesValues.js b/Plotting/NodesValues.js new file mode 100644 index 000000000..5418ff340 --- /dev/null +++ b/Plotting/NodesValues.js @@ -0,0 +1,32 @@ +function newNodesValues () { + const MODULE_NAME = 'Nodes Values' + const logger = newWebDebugLog() + logger.fileName = MODULE_NAME + + let thisObject = { + onRecordChange: onRecordChange, + initialize: initialize, + finalize: finalize + } + + let rootNode + return thisObject + + function finalize () { + rootNode = undefined + } + + function initialize (pRootNode) { + rootNode = pRootNode + } + + function onRecordChange (currentRecord) { + evalNode(rootNode, currentRecord.array, 0, applyValue) + } + + function applyValue (node, value) { + if (node.payload === undefined) { return } + if (node.payload.uiObject === undefined) { return } + node.payload.uiObject.setValue(value) + } +} diff --git a/Plotter.js b/Plotting/Plotter.js similarity index 99% rename from Plotter.js rename to Plotting/Plotter.js index ca72ed893..094b0eb65 100644 --- a/Plotter.js +++ b/Plotting/Plotter.js @@ -245,7 +245,9 @@ function newPlotter () { function draw () { try { thisObject.container.frame.draw() - plotChart() + if (productDefinition.referenceParent.shapes !== undefined) { + plotShapes() + } } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] draw -> err = ' + err.stack) } } @@ -489,7 +491,7 @@ function newPlotter () { } } - function plotChart () { + function plotShapes () { try { /* Clean the pannel at places where there is no record. */ let currentRecord = { @@ -792,7 +794,7 @@ function newPlotter () { logged = false } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] plotChart -> err = ' + err.stack) } + if (ERROR_LOG === true) { logger.write('[ERROR] plotShapes -> err = ' + err.stack) } } } diff --git a/Utilities/RecursiveEvalNode.js b/Utilities/RecursiveEvalNode.js new file mode 100644 index 000000000..8e4a0f6a9 --- /dev/null +++ b/Utilities/RecursiveEvalNode.js @@ -0,0 +1,45 @@ +/* +This function scans a node hiriatchy recursively. At each node it calls the callback +provided with the corresponfing value of the array. +*/ + +function evalNode (node, array, index, callback) { + if (node === undefined) { return } + if (array === undefined) { return } + if (index === undefined) { return } + if (callback === undefined) { return } + + callback(node, array[index]) + + /* Now we go down through all this node children */ + let nodeDefinition = APP_SCHEMA_MAP.get(node.type) + if (nodeDefinition === undefined) { return } + + if (nodeDefinition.properties !== undefined) { + let previousPropertyName // Since there are cases where there are many properties with the same name,because they can hold nodes of different types but only one at the time, we have to avoind counting each property of those as individual children. + for (let i = 0; i < nodeDefinition.properties.length; i++) { + let property = nodeDefinition.properties[i] + + switch (property.type) { + case 'node': { + if (property.name !== previousPropertyName) { + if (node[property.name] !== undefined) { + evalNode(node[property.name], array, index + 1, callback) + } + previousPropertyName = property.name + } + break + } + case 'array': { + if (node[property.name] !== undefined) { + let nodePropertyArray = node[property.name] + for (let m = 0; m < nodePropertyArray.length; m++) { + evalNode(nodePropertyArray[m], array, index + 1, callback) + } + } + break + } + } + } + } +}