Files
Superalgos/ConditionsPanel.js
T

131 lines
3.3 KiB
JavaScript

function newAAMastersPlottersTradingSimulationConditionsConditionsPanel() {
var thisObject = {
onEventRaised: onEventRaised,
container: undefined,
draw: draw,
getContainer: getContainer,
initialize: initialize
};
var container = newContainer();
container.initialize();
thisObject.container = container;
container.displacement.containerName = "Conditions Panel";
container.frame.containerName = "Conditions Panel";
let currentRecord;
return thisObject;
function initialize() {
thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL;
thisObject.container.frame.height = UI_PANEL.HEIGHT.NORMAL * 1;
thisObject.container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width * 2;
thisObject.container.frame.position.y = viewPort.visibleArea.topRight.y;
}
function getContainer(point) {
var container;
/* First we check if this point is inside this space. */
if (this.container.frame.isThisPointHere(point, true) === true) {
return this.container;
} else {
/* This point does not belong to this space. */
return undefined;
}
}
function onEventRaised(lastCurrentRecord) {
currentRecord = lastCurrentRecord;
}
function draw() {
this.container.frame.draw(false, false, true);
plotCurrentRecordInfo();
}
function plotCurrentRecordInfo() {
if (currentRecord === undefined) { return; }
if (currentRecord.conditionsNames === undefined) { return; }
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;
let y = 0;
let increment = 0.06;
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.
y = y + increment;
let opacity;
if (currentRecord.conditionsValues[i] === 1) {
opacity = '1.00'
} else {
opacity = '0.50';
}
printLabel(currentRecord.conditionsNames[i], X_AXIS, frameTitleHeight + frameBodyHeight * y, opacity);
}
function printLabel(labelToPrint, x, y, opacity) {
let labelPoint;
let fontSize = 10;
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY;
let label = '' + labelToPrint;
if (isNaN(label) === false) {
label = Number(label).toLocaleString();
}
let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO;
labelPoint = {
x: x - xOffset,
y: y
};
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint);
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')';
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y);
}
browserCanvasContext.closePath();
browserCanvasContext.fill();
}
}