Obect State at Viewport
This commit is contained in:
1 parent
1a05181968
commit
349a943222
3 files changed
+38
-13
No files matched your search
@@ -2,8 +2,6 @@
|
||||
let canvas
|
||||
let markets
|
||||
let ecosystem = newEcosystem()
|
||||
let INITIAL_ZOOM_LEVEL = -26 // This is the zoom level at the view port in which the APP starts.
|
||||
let INITIAL_TIME_PERIOD = recalculatePeriod(MIN_ZOOM_LEVEL) // This value will be overwritten at the viewPort.initialize if the user had a prevous session with this same browser.
|
||||
let viewPort = newViewPort()
|
||||
|
||||
function newDashboard () {
|
||||
|
||||
@@ -117,6 +117,8 @@ function convertTimePeriodToName(pTimePeriod) {
|
||||
|
||||
window.AT_BREAKPOINT = false;
|
||||
|
||||
|
||||
|
||||
const USDT_BTC_HTH = 19900; // This is needed to know the scale of the market time line.
|
||||
|
||||
const WIDHTER_VOLUME_BAR_BASE_FACTOR = 2.5;
|
||||
@@ -144,6 +146,8 @@ const _2_MINUTES_IN_MILISECONDS = 2 * 60 * 1000;
|
||||
const _1_MINUTE_IN_MILISECONDS = 1 * 60 * 1000;
|
||||
|
||||
let NEW_SESSION_INITIAL_DATE = new Date(); // This value will be overwritten at the viewPort.initialize if the user had a prevous session with this same browser.
|
||||
let INITIAL_ZOOM_LEVEL = -28.25 // This is the zoom level at the view port in which the APP starts.
|
||||
let INITIAL_TIME_PERIOD = ONE_DAY_IN_MILISECONDS // This value will be overwritten at the viewPort.initialize if the user had a prevous session with this same browser.
|
||||
|
||||
let maxDate = new Date();
|
||||
maxDate.setMilliseconds(0);
|
||||
|
||||
+34
-11
@@ -1,5 +1,12 @@
|
||||
|
||||
function newViewPort () {
|
||||
const MODULE_NAME = 'Viewport'
|
||||
const INFO_LOG = false
|
||||
const INTENSIVE_LOG = false
|
||||
const ERROR_LOG = true
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
const CONSOLE_LOG = true
|
||||
|
||||
let ANIMATION_INCREMENT = 0.25
|
||||
@@ -62,6 +69,8 @@ function newViewPort () {
|
||||
|
||||
thisObject.eventHandler = newEventHandler()
|
||||
|
||||
let objectStorage = {}
|
||||
|
||||
return thisObject
|
||||
|
||||
function initialize () {
|
||||
@@ -71,6 +80,8 @@ function newViewPort () {
|
||||
bottomRight: { x: browserCanvas.width - RIGHT_MARGIN, y: browserCanvas.height - BOTTOM_MARGIN},
|
||||
bottomLeft: { x: LEFT_MARGIN, y: browserCanvas.height - BOTTOM_MARGIN}
|
||||
}
|
||||
|
||||
readObjectState()
|
||||
}
|
||||
|
||||
function getDisplacement () {
|
||||
@@ -106,17 +117,6 @@ function newViewPort () {
|
||||
changeZoom(thisObject.zoomLevel + ANIMATION_INCREMENT, thisObject.zoomLevel)
|
||||
}
|
||||
|
||||
/*
|
||||
if (offsetIncrement.x !== 0) {
|
||||
|
||||
if (Math.trunc(Math.abs(targetOffset.x - offset.x) * 1000) >= Math.trunc(Math.abs(offsetIncrement.x) * 1000)) {
|
||||
offset.x = offset.x + offsetIncrement.x;
|
||||
} else {
|
||||
offsetIncrement.x = 0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (offsetIncrement.y !== 0) {
|
||||
if (Math.trunc(Math.abs(targetOffset.y - offset.y) * 1000) >= Math.trunc(Math.abs(offsetIncrement.y) * 1000)) {
|
||||
offset.y = offset.y + offsetIncrement.y
|
||||
@@ -132,6 +132,8 @@ function newViewPort () {
|
||||
offset.x = offset.x + displaceVector.x
|
||||
offset.y = offset.y + displaceVector.y
|
||||
|
||||
saveObjectState()
|
||||
|
||||
let event = {
|
||||
newOffset: offset
|
||||
}
|
||||
@@ -157,6 +159,8 @@ function newViewPort () {
|
||||
thisObject.zoomTargetLevel = level
|
||||
thisObject.zoomLevel = level
|
||||
|
||||
saveObjectState()
|
||||
|
||||
ANIMATION_INCREMENT = Math.abs(thisObject.zoomTargetLevel - thisObject.zoomLevel) / 3
|
||||
|
||||
let event = {
|
||||
@@ -251,6 +255,8 @@ function newViewPort () {
|
||||
offset.x = offset.x - newMouse.x + thisObject.mousePosition.x
|
||||
offset.y = offset.y - newMouse.y + thisObject.mousePosition.y
|
||||
|
||||
saveObjectState()
|
||||
|
||||
targetOffset.x = offset.x
|
||||
targetOffset.y = offset.y
|
||||
|
||||
@@ -401,4 +407,21 @@ function newViewPort () {
|
||||
|
||||
browserCanvasContext.stroke()
|
||||
}
|
||||
|
||||
function saveObjectState () {
|
||||
objectStorage.offset = offset
|
||||
objectStorage.zoomLevel = thisObject.zoomLevel
|
||||
window.localStorage.setItem(MODULE_NAME, JSON.stringify(objectStorage))
|
||||
}
|
||||
|
||||
function readObjectState () {
|
||||
let objectStorageString = window.localStorage.getItem(MODULE_NAME)
|
||||
if (objectStorageString !== null && objectStorageString !== '') {
|
||||
objectStorage = JSON.parse(objectStorageString)
|
||||
offset = objectStorage.offset
|
||||
thisObject.zoomLevel = objectStorage.zoomLevel
|
||||
|
||||
INITIAL_TIME_PERIOD = recalculatePeriod(thisObject.zoomLevel)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user