Change in Code Indentation

This commit is contained in:
Luis Fernando Molina committed 2020-07-29 11:09:04 +02:00
1 parent 1a52e5494e
commit 199a71a4e5
89 files changed
+22093 -22093

No files matched your search

+103 -103
View File
@@ -1,139 +1,139 @@
function getSideDays (timeFrame) {
let daysOnSides
function getSideDays(timeFrame) {
let daysOnSides
if (timeFrame < _1_HOUR_IN_MILISECONDS) {
daysOnSides = 1
}
if (timeFrame < _1_HOUR_IN_MILISECONDS) {
daysOnSides = 1
}
if (timeFrame === _1_HOUR_IN_MILISECONDS) {
daysOnSides = 9
}
if (timeFrame === _1_HOUR_IN_MILISECONDS) {
daysOnSides = 9
}
if (timeFrame === _2_HOURS_IN_MILISECONDS) {
daysOnSides = 10
}
if (timeFrame === _2_HOURS_IN_MILISECONDS) {
daysOnSides = 10
}
if (timeFrame === _3_HOURS_IN_MILISECONDS) {
daysOnSides = 12
}
if (timeFrame === _3_HOURS_IN_MILISECONDS) {
daysOnSides = 12
}
if (timeFrame === _4_HOURS_IN_MILISECONDS) {
daysOnSides = 20
}
if (timeFrame === _4_HOURS_IN_MILISECONDS) {
daysOnSides = 20
}
if (timeFrame === _6_HOURS_IN_MILISECONDS) {
daysOnSides = 35
}
if (timeFrame === _6_HOURS_IN_MILISECONDS) {
daysOnSides = 35
}
if (timeFrame === _8_HOURS_IN_MILISECONDS) {
daysOnSides = 44
}
if (timeFrame === _8_HOURS_IN_MILISECONDS) {
daysOnSides = 44
}
if (timeFrame === _12_HOURS_IN_MILISECONDS) {
daysOnSides = 56
}
if (timeFrame === _12_HOURS_IN_MILISECONDS) {
daysOnSides = 56
}
if (timeFrame === ONE_DAY_IN_MILISECONDS) {
daysOnSides = 154
}
if (timeFrame === ONE_DAY_IN_MILISECONDS) {
daysOnSides = 154
}
return daysOnSides
return daysOnSides
}
function getCondenseFactor (timeFrame) {
switch (timeFrame) {
case _1_MINUTE_IN_MILISECONDS: return 1
case _5_MINUTES_IN_MILISECONDS: return 5
case _10_MINUTES_IN_MILISECONDS: return 10
case _30_MINUTES_IN_MILISECONDS: return 50
case _1_HOUR_IN_MILISECONDS: return 100
}
function getCondenseFactor(timeFrame) {
switch (timeFrame) {
case _1_MINUTE_IN_MILISECONDS: return 1
case _5_MINUTES_IN_MILISECONDS: return 5
case _10_MINUTES_IN_MILISECONDS: return 10
case _30_MINUTES_IN_MILISECONDS: return 50
case _1_HOUR_IN_MILISECONDS: return 100
}
}
function getTransparenceFactor (timeFrame) {
switch (timeFrame) {
case _1_MINUTE_IN_MILISECONDS: return '0.12'
case _5_MINUTES_IN_MILISECONDS: return '0.10'
case _10_MINUTES_IN_MILISECONDS: return '0.08'
case _30_MINUTES_IN_MILISECONDS: return '0.06'
case _1_HOUR_IN_MILISECONDS: return '0.04'
}
function getTransparenceFactor(timeFrame) {
switch (timeFrame) {
case _1_MINUTE_IN_MILISECONDS: return '0.12'
case _5_MINUTES_IN_MILISECONDS: return '0.10'
case _10_MINUTES_IN_MILISECONDS: return '0.08'
case _30_MINUTES_IN_MILISECONDS: return '0.06'
case _1_HOUR_IN_MILISECONDS: return '0.04'
}
}
function recalculatePeriod (zoomLevel) {
// console.log('NEW ZOOM LEVEL', zoomLevel)
if (zoomLevel > 400) {
return _1_MINUTE_IN_MILISECONDS
}
function recalculatePeriod(zoomLevel) {
// console.log('NEW ZOOM LEVEL', zoomLevel)
if (zoomLevel > 400) {
return _1_MINUTE_IN_MILISECONDS
}
if (zoomLevel > 360) {
return _2_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 360) {
return _2_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 330) {
return _3_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 330) {
return _3_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 300) {
return _4_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 300) {
return _4_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 270) {
return _5_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 270) {
return _5_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 250) {
return _10_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 250) {
return _10_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 230) {
return _15_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 230) {
return _15_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 210) {
return _20_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 210) {
return _20_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 190) {
return _30_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 190) {
return _30_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 170) {
return _40_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 170) {
return _40_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 150) {
return _45_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 150) {
return _45_MINUTES_IN_MILISECONDS
}
if (zoomLevel > 130) {
return _1_HOUR_IN_MILISECONDS
}
if (zoomLevel > 130) {
return _1_HOUR_IN_MILISECONDS
}
if (zoomLevel > 110) {
return _2_HOURS_IN_MILISECONDS
}
if (zoomLevel > 110) {
return _2_HOURS_IN_MILISECONDS
}
if (zoomLevel > 80) {
return _3_HOURS_IN_MILISECONDS
}
if (zoomLevel > 80) {
return _3_HOURS_IN_MILISECONDS
}
if (zoomLevel > 50) {
return _4_HOURS_IN_MILISECONDS
}
if (zoomLevel > 50) {
return _4_HOURS_IN_MILISECONDS
}
if (zoomLevel > 35) {
return _6_HOURS_IN_MILISECONDS
}
if (zoomLevel > 35) {
return _6_HOURS_IN_MILISECONDS
}
if (zoomLevel > 20) {
return _8_HOURS_IN_MILISECONDS
}
if (zoomLevel > 20) {
return _8_HOURS_IN_MILISECONDS
}
if (zoomLevel > 10) {
return _12_HOURS_IN_MILISECONDS
}
if (zoomLevel > 10) {
return _12_HOURS_IN_MILISECONDS
}
return ONE_DAY_IN_MILISECONDS
return ONE_DAY_IN_MILISECONDS
}
+306 -306
View File
@@ -1,4 +1,4 @@
/*
/*
This Object object is responsible for defining the coordinate system in a TimeLine.
@@ -7,320 +7,320 @@ The scale on the Y axis depends on the data that wants to be plotted. Usually we
*/
function newCoordinateSystem () {
let thisObject = {
min: undefined,
max: undefined,
parentMin: undefined,
parentMax: undefined,
childrenMin: undefined,
childrenMax: undefined,
maxHeight: undefined,
maxWidth: undefined,
scale: undefined,
eventHandler: undefined,
autoMinXScale: true,
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,
reportParentXValue: reportParentXValue,
reportParentYValue: reportParentYValue,
reportXValue: reportXValue,
reportYValue: reportYValue,
zoomX: zoomX,
zoomY: zoomY,
recalculateScale: recalculateScale,
transformThisPoint: transformThisPoint,
transformThisPoint2: transformThisPoint2,
unInverseTransform: unInverseTransform,
inverseTransformUncappedY: inverseTransformUncappedY,
initializeX: initializeX,
initializeY: initializeY,
initialize: initialize,
finalize: finalize
}
thisObject.min = {
x: 0,
y: 0
}
thisObject.max = {
x: 0,
y: 0
}
thisObject.parentMin = {
x: 0,
y: 0
}
thisObject.parentMax = {
x: 0,
y: 0
}
thisObject.childrenMin = {
x: 0,
y: 0
}
thisObject.childrenMax = {
x: 0,
y: 0
}
thisObject.scale = {
x: 0,
y: 0
}
thisObject.eventHandler = newEventHandler()
thisObject.eventHandler.name = 'Coordinate System'
let newXMax = -VERY_LARGE_NUMBER
let newXMin = VERY_LARGE_NUMBER
let newYMax = -VERY_LARGE_NUMBER
let newYMin = VERY_LARGE_NUMBER
let parentMinChanged = false
let parentMaxChanged = false
return thisObject
function finalize () {
thisObject.eventHandler.finalize()
thisObject.eventHandler = undefined
}
function initialize (minValue, maxValue, pMaxWidth, pMaxHeight) {
/* Defines the min and max value of rate that we are going to transport to the available screen at the center position. */
thisObject.min.x = minValue.x
thisObject.max.x = maxValue.x
thisObject.min.y = minValue.y
thisObject.max.y = maxValue.y
thisObject.maxWidth = pMaxWidth
thisObject.maxHeight = pMaxHeight
recalculateScale()
}
function reportXValue (value) {
if (thisObject.autoMinXScale === true) {
if (value < newXMin && value !== 0) {
newXMin = value
}
}
if (thisObject.autoMaxXScale === true) {
if (value > newXMax && value !== 0) {
newXMax = value
}
}
}
function reportYValue (value) {
if (thisObject.autoMinYScale === true) {
if (value < newYMin) {
newYMin = value
}
}
if (thisObject.autoMaxYScale === true) {
if (value > newYMax) {
newYMax = value
}
}
}
function reportParentXValue (min, max) {
if (thisObject.autoMinXScale === true) {
if (thisObject.parentMin.x !== min) {
thisObject.parentMin.x = min
}
}
if (thisObject.autoMaxXScale === true) {
if (thisObject.parentMax.x !== max) {
thisObject.parentMax.x = max
}
}
}
function reportParentYValue (min, max) {
if (thisObject.autoMinYScale === true) {
if (thisObject.parentMin.y !== min) {
thisObject.parentMin.y = min
}
}
if (thisObject.autoMaxYScale === true) {
if (thisObject.parentMax.y !== max) {
thisObject.parentMax.y = max
}
}
}
function physics () {
let mustRecalculate = false
if ((thisObject.autoMinXScale === true || thisObject.autoMaxXScale === true)) {
if (thisObject.autoMaxXScale === true && thisObject.childrenMax.x !== newXMax && newXMax !== -VERY_LARGE_NUMBER) {
thisObject.childrenMax.x = newXMax
}
if (thisObject.autoMaxXScale === true) {
newXMax = -VERY_LARGE_NUMBER
}
if (thisObject.autoMinXScale === true && thisObject.childrenMin.x !== newXMin && newXMin !== VERY_LARGE_NUMBER) {
thisObject.childrenMin.x = newXMin
newXMin = VERY_LARGE_NUMBER
}
if (thisObject.autoMinXScale === true) {
newXMin = VERY_LARGE_NUMBER
}
function newCoordinateSystem() {
let thisObject = {
min: undefined,
max: undefined,
parentMin: undefined,
parentMax: undefined,
childrenMin: undefined,
childrenMax: undefined,
maxHeight: undefined,
maxWidth: undefined,
scale: undefined,
eventHandler: undefined,
autoMinXScale: true,
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,
reportParentXValue: reportParentXValue,
reportParentYValue: reportParentYValue,
reportXValue: reportXValue,
reportYValue: reportYValue,
zoomX: zoomX,
zoomY: zoomY,
recalculateScale: recalculateScale,
transformThisPoint: transformThisPoint,
transformThisPoint2: transformThisPoint2,
unInverseTransform: unInverseTransform,
inverseTransformUncappedY: inverseTransformUncappedY,
initializeX: initializeX,
initializeY: initializeY,
initialize: initialize,
finalize: finalize
}
if ((thisObject.autoMinYScale === true || thisObject.autoMaxYScale === true)) {
if (thisObject.autoMaxYScale === true && thisObject.childrenMax.y !== newYMax && newYMax !== -VERY_LARGE_NUMBER) {
thisObject.childrenMax.y = newYMax
}
if (thisObject.autoMaxYScale === true) {
newYMax = -VERY_LARGE_NUMBER
}
if (thisObject.autoMinYScale === true && thisObject.childrenMin.y !== newYMin && newYMin !== VERY_LARGE_NUMBER) {
thisObject.childrenMin.y = newYMin
newYMin = VERY_LARGE_NUMBER
}
if (thisObject.autoMinYScale === true) {
newYMin = VERY_LARGE_NUMBER
}
thisObject.min = {
x: 0,
y: 0
}
thisObject.max = {
x: 0,
y: 0
}
thisObject.parentMin = {
x: 0,
y: 0
}
thisObject.parentMax = {
x: 0,
y: 0
}
thisObject.childrenMin = {
x: 0,
y: 0
}
thisObject.childrenMax = {
x: 0,
y: 0
}
/* Here we will see if any of the children or parent values modify the current status quo */
/* Min */
let minX = Math.min(thisObject.childrenMin.x, thisObject.parentMin.x)
let minY = Math.min(thisObject.childrenMin.y, thisObject.parentMin.y)
let maxX = Math.max(thisObject.childrenMax.x, thisObject.parentMax.x)
let maxY = Math.max(thisObject.childrenMax.y, thisObject.parentMax.y)
if (thisObject.parentMin.x === 0) {
minX = thisObject.childrenMin.x
thisObject.scale = {
x: 0,
y: 0
}
if (thisObject.parentMin.y === 0) {
minY = thisObject.childrenMin.y
thisObject.eventHandler = newEventHandler()
thisObject.eventHandler.name = 'Coordinate System'
let newXMax = -VERY_LARGE_NUMBER
let newXMin = VERY_LARGE_NUMBER
let newYMax = -VERY_LARGE_NUMBER
let newYMin = VERY_LARGE_NUMBER
let parentMinChanged = false
let parentMaxChanged = false
return thisObject
function finalize() {
thisObject.eventHandler.finalize()
thisObject.eventHandler = undefined
}
if (thisObject.parentMax.x === 0) {
maxX = thisObject.childrenMax.x
function initialize(minValue, maxValue, pMaxWidth, pMaxHeight) {
/* Defines the min and max value of rate that we are going to transport to the available screen at the center position. */
thisObject.min.x = minValue.x
thisObject.max.x = maxValue.x
thisObject.min.y = minValue.y
thisObject.max.y = maxValue.y
thisObject.maxWidth = pMaxWidth
thisObject.maxHeight = pMaxHeight
recalculateScale()
}
if (thisObject.parentMax.y === 0) {
maxY = thisObject.childrenMax.y
function reportXValue(value) {
if (thisObject.autoMinXScale === true) {
if (value < newXMin && value !== 0) {
newXMin = value
}
}
if (thisObject.autoMaxXScale === true) {
if (value > newXMax && value !== 0) {
newXMax = value
}
}
}
if (minX !== 0 && thisObject.min.x !== minX && thisObject.autoMinXScale === true) {
thisObject.min.x = minX
mustRecalculate = true
function reportYValue(value) {
if (thisObject.autoMinYScale === true) {
if (value < newYMin) {
newYMin = value
}
}
if (thisObject.autoMaxYScale === true) {
if (value > newYMax) {
newYMax = value
}
}
}
if (minY !== 0 && thisObject.min.y !== minY && thisObject.autoMinYScale === true) {
thisObject.min.y = minY
mustRecalculate = true
function reportParentXValue(min, max) {
if (thisObject.autoMinXScale === true) {
if (thisObject.parentMin.x !== min) {
thisObject.parentMin.x = min
}
}
if (thisObject.autoMaxXScale === true) {
if (thisObject.parentMax.x !== max) {
thisObject.parentMax.x = max
}
}
}
if (maxX !== 0 && thisObject.max.x !== maxX && thisObject.autoMaxXScale === true) {
thisObject.max.x = maxX
mustRecalculate = true
function reportParentYValue(min, max) {
if (thisObject.autoMinYScale === true) {
if (thisObject.parentMin.y !== min) {
thisObject.parentMin.y = min
}
}
if (thisObject.autoMaxYScale === true) {
if (thisObject.parentMax.y !== max) {
thisObject.parentMax.y = max
}
}
}
if (maxY !== 0 && thisObject.max.y !== maxY && thisObject.autoMaxYScale === true) {
thisObject.max.y = maxY
mustRecalculate = true
function physics() {
let mustRecalculate = false
if ((thisObject.autoMinXScale === true || thisObject.autoMaxXScale === true)) {
if (thisObject.autoMaxXScale === true && thisObject.childrenMax.x !== newXMax && newXMax !== -VERY_LARGE_NUMBER) {
thisObject.childrenMax.x = newXMax
}
if (thisObject.autoMaxXScale === true) {
newXMax = -VERY_LARGE_NUMBER
}
if (thisObject.autoMinXScale === true && thisObject.childrenMin.x !== newXMin && newXMin !== VERY_LARGE_NUMBER) {
thisObject.childrenMin.x = newXMin
newXMin = VERY_LARGE_NUMBER
}
if (thisObject.autoMinXScale === true) {
newXMin = VERY_LARGE_NUMBER
}
}
if ((thisObject.autoMinYScale === true || thisObject.autoMaxYScale === true)) {
if (thisObject.autoMaxYScale === true && thisObject.childrenMax.y !== newYMax && newYMax !== -VERY_LARGE_NUMBER) {
thisObject.childrenMax.y = newYMax
}
if (thisObject.autoMaxYScale === true) {
newYMax = -VERY_LARGE_NUMBER
}
if (thisObject.autoMinYScale === true && thisObject.childrenMin.y !== newYMin && newYMin !== VERY_LARGE_NUMBER) {
thisObject.childrenMin.y = newYMin
newYMin = VERY_LARGE_NUMBER
}
if (thisObject.autoMinYScale === true) {
newYMin = VERY_LARGE_NUMBER
}
}
/* Here we will see if any of the children or parent values modify the current status quo */
/* Min */
let minX = Math.min(thisObject.childrenMin.x, thisObject.parentMin.x)
let minY = Math.min(thisObject.childrenMin.y, thisObject.parentMin.y)
let maxX = Math.max(thisObject.childrenMax.x, thisObject.parentMax.x)
let maxY = Math.max(thisObject.childrenMax.y, thisObject.parentMax.y)
if (thisObject.parentMin.x === 0) {
minX = thisObject.childrenMin.x
}
if (thisObject.parentMin.y === 0) {
minY = thisObject.childrenMin.y
}
if (thisObject.parentMax.x === 0) {
maxX = thisObject.childrenMax.x
}
if (thisObject.parentMax.y === 0) {
maxY = thisObject.childrenMax.y
}
if (minX !== 0 && thisObject.min.x !== minX && thisObject.autoMinXScale === true) {
thisObject.min.x = minX
mustRecalculate = true
}
if (minY !== 0 && thisObject.min.y !== minY && thisObject.autoMinYScale === true) {
thisObject.min.y = minY
mustRecalculate = true
}
if (maxX !== 0 && thisObject.max.x !== maxX && thisObject.autoMaxXScale === true) {
thisObject.max.x = maxX
mustRecalculate = true
}
if (maxY !== 0 && thisObject.max.y !== maxY && thisObject.autoMaxYScale === true) {
thisObject.max.y = maxY
mustRecalculate = true
}
if (mustRecalculate === true) {
recalculateScale()
}
}
if (mustRecalculate === true) {
recalculateScale()
function recalculateScale(event) {
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)
}
}
function recalculateScale (event) {
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)
function zoomX(factor, mousePosition, container) {
let mouseAtCointainer = unTransformThisPoint(mousePosition, container)
let leftDistance = mouseAtCointainer.x
let rightDistance = container.frame.width - mouseAtCointainer.x
let diff = thisObject.max.x - thisObject.min.x
let min = thisObject.min.x + diff * factor * leftDistance / (container.frame.width / 2)
let max = thisObject.max.x - diff * factor * rightDistance / (container.frame.width / 2)
thisObject.eventHandler.raiseEvent('Scale Changed', event)
}
function zoomX (factor, mousePosition, container) {
let mouseAtCointainer = unTransformThisPoint(mousePosition, container)
let leftDistance = mouseAtCointainer.x
let rightDistance = container.frame.width - mouseAtCointainer.x
let diff = thisObject.max.x - thisObject.min.x
let min = thisObject.min.x + diff * factor * leftDistance / (container.frame.width / 2)
let max = thisObject.max.x - diff * factor * rightDistance / (container.frame.width / 2)
if (min < max) {
let mustRecalculate = false
if (thisObject.autoMinXScale === false) {
thisObject.min.x = min
mustRecalculate = true
}
if (thisObject.autoMaxXScale === false) {
thisObject.max.x = max
mustRecalculate = true
}
if (mustRecalculate === true) {
thisObject.recalculateScale()
}
if (min < max) {
let mustRecalculate = false
if (thisObject.autoMinXScale === false) {
thisObject.min.x = min
mustRecalculate = true
}
if (thisObject.autoMaxXScale === false) {
thisObject.max.x = max
mustRecalculate = true
}
if (mustRecalculate === true) {
thisObject.recalculateScale()
}
}
}
}
function zoomY (factor, mousePosition, container) {
let mouseAtCointainer = unTransformThisPoint(mousePosition, container)
let topDistance = mouseAtCointainer.y
let bottomDistance = container.frame.height - mouseAtCointainer.y
let diff = thisObject.max.y - thisObject.min.y
let min = thisObject.min.y + diff * factor * bottomDistance / (container.frame.height / 2)
let max = thisObject.max.y - diff * factor * topDistance / (container.frame.height / 2)
function zoomY(factor, mousePosition, container) {
let mouseAtCointainer = unTransformThisPoint(mousePosition, container)
let topDistance = mouseAtCointainer.y
let bottomDistance = container.frame.height - mouseAtCointainer.y
let diff = thisObject.max.y - thisObject.min.y
let min = thisObject.min.y + diff * factor * bottomDistance / (container.frame.height / 2)
let max = thisObject.max.y - diff * factor * topDistance / (container.frame.height / 2)
if (min < max) {
let mustRecalculate = false
if (thisObject.autoMinYScale === false) {
thisObject.min.y = min
mustRecalculate = true
}
if (thisObject.autoMaxYScale === false) {
thisObject.max.y = max
mustRecalculate = true
}
if (mustRecalculate === true) {
thisObject.recalculateScale()
}
if (min < max) {
let mustRecalculate = false
if (thisObject.autoMinYScale === false) {
thisObject.min.y = min
mustRecalculate = true
}
if (thisObject.autoMaxYScale === false) {
thisObject.max.y = max
mustRecalculate = true
}
if (mustRecalculate === true) {
thisObject.recalculateScale()
}
}
}
}
function initializeX (minValue, maxValue, maxWidth) {
thisObject.min.x = minValue.x // * 0.999; // 0.1% less
thisObject.max.x = maxValue.x // * 1.001; // 0.1% more
function initializeX(minValue, maxValue, maxWidth) {
thisObject.min.x = minValue.x // * 0.999; // 0.1% less
thisObject.max.x = maxValue.x // * 1.001; // 0.1% more
thisObject.scale.x = thisObject.maxWidth / (thisObject.max.x - thisObject.min.x)
}
thisObject.scale.x = thisObject.maxWidth / (thisObject.max.x - thisObject.min.x)
}
function initializeY (minValue, maxValue, pMaxHeight) {
thisObject.min.y = minValue.y // * 0.999; // 0.1% less
thisObject.max.y = maxValue.y // * 1.001; // 0.1% more
function initializeY(minValue, maxValue, pMaxHeight) {
thisObject.min.y = minValue.y // * 0.999; // 0.1% less
thisObject.max.y = maxValue.y // * 1.001; // 0.1% more
thisObject.scale.y = pMaxHeight / (thisObject.max.y - thisObject.min.y)
thisObject.scale.y = pMaxHeight / (thisObject.max.y - thisObject.min.y)
thisObject.maxHeight = pMaxHeight
}
thisObject.maxHeight = pMaxHeight
}
function transformThisPoint (point) {
function transformThisPoint(point) {
/*
This is the straigh fordward transformation this object provides. The input is a point on the data set that wants to be plotted in a timeline.
@@ -334,38 +334,38 @@ function newCoordinateSystem () {
*/
point = {
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
point = {
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
}
return point
}
function transformThisPoint2(point) {
point = {
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
}
function transformThisPoint2 (point) {
point = {
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
}
return point
}
function unInverseTransform(point, inverseY) {
point = {
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
}
function unInverseTransform (point, inverseY) {
point = {
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
}
return point
}
function inverseTransformUncappedY(point, inverseY) {
point = {
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
}
function inverseTransformUncappedY (point, inverseY) {
point = {
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
}
return point
}
}
File diff suppressed because it is too large. Load diff
+434 -434
View File
@@ -1,459 +1,459 @@
function newPlottersManager () {
const MODULE_NAME = 'Plotters Manager'
const ERROR_LOG = true
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
function newPlottersManager() {
const MODULE_NAME = 'Plotters Manager'
const ERROR_LOG = true
const logger = newWebDebugLog()
logger.fileName = MODULE_NAME
let timeFrame = INITIAL_TIME_PERIOD
let datetime = NEW_SESSION_INITIAL_DATE
let timeFrame = INITIAL_TIME_PERIOD
let datetime = NEW_SESSION_INITIAL_DATE
let thisObject = {
fitFunction: undefined,
container: undefined,
payload: undefined,
connectors: [],
setDatetime: setDatetime,
setTimeFrame: setTimeFrame,
setCoordinateSystem: setCoordinateSystem,
draw: draw,
getContainer: getContainer,
initialize: initialize,
finalize: finalize
}
thisObject.connectors = []
let initializationReady = false
let layersPanel
let onLayerStatusChangedEventSuscriptionId
let coordinateSystem
setupContainer()
return thisObject
function setupContainer () {
thisObject.container = newContainer()
thisObject.container.initialize(MODULE_NAME)
}
function finalize () {
layersPanel.container.eventHandler.stopListening(onLayerStatusChangedEventSuscriptionId)
layersPanel = undefined
for (let i = 0; i < thisObject.connectors.length; i++) {
let connector = thisObject.connectors[i]
/* Then the panels. */
for (let j = 0; j < connector.panels.length; j++) {
canvas.panelsSpace.destroyPanel(connector.panels[j])
connector.panels[j] = undefined
}
connector.panels = undefined
/* Finalize the plotters */
if (connector.plotter.finalize !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.plotter.onRecordChangeEventsSubscriptionId)
connector.plotter.finalize()
}
connector.plotter = undefined
/* Finally the Storage Objects */
finalizeStorage(connector.storage)
connector.storage = undefined
connector = undefined
let thisObject = {
fitFunction: undefined,
container: undefined,
payload: undefined,
connectors: [],
setDatetime: setDatetime,
setTimeFrame: setTimeFrame,
setCoordinateSystem: setCoordinateSystem,
draw: draw,
getContainer: getContainer,
initialize: initialize,
finalize: finalize
}
thisObject.connectors = []
coordinateSystem = undefined
thisObject.container.finalize()
thisObject.container = undefined
thisObject.payload = undefined
}
let initializationReady = false
let layersPanel
let onLayerStatusChangedEventSuscriptionId
let coordinateSystem
function finalizeStorage (storage) {
storage.eventHandler.stopListening(storage.onMarketFileLoadedLayerEventsSubscriptionId)
storage.eventHandler.stopListening(storage.onDailyFileLoadedLayerEventsSubscriptionId)
storage.eventHandler.stopListening(storage.onSingleFileLoadedLayerEventsSubscriptionId)
storage.eventHandler.stopListening(storage.onFileSequenceLoadedLayerEventsSubscriptionId)
storage.eventHandler.stopListening(storage.onDailyFileLoadedPlotterEventsSubscriptionId)
storage.finalize()
}
setupContainer()
return thisObject
function initialize (pLayersPanel) {
/* Remember this */
layersPanel = pLayersPanel
/* Listen to the event of change of status */
onLayerStatusChangedEventSuscriptionId = layersPanel.container.eventHandler.listenToEvent('Layer Status Changed', onLayerStatusChanged)
}
function initializePlotter (layer) {
try {
/* Before Initializing a Plotter, we need the Storage it will use, loaded with the files it will initially need. */
let storage = newProductStorage(layer.payload.node.id)
/*
Before Initializing the Storage, we will put the Layer to listen to the events the storage will raise every time a file is loaded,
so that the UI can somehow show this. There are different types of events.
*/
for (let i = 0; i < layer.definition.referenceParent.referenceParent.datasets.length; i++) {
let dataset = layer.definition.referenceParent.referenceParent.datasets[i]
switch (dataset.config.type) {
case 'Market Files': {
storage.onMarketFileLoadedLayerEventsSubscriptionId = storage.eventHandler.listenToEvent('Market File Loaded', layer.onMarketFileLoaded)
}
break
case 'Daily Files': {
storage.onDailyFileLoadedLayerEventsSubscriptionId = storage.eventHandler.listenToEvent('Daily File Loaded', layer.onDailyFileLoaded)
}
break
case 'Single File': {
storage.onSingleFileLoadedLayerEventsSubscriptionId = storage.eventHandler.listenToEvent('Single File Loaded', layer.onSingleFileLoaded)
}
break
case 'File Sequence': {
storage.onFileSequenceLoadedLayerEventsSubscriptionId = storage.eventHandler.listenToEvent('File Sequence Loaded', layer.onFileSequenceLoaded)
}
break
default: {
if (ERROR_LOG === true) {
logger.write('[ERROR] initializePlotter -> Dataset Type Incorrect or Undefined -> dataset.type = ' + dataset.type)
}
return
}
}
}
let baseAsset = layer.definition.referenceParent.parentNode.referenceParent.baseAsset.referenceParent.config.codeName
let quotedAsset = layer.definition.referenceParent.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName
let market = {
baseAsset: baseAsset,
quotedAsset: quotedAsset
}
let productDefinition = layer.definition.referenceParent.referenceParent
let bot = layer.definition.referenceParent.referenceParent.parentNode
let dataMine = layer.definition.referenceParent.referenceParent.parentNode.parentNode
let exchange = layer.definition.referenceParent.parentNode.referenceParent.parentNode.parentNode
let plotterModule = layer.definition.referenceParent.referenceParent.referenceParent
let session
let tradingSystem
let tradingEngine
/*
A layer can be referencing a Data Product in two different branches of the Network hiriatchy.
In one of those braches we can get the Session node, at the other we Cannot.
*/
if (layer.definition.referenceParent.parentNode.parentNode !== undefined) {
if (layer.definition.referenceParent.parentNode.parentNode.type === 'Session Reference') {
if (layer.definition.referenceParent.parentNode.parentNode.referenceParent !== undefined) {
session = layer.definition.referenceParent.parentNode.parentNode.referenceParent
/* From the session we might be able to reach the Trading System or the Trading Engine */
if (session.tradingSystemReference !== undefined) {
tradingSystem = session.tradingSystemReference.referenceParent
}
if (session.tradingEngineReference !== undefined) {
tradingEngine = session.tradingEngineReference.referenceParent
}
}
}
}
let host = layer.networkNode.config.host
let webPort = layer.networkNode.config.webPort
if (host === undefined) { host = 'localhost' }
if (webPort === undefined) { webPort = window.location.port }
let eventsServerClient = canvas.designSpace.workspace.eventsServerClients.get(layer.networkNode.id)
storage.initialize(
dataMine,
bot,
session,
productDefinition,
exchange,
market,
datetime,
timeFrame,
host,
webPort,
eventsServerClient,
onProductStorageInitialized
)
function onProductStorageInitialized (err) {
if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) {
/* Now we have all the initial data loaded and ready to be delivered to the new instance of the plotter. */
let plotter
if (plotterModule.config.isLegacy !== true) {
plotter = newPlotter()
} else {
plotter = getNewPlotter(dataMine.config.codeName, plotterModule.parentNode.config.codeName, plotterModule.config.codeName)
}
plotter.container.connectToParent(thisObject.container, true, true, false, true, true, true, false, false, true)
plotter.container.frame.position.x = thisObject.container.frame.width / 2 - plotter.container.frame.width / 2
plotter.container.frame.position.y = thisObject.container.frame.height / 2 - plotter.container.frame.height / 2
plotter.fitFunction = thisObject.fitFunction
plotter.initialize(storage, datetime, timeFrame, coordinateSystem, onPlotterInizialized, productDefinition)
function onPlotterInizialized () {
let connector = {
layer: layer,
plotter: plotter,
storage: storage
}
/* Let the Plotter listen to the event of Cursor Files loaded, so that it can react recalculating if needed. */
plotter.onDailyFileLoadedPlotterEventsSubscriptionId = storage.eventHandler.listenToEvent('Daily File Loaded', plotter.onDailyFileLoaded)
/* Lets load now this plotter panels. */
connector.panels = []
if (productDefinition !== undefined) {
/* Here we setup the panels associated with this plotter */
for (let i = 0; i < plotterModule.panels.length; i++) {
let panel = plotterModule.panels[i]
let parameters = {
dataMine: dataMine.config.codeName,
plotterCodeName: plotterModule.parentNode.config.codeName,
moduleCodeName: plotterModule.config.codeName,
panelNode: panel
}
let owner = thisObject.payload.node.payload.parentNode.id // Panels are owned by the time machine.
let plotterPanelHandle = canvas.panelsSpace.createNewPanel('Plotter Panel', parameters, owner, layer.session)
let plotterPanel = canvas.panelsSpace.getPanel(plotterPanelHandle)
/* Connect Panel to the Plotter via an Event. */
connector.plotter.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', plotterPanel.onRecordChange)
connector.panels.push(plotterPanelHandle)
}
connector.layer.panels = connector.panels
/*
Next we will check the different types of Plotting related to connecting to an existing node branch.
*/
if (plotterModule.nodesHighlights !== undefined && plotterModule.config.connectTo !== undefined) {
connector.nodesHighlights = newNodesHighlights()
switch (plotterModule.config.connectTo) {
case 'Trading System':
connector.nodesHighlights.initialize(tradingSystem)
break
case 'Trading Engine':
connector.nodesHighlights.initialize(tradingEngine)
break
}
connector.nodesHighlights.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesHighlights.onRecordChange)
}
if (plotterModule.nodesValues !== undefined && plotterModule.config.connectTo !== undefined) {
connector.nodesValues = newNodesValues()
switch (plotterModule.config.connectTo) {
case 'Trading System':
connector.nodesValues.initialize(tradingSystem)
break
case 'Trading Engine':
connector.nodesValues.initialize(tradingEngine)
break
}
connector.nodesValues.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesValues.onRecordChange)
}
if (plotterModule.nodesErrors !== undefined && plotterModule.config.connectTo !== undefined) {
connector.nodesErrors = newNodesErrors()
switch (plotterModule.config.connectTo) {
case 'Trading System':
connector.nodesErrors.initialize(tradingSystem)
break
case 'Trading Engine':
connector.nodesErrors.initialize(tradingEngine)
break
}
connector.nodesErrors.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesErrors.onRecordChange)
}
if (plotterModule.nodesRunning !== undefined && plotterModule.config.connectTo !== undefined) {
connector.nodesRunning = newNodesRunning()
switch (plotterModule.config.connectTo) {
case 'Trading System':
connector.nodesRunning.initialize(tradingSystem)
break
case 'Trading Engine':
connector.nodesRunning.initialize(tradingEngine)
break
}
connector.nodesRunning.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesRunning.onRecordChange)
}
if (plotterModule.nodesStatus !== undefined && plotterModule.config.connectTo !== undefined) {
connector.nodesStatus = newNodesStatus()
switch (plotterModule.config.connectTo) {
case 'Trading System':
connector.nodesStatus.initialize(tradingSystem)
break
case 'Trading Engine':
connector.nodesStatus.initialize(tradingEngine)
break
}
connector.nodesStatus.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesStatus.onRecordChange)
}
if (plotterModule.nodesProgress !== undefined && plotterModule.config.connectTo !== undefined) {
connector.nodesProgress = newNodesProgress()
switch (plotterModule.config.connectTo) {
case 'Trading System':
connector.nodesProgress.initialize(tradingSystem)
break
case 'Trading Engine':
connector.nodesProgress.initialize(tradingEngine)
break
}
connector.nodesProgress.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesProgress.onRecordChange)
}
if (plotterModule.nodesAnnouncements !== undefined && plotterModule.config.connectTo !== undefined) {
connector.nodesAnnounements = newNodesAnnouncements()
switch (plotterModule.config.connectTo) {
case 'Trading System':
connector.nodesAnnounements.initialize(tradingSystem)
break
case 'Trading Engine':
connector.nodesAnnounements.initialize(tradingEngine)
break
}
connector.nodesAnnounements.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesAnnounements.onRecordChange)
}
/*
Another type of plotting is with Record Values. This method uses the record definition to find the target node
and from there is looks into its children all based on the Record Definition configuration.
*/
if (plotterModule.recordValues !== undefined) {
connector.recordValues = newRecordValues()
connector.recordValues.initialize(tradingSystem, tradingEngine, productDefinition)
connector.recordValues.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.recordValues.onRecordChange)
}
}
thisObject.connectors.push(connector)
}
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initializePlotter -> err = ' + err.stack) }
function setupContainer() {
thisObject.container = newContainer()
thisObject.container.initialize(MODULE_NAME)
}
}
function onLayerStatusChanged (layer) {
if (layer.status === LAYER_STATUS.LOADING) {
/* Lets see if we can find the Plotter of this card on our Active Plotters list, other wise we will initialize it */
let found = false
for (let i = 0; i < thisObject.connectors.length; i++) {
let connector = thisObject.connectors[i]
if (connector.layer.payload.node.id === layer.payload.node.id) {
found = true
}
}
if (found === false) {
initializePlotter(layer, onProductPlotterInitialized)
function onProductPlotterInitialized (err) {
/* There is no policy yet of what to do if this fails. */
}
}
}
if (layer.status === LAYER_STATUS.OFF) {
/* If the plotter of this card is not on our Active Plotters list, then we remove it. */
for (let i = 0; i < thisObject.connectors.length; i++) {
let connector = thisObject.connectors[i]
if (connector.layer.payload.node.id === layer.payload.node.id) {
/* Then the panels. */
for (let j = 0; j < connector.panels.length; j++) {
canvas.panelsSpace.destroyPanel(connector.panels[j])
}
function finalize() {
layersPanel.container.eventHandler.stopListening(onLayerStatusChangedEventSuscriptionId)
layersPanel = undefined
for (let i = 0; i < thisObject.connectors.length; i++) {
let connector = thisObject.connectors[i]
/* Then the panels. */
for (let j = 0; j < connector.panels.length; j++) {
canvas.panelsSpace.destroyPanel(connector.panels[j])
connector.panels[j] = undefined
}
connector.panels = undefined
/* Finalize the plotters */
if (connector.plotter.finalize !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.plotter.onRecordChangeEventsSubscriptionId)
connector.plotter.finalize()
}
connector.plotter = undefined
/* Finally the Storage Objects */
finalizeNodesPlotting(connector)
if (connector.plotter.finalize !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.plotter.onRecordChangeEventsSubscriptionId)
connector.plotter.container.finalize()
connector.plotter.finalize()
}
finalizeStorage(connector.storage)
thisObject.connectors.splice(i, 1) // Delete item from array.
return // We already found the product woth changes and processed it.
finalizeStorage(connector.storage)
connector.storage = undefined
connector = undefined
}
}
}
}
thisObject.connectors = []
coordinateSystem = undefined
function finalizeNodesPlotting (connector) {
if (connector.nodesHighlights !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.nodesHighlights.onRecordChangeEventsSubscriptionId)
connector.nodesHighlights.finalize()
thisObject.container.finalize()
thisObject.container = undefined
thisObject.payload = undefined
}
if (connector.nodesValues !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.nodesValues.onRecordChangeEventsSubscriptionId)
connector.nodesValues.finalize()
}
if (connector.nodesErrors !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.nodesErrors.onRecordChangeEventsSubscriptionId)
connector.nodesErrors.finalize()
}
if (connector.nodesStatus !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.nodesStatus.onRecordChangeEventsSubscriptionId)
connector.nodesStatus.finalize()
}
if (connector.nodesProgress !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.Progress.onRecordChangeEventsSubscriptionId)
connector.Progress.finalize()
}
if (connector.nodesRunning !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.nodesRunning.onRecordChangeEventsSubscriptionId)
connector.nodesRunning.finalize()
}
if (connector.recordValues !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.recordValues.onRecordChangeEventsSubscriptionId)
connector.recordValues.finalize()
}
}
function setTimeFrame (pTimeFrame) {
timeFrame = pTimeFrame
for (let i = 0; i < thisObject.connectors.length; i++) {
let connector = thisObject.connectors[i]
connector.layer.setTimeFrame(timeFrame)
connector.storage.setTimeFrame(timeFrame)
connector.plotter.setTimeFrame(timeFrame)
function finalizeStorage(storage) {
storage.eventHandler.stopListening(storage.onMarketFileLoadedLayerEventsSubscriptionId)
storage.eventHandler.stopListening(storage.onDailyFileLoadedLayerEventsSubscriptionId)
storage.eventHandler.stopListening(storage.onSingleFileLoadedLayerEventsSubscriptionId)
storage.eventHandler.stopListening(storage.onFileSequenceLoadedLayerEventsSubscriptionId)
storage.eventHandler.stopListening(storage.onDailyFileLoadedPlotterEventsSubscriptionId)
storage.finalize()
}
}
function setDatetime (pDatetime) {
datetime = pDatetime
for (let i = 0; i < thisObject.connectors.length; i++) {
let connector = thisObject.connectors[i]
connector.layer.setDatetime(pDatetime)
connector.storage.setDatetime(pDatetime)
connector.plotter.setDatetime(pDatetime)
function initialize(pLayersPanel) {
/* Remember this */
layersPanel = pLayersPanel
/* Listen to the event of change of status */
onLayerStatusChangedEventSuscriptionId = layersPanel.container.eventHandler.listenToEvent('Layer Status Changed', onLayerStatusChanged)
}
}
function setCoordinateSystem (pCoordinateSystem) {
coordinateSystem = pCoordinateSystem
for (let i = 0; i < thisObject.connectors.length; i++) {
let connector = thisObject.connectors[i]
connector.plotter.setCoordinateSystem(coordinateSystem)
function initializePlotter(layer) {
try {
/* Before Initializing a Plotter, we need the Storage it will use, loaded with the files it will initially need. */
let storage = newProductStorage(layer.payload.node.id)
/*
Before Initializing the Storage, we will put the Layer to listen to the events the storage will raise every time a file is loaded,
so that the UI can somehow show this. There are different types of events.
*/
for (let i = 0; i < layer.definition.referenceParent.referenceParent.datasets.length; i++) {
let dataset = layer.definition.referenceParent.referenceParent.datasets[i]
switch (dataset.config.type) {
case 'Market Files': {
storage.onMarketFileLoadedLayerEventsSubscriptionId = storage.eventHandler.listenToEvent('Market File Loaded', layer.onMarketFileLoaded)
}
break
case 'Daily Files': {
storage.onDailyFileLoadedLayerEventsSubscriptionId = storage.eventHandler.listenToEvent('Daily File Loaded', layer.onDailyFileLoaded)
}
break
case 'Single File': {
storage.onSingleFileLoadedLayerEventsSubscriptionId = storage.eventHandler.listenToEvent('Single File Loaded', layer.onSingleFileLoaded)
}
break
case 'File Sequence': {
storage.onFileSequenceLoadedLayerEventsSubscriptionId = storage.eventHandler.listenToEvent('File Sequence Loaded', layer.onFileSequenceLoaded)
}
break
default: {
if (ERROR_LOG === true) {
logger.write('[ERROR] initializePlotter -> Dataset Type Incorrect or Undefined -> dataset.type = ' + dataset.type)
}
return
}
}
}
let baseAsset = layer.definition.referenceParent.parentNode.referenceParent.baseAsset.referenceParent.config.codeName
let quotedAsset = layer.definition.referenceParent.parentNode.referenceParent.quotedAsset.referenceParent.config.codeName
let market = {
baseAsset: baseAsset,
quotedAsset: quotedAsset
}
let productDefinition = layer.definition.referenceParent.referenceParent
let bot = layer.definition.referenceParent.referenceParent.parentNode
let dataMine = layer.definition.referenceParent.referenceParent.parentNode.parentNode
let exchange = layer.definition.referenceParent.parentNode.referenceParent.parentNode.parentNode
let plotterModule = layer.definition.referenceParent.referenceParent.referenceParent
let session
let tradingSystem
let tradingEngine
/*
A layer can be referencing a Data Product in two different branches of the Network hiriatchy.
In one of those braches we can get the Session node, at the other we Cannot.
*/
if (layer.definition.referenceParent.parentNode.parentNode !== undefined) {
if (layer.definition.referenceParent.parentNode.parentNode.type === 'Session Reference') {
if (layer.definition.referenceParent.parentNode.parentNode.referenceParent !== undefined) {
session = layer.definition.referenceParent.parentNode.parentNode.referenceParent
/* From the session we might be able to reach the Trading System or the Trading Engine */
if (session.tradingSystemReference !== undefined) {
tradingSystem = session.tradingSystemReference.referenceParent
}
if (session.tradingEngineReference !== undefined) {
tradingEngine = session.tradingEngineReference.referenceParent
}
}
}
}
let host = layer.networkNode.config.host
let webPort = layer.networkNode.config.webPort
if (host === undefined) { host = 'localhost' }
if (webPort === undefined) { webPort = window.location.port }
let eventsServerClient = canvas.designSpace.workspace.eventsServerClients.get(layer.networkNode.id)
storage.initialize(
dataMine,
bot,
session,
productDefinition,
exchange,
market,
datetime,
timeFrame,
host,
webPort,
eventsServerClient,
onProductStorageInitialized
)
function onProductStorageInitialized(err) {
if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) {
/* Now we have all the initial data loaded and ready to be delivered to the new instance of the plotter. */
let plotter
if (plotterModule.config.isLegacy !== true) {
plotter = newPlotter()
} else {
plotter = getNewPlotter(dataMine.config.codeName, plotterModule.parentNode.config.codeName, plotterModule.config.codeName)
}
plotter.container.connectToParent(thisObject.container, true, true, false, true, true, true, false, false, true)
plotter.container.frame.position.x = thisObject.container.frame.width / 2 - plotter.container.frame.width / 2
plotter.container.frame.position.y = thisObject.container.frame.height / 2 - plotter.container.frame.height / 2
plotter.fitFunction = thisObject.fitFunction
plotter.initialize(storage, datetime, timeFrame, coordinateSystem, onPlotterInizialized, productDefinition)
function onPlotterInizialized() {
let connector = {
layer: layer,
plotter: plotter,
storage: storage
}
/* Let the Plotter listen to the event of Cursor Files loaded, so that it can react recalculating if needed. */
plotter.onDailyFileLoadedPlotterEventsSubscriptionId = storage.eventHandler.listenToEvent('Daily File Loaded', plotter.onDailyFileLoaded)
/* Lets load now this plotter panels. */
connector.panels = []
if (productDefinition !== undefined) {
/* Here we setup the panels associated with this plotter */
for (let i = 0; i < plotterModule.panels.length; i++) {
let panel = plotterModule.panels[i]
let parameters = {
dataMine: dataMine.config.codeName,
plotterCodeName: plotterModule.parentNode.config.codeName,
moduleCodeName: plotterModule.config.codeName,
panelNode: panel
}
let owner = thisObject.payload.node.payload.parentNode.id // Panels are owned by the time machine.
let plotterPanelHandle = canvas.panelsSpace.createNewPanel('Plotter Panel', parameters, owner, layer.session)
let plotterPanel = canvas.panelsSpace.getPanel(plotterPanelHandle)
/* Connect Panel to the Plotter via an Event. */
connector.plotter.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', plotterPanel.onRecordChange)
connector.panels.push(plotterPanelHandle)
}
connector.layer.panels = connector.panels
/*
Next we will check the different types of Plotting related to connecting to an existing node branch.
*/
if (plotterModule.nodesHighlights !== undefined && plotterModule.config.connectTo !== undefined) {
connector.nodesHighlights = newNodesHighlights()
switch (plotterModule.config.connectTo) {
case 'Trading System':
connector.nodesHighlights.initialize(tradingSystem)
break
case 'Trading Engine':
connector.nodesHighlights.initialize(tradingEngine)
break
}
connector.nodesHighlights.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesHighlights.onRecordChange)
}
if (plotterModule.nodesValues !== undefined && plotterModule.config.connectTo !== undefined) {
connector.nodesValues = newNodesValues()
switch (plotterModule.config.connectTo) {
case 'Trading System':
connector.nodesValues.initialize(tradingSystem)
break
case 'Trading Engine':
connector.nodesValues.initialize(tradingEngine)
break
}
connector.nodesValues.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesValues.onRecordChange)
}
if (plotterModule.nodesErrors !== undefined && plotterModule.config.connectTo !== undefined) {
connector.nodesErrors = newNodesErrors()
switch (plotterModule.config.connectTo) {
case 'Trading System':
connector.nodesErrors.initialize(tradingSystem)
break
case 'Trading Engine':
connector.nodesErrors.initialize(tradingEngine)
break
}
connector.nodesErrors.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesErrors.onRecordChange)
}
if (plotterModule.nodesRunning !== undefined && plotterModule.config.connectTo !== undefined) {
connector.nodesRunning = newNodesRunning()
switch (plotterModule.config.connectTo) {
case 'Trading System':
connector.nodesRunning.initialize(tradingSystem)
break
case 'Trading Engine':
connector.nodesRunning.initialize(tradingEngine)
break
}
connector.nodesRunning.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesRunning.onRecordChange)
}
if (plotterModule.nodesStatus !== undefined && plotterModule.config.connectTo !== undefined) {
connector.nodesStatus = newNodesStatus()
switch (plotterModule.config.connectTo) {
case 'Trading System':
connector.nodesStatus.initialize(tradingSystem)
break
case 'Trading Engine':
connector.nodesStatus.initialize(tradingEngine)
break
}
connector.nodesStatus.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesStatus.onRecordChange)
}
if (plotterModule.nodesProgress !== undefined && plotterModule.config.connectTo !== undefined) {
connector.nodesProgress = newNodesProgress()
switch (plotterModule.config.connectTo) {
case 'Trading System':
connector.nodesProgress.initialize(tradingSystem)
break
case 'Trading Engine':
connector.nodesProgress.initialize(tradingEngine)
break
}
connector.nodesProgress.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesProgress.onRecordChange)
}
if (plotterModule.nodesAnnouncements !== undefined && plotterModule.config.connectTo !== undefined) {
connector.nodesAnnounements = newNodesAnnouncements()
switch (plotterModule.config.connectTo) {
case 'Trading System':
connector.nodesAnnounements.initialize(tradingSystem)
break
case 'Trading Engine':
connector.nodesAnnounements.initialize(tradingEngine)
break
}
connector.nodesAnnounements.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.nodesAnnounements.onRecordChange)
}
/*
Another type of plotting is with Record Values. This method uses the record definition to find the target node
and from there is looks into its children all based on the Record Definition configuration.
*/
if (plotterModule.recordValues !== undefined) {
connector.recordValues = newRecordValues()
connector.recordValues.initialize(tradingSystem, tradingEngine, productDefinition)
connector.recordValues.onRecordChangeEventsSubscriptionId = connector.plotter.container.eventHandler.listenToEvent('Current Record Changed', connector.recordValues.onRecordChange)
}
}
thisObject.connectors.push(connector)
}
}
}
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] initializePlotter -> err = ' + err.stack) }
}
}
}
function getContainer (point) {
}
function onLayerStatusChanged(layer) {
if (layer.status === LAYER_STATUS.LOADING) {
/* Lets see if we can find the Plotter of this card on our Active Plotters list, other wise we will initialize it */
let found = false
for (let i = 0; i < thisObject.connectors.length; i++) {
let connector = thisObject.connectors[i]
if (connector.layer.payload.node.id === layer.payload.node.id) {
found = true
}
}
if (found === false) {
initializePlotter(layer, onProductPlotterInitialized)
function onProductPlotterInitialized(err) {
/* There is no policy yet of what to do if this fails. */
}
}
}
if (layer.status === LAYER_STATUS.OFF) {
/* If the plotter of this card is not on our Active Plotters list, then we remove it. */
for (let i = 0; i < thisObject.connectors.length; i++) {
let connector = thisObject.connectors[i]
if (connector.layer.payload.node.id === layer.payload.node.id) {
/* Then the panels. */
for (let j = 0; j < connector.panels.length; j++) {
canvas.panelsSpace.destroyPanel(connector.panels[j])
}
/* Finally the Storage Objects */
finalizeNodesPlotting(connector)
if (connector.plotter.finalize !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.plotter.onRecordChangeEventsSubscriptionId)
connector.plotter.container.finalize()
connector.plotter.finalize()
}
finalizeStorage(connector.storage)
thisObject.connectors.splice(i, 1) // Delete item from array.
return // We already found the product woth changes and processed it.
}
}
}
}
function draw () {
if (thisObject.connectors === undefined) { return } // We need to wait
function finalizeNodesPlotting(connector) {
if (connector.nodesHighlights !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.nodesHighlights.onRecordChangeEventsSubscriptionId)
connector.nodesHighlights.finalize()
}
if (connector.nodesValues !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.nodesValues.onRecordChangeEventsSubscriptionId)
connector.nodesValues.finalize()
}
if (connector.nodesErrors !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.nodesErrors.onRecordChangeEventsSubscriptionId)
connector.nodesErrors.finalize()
}
if (connector.nodesStatus !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.nodesStatus.onRecordChangeEventsSubscriptionId)
connector.nodesStatus.finalize()
}
if (connector.nodesProgress !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.Progress.onRecordChangeEventsSubscriptionId)
connector.Progress.finalize()
}
if (connector.nodesRunning !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.nodesRunning.onRecordChangeEventsSubscriptionId)
connector.nodesRunning.finalize()
}
if (connector.recordValues !== undefined) {
connector.plotter.container.eventHandler.stopListening(connector.recordValues.onRecordChangeEventsSubscriptionId)
connector.recordValues.finalize()
}
}
function setTimeFrame(pTimeFrame) {
timeFrame = pTimeFrame
for (let i = 0; i < thisObject.connectors.length; i++) {
let connector = thisObject.connectors[i]
connector.layer.setTimeFrame(timeFrame)
connector.storage.setTimeFrame(timeFrame)
connector.plotter.setTimeFrame(timeFrame)
}
}
function setDatetime(pDatetime) {
datetime = pDatetime
for (let i = 0; i < thisObject.connectors.length; i++) {
let connector = thisObject.connectors[i]
connector.layer.setDatetime(pDatetime)
connector.storage.setDatetime(pDatetime)
connector.plotter.setDatetime(pDatetime)
}
}
function setCoordinateSystem(pCoordinateSystem) {
coordinateSystem = pCoordinateSystem
for (let i = 0; i < thisObject.connectors.length; i++) {
let connector = thisObject.connectors[i]
connector.plotter.setCoordinateSystem(coordinateSystem)
}
}
function getContainer(point) {
}
function draw() {
if (thisObject.connectors === undefined) { return } // We need to wait
/* First the Product Plotters. */
let maxElementsPlotted = 0
for (let i = 0; i < thisObject.connectors.length; i++) {
let connector = thisObject.connectors[thisObject.connectors.length - i - 1]
let elementsPlotted = connector.plotter.draw()
if (elementsPlotted !== undefined) {
if (elementsPlotted > maxElementsPlotted) {
maxElementsPlotted = elementsPlotted
let maxElementsPlotted = 0
for (let i = 0; i < thisObject.connectors.length; i++) {
let connector = thisObject.connectors[thisObject.connectors.length - i - 1]
let elementsPlotted = connector.plotter.draw()
if (elementsPlotted !== undefined) {
if (elementsPlotted > maxElementsPlotted) {
maxElementsPlotted = elementsPlotted
}
}
}
}
return maxElementsPlotted
}
return maxElementsPlotted
}
}
File diff suppressed because it is too large. Load diff
+399 -399
View File
@@ -1,424 +1,424 @@
function newTimelineChart () {
const MODULE_NAME = 'Timeline Chart'
const INFO_LOG = false
const INTENSIVE_LOG = false
const ERROR_LOG = true
let logger = newWebDebugLog()
logger.fileName = MODULE_NAME
function newTimelineChart() {
const MODULE_NAME = 'Timeline Chart'
const INFO_LOG = false
const INTENSIVE_LOG = false
const ERROR_LOG = true
let logger = newWebDebugLog()
logger.fileName = MODULE_NAME
let timeFrame = INITIAL_TIME_PERIOD
let datetime = NEW_SESSION_INITIAL_DATE
let timeFrame = INITIAL_TIME_PERIOD
let datetime = NEW_SESSION_INITIAL_DATE
let thisObject = {
container: undefined,
fitFunction: undefined,
rateScale: undefined,
timeFrameScale: undefined,
payload: undefined,
layersManager: undefined,
plotterManager: undefined,
upstreamTimeFrame: undefined,
setDatetime: setDatetime,
setTimeFrame: setTimeFrame,
physics: physics,
draw: draw,
drawBackground: drawBackground,
drawForeground: drawForeground,
getContainer: getContainer,
initialize: initialize,
finalize: finalize
}
let timeMachineCoordinateSystem
let timelineChartCoordinateSystem = newCoordinateSystem()
timelineChartCoordinateSystem.name = 'TIMELINE CHART'
let coordinateSystem
let layersPanel
let layersPanelHandle
let onMouseOverEventSuscriptionId
let onMouseNotOverEventSuscriptionId
let rateScaleUpstreamEventSuscriptionId
let rateScaleMouseOverEventSuscriptionId
let timeFrameScaleEventSuscriptionId
let timeFrameScaleMouseOverEventSuscriptionId
let scaleChangedEventSubscriptionId
let drawScales = false
let mouse = {
position: {
x: 0,
y: 0
}
}
setupContainer()
return thisObject
function setupContainer () {
thisObject.container = newContainer()
thisObject.container.initialize(MODULE_NAME)
thisObject.container.detectMouseOver = true
}
function finalize () {
timeMachineCoordinateSystem.eventHandler.stopListening(scaleChangedEventSubscriptionId)
if (thisObject.layersManager !== undefined) {
finalizeLayersManager()
let thisObject = {
container: undefined,
fitFunction: undefined,
rateScale: undefined,
timeFrameScale: undefined,
payload: undefined,
layersManager: undefined,
plotterManager: undefined,
upstreamTimeFrame: undefined,
setDatetime: setDatetime,
setTimeFrame: setTimeFrame,
physics: physics,
draw: draw,
drawBackground: drawBackground,
drawForeground: drawForeground,
getContainer: getContainer,
initialize: initialize,
finalize: finalize
}
if (thisObject.rateScale !== undefined) {
finalizeRateScale()
}
let timeMachineCoordinateSystem
let timelineChartCoordinateSystem = newCoordinateSystem()
timelineChartCoordinateSystem.name = 'TIMELINE CHART'
if (thisObject.timeFrameScale !== undefined) {
finalizeTimeFrameScale()
}
let coordinateSystem
thisObject.container.eventHandler.stopListening(onMouseOverEventSuscriptionId)
thisObject.container.eventHandler.stopListening(onMouseNotOverEventSuscriptionId)
thisObject.container.finalize()
thisObject.container = undefined
thisObject.payload = undefined
let layersPanel
let layersPanelHandle
mouse = undefined
logger = undefined
let onMouseOverEventSuscriptionId
let onMouseNotOverEventSuscriptionId
let rateScaleUpstreamEventSuscriptionId
let rateScaleMouseOverEventSuscriptionId
let timeFrameScaleEventSuscriptionId
let timeFrameScaleMouseOverEventSuscriptionId
let scaleChangedEventSubscriptionId
timeMachineCoordinateSystem = undefined
timelineChartCoordinateSystem.finalize()
timelineChartCoordinateSystem = undefined
coordinateSystem = undefined
layersPanel = undefined
layersPanelHandle = undefined
}
function finalizeLayersManager () {
if (thisObject.plotterManager !== undefined) {
thisObject.plotterManager.finalize()
}
thisObject.plotterManager = undefined
thisObject.layersManager = undefined
canvas.panelsSpace.destroyPanel(layersPanelHandle)
}
function finalizeTimeFrameScale () {
if (thisObject.timeFrameScale === undefined) { return }
thisObject.timeFrameScale.container.eventHandler.stopListening(timeFrameScaleEventSuscriptionId)
thisObject.timeFrameScale.container.eventHandler.stopListening(timeFrameScaleMouseOverEventSuscriptionId)
thisObject.timeFrameScale.finalize()
thisObject.timeFrameScale = undefined
if (thisObject.upstreamTimeFrame !== undefined) {
timeFrame = thisObject.upstreamTimeFrame
if (thisObject.plotterManager !== undefined) {
thisObject.plotterManager.setTimeFrame(timeFrame)
}
}
}
function finalizeRateScale () {
if (thisObject.rateScale === undefined) { return }
thisObject.rateScale.container.eventHandler.stopListening(rateScaleMouseOverEventSuscriptionId)
thisObject.container.parentContainer.eventHandler.stopListening(rateScaleUpstreamEventSuscriptionId)
thisObject.rateScale.finalize()
thisObject.rateScale = undefined
/* Resets the local container with the dimessions of its parent, the Time Machine */
thisObject.container.frame.position.x = 0
thisObject.container.frame.position.y = 0
thisObject.container.frame.height = thisObject.container.parentContainer.frame.height
thisObject.container.frame.width = thisObject.container.parentContainer.frame.width
}
function initialize (pTimeMachineCoordinateSystem, pTimeFrame) {
/* We load the logow we will need for the background. */
timeMachineCoordinateSystem = pTimeMachineCoordinateSystem
coordinateSystem = timeMachineCoordinateSystem
initializeCoordinateSystem()
timeFrame = pTimeFrame
onMouseOverEventSuscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver)
onMouseNotOverEventSuscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseNotOver', onMouseNotOver)
scaleChangedEventSubscriptionId = timeMachineCoordinateSystem.eventHandler.listenToEvent('Scale Changed', onScaleChanged)
}
function initializeCoordinateSystem () {
let minValue = {
x: timeMachineCoordinateSystem.min.x,
y: 0
}
let maxValue = {
x: timeMachineCoordinateSystem.max.x,
y: nextPorwerOf10(MAX_DEFAULT_RATE_SCALE_VALUE) / 4
}
if (thisObject.rateScale !== undefined) {
minValue.y = thisObject.rateScale.minValue
maxValue.y = thisObject.rateScale.maxValue
}
timelineChartCoordinateSystem.initialize(
minValue,
maxValue,
thisObject.container.frame.width,
thisObject.container.frame.height
)
}
function initializeLayersManager () {
let owner = thisObject.payload.node.payload.parentNode.id // The real owner is the Time Machine
layersPanelHandle = canvas.panelsSpace.createNewPanel('Layers Panel', undefined, owner)
thisObject.layersManager = canvas.panelsSpace.getPanel(layersPanelHandle)
thisObject.layersManager.payload = thisObject.payload.node.layersManager.payload
thisObject.layersManager.initialize()
/* Initialize the Plotter Manager */
thisObject.plotterManager = newPlottersManager()
thisObject.plotterManager.container.connectToParent(thisObject.container, true, true, false, true, true, true, false, false, true)
thisObject.plotterManager.container.frame.position.x = 0
thisObject.plotterManager.container.frame.position.y = 0
thisObject.plotterManager.fitFunction = thisObject.fitFunction
thisObject.plotterManager.payload = thisObject.payload
thisObject.plotterManager.initialize(thisObject.layersManager)
thisObject.plotterManager.setTimeFrame(timeFrame)
thisObject.plotterManager.setDatetime(datetime)
thisObject.plotterManager.setCoordinateSystem(coordinateSystem)
}
function initializeRateScale () {
thisObject.rateScale = newRateScale()
thisObject.rateScale.fitFunction = thisObject.fitFunction
thisObject.rateScale.payload = thisObject.payload.node.rateScale.payload
rateScaleMouseOverEventSuscriptionId = thisObject.rateScale.container.eventHandler.listenToEvent('onMouseOverScale', rateScaleMouseOver)
thisObject.rateScale.initialize(timelineChartCoordinateSystem, thisObject.container.parentContainer, thisObject.container)
function rateScaleMouseOver (event) {
thisObject.container.eventHandler.raiseEvent('onChildrenMouseOver', event)
}
}
function initializeTimeFrameScale () {
thisObject.timeFrameScale = newTimeFrameScale()
thisObject.timeFrameScale.fitFunction = thisObject.fitFunction
thisObject.timeFrameScale.payload = thisObject.payload.node.timeFrameScale.payload
timeFrameScaleEventSuscriptionId = thisObject.timeFrameScale.container.eventHandler.listenToEvent('Time Frame Value Changed', timeFrameScaleValueChanged)
timeFrameScaleMouseOverEventSuscriptionId = thisObject.timeFrameScale.container.eventHandler.listenToEvent('onMouseOverScale', timeFrameScaleMouseOver)
thisObject.timeFrameScale.initialize(thisObject.container.parentContainer)
function timeFrameScaleValueChanged (event) {
let currentTimeFrame = timeFrame
timeFrame = event.timeFrame
if (timeFrame !== currentTimeFrame) {
if (thisObject.plotterManager !== undefined) {
thisObject.plotterManager.setTimeFrame(timeFrame)
let drawScales = false
let mouse = {
position: {
x: 0,
y: 0
}
}
}
function timeFrameScaleMouseOver (event) {
thisObject.container.eventHandler.raiseEvent('onChildrenMouseOver', event)
}
}
setupContainer()
return thisObject
function onScaleChanged (event) {
if (thisObject.rateScale !== undefined) {
thisObject.rateScale.onUpstreamScaleChanged(event)
}
timelineChartCoordinateSystem.min.x = timeMachineCoordinateSystem.min.x
timelineChartCoordinateSystem.max.x = timeMachineCoordinateSystem.max.x
timelineChartCoordinateSystem.maxHeight = timeMachineCoordinateSystem.maxHeight
timelineChartCoordinateSystem.maxWidth = timeMachineCoordinateSystem.maxWidth
timelineChartCoordinateSystem.autoMinXScale = timeMachineCoordinateSystem.autoMinXScale
timelineChartCoordinateSystem.autoMaxXScale = timeMachineCoordinateSystem.autoMaxXScale
timelineChartCoordinateSystem.recalculateScale()
}
function setTimeFrame (pTimeFrame) {
timeFrame = pTimeFrame
if (thisObject.plotterManager !== undefined) {
thisObject.plotterManager.setTimeFrame(timeFrame)
}
}
function setDatetime (pDatetime) {
datetime = pDatetime
if (thisObject.plotterManager !== undefined) {
thisObject.plotterManager.setDatetime(datetime)
}
}
function onMouseOver (event) {
/* This event gets to the timelinechart container because it inherits it from the time machine container, which is the one raising Mouse Over and Mouse not Over Events to its children. */
drawScales = true
if (thisObject.rateScale !== undefined) {
thisObject.rateScale.onMouseOverSomeTimeMachineContainer(event)
function setupContainer() {
thisObject.container = newContainer()
thisObject.container.initialize(MODULE_NAME)
thisObject.container.detectMouseOver = true
}
if (thisObject.timeFrameScale !== undefined) {
thisObject.timeFrameScale.onMouseOverSomeTimeMachineContainer(event)
}
function finalize() {
timeMachineCoordinateSystem.eventHandler.stopListening(scaleChangedEventSubscriptionId)
mouse.position.x = event.x
mouse.position.y = event.y
}
function onMouseNotOver (event) {
/* This event is inherited from the Time Machine */
drawScales = false
if (thisObject.rateScale !== undefined) {
thisObject.rateScale.visible = false
}
if (thisObject.timeFrameScale !== undefined) {
thisObject.timeFrameScale.visible = false
}
}
function getContainer (point, purpose) {
let container
if (thisObject.rateScale !== undefined && thisObject.rateScale.isVisible === true) {
container = thisObject.rateScale.getContainer(point, purpose)
if (container !== undefined) {
if (container.isForThisPurpose(purpose)) {
return container
if (thisObject.layersManager !== undefined) {
finalizeLayersManager()
}
}
}
if (thisObject.timeFrameScale !== undefined && thisObject.timeFrameScale.isVisible === true) {
container = thisObject.timeFrameScale.getContainer(point, purpose)
if (container !== undefined) {
if (container.isForThisPurpose(purpose)) {
return container
if (thisObject.rateScale !== undefined) {
finalizeRateScale()
}
}
}
return container
}
function physics () {
thisObjectPhysics()
childrenPhysics()
syncWithDesignerScales()
syncWithDesignerLayersManager()
}
function thisObjectPhysics () {
/* Only if the plotter manager has some layer turned on, we will pass the min and max upstream. */
if (thisObject.plotterManager !== undefined && thisObject.plotterManager.connectors.length > 0) {
timelineChartCoordinateSystem.reportParentXValue(timeMachineCoordinateSystem.min.x, timeMachineCoordinateSystem.max.x)
timelineChartCoordinateSystem.physics()
timeMachineCoordinateSystem.reportXValue(timelineChartCoordinateSystem.childrenMin.x)
timeMachineCoordinateSystem.reportXValue(timelineChartCoordinateSystem.childrenMax.x)
}
}
function syncWithDesignerLayersManager () {
if (thisObject.payload.node === undefined) {
finalizeLayersManager()
return
}
if (thisObject.payload.node.layersManager === undefined && thisObject.layersManager !== undefined) {
finalizeLayersManager()
}
if (thisObject.payload.node.layersManager !== undefined && thisObject.layersManager === undefined) {
initializeLayersManager()
}
}
function syncWithDesignerScales () {
if (thisObject.payload.node === undefined) {
finalizeRateScale()
finalizeTimeFrameScale()
return
}
if (thisObject.payload.node.rateScale === undefined && thisObject.rateScale !== undefined) {
finalizeRateScale()
coordinateSystem = timeMachineCoordinateSystem
if (thisObject.plotterManager !== undefined) {
thisObject.plotterManager.setCoordinateSystem(coordinateSystem)
}
}
if (thisObject.payload.node.rateScale !== undefined && thisObject.rateScale === undefined) {
initializeRateScale()
coordinateSystem = timelineChartCoordinateSystem
if (thisObject.plotterManager !== undefined) {
thisObject.plotterManager.setCoordinateSystem(coordinateSystem)
}
}
if (thisObject.payload.node.timeFrameScale === undefined && thisObject.timeFrameScale !== undefined) {
finalizeTimeFrameScale()
}
if (thisObject.payload.node.timeFrameScale !== undefined && thisObject.timeFrameScale === undefined) {
initializeTimeFrameScale()
}
}
function childrenPhysics () {
if (thisObject.rateScale !== undefined) {
thisObject.rateScale.layersOn = thisObject.plotterManager.connectors.length
thisObject.rateScale.physics()
}
if (thisObject.timeFrameScale !== undefined) {
thisObject.timeFrameScale.layersOn = thisObject.plotterManager.connectors.length
thisObject.timeFrameScale.physics()
}
}
function drawBackground () {
if (thisObject.container.frame.isInViewPort()) {
if (drawScales === true) {
if (thisObject.rateScale !== undefined && thisObject.rateScale.isVisible === true) { thisObject.rateScale.drawBackground() }
}
drawChartsBackground()
if (thisObject.plotterManager !== undefined) {
let elementsPlotted = thisObject.plotterManager.draw()
if (thisObject.timeFrameScale !== undefined) {
thisObject.timeFrameScale.adjustTimeFrame(elementsPlotted)
} else {
return elementsPlotted
finalizeTimeFrameScale()
}
}
}
}
function draw () {
if (thisObject.container.frame.isInViewPort()) {
if (drawScales === true) {
if (thisObject.timeFrameScale !== undefined && thisObject.timeFrameScale.isVisible === true) { thisObject.timeFrameScale.draw() }
if (thisObject.rateScale !== undefined && thisObject.rateScale.isVisible === true) { thisObject.rateScale.draw() }
}
}
}
thisObject.container.eventHandler.stopListening(onMouseOverEventSuscriptionId)
thisObject.container.eventHandler.stopListening(onMouseNotOverEventSuscriptionId)
thisObject.container.finalize()
thisObject.container = undefined
thisObject.payload = undefined
function drawForeground () {
if (thisObject.container.frame.isInViewPort()) {
if (drawScales === true) {
if (thisObject.timeFrameScale !== undefined && thisObject.timeFrameScale.isVisible === true) { thisObject.timeFrameScale.drawForeground() }
if (thisObject.rateScale !== undefined && thisObject.rateScale.isVisible === true) { thisObject.rateScale.drawForeground() }
}
}
}
mouse = undefined
logger = undefined
function drawChartsBackground () {
drawContainerBackground(thisObject.container, UI_COLOR.WHITE, 0, thisObject.fitFunction)
}
timeMachineCoordinateSystem = undefined
timelineChartCoordinateSystem.finalize()
timelineChartCoordinateSystem = undefined
coordinateSystem = undefined
layersPanel = undefined
layersPanelHandle = undefined
}
function finalizeLayersManager() {
if (thisObject.plotterManager !== undefined) {
thisObject.plotterManager.finalize()
}
thisObject.plotterManager = undefined
thisObject.layersManager = undefined
canvas.panelsSpace.destroyPanel(layersPanelHandle)
}
function finalizeTimeFrameScale() {
if (thisObject.timeFrameScale === undefined) { return }
thisObject.timeFrameScale.container.eventHandler.stopListening(timeFrameScaleEventSuscriptionId)
thisObject.timeFrameScale.container.eventHandler.stopListening(timeFrameScaleMouseOverEventSuscriptionId)
thisObject.timeFrameScale.finalize()
thisObject.timeFrameScale = undefined
if (thisObject.upstreamTimeFrame !== undefined) {
timeFrame = thisObject.upstreamTimeFrame
if (thisObject.plotterManager !== undefined) {
thisObject.plotterManager.setTimeFrame(timeFrame)
}
}
}
function finalizeRateScale() {
if (thisObject.rateScale === undefined) { return }
thisObject.rateScale.container.eventHandler.stopListening(rateScaleMouseOverEventSuscriptionId)
thisObject.container.parentContainer.eventHandler.stopListening(rateScaleUpstreamEventSuscriptionId)
thisObject.rateScale.finalize()
thisObject.rateScale = undefined
/* Resets the local container with the dimessions of its parent, the Time Machine */
thisObject.container.frame.position.x = 0
thisObject.container.frame.position.y = 0
thisObject.container.frame.height = thisObject.container.parentContainer.frame.height
thisObject.container.frame.width = thisObject.container.parentContainer.frame.width
}
function initialize(pTimeMachineCoordinateSystem, pTimeFrame) {
/* We load the logow we will need for the background. */
timeMachineCoordinateSystem = pTimeMachineCoordinateSystem
coordinateSystem = timeMachineCoordinateSystem
initializeCoordinateSystem()
timeFrame = pTimeFrame
onMouseOverEventSuscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver)
onMouseNotOverEventSuscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseNotOver', onMouseNotOver)
scaleChangedEventSubscriptionId = timeMachineCoordinateSystem.eventHandler.listenToEvent('Scale Changed', onScaleChanged)
}
function initializeCoordinateSystem() {
let minValue = {
x: timeMachineCoordinateSystem.min.x,
y: 0
}
let maxValue = {
x: timeMachineCoordinateSystem.max.x,
y: nextPorwerOf10(MAX_DEFAULT_RATE_SCALE_VALUE) / 4
}
if (thisObject.rateScale !== undefined) {
minValue.y = thisObject.rateScale.minValue
maxValue.y = thisObject.rateScale.maxValue
}
timelineChartCoordinateSystem.initialize(
minValue,
maxValue,
thisObject.container.frame.width,
thisObject.container.frame.height
)
}
function initializeLayersManager() {
let owner = thisObject.payload.node.payload.parentNode.id // The real owner is the Time Machine
layersPanelHandle = canvas.panelsSpace.createNewPanel('Layers Panel', undefined, owner)
thisObject.layersManager = canvas.panelsSpace.getPanel(layersPanelHandle)
thisObject.layersManager.payload = thisObject.payload.node.layersManager.payload
thisObject.layersManager.initialize()
/* Initialize the Plotter Manager */
thisObject.plotterManager = newPlottersManager()
thisObject.plotterManager.container.connectToParent(thisObject.container, true, true, false, true, true, true, false, false, true)
thisObject.plotterManager.container.frame.position.x = 0
thisObject.plotterManager.container.frame.position.y = 0
thisObject.plotterManager.fitFunction = thisObject.fitFunction
thisObject.plotterManager.payload = thisObject.payload
thisObject.plotterManager.initialize(thisObject.layersManager)
thisObject.plotterManager.setTimeFrame(timeFrame)
thisObject.plotterManager.setDatetime(datetime)
thisObject.plotterManager.setCoordinateSystem(coordinateSystem)
}
function initializeRateScale() {
thisObject.rateScale = newRateScale()
thisObject.rateScale.fitFunction = thisObject.fitFunction
thisObject.rateScale.payload = thisObject.payload.node.rateScale.payload
rateScaleMouseOverEventSuscriptionId = thisObject.rateScale.container.eventHandler.listenToEvent('onMouseOverScale', rateScaleMouseOver)
thisObject.rateScale.initialize(timelineChartCoordinateSystem, thisObject.container.parentContainer, thisObject.container)
function rateScaleMouseOver(event) {
thisObject.container.eventHandler.raiseEvent('onChildrenMouseOver', event)
}
}
function initializeTimeFrameScale() {
thisObject.timeFrameScale = newTimeFrameScale()
thisObject.timeFrameScale.fitFunction = thisObject.fitFunction
thisObject.timeFrameScale.payload = thisObject.payload.node.timeFrameScale.payload
timeFrameScaleEventSuscriptionId = thisObject.timeFrameScale.container.eventHandler.listenToEvent('Time Frame Value Changed', timeFrameScaleValueChanged)
timeFrameScaleMouseOverEventSuscriptionId = thisObject.timeFrameScale.container.eventHandler.listenToEvent('onMouseOverScale', timeFrameScaleMouseOver)
thisObject.timeFrameScale.initialize(thisObject.container.parentContainer)
function timeFrameScaleValueChanged(event) {
let currentTimeFrame = timeFrame
timeFrame = event.timeFrame
if (timeFrame !== currentTimeFrame) {
if (thisObject.plotterManager !== undefined) {
thisObject.plotterManager.setTimeFrame(timeFrame)
}
}
}
function timeFrameScaleMouseOver(event) {
thisObject.container.eventHandler.raiseEvent('onChildrenMouseOver', event)
}
}
function onScaleChanged(event) {
if (thisObject.rateScale !== undefined) {
thisObject.rateScale.onUpstreamScaleChanged(event)
}
timelineChartCoordinateSystem.min.x = timeMachineCoordinateSystem.min.x
timelineChartCoordinateSystem.max.x = timeMachineCoordinateSystem.max.x
timelineChartCoordinateSystem.maxHeight = timeMachineCoordinateSystem.maxHeight
timelineChartCoordinateSystem.maxWidth = timeMachineCoordinateSystem.maxWidth
timelineChartCoordinateSystem.autoMinXScale = timeMachineCoordinateSystem.autoMinXScale
timelineChartCoordinateSystem.autoMaxXScale = timeMachineCoordinateSystem.autoMaxXScale
timelineChartCoordinateSystem.recalculateScale()
}
function setTimeFrame(pTimeFrame) {
timeFrame = pTimeFrame
if (thisObject.plotterManager !== undefined) {
thisObject.plotterManager.setTimeFrame(timeFrame)
}
}
function setDatetime(pDatetime) {
datetime = pDatetime
if (thisObject.plotterManager !== undefined) {
thisObject.plotterManager.setDatetime(datetime)
}
}
function onMouseOver(event) {
/* This event gets to the timelinechart container because it inherits it from the time machine container, which is the one raising Mouse Over and Mouse not Over Events to its children. */
drawScales = true
if (thisObject.rateScale !== undefined) {
thisObject.rateScale.onMouseOverSomeTimeMachineContainer(event)
}
if (thisObject.timeFrameScale !== undefined) {
thisObject.timeFrameScale.onMouseOverSomeTimeMachineContainer(event)
}
mouse.position.x = event.x
mouse.position.y = event.y
}
function onMouseNotOver(event) {
/* This event is inherited from the Time Machine */
drawScales = false
if (thisObject.rateScale !== undefined) {
thisObject.rateScale.visible = false
}
if (thisObject.timeFrameScale !== undefined) {
thisObject.timeFrameScale.visible = false
}
}
function getContainer(point, purpose) {
let container
if (thisObject.rateScale !== undefined && thisObject.rateScale.isVisible === true) {
container = thisObject.rateScale.getContainer(point, purpose)
if (container !== undefined) {
if (container.isForThisPurpose(purpose)) {
return container
}
}
}
if (thisObject.timeFrameScale !== undefined && thisObject.timeFrameScale.isVisible === true) {
container = thisObject.timeFrameScale.getContainer(point, purpose)
if (container !== undefined) {
if (container.isForThisPurpose(purpose)) {
return container
}
}
}
return container
}
function physics() {
thisObjectPhysics()
childrenPhysics()
syncWithDesignerScales()
syncWithDesignerLayersManager()
}
function thisObjectPhysics() {
/* Only if the plotter manager has some layer turned on, we will pass the min and max upstream. */
if (thisObject.plotterManager !== undefined && thisObject.plotterManager.connectors.length > 0) {
timelineChartCoordinateSystem.reportParentXValue(timeMachineCoordinateSystem.min.x, timeMachineCoordinateSystem.max.x)
timelineChartCoordinateSystem.physics()
timeMachineCoordinateSystem.reportXValue(timelineChartCoordinateSystem.childrenMin.x)
timeMachineCoordinateSystem.reportXValue(timelineChartCoordinateSystem.childrenMax.x)
}
}
function syncWithDesignerLayersManager() {
if (thisObject.payload.node === undefined) {
finalizeLayersManager()
return
}
if (thisObject.payload.node.layersManager === undefined && thisObject.layersManager !== undefined) {
finalizeLayersManager()
}
if (thisObject.payload.node.layersManager !== undefined && thisObject.layersManager === undefined) {
initializeLayersManager()
}
}
function syncWithDesignerScales() {
if (thisObject.payload.node === undefined) {
finalizeRateScale()
finalizeTimeFrameScale()
return
}
if (thisObject.payload.node.rateScale === undefined && thisObject.rateScale !== undefined) {
finalizeRateScale()
coordinateSystem = timeMachineCoordinateSystem
if (thisObject.plotterManager !== undefined) {
thisObject.plotterManager.setCoordinateSystem(coordinateSystem)
}
}
if (thisObject.payload.node.rateScale !== undefined && thisObject.rateScale === undefined) {
initializeRateScale()
coordinateSystem = timelineChartCoordinateSystem
if (thisObject.plotterManager !== undefined) {
thisObject.plotterManager.setCoordinateSystem(coordinateSystem)
}
}
if (thisObject.payload.node.timeFrameScale === undefined && thisObject.timeFrameScale !== undefined) {
finalizeTimeFrameScale()
}
if (thisObject.payload.node.timeFrameScale !== undefined && thisObject.timeFrameScale === undefined) {
initializeTimeFrameScale()
}
}
function childrenPhysics() {
if (thisObject.rateScale !== undefined) {
thisObject.rateScale.layersOn = thisObject.plotterManager.connectors.length
thisObject.rateScale.physics()
}
if (thisObject.timeFrameScale !== undefined) {
thisObject.timeFrameScale.layersOn = thisObject.plotterManager.connectors.length
thisObject.timeFrameScale.physics()
}
}
function drawBackground() {
if (thisObject.container.frame.isInViewPort()) {
if (drawScales === true) {
if (thisObject.rateScale !== undefined && thisObject.rateScale.isVisible === true) { thisObject.rateScale.drawBackground() }
}
drawChartsBackground()
if (thisObject.plotterManager !== undefined) {
let elementsPlotted = thisObject.plotterManager.draw()
if (thisObject.timeFrameScale !== undefined) {
thisObject.timeFrameScale.adjustTimeFrame(elementsPlotted)
} else {
return elementsPlotted
}
}
}
}
function draw() {
if (thisObject.container.frame.isInViewPort()) {
if (drawScales === true) {
if (thisObject.timeFrameScale !== undefined && thisObject.timeFrameScale.isVisible === true) { thisObject.timeFrameScale.draw() }
if (thisObject.rateScale !== undefined && thisObject.rateScale.isVisible === true) { thisObject.rateScale.draw() }
}
}
}
function drawForeground() {
if (thisObject.container.frame.isInViewPort()) {
if (drawScales === true) {
if (thisObject.timeFrameScale !== undefined && thisObject.timeFrameScale.isVisible === true) { thisObject.timeFrameScale.drawForeground() }
if (thisObject.rateScale !== undefined && thisObject.rateScale.isVisible === true) { thisObject.rateScale.drawForeground() }
}
}
}
function drawChartsBackground() {
drawContainerBackground(thisObject.container, UI_COLOR.WHITE, 0, thisObject.fitFunction)
}
}
+372 -372
View File
@@ -1,421 +1,421 @@
function newViewport () {
const MODULE_NAME = 'Viewport'
function newViewport() {
const MODULE_NAME = 'Viewport'
const MIN_ZOOM_LEVEL = 0
const MAX_ZOOM_LEVEL = 500
const MIN_ZOOM_LEVEL = 0
const MAX_ZOOM_LEVEL = 500
let ANIMATION_INCREMENT = 0.25
let ANIMATION_STEPS = 5
let ANIMATION_INCREMENT = 0.25
let ANIMATION_STEPS = 5
let TOP_MARGIN = 40 + TOP_SPACE_HEIGHT
let BOTTOM_MARGIN = 42 + COCKPIT_SPACE_HEIGHT
let LEFT_MARGIN = 0
let RIGHT_MARGIN = 0
let MARGINS = {
TOP: TOP_MARGIN,
BOTTOM: BOTTOM_MARGIN,
LEFT: LEFT_MARGIN,
RIGHT: RIGHT_MARGIN
}
let TOP_MARGIN = 40 + TOP_SPACE_HEIGHT
let BOTTOM_MARGIN = 42 + COCKPIT_SPACE_HEIGHT
let LEFT_MARGIN = 0
let RIGHT_MARGIN = 0
let MARGINS = {
TOP: TOP_MARGIN,
BOTTOM: BOTTOM_MARGIN,
LEFT: LEFT_MARGIN,
RIGHT: RIGHT_MARGIN
}
let thisObject = {
visible: false,
visibleArea: undefined,
width: undefined,
height: undefined,
eventHandler: undefined,
zoomTargetLevel: undefined,
zoomLevel: undefined,
mousePosition: undefined,
margins: MARGINS,
payload: undefined,
zoomAtCenter: zoomAtCenter,
changeZoom: changeZoom,
onMouseWheel: onMouseWheel,
transformThisPoint: transformThisPoint,
unTransformThisPoint: unTransformThisPoint,
isThisPointVisible: isThisPointVisible,
isThisPointInViewport: isThisPointInViewport,
fitIntoVisibleArea: fitIntoVisibleArea,
fitIntoViewport: fitIntoViewport,
displace: displace,
displaceToContainer: displaceToContainer,
physics: physics,
raiseEvents: raiseEvents,
resize: resize,
initialize: initialize,
finalize: finalize
}
let increment = 0.035
let position = {
x: 0,
y: 0
}
let thisObject = {
visible: false,
visibleArea: undefined,
width: undefined,
height: undefined,
eventHandler: undefined,
zoomTargetLevel: undefined,
zoomLevel: undefined,
mousePosition: undefined,
margins: MARGINS,
payload: undefined,
zoomAtCenter: zoomAtCenter,
changeZoom: changeZoom,
onMouseWheel: onMouseWheel,
transformThisPoint: transformThisPoint,
unTransformThisPoint: unTransformThisPoint,
isThisPointVisible: isThisPointVisible,
isThisPointInViewport: isThisPointInViewport,
fitIntoVisibleArea: fitIntoVisibleArea,
fitIntoViewport: fitIntoViewport,
displace: displace,
displaceToContainer: displaceToContainer,
physics: physics,
raiseEvents: raiseEvents,
resize: resize,
initialize: initialize,
finalize: finalize
}
let increment = 0.035
let position = {
x: 0,
y: 0
}
thisObject.mousePosition = {
x: 0,
y: 0
}
thisObject.eventHandler = newEventHandler()
thisObject.mousePosition = {
x: 0,
y: 0
}
thisObject.eventHandler = newEventHandler()
/* Initial default value */
thisObject.zoomLevel = MIN_ZOOM_LEVEL
thisObject.zoomTargetLevel = Math.round(MIN_ZOOM_LEVEL)
INITIAL_TIME_PERIOD = recalculatePeriod(thisObject.zoomLevel)
/* Initial default value */
thisObject.zoomLevel = MIN_ZOOM_LEVEL
thisObject.zoomTargetLevel = Math.round(MIN_ZOOM_LEVEL)
INITIAL_TIME_PERIOD = recalculatePeriod(thisObject.zoomLevel)
let overrideMousePositionCounter = 0
let overrideMousePositionCounter = 0
return thisObject
return thisObject
function finalize () {
thisObject.eventHandler.finalize()
thisObject.payload = undefined
thisObject = undefined
}
function finalize() {
thisObject.eventHandler.finalize()
thisObject.payload = undefined
thisObject = undefined
}
function initialize () {
if (thisObject.payload !== undefined) {
/* Read the position from the frame structure */
function initialize() {
if (thisObject.payload !== undefined) {
/* Read the position from the frame structure */
let frame = {
position: {
x: 0,
y: 0
let frame = {
position: {
x: 0,
y: 0
}
}
loadFrame(thisObject.payload, frame)
if (!isNaN(frame.position.x)) {
position.x = frame.position.x
}
if (!isNaN(frame.position.y)) {
position.y = frame.position.y
}
}
}
loadFrame(thisObject.payload, frame)
if (!isNaN(frame.position.x)) {
position.x = frame.position.x
}
if (!isNaN(frame.position.y)) {
position.y = frame.position.y
}
resize()
readObjectState()
}
resize()
readObjectState()
}
function resize() {
TOP_MARGIN = 40 + TOP_SPACE_HEIGHT
BOTTOM_MARGIN = 42 + browserCanvas.height - COCKPIT_SPACE_POSITION
LEFT_MARGIN = 0
RIGHT_MARGIN = 0
MARGINS = {
TOP: TOP_MARGIN,
BOTTOM: BOTTOM_MARGIN,
LEFT: LEFT_MARGIN,
RIGHT: RIGHT_MARGIN
}
function resize () {
TOP_MARGIN = 40 + TOP_SPACE_HEIGHT
BOTTOM_MARGIN = 42 + browserCanvas.height - COCKPIT_SPACE_POSITION
LEFT_MARGIN = 0
RIGHT_MARGIN = 0
MARGINS = {
TOP: TOP_MARGIN,
BOTTOM: BOTTOM_MARGIN,
LEFT: LEFT_MARGIN,
RIGHT: RIGHT_MARGIN
thisObject.visibleArea = {
topLeft: { x: LEFT_MARGIN, y: TOP_MARGIN },
topRight: { x: browserCanvas.width - RIGHT_MARGIN, y: TOP_MARGIN },
bottomRight: { x: browserCanvas.width - RIGHT_MARGIN, y: browserCanvas.height - BOTTOM_MARGIN },
bottomLeft: { x: LEFT_MARGIN, y: browserCanvas.height - BOTTOM_MARGIN }
}
thisObject.width = thisObject.visibleArea.topRight.x - thisObject.visibleArea.topLeft.x
thisObject.height = thisObject.visibleArea.bottomRight.y - thisObject.visibleArea.topLeft.y
thisObject.center = {
x: LEFT_MARGIN + thisObject.width / 2,
y: TOP_MARGIN + thisObject.height / 2
}
}
thisObject.visibleArea = {
topLeft: { x: LEFT_MARGIN, y: TOP_MARGIN },
topRight: { x: browserCanvas.width - RIGHT_MARGIN, y: TOP_MARGIN },
bottomRight: { x: browserCanvas.width - RIGHT_MARGIN, y: browserCanvas.height - BOTTOM_MARGIN},
bottomLeft: { x: LEFT_MARGIN, y: browserCanvas.height - BOTTOM_MARGIN}
function raiseEvents() {
if (thisObject.visible === false) { return }
let event = {
newPosition: position
}
thisObject.eventHandler.raiseEvent('Position Changed', event)
}
thisObject.width = thisObject.visibleArea.topRight.x - thisObject.visibleArea.topLeft.x
thisObject.height = thisObject.visibleArea.bottomRight.y - thisObject.visibleArea.topLeft.y
thisObject.center = {
x: LEFT_MARGIN + thisObject.width / 2,
y: TOP_MARGIN + thisObject.height / 2
}
}
function raiseEvents () {
if (thisObject.visible === false) { return }
let event = {
newPosition: position
function displaceToContainer(container) {
let targetPoint = {
x: -container.frame.position.x - container.frame.width / 2,
y: -container.frame.position.y - container.frame.height / 2
}
position.x = targetPoint.x + browserCanvas.width / 2
position.y = targetPoint.y + (COCKPIT_SPACE_POSITION - TOP_SPACE_HEIGHT) / 2 + TOP_SPACE_HEIGHT
}
thisObject.eventHandler.raiseEvent('Position Changed', event)
}
function displaceToContainer (container) {
let targetPoint = {
x: -container.frame.position.x - container.frame.width / 2,
y: -container.frame.position.y - container.frame.height / 2
}
position.x = targetPoint.x + browserCanvas.width / 2
position.y = targetPoint.y + (COCKPIT_SPACE_POSITION - TOP_SPACE_HEIGHT) / 2 + TOP_SPACE_HEIGHT
}
function zoomAtCenter (level) {
thisObject.zoomTargetLevel = Math.round(level)
overrideMousePositionCounter = 50
ANIMATION_INCREMENT = 0.5
}
function mousePositionPhysics () {
if (overrideMousePositionCounter > 0) {
thisObject.mousePosition.x = browserCanvas.width / 2
thisObject.mousePosition.y = (COCKPIT_SPACE_POSITION - TOP_SPACE_HEIGHT) / 2 + TOP_SPACE_HEIGHT
overrideMousePositionCounter--
if (overrideMousePositionCounter < 0) {
overrideMousePositionCounter = 0
}
}
}
function physics () {
if (thisObject.visible === false) { return }
mousePositionPhysics()
animationPhysics()
positioningPhysics()
readObjectState()
}
function positioningPhysics () {
if (thisObject.visible === false) { return }
if (thisObject.payload === undefined) { return }
/* Save the position at the frame lavel */
let frame = {}
frame.position = position
saveFrame(thisObject.payload, frame)
}
function animationPhysics () {
if (thisObject.zoomLevel < thisObject.zoomTargetLevel) {
if (thisObject.zoomTargetLevel - thisObject.zoomLevel < ANIMATION_INCREMENT) {
ANIMATION_INCREMENT = Math.round(Math.abs(thisObject.zoomTargetLevel - thisObject.zoomLevel) * 100) / 100
}
thisObject.zoomLevel = Math.round((thisObject.zoomLevel + ANIMATION_INCREMENT) * 100) / 100
changeZoom(thisObject.zoomLevel - ANIMATION_INCREMENT, thisObject.zoomLevel)
function zoomAtCenter(level) {
thisObject.zoomTargetLevel = Math.round(level)
overrideMousePositionCounter = 50
ANIMATION_INCREMENT = 0.5
}
if (thisObject.zoomLevel > thisObject.zoomTargetLevel) {
if (thisObject.zoomLevel - thisObject.zoomTargetLevel < ANIMATION_INCREMENT) {
ANIMATION_INCREMENT = Math.round(Math.abs(thisObject.zoomTargetLevel - thisObject.zoomLevel) * 100) / 100
}
thisObject.zoomLevel = Math.round((thisObject.zoomLevel - ANIMATION_INCREMENT) * 100) / 100
changeZoom(thisObject.zoomLevel + ANIMATION_INCREMENT, thisObject.zoomLevel)
}
}
function mousePositionPhysics() {
if (overrideMousePositionCounter > 0) {
thisObject.mousePosition.x = browserCanvas.width / 2
thisObject.mousePosition.y = (COCKPIT_SPACE_POSITION - TOP_SPACE_HEIGHT) / 2 + TOP_SPACE_HEIGHT
function onMouseWheel (event) {
if (thisObject.visible === false) { return }
if ((event.ctrlKey === true || event.metaKey === true)) { return }
let morePower = 1
if (IS_MAC) {
event.delta = event.delta * MAC_AMOUNT_FACTOR
overrideMousePositionCounter--
if (overrideMousePositionCounter < 0) {
overrideMousePositionCounter = 0
}
}
}
let amount = event.delta
if (event.buttons === 4) { morePower = 2 } // Mouse wheel pressed.
/* We adjust the sensitivity for Mac Users */
if (thisObject.zoomTargetLevel > 10) {
amount = amount * 2
}
if (thisObject.zoomTargetLevel > 25) {
amount = amount * 3
}
if (thisObject.zoomTargetLevel > 50) {
amount = amount * 3.5
function physics() {
if (thisObject.visible === false) { return }
mousePositionPhysics()
animationPhysics()
positioningPhysics()
readObjectState()
}
if (thisObject.zoomTargetLevel + amount * morePower > MAX_ZOOM_LEVEL) {
return false
}
if (thisObject.zoomTargetLevel + amount * morePower < MIN_ZOOM_LEVEL) {
return false
}
thisObject.zoomTargetLevel = Math.round(thisObject.zoomTargetLevel + amount * morePower)
ANIMATION_INCREMENT = Math.round(Math.abs(thisObject.zoomTargetLevel - thisObject.zoomLevel) / ANIMATION_STEPS * 100) / 100
let newEvent = {
newLevel: thisObject.zoomTargetLevel,
newPosition: position,
type: undefined,
shiftKey: event.shiftKey
function positioningPhysics() {
if (thisObject.visible === false) { return }
if (thisObject.payload === undefined) { return }
/* Save the position at the frame lavel */
let frame = {}
frame.position = position
saveFrame(thisObject.payload, frame)
}
if (amount > 0) {
newEvent.type = 'Zoom In'
} else {
newEvent.type = 'Zoom Out'
function animationPhysics() {
if (thisObject.zoomLevel < thisObject.zoomTargetLevel) {
if (thisObject.zoomTargetLevel - thisObject.zoomLevel < ANIMATION_INCREMENT) {
ANIMATION_INCREMENT = Math.round(Math.abs(thisObject.zoomTargetLevel - thisObject.zoomLevel) * 100) / 100
}
thisObject.zoomLevel = Math.round((thisObject.zoomLevel + ANIMATION_INCREMENT) * 100) / 100
changeZoom(thisObject.zoomLevel - ANIMATION_INCREMENT, thisObject.zoomLevel)
}
if (thisObject.zoomLevel > thisObject.zoomTargetLevel) {
if (thisObject.zoomLevel - thisObject.zoomTargetLevel < ANIMATION_INCREMENT) {
ANIMATION_INCREMENT = Math.round(Math.abs(thisObject.zoomTargetLevel - thisObject.zoomLevel) * 100) / 100
}
thisObject.zoomLevel = Math.round((thisObject.zoomLevel - ANIMATION_INCREMENT) * 100) / 100
changeZoom(thisObject.zoomLevel + ANIMATION_INCREMENT, thisObject.zoomLevel)
}
}
thisObject.eventHandler.raiseEvent('Zoom Changed', newEvent)
return true
}
function onMouseWheel(event) {
if (thisObject.visible === false) { return }
if ((event.ctrlKey === true || event.metaKey === true)) { return }
let morePower = 1
function fitIntoVisibleArea (point) {
let pointCopy = {
x: point.x,
y: point.y
if (IS_MAC) {
event.delta = event.delta * MAC_AMOUNT_FACTOR
}
let amount = event.delta
if (event.buttons === 4) { morePower = 2 } // Mouse wheel pressed.
/* We adjust the sensitivity for Mac Users */
if (thisObject.zoomTargetLevel > 10) {
amount = amount * 2
}
if (thisObject.zoomTargetLevel > 25) {
amount = amount * 3
}
if (thisObject.zoomTargetLevel > 50) {
amount = amount * 3.5
}
if (thisObject.zoomTargetLevel + amount * morePower > MAX_ZOOM_LEVEL) {
return false
}
if (thisObject.zoomTargetLevel + amount * morePower < MIN_ZOOM_LEVEL) {
return false
}
thisObject.zoomTargetLevel = Math.round(thisObject.zoomTargetLevel + amount * morePower)
ANIMATION_INCREMENT = Math.round(Math.abs(thisObject.zoomTargetLevel - thisObject.zoomLevel) / ANIMATION_STEPS * 100) / 100
let newEvent = {
newLevel: thisObject.zoomTargetLevel,
newPosition: position,
type: undefined,
shiftKey: event.shiftKey
}
if (amount > 0) {
newEvent.type = 'Zoom In'
} else {
newEvent.type = 'Zoom Out'
}
thisObject.eventHandler.raiseEvent('Zoom Changed', newEvent)
return true
}
/* Here we check the boundaries of the resulting points, so they dont go out of the visible area. */
if (pointCopy.x > thisObject.visibleArea.bottomRight.x + 1) {
pointCopy.x = thisObject.visibleArea.bottomRight.x + 1
function fitIntoVisibleArea(point) {
let pointCopy = {
x: point.x,
y: point.y
}
/* Here we check the boundaries of the resulting points, so they dont go out of the visible area. */
if (pointCopy.x > thisObject.visibleArea.bottomRight.x + 1) {
pointCopy.x = thisObject.visibleArea.bottomRight.x + 1
}
if (pointCopy.x < thisObject.visibleArea.topLeft.x - 1) {
pointCopy.x = thisObject.visibleArea.topLeft.x - 1
}
if (pointCopy.y > thisObject.visibleArea.bottomRight.y + 1) {
pointCopy.y = thisObject.visibleArea.bottomRight.y + 1
}
if (pointCopy.y < thisObject.visibleArea.topLeft.y - 1) {
pointCopy.y = thisObject.visibleArea.topLeft.y - 1
}
return pointCopy
}
if (pointCopy.x < thisObject.visibleArea.topLeft.x - 1) {
pointCopy.x = thisObject.visibleArea.topLeft.x - 1
function fitIntoViewport(point) {
let pointCopy = {
x: point.x,
y: point.y
}
if (pointCopy.y > COCKPIT_SPACE_POSITION) {
pointCopy.y = COCKPIT_SPACE_POSITION
}
return pointCopy
}
if (pointCopy.y > thisObject.visibleArea.bottomRight.y + 1) {
pointCopy.y = thisObject.visibleArea.bottomRight.y + 1
}
function displace(displaceVector, recalculate) {
if (thisObject.visible === false) { return }
position.x = position.x + displaceVector.x
position.y = position.y + displaceVector.y
if (pointCopy.y < thisObject.visibleArea.topLeft.y - 1) {
pointCopy.y = thisObject.visibleArea.topLeft.y - 1
}
return pointCopy
}
function fitIntoViewport (point) {
let pointCopy = {
x: point.x,
y: point.y
}
if (pointCopy.y > COCKPIT_SPACE_POSITION) {
pointCopy.y = COCKPIT_SPACE_POSITION
}
return pointCopy
}
function displace (displaceVector, recalculate) {
if (thisObject.visible === false) { return }
position.x = position.x + displaceVector.x
position.y = position.y + displaceVector.y
saveObjectState()
let event = {
newPosition: position,
recalculate: recalculate
}
thisObject.eventHandler.raiseEvent('Position Changed', event)
}
function changeZoom (oldLevel, newLevel) {
if (thisObject.visible === false) { return }
let oldMouse = unTransformThisPoint(thisObject.mousePosition, oldLevel)
let newMouse = transformThisPoint(oldMouse, newLevel)
position.x = position.x - newMouse.x + thisObject.mousePosition.x
position.y = position.y - newMouse.y + thisObject.mousePosition.y
saveObjectState()
thisObject.eventHandler.raiseEvent('Zoom Changed')
}
function transformThisPoint (point, level) {
if (thisObject.visible === false) { return }
let transformedPoint = {
x: 0,
y: 0
}
if (level === undefined) {
transformedPoint.x = point.x * (1 + thisObject.zoomLevel) + position.x
transformedPoint.y = point.y * (1 + thisObject.zoomLevel) + position.y
} else {
transformedPoint.x = point.x * (1 + level) + position.x
transformedPoint.y = point.y * (1 + level) + position.y
}
return transformedPoint
}
function unTransformThisPoint (point, level) {
let pointWithoutZoom = {
x: 0,
y: 0
}
if (level === undefined) {
pointWithoutZoom.x = (point.x - position.x) / (1 + thisObject.zoomLevel)
pointWithoutZoom.y = (point.y - position.y) / (1 + thisObject.zoomLevel)
} else {
pointWithoutZoom.x = (point.x - position.x) / (1 + level)
pointWithoutZoom.y = (point.y - position.y) / (1 + level)
}
return pointWithoutZoom
}
function isThisPointVisible (point) {
if (thisObject.visible === false) { return }
if (point.x < thisObject.visibleArea.topLeft.x || point.x > thisObject.visibleArea.bottomRight.x || point.y < thisObject.visibleArea.topLeft.y || point.y > thisObject.visibleArea.bottomRight.y) {
return false
} else {
return true
}
}
function isThisPointInViewport (point) {
if (thisObject.visible === false) { return }
if (point.y > COCKPIT_SPACE_POSITION) {
return false
} else {
return true
}
}
function saveObjectState () {
if (thisObject.payload === undefined) { return }
/* Save the zoom at the node config, so that the user can change it if he wishes to. */
try {
let config = JSON.parse(thisObject.payload.node.config)
config.zoom = (thisObject.zoomTargetLevel - MIN_ZOOM_LEVEL) / (MAX_ZOOM_LEVEL - MIN_ZOOM_LEVEL) * 100
config.zoom = config.zoom.toFixed(2)
thisObject.payload.node.config = JSON.stringify(config)
} catch (err) {
// we ignore errors here since most likely they will be parsing errors.
}
}
function readObjectState () {
if (thisObject.payload === undefined) { return }
/* Read the zoom level from the node config */
try {
let config = JSON.parse(thisObject.payload.node.config)
if (isNaN(config.zoom) || config.zoom === null || config.zoom === undefined) {
saveObjectState()
return
}
config.zoom = config.zoom / 100 * (MAX_ZOOM_LEVEL - MIN_ZOOM_LEVEL) + MIN_ZOOM_LEVEL
if (config.zoom < MIN_ZOOM_LEVEL) { config.zoom = MIN_ZOOM_LEVEL }
if (config.zoom > MAX_ZOOM_LEVEL) { config.zoom = MAX_ZOOM_LEVEL }
if (config.zoom.toFixed(2) !== thisObject.zoomTargetLevel.toFixed(2)) {
newZoomLevel(config.zoom)
} else {
let event = {
newPosition: position,
recalculate: recalculate
}
thisObject.eventHandler.raiseEvent('Position Changed', event)
}
function changeZoom(oldLevel, newLevel) {
if (thisObject.visible === false) { return }
let oldMouse = unTransformThisPoint(thisObject.mousePosition, oldLevel)
let newMouse = transformThisPoint(oldMouse, newLevel)
position.x = position.x - newMouse.x + thisObject.mousePosition.x
position.y = position.y - newMouse.y + thisObject.mousePosition.y
saveObjectState()
}
} catch (err) {
// we ignore errors here since most likely they will be parsing errors.
thisObject.eventHandler.raiseEvent('Zoom Changed')
}
function newZoomLevel (level) {
thisObject.zoomLevel = Math.round(level)
thisObject.zoomTargetLevel = Math.round(level)
INITIAL_TIME_PERIOD = recalculatePeriod(level)
saveObjectState()
ANIMATION_INCREMENT = 0
function transformThisPoint(point, level) {
if (thisObject.visible === false) { return }
let transformedPoint = {
x: 0,
y: 0
}
let event = {
newLevel: thisObject.zoomTargetLevel,
newPosition: position,
type: undefined
}
thisObject.eventHandler.raiseEvent('Zoom Changed', event)
return true
if (level === undefined) {
transformedPoint.x = point.x * (1 + thisObject.zoomLevel) + position.x
transformedPoint.y = point.y * (1 + thisObject.zoomLevel) + position.y
} else {
transformedPoint.x = point.x * (1 + level) + position.x
transformedPoint.y = point.y * (1 + level) + position.y
}
return transformedPoint
}
function unTransformThisPoint(point, level) {
let pointWithoutZoom = {
x: 0,
y: 0
}
if (level === undefined) {
pointWithoutZoom.x = (point.x - position.x) / (1 + thisObject.zoomLevel)
pointWithoutZoom.y = (point.y - position.y) / (1 + thisObject.zoomLevel)
} else {
pointWithoutZoom.x = (point.x - position.x) / (1 + level)
pointWithoutZoom.y = (point.y - position.y) / (1 + level)
}
return pointWithoutZoom
}
function isThisPointVisible(point) {
if (thisObject.visible === false) { return }
if (point.x < thisObject.visibleArea.topLeft.x || point.x > thisObject.visibleArea.bottomRight.x || point.y < thisObject.visibleArea.topLeft.y || point.y > thisObject.visibleArea.bottomRight.y) {
return false
} else {
return true
}
}
function isThisPointInViewport(point) {
if (thisObject.visible === false) { return }
if (point.y > COCKPIT_SPACE_POSITION) {
return false
} else {
return true
}
}
function saveObjectState() {
if (thisObject.payload === undefined) { return }
/* Save the zoom at the node config, so that the user can change it if he wishes to. */
try {
let config = JSON.parse(thisObject.payload.node.config)
config.zoom = (thisObject.zoomTargetLevel - MIN_ZOOM_LEVEL) / (MAX_ZOOM_LEVEL - MIN_ZOOM_LEVEL) * 100
config.zoom = config.zoom.toFixed(2)
thisObject.payload.node.config = JSON.stringify(config)
} catch (err) {
// we ignore errors here since most likely they will be parsing errors.
}
}
function readObjectState() {
if (thisObject.payload === undefined) { return }
/* Read the zoom level from the node config */
try {
let config = JSON.parse(thisObject.payload.node.config)
if (isNaN(config.zoom) || config.zoom === null || config.zoom === undefined) {
saveObjectState()
return
}
config.zoom = config.zoom / 100 * (MAX_ZOOM_LEVEL - MIN_ZOOM_LEVEL) + MIN_ZOOM_LEVEL
if (config.zoom < MIN_ZOOM_LEVEL) { config.zoom = MIN_ZOOM_LEVEL }
if (config.zoom > MAX_ZOOM_LEVEL) { config.zoom = MAX_ZOOM_LEVEL }
if (config.zoom.toFixed(2) !== thisObject.zoomTargetLevel.toFixed(2)) {
newZoomLevel(config.zoom)
} else {
saveObjectState()
}
} catch (err) {
// we ignore errors here since most likely they will be parsing errors.
}
function newZoomLevel(level) {
thisObject.zoomLevel = Math.round(level)
thisObject.zoomTargetLevel = Math.round(level)
INITIAL_TIME_PERIOD = recalculatePeriod(level)
saveObjectState()
ANIMATION_INCREMENT = 0
let event = {
newLevel: thisObject.zoomTargetLevel,
newPosition: position,
type: undefined
}
thisObject.eventHandler.raiseEvent('Zoom Changed', event)
return true
}
}
}
}