diff --git a/Candles.js b/Candles.js index 0b9393412..0c2a4e70e 100644 --- a/Candles.js +++ b/Candles.js @@ -198,10 +198,17 @@ /* Now we calculate which candle has this new time, because it will give us the y coordinate. */ + let candleFound = false; + let lastClose; + for (let i = 0; i < candles.length; i++) { + lastClose = candles[i].close; + if (value >= candles[i].begin && value <= candles[i].end) { + candleFound = true; + let targetPoint = { x: value, y: candles[i].open @@ -253,6 +260,31 @@ } } + if (candleFound === false) { + + let targetPoint = { + x: value, + y: lastClose + }; + + targetPoint = timeLineCoordinateSystem.transformThisPoint(targetPoint); + targetPoint = transformThisPoint(targetPoint, thisObject.container); + + let center = { + x: (viewPort.visibleArea.bottomRight.x - viewPort.visibleArea.bottomLeft.x) / 2, + y: (viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topRight.y) / 2 + }; + + let displaceVector = { + x: center.x - targetPoint.x, + y: center.y - targetPoint.y + }; + + viewPort.displace(displaceVector); + + return; + } + } catch (err) { if (ERROR_LOG === true) { logger.write("[ERROR] positionAtDatetime -> err.message = " + err.message); }