From 7692e3685d76c08554eb0051085a2d77d226ec5c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 31 Jan 2020 11:47:11 +0100 Subject: [PATCH] events at coordinate system --- Candles.js | 30 ++++++++++++++++++++++++++++-- Volumes.js | 30 ++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/Candles.js b/Candles.js index 7daa2bf90..9ea30488e 100644 --- a/Candles.js +++ b/Candles.js @@ -57,7 +57,9 @@ let dimmensionsChangedEventSubscriptionId let marketFilesUpdatedEventSubscriptionId let dailyFilesUpdatedEventSubscriptionId + let scaleChangedEventSubscriptionId + let userPositionDate return thisObject; function finalize() { @@ -85,6 +87,7 @@ thisObject.fitFunction = undefined + finalizeCoordinateSystem() coordinateSystem = undefined } catch (err) { @@ -104,6 +107,7 @@ datetime = pDatetime; timeFrame = pTimeFrame; coordinateSystem = pCoordinateSystem + initializeCoordinateSystem() /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ @@ -139,6 +143,18 @@ } } + function initializeCoordinateSystem() { + scaleChangedEventSubscriptionId = coordinateSystem.eventHandler.listenToEvent('Scale Changed', onScaleChanged) + } + + function finalizeCoordinateSystem() { + coordinateSystem.eventHandler.stopListening(scaleChangedEventSubscriptionId) + } + + function onScaleChanged() { + recalculate(); + } + function onMouseOver(event) { let userPosition = getDateFromPoint(event, thisObject.container, coordinateSystem) userPositionDate = userPosition.valueOf() @@ -226,7 +242,9 @@ } function setCoordinateSystem(pCoordinateSystem) { + finalizeCoordinateSystem() coordinateSystem = pCoordinateSystem + initializeCoordinateSystem() } function onDailyFileLoaded(event) { @@ -340,7 +358,11 @@ if (candle.open < candle.close) { candle.direction = 'up'; } if (candle.open === candle.close) { candle.direction = 'side'; } - if (candle.begin >= farLeftDate.valueOf() && candle.end <= farRightDate.valueOf()) { + + if ( + (candle.begin >= farLeftDate.valueOf() && candle.end <= farRightDate.valueOf()) && + (candle.begin >= coordinateSystem.min.x && candle.end <= coordinateSystem.max.x) + ) { candles.push(candle); @@ -416,7 +438,11 @@ if (candle.open < candle.close) { candle.direction = 'up'; } if (candle.open === candle.close) { candle.direction = 'side'; } - if (candle.begin >= leftDate.valueOf() && candle.end <= rightDate.valueOf()) { + if ( + (candle.begin >= leftDate.valueOf() && candle.end <= rightDate.valueOf()) && + (candle.begin >= coordinateSystem.min.x && candle.end <= coordinateSystem.max.x) + ) + { candles.push(candle); diff --git a/Volumes.js b/Volumes.js index 185fa070d..0a9a29236 100644 --- a/Volumes.js +++ b/Volumes.js @@ -56,7 +56,9 @@ let dimmensionsChangedEventSubscriptionId let marketFilesUpdatedEventSubscriptionId let dailyFilesUpdatedEventSubscriptionId + let scaleChangedEventSubscriptionId + let userPositionDate return thisObject; function finalize() { @@ -84,6 +86,7 @@ thisObject.fitFunction = undefined + finalizeCoordinateSystem() coordinateSystem = undefined } catch (err) { @@ -103,6 +106,7 @@ datetime = pDatetime; timeFrame = pTimeFrame; coordinateSystem = pCoordinateSystem + initializeCoordinateSystem() /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ @@ -142,6 +146,20 @@ } } + function initializeCoordinateSystem() { + scaleChangedEventSubscriptionId = coordinateSystem.eventHandler.listenToEvent('Scale Changed', onScaleChanged) + } + + function finalizeCoordinateSystem() { + coordinateSystem.eventHandler.stopListening(scaleChangedEventSubscriptionId) + } + + function onScaleChanged() { + recalculateScaleX(); + recalculate(); + recalculateScaleY(); + } + function onMouseOver(event) { let userPosition = getDateFromPoint(event, thisObject.container, coordinateSystem) userPositionDate = userPosition.valueOf() @@ -249,7 +267,9 @@ } function setCoordinateSystem(pCoordinateSystem) { + finalizeCoordinateSystem() coordinateSystem = pCoordinateSystem + initializeCoordinateSystem() } function onDailyFileLoaded(event) { @@ -353,7 +373,10 @@ volume.begin = dailyFile[i][2]; volume.end = dailyFile[i][3]; - if (volume.begin >= farLeftDate.valueOf() && volume.end <= farRightDate.valueOf()) { + if ( + (volume.begin >= farLeftDate.valueOf() && volume.end <= farRightDate.valueOf()) && + (volume.begin >= coordinateSystem.min.x && volume.end <= coordinateSystem.max.x) + ) { volumes.push(volume); @@ -424,7 +447,10 @@ volume.begin = marketFile[i][2]; volume.end = marketFile[i][3]; - if (volume.begin >= leftDate.valueOf() && volume.end <= rightDate.valueOf()) { + if ( + (volume.begin >= leftDate.valueOf() && volume.end <= rightDate.valueOf()) && + (volume.begin >= coordinateSystem.min.x && volume.end <= coordinateSystem.max.x) + ) { volumes.push(volume);