diff --git a/ChartsSpace/TimeMachine.js b/ChartsSpace/TimeMachine.js index 5baf9bb8c..6ab58e459 100644 --- a/ChartsSpace/TimeMachine.js +++ b/ChartsSpace/TimeMachine.js @@ -526,7 +526,7 @@ function newTimeMachine () { let maxValue = { x: MAX_PLOTABLE_DATE.valueOf(), - y: nextPorwerOf10(USDT_BTC_HTH) / 4 + y: nextPorwerOf10(MAX_DEFAULT_RATE_SCALE_VALUE) / 4 } timeMachineCoordinateSystem.initialize( diff --git a/ChartsSpace/TimelineChart.js b/ChartsSpace/TimelineChart.js index 8bba45db6..05a1bbf65 100644 --- a/ChartsSpace/TimelineChart.js +++ b/ChartsSpace/TimelineChart.js @@ -455,7 +455,7 @@ function newTimelineChart () { let maxValue = { x: MAX_PLOTABLE_DATE.valueOf(), - y: nextPorwerOf10(USDT_BTC_HTH) / 4 + y: nextPorwerOf10(MAX_DEFAULT_RATE_SCALE_VALUE) / 4 } timelineChartCoordinateSystem.initialize( diff --git a/ChartsSpace/ViewPort.js b/ChartsSpace/ViewPort.js index 01b7d5627..354c43747 100644 --- a/ChartsSpace/ViewPort.js +++ b/ChartsSpace/ViewPort.js @@ -135,11 +135,11 @@ function newViewport () { function physics () { animationPhysics() - positioningphysics() + positioningPhysics() readObjectState() } - function positioningphysics () { + function positioningPhysics () { if (thisObject.payload === undefined) { return } /* Save the position at the frame lavel */ let frame = {} diff --git a/Globals.js b/Globals.js index e3d45800f..bb8d53ef0 100644 --- a/Globals.js +++ b/Globals.js @@ -117,7 +117,7 @@ const DEFAULT_CONFIG_TEXT = '// Write your config here' const DEFAULT_FORMULA_TEXT = '// Write your formula here' const DEFAULT_CODE_TEXT = '// Write your code here' -const USDT_BTC_HTH = 19900; // This is needed to know the scale of the market time line. +const MAX_DEFAULT_RATE_SCALE_VALUE = 19900; // This is needed to know the scale of the market time line. const WIDHTER_VOLUME_BAR_BASE_FACTOR = 2.5; const LESS_WIDHTER_VOLUME_BAR_TOP_FACTOR = 1 / 4; diff --git a/Plotter.js b/Plotter.js index 2f73675b7..13b35c216 100644 --- a/Plotter.js +++ b/Plotter.js @@ -450,7 +450,7 @@ function newPlotter () { let maxValue = { x: MAX_PLOTABLE_DATE.valueOf(), - y: nextPorwerOf10(USDT_BTC_HTH) / 4 // TODO: This 4 is temporary + y: nextPorwerOf10(MAX_DEFAULT_RATE_SCALE_VALUE) / 4 // TODO: This 4 is temporary } coordinateSystem.initialize( diff --git a/Project.njsproj b/Project.njsproj index 99fe110d0..3dedf7ed3 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -158,7 +158,7 @@ - + Code diff --git a/Scales/RateScale.js b/Scales/RateScale.js index 8e9360c05..822bcd31c 100644 --- a/Scales/RateScale.js +++ b/Scales/RateScale.js @@ -8,6 +8,8 @@ function newRateScale () { payload: undefined, scale: undefined, offset: undefined, + minValue: undefined, + maxValue: undefined, setScale: setScale, onMouseOverSomeTimeMachineContainer: onMouseOverSomeTimeMachineContainer, physics: physics, @@ -50,7 +52,7 @@ function newRateScale () { let onMouseOverEventSubscriptionId let onMouseNotOverEventSubscriptionId - let timeLineCoordinateSystem + let coordinateSystem let limitingContainer let rateCalculationsContainer @@ -75,14 +77,14 @@ function newRateScale () { thisObject.fitFunction = undefined thisObject.payload = undefined - timeLineCoordinateSystem = undefined + coordinateSystem = undefined limitingContainer = undefined rateCalculationsContainer = undefined mouse = undefined } - function initialize (pTimeLineCoordinateSystem, pLimitingContainer, pRateCalculationsContainer) { - timeLineCoordinateSystem = pTimeLineCoordinateSystem + function initialize (pCoordinateSystem, pLimitingContainer, pRateCalculationsContainer) { + coordinateSystem = pCoordinateSystem limitingContainer = pLimitingContainer rateCalculationsContainer = pRateCalculationsContainer @@ -233,10 +235,7 @@ function newRateScale () { saveObjectState() return } - if (isNaN(code.offset) || code.offset === null || code.offset === undefined) { - saveObjectState() - return - } + code.scale = code.scale / 100 * MAX_SCALE if (code.scale < MIN_SCALE) { code.scale = MIN_SCALE } if (code.scale > MAX_SCALE) { code.scale = MAX_SCALE } @@ -258,6 +257,11 @@ function newRateScale () { return } + if (isNaN(code.offset) || code.offset === null || code.offset === undefined) { + saveObjectState() + return + } + if (code.offset < MIN_OFFSET) { code.offset = MIN_OFFSET } if (code.offset > MAX_OFFSET) { code.offset = MAX_OFFSET } @@ -277,6 +281,18 @@ function newRateScale () { saveObjectState() return } + + if (isNaN(code.minValue) || code.minValue === null || code.minValue === undefined) { + saveObjectState() + return + } + if (isNaN(code.maxValue) || code.maxValue === null || code.maxValue === undefined) { + saveObjectState() + return + } + + coordinateSystem.min.y = code.minValue + coordinateSystem.max.y = code.maxValue } catch (err) { // we ignore errors here since most likely they will be parsing errors. } @@ -286,10 +302,10 @@ function newRateScale () { offsetTimer-- scaleTimer-- readObjectState() - positioningphysics() + positioningPhysics() } - function positioningphysics () { + function positioningPhysics () { /* Container Limits */ let upCorner = { @@ -336,7 +352,7 @@ function newRateScale () { y: mouse.position.y + thisObject.offset } - thisObject.rate = getRateFromPoint(ratePoint, rateCalculationsContainer, timeLineCoordinateSystem) + thisObject.rate = getRateFromPoint(ratePoint, rateCalculationsContainer, coordinateSystem) /* rateScale Positioning */ ratePoint = { @@ -376,8 +392,8 @@ function newRateScale () { let rate = thisObject.rate - if (rate < timeLineCoordinateSystem.min.y) { rate = timeLineCoordinateSystem.min.y } - if (rate > timeLineCoordinateSystem.max.y) { rate = timeLineCoordinateSystem.max.y } + if (rate < coordinateSystem.min.y) { rate = coordinateSystem.min.y } + if (rate > coordinateSystem.max.y) { rate = coordinateSystem.max.y } let label = (rate - Math.trunc(rate)).toFixed(2) let labelArray = label.split('.') diff --git a/Scales/TimeFrameScale.js b/Scales/TimeFrameScale.js index 7477ccb7b..6792db3a5 100644 --- a/Scales/TimeFrameScale.js +++ b/Scales/TimeFrameScale.js @@ -32,7 +32,7 @@ function newTimeFrameScale () { let onMouseOverEventSubscriptionId let onMouseNotOverEventSubscriptionId - let timeLineCoordinateSystem + let coordinateSystem let limitingContainer let mouse = { @@ -69,8 +69,8 @@ function newTimeFrameScale () { thisObject.payload = undefined } - function initialize (pTimeLineCoordinateSystem, pLimitingContainer) { - timeLineCoordinateSystem = pTimeLineCoordinateSystem + function initialize (pCoordinateSystem, pLimitingContainer) { + coordinateSystem = pCoordinateSystem limitingContainer = pLimitingContainer readObjectState() @@ -114,10 +114,10 @@ function newTimeFrameScale () { function physics () { readObjectState() - positioningphysics() + positioningPhysics() } - function positioningphysics () { + function positioningPhysics () { /* Container Limits */ let upCorner = { diff --git a/Scales/TimeScale.js b/Scales/TimeScale.js index 5d2d193fb..16a81aad0 100644 --- a/Scales/TimeScale.js +++ b/Scales/TimeScale.js @@ -40,7 +40,7 @@ function newTimeScale () { let onMouseOverEventSubscriptionId let onMouseNotOverEventSubscriptionId - let timeLineCoordinateSystem + let coordinateSystem let limitingContainer let mouse = { @@ -62,13 +62,13 @@ function newTimeScale () { thisObject.fitFunction = undefined thisObject.payload = undefined - timeLineCoordinateSystem = undefined + coordinateSystem = undefined limitingContainer = undefined mouse = undefined } - function initialize (pTimeLineCoordinateSystem, pLimitingContainer) { - timeLineCoordinateSystem = pTimeLineCoordinateSystem + function initialize (pCoordinateSystem, pLimitingContainer) { + coordinateSystem = pCoordinateSystem limitingContainer = pLimitingContainer onMouseWheelEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel) @@ -195,10 +195,10 @@ function newTimeScale () { function physics () { scaleTimer-- readObjectState() - positioningphysics() + positioningPhysics() } - function positioningphysics () { + function positioningPhysics () { /* Container Limits */ let upCorner = { @@ -223,7 +223,7 @@ function newTimeScale () { y: 0 } - let mouseDate = getDateFromPoint(timePoint, limitingContainer, timeLineCoordinateSystem) + let mouseDate = getDateFromPoint(timePoint, limitingContainer, coordinateSystem) thisObject.date = new Date(mouseDate) diff --git a/Utilities.js b/Utilities.js index 5ec3e13b4..73029d645 100644 --- a/Utilities.js +++ b/Utilities.js @@ -82,30 +82,30 @@ function pad (str, max) { return str.length < max ? pad('0' + str, max) : str } -function getDateFromPoint (point, container, timeLineCoordinateSystem) { +function getDateFromPoint (point, container, coordinateSystem) { point = unTransformThisPoint(point, container) - point = timeLineCoordinateSystem.unInverseTransform(point, container.frame.height) + point = coordinateSystem.unInverseTransform(point, container.frame.height) let date = new Date(point.x) return date } -function getRateFromPoint (point, container, timeLineCoordinateSystem) { +function getRateFromPoint (point, container, coordinateSystem) { point = unTransformThisPoint(point, container) - point = timeLineCoordinateSystem.unInverseTransform(point, container.frame.height) + point = coordinateSystem.unInverseTransform(point, container.frame.height) return point.y } -function getMilisecondsFromPoint (point, container, timeLineCoordinateSystem) { +function getMilisecondsFromPoint (point, container, coordinateSystem) { point = unTransformThisPoint(point, container) - point = timeLineCoordinateSystem.unInverseTransform(point, container.frame.height) + point = coordinateSystem.unInverseTransform(point, container.frame.height) return point.x } -function saveUserPosition (container, timeLineCoordinateSystem, position) { +function saveUserPosition (container, coordinateSystem, position) { if (position === undefined) { position = { x: (canvas.chartSpace.viewport.visibleArea.bottomRight.x - canvas.chartSpace.viewport.visibleArea.topLeft.x) / 2, @@ -114,8 +114,8 @@ function saveUserPosition (container, timeLineCoordinateSystem, position) { } let userPosition = { - date: getDateFromPoint(position, container, timeLineCoordinateSystem), - rate: getRateFromPoint(position, container, timeLineCoordinateSystem), + date: getDateFromPoint(position, container, coordinateSystem), + rate: getRateFromPoint(position, container, coordinateSystem), market: DEFAULT_MARKET, zoom: canvas.chartSpace.viewport.zoomTargetLevel } @@ -123,14 +123,14 @@ function saveUserPosition (container, timeLineCoordinateSystem, position) { window.localStorage.setItem('userPosition', JSON.stringify(userPosition)) } -function getUserPosition (timeLineCoordinateSystem) { +function getUserPosition (coordinateSystem) { let savedPosition = window.localStorage.getItem('userPosition') let userPosition if (savedPosition === null) { userPosition = { date: (new Date()).toString(), - rate: timeLineCoordinateSystem.max.y / 2, + rate: coordinateSystem.max.y / 2, market: DEFAULT_MARKET, zoom: INITIAL_ZOOM_LEVEL } @@ -146,8 +146,8 @@ function getUserPosition (timeLineCoordinateSystem) { return userPosition } -function moveToUserPosition (container, timeLineCoordinateSystem, ignoreX, ignoreY, center, moveContainer) { - let userPosition = getUserPosition(timeLineCoordinateSystem) +function moveToUserPosition (container, coordinateSystem, ignoreX, ignoreY, center, moveContainer) { + let userPosition = getUserPosition(coordinateSystem) INITIAL_TIME_PERIOD = recalculatePeriod(userPosition.zoom) NEW_SESSION_INITIAL_DATE = new Date(userPosition.date) @@ -159,7 +159,7 @@ function moveToUserPosition (container, timeLineCoordinateSystem, ignoreX, ignor /* Put this po int in the coordinate system of the canvas.chartSpace.viewport */ - targetPoint = timeLineCoordinateSystem.transformThisPoint(targetPoint) + targetPoint = coordinateSystem.transformThisPoint(targetPoint) targetPoint = transformThisPoint(targetPoint, container) let centerPoint