From e0e7483e384ef14f0e7d576af75d3caa43b77520 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 7 Mar 2019 13:57:15 +0100 Subject: [PATCH] Conditions Panel Working from SimulationLogic --- Conditions.js | 17 +++++++-------- ConditionsPanel.js | 54 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/Conditions.js b/Conditions.js index be5e1e429..b352eef41 100644 --- a/Conditions.js +++ b/Conditions.js @@ -48,6 +48,7 @@ /* these are module specific variables: */ let conditions = []; + let headers; let smileyHappy; let smileySad; @@ -390,8 +391,9 @@ rightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); conditions = []; + headers = marketFile[0]; - for (let i = 0; i < marketFile.length; i++) { + for (let i = 0; i < marketFile[1].length; i++) { let record = { begin: undefined, @@ -399,13 +401,9 @@ conditions: undefined }; - record.begin = marketFile[i][0]; - record.end = marketFile[i][1]; - record.conditions = marketFile[i]; - - if (i === 0) { // The first record contains headers needed to be printed. - conditions.push(record); - } + record.begin = marketFile[1][i][0]; + record.end = marketFile[1][i][1]; + record.conditions = marketFile[1][i]; if (record.begin >= leftDate.valueOf() && record.end <= rightDate.valueOf()) { @@ -500,7 +498,7 @@ if (dateValue >= conditionRecord.begin && dateValue <= conditionRecord.end) { let currentRecord = { - conditionsNames: conditions[0].conditions, + conditionsNames: headers, conditionsValues: conditionRecord.conditions }; thisObject.container.eventHandler.raiseEvent("Current Condition Record Changed", currentRecord); @@ -576,3 +574,4 @@ + diff --git a/ConditionsPanel.js b/ConditionsPanel.js index 55e820318..fe9087e59 100644 --- a/ConditionsPanel.js +++ b/ConditionsPanel.js @@ -79,21 +79,59 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { let y = 0; let increment = 0.06; + let opacity; + let label; browserCanvasContext.beginPath(); - for (let i = 2; i < currentRecord.conditionsNames.length; i++) { // Jump the first 2 items since they are the .begin and the .end of the record. + let simulationLogic = currentRecord.conditionsNames; + let conditionIndex = 2; // Jump the first 2 items since they are the .begin and the .end of the record. + + for (let j = 0; j < simulationLogic.strategies.length; j++) { + + let strategy = simulationLogic.strategies[j]; + y = y + increment; - let opacity; - if (currentRecord.conditionsValues[i] === 1) { - opacity = '1.00' - } else { + y = y + increment; + opacity = '1.00'; + label = 'Strategy: ' + strategy.name; + printLabel(label, X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + + y = y + increment; + opacity = '0.50'; + label = 'Entry Point'; + printLabel(label, X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + + for (let k = 0; k < strategy.entryPoint.situations.length; k++) { + + let situation = strategy.entryPoint.situations[k]; + + y = y + increment; opacity = '0.50'; + label = 'Situation: ' + situation.name; + printLabel(label, X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity, UI_COLOR.DARK); + + for (let m = 0; m < situation.conditions.length; m++) { + + let condition = situation.conditions[m]; + let color; + + y = y + increment; + if (currentRecord.conditionsValues[conditionIndex] === 1) { + opacity = '0.50' + color = UI_COLOR.PATINATED_TURQUOISE; + } else { + opacity = '0.50'; + color = UI_COLOR.RUSTED_RED; + } + conditionIndex++; + label = condition.name; + printLabel(label, X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity, color); + } } - printLabel(currentRecord.conditionsNames[i], X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity); } - function printLabel(labelToPrint, x, y, opacity) { + function printLabel(labelToPrint, x, y, opacity, color) { let labelPoint; let fontSize = 10; @@ -113,7 +151,7 @@ function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() { labelPoint = thisObject.container.frame.frameThisPoint(labelPoint); - browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'; + browserCanvasContext.fillStyle = 'rgba(' + color + ', ' + opacity + ')'; browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); }