From 6798b4bf0f189329b06a49c8259b4b3ec4332f8c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 1 Apr 2020 14:00:14 +0200 Subject: [PATCH] scale improvements --- CanvasApp/ChartingSpace/CoordinateSystem.js | 24 +++++++++++-------- CanvasApp/ChartingSpace/EdgeEditor.js | 5 ++-- CanvasApp/FloatingSpace/UiObjectTitle.js | 18 ++++++++++++-- CanvasApp/Scales/AutoScaleButton.js | 22 +++++++++++++---- .../Plotters-Trading-Simulation/Strategies.js | 2 +- .../Plotters-Trading-Simulation/Trades.js | 2 +- 6 files changed, 52 insertions(+), 21 deletions(-) diff --git a/CanvasApp/ChartingSpace/CoordinateSystem.js b/CanvasApp/ChartingSpace/CoordinateSystem.js index 4e28a1716..653004e23 100644 --- a/CanvasApp/ChartingSpace/CoordinateSystem.js +++ b/CanvasApp/ChartingSpace/CoordinateSystem.js @@ -19,6 +19,10 @@ function newCoordinateSystem () { autoMaxXScale: true, autoMinYScale: true, autoMaxYScale: true, + HORIZONTAL_MARGIN_FACTOR: 0.80, + VERTICAL_MARGIN_FACTOR: 0.90, + HORIZONTAL_MARGIN_INVERSE_FACTOR: 0.20, + VERTICAL_MARGIN_INVERSE_FACTOR: 0.10, physics: physics, reportXValue: reportXValue, reportYValue: reportYValue, @@ -193,8 +197,8 @@ function newCoordinateSystem () { } function recalculateScale (event) { - thisObject.scale.x = thisObject.maxWidth / (thisObject.max.x - thisObject.min.x) - thisObject.scale.y = thisObject.maxHeight / (thisObject.max.y - thisObject.min.y) + thisObject.scale.x = thisObject.maxWidth * thisObject.HORIZONTAL_MARGIN_FACTOR / (thisObject.max.x - thisObject.min.x) + thisObject.scale.y = thisObject.maxHeight * thisObject.VERTICAL_MARGIN_FACTOR / (thisObject.max.y - thisObject.min.y) thisObject.eventHandler.raiseEvent('Scale Changed', event) } @@ -230,8 +234,8 @@ function newCoordinateSystem () { */ point = { - x: (point.x - thisObject.min.x) * thisObject.scale.x, - y: thisObject.maxHeight - (point.y - thisObject.min.y) * thisObject.scale.y + x: (point.x - thisObject.min.x) * thisObject.scale.x + thisObject.maxWidth * thisObject.HORIZONTAL_MARGIN_INVERSE_FACTOR / 2, + y: thisObject.maxHeight - (point.y - thisObject.min.y) * thisObject.scale.y - thisObject.maxHeight * thisObject.VERTICAL_MARGIN_INVERSE_FACTOR / 2 } return point @@ -239,8 +243,8 @@ function newCoordinateSystem () { function transformThisPoint2 (point) { point = { - x: (point.x - thisObject.min.x) * thisObject.scale.x, - y: (thisObject.maxHeight - point.y - thisObject.min.y) * thisObject.scale.y + x: (point.x - thisObject.min.x) * thisObject.scale.x + thisObject.maxWidth * thisObject.HORIZONTAL_MARGIN_INVERSE_FACTOR / 2, + y: (thisObject.maxHeight - point.y - thisObject.min.y) * thisObject.scale.y - thisObject.maxHeight * thisObject.VERTICAL_MARGIN_INVERSE_FACTOR / 2 } return point @@ -248,8 +252,8 @@ function newCoordinateSystem () { function unInverseTransform (point, inverseY) { point = { - x: (point.x / thisObject.scale.x) + thisObject.min.x, - y: (inverseY - point.y) / thisObject.scale.y + thisObject.min.y + x: ((point.x - thisObject.maxWidth * thisObject.HORIZONTAL_MARGIN_INVERSE_FACTOR / 2) / thisObject.scale.x) + thisObject.min.x, + y: (inverseY * thisObject.VERTICAL_MARGIN_FACTOR - point.y + thisObject.maxHeight * thisObject.VERTICAL_MARGIN_INVERSE_FACTOR / 2) / thisObject.scale.y + thisObject.min.y } return point @@ -257,8 +261,8 @@ function newCoordinateSystem () { function inverseTransformUncappedY (point, inverseY) { point = { - x: (point.x - thisObject.min.x) * thisObject.scale.x, - y: (inverseY - point.y) * thisObject.scale.y + x: (point.x - thisObject.min.x) * thisObject.scale.x + thisObject.maxWidth * thisObject.HORIZONTAL_MARGIN_INVERSE_FACTOR / 2, + y: (inverseY * thisObject.VERTICAL_MARGIN_FACTOR - point.y) * thisObject.scale.y - thisObject.maxHeight * thisObject.VERTICAL_MARGIN_INVERSE_FACTOR / 2 } return point diff --git a/CanvasApp/ChartingSpace/EdgeEditor.js b/CanvasApp/ChartingSpace/EdgeEditor.js index 02af47f99..df338ece4 100644 --- a/CanvasApp/ChartingSpace/EdgeEditor.js +++ b/CanvasApp/ChartingSpace/EdgeEditor.js @@ -268,6 +268,7 @@ function newEdgeEditor () { } function draggingPhysics () { + if (coordinateSystemWhenDragStarted === undefined) { return } if (thisObject.container.frame.position.x === 0 && thisObject.container.frame.position.y === 0) { return } let mouseNoZoom = canvas.chartingSpace.viewport.unTransformThisPoint(mouse.position) @@ -324,7 +325,7 @@ function newEdgeEditor () { break case 'left or right arrow key pressed': { let point = { - x: -dragVector.x, + x: -dragVector.x + thisObject.container.frame.width * coordinateSystem.HORIZONTAL_MARGIN_INVERSE_FACTOR / 2, y: 0 } @@ -342,7 +343,7 @@ function newEdgeEditor () { case 'up or down arrow key pressed': { let point = { x: 0, - y: -dragVector.y + y: -dragVector.y + thisObject.container.frame.height * coordinateSystem.VERTICAL_MARGIN_INVERSE_FACTOR / 2 } let newMaxRate = getRateFromPointAtContainer(point, thisObject.container.parentContainer, coordinateSystem) diff --git a/CanvasApp/FloatingSpace/UiObjectTitle.js b/CanvasApp/FloatingSpace/UiObjectTitle.js index cb723a0b0..cc3dd557a 100644 --- a/CanvasApp/FloatingSpace/UiObjectTitle.js +++ b/CanvasApp/FloatingSpace/UiObjectTitle.js @@ -12,6 +12,7 @@ function newUiObjectTitle () { editMode: undefined, container: undefined, payload: undefined, + isDefault: undefined, enterEditMode: enterEditMode, exitEditMode: exitEditMode, physics: physics, @@ -81,6 +82,19 @@ function newUiObjectTitle () { } function physics () { + inheritancePhysics() + defaultPhysics() + } + + function defaultPhysics () { + if (thisObject.payload.title !== 'New ' + thisObject.payload.node.type && thisObject.payload.title !== 'My ' + thisObject.payload.node.type) { + thisObject.isDefault = false + } else { + thisObject.isDefault = true + } + } + + function inheritancePhysics () { if (thisObject.payload.title === undefined) { return } /* It is possible to override the default title by setting the APP SCHEMA property 'title' */ @@ -255,7 +269,7 @@ function newUiObjectTitle () { } function draw () { - if (thisObject.isOnFocus === true || thisObject.allwaysVisible === true) { + if (thisObject.isOnFocus === true || thisObject.allwaysVisible === true || thisObject.isDefault === false) { if (thisObject.payload.uiObject.codeEditor !== undefined) { if (thisObject.payload.uiObject.codeEditor.visible !== true) { drawTitleBackground() @@ -291,7 +305,7 @@ function newUiObjectTitle () { let fontSize = thisObject.payload.floatingObject.currentFontSize let label - if (radius > 6 && (thisObject.isOnFocus === true || thisObject.allwaysVisible === true)) { + if (radius > 6 && (thisObject.isOnFocus === true || thisObject.allwaysVisible === true || thisObject.isDefault === false)) { browserCanvasContext.strokeStyle = thisObject.payload.floatingObject.labelStrokeStyle browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY diff --git a/CanvasApp/Scales/AutoScaleButton.js b/CanvasApp/Scales/AutoScaleButton.js index 1034443ca..597f1c2b2 100644 --- a/CanvasApp/Scales/AutoScaleButton.js +++ b/CanvasApp/Scales/AutoScaleButton.js @@ -85,10 +85,10 @@ function newAutoScaleButton () { currentStatus = 2 } if (thisObject.autoMinScale === false && thisObject.autoMaxScale === true) { - currentStatus = 3 + currentStatus = 4 } if (thisObject.autoMinScale === true && thisObject.autoMaxScale === true) { - currentStatus = 4 + currentStatus = 6 } } function onMouseWheel (event) { @@ -100,8 +100,8 @@ function newAutoScaleButton () { delta = 1 } currentStatus = currentStatus + delta - if (currentStatus === 5) { currentStatus = 1 } - if (currentStatus === 0) { currentStatus = 4 } + if (currentStatus === 7) { currentStatus = 1 } + if (currentStatus === 0) { currentStatus = 6 } switch (currentStatus) { case 1: { @@ -118,11 +118,23 @@ function newAutoScaleButton () { } case 3: { thisObject.autoMinScale = false - thisObject.autoMaxScale = true + thisObject.autoMaxScale = false update() return } case 4: { + thisObject.autoMinScale = false + thisObject.autoMaxScale = true + update() + return + } + case 5: { + thisObject.autoMinScale = false + thisObject.autoMaxScale = false + update() + return + } + case 6: { thisObject.autoMinScale = true thisObject.autoMaxScale = true update() diff --git a/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/Strategies.js b/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/Strategies.js index c522c7a82..5f49a356a 100644 --- a/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/Strategies.js +++ b/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/Strategies.js @@ -582,7 +582,7 @@ let digit = record.begin.toFixed(0).substring(7,8) let positionY = recordPoint3.y - (recordPoint3.y - recordPoint1.y) / 2 + (Number(digit) * 10 - 50) if (canvas.chartingSpace.viewport.zoomLevel >= ZOOM_OUT_THRESHOLD_FOR_HIDDING_CHARTS_LABELS) { - if (record.triggerOnSituation !== "My Situation") { + if (record.triggerOnSituation !== "New Situation") { printLabel(record.triggerOnSituation, recordPoint1.x + 5, positionY, '1', 12); } } diff --git a/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/Trades.js b/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/Trades.js index f90c577bc..9da7b37b6 100644 --- a/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/Trades.js +++ b/Legacy-Code/TradingEngines/plotters/Plotters-Trading-Simulation/Trades.js @@ -522,7 +522,7 @@ let line1 = ''; let line2 = ''; - if (line0 === 'My Situation') { + if (line0 === 'New Situation') { line0 = '' }