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

+185 -185
View File
@@ -1,206 +1,206 @@
function newAutoScaleButton () {
let thisObject = {
container: undefined,
fitFunction: undefined,
parentContainer: undefined,
autoMinScale: undefined,
autoMaxScale: undefined,
setStatus: setStatus,
draw: draw,
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
initialize: initialize,
finalize: finalize
}
function newAutoScaleButton() {
let thisObject = {
container: undefined,
fitFunction: undefined,
parentContainer: undefined,
autoMinScale: undefined,
autoMaxScale: undefined,
setStatus: setStatus,
draw: draw,
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
initialize: initialize,
finalize: finalize
}
/* Cointainer stuff */
thisObject.container = newContainer()
thisObject.container.name = 'Auto Scale Button'
thisObject.container.initialize()
thisObject.container.isClickeable = true
thisObject.container.isDraggeable = false
thisObject.container.frame.containerName = 'Auto Scale Button'
/* Cointainer stuff */
thisObject.container = newContainer()
thisObject.container.name = 'Auto Scale Button'
thisObject.container.initialize()
thisObject.container.isClickeable = true
thisObject.container.isDraggeable = false
thisObject.container.frame.containerName = 'Auto Scale Button'
const ICON_SIZE = 36
let onMouseWheelEventSubscriptionId
let coordinateSystem
let axis
let currentStatus
return thisObject
const ICON_SIZE = 36
let onMouseWheelEventSubscriptionId
let coordinateSystem
let axis
let currentStatus
return thisObject
function finalize () {
thisObject.container.eventHandler.stopListening(onMouseWheelEventSubscriptionId)
thisObject.container.finalize()
thisObject.container = undefined
thisObject.fitFunction = undefined
thisObject.parentContainer = undefined
thisObject.panels = undefined
function finalize() {
thisObject.container.eventHandler.stopListening(onMouseWheelEventSubscriptionId)
thisObject.container.finalize()
thisObject.container = undefined
thisObject.fitFunction = undefined
thisObject.parentContainer = undefined
thisObject.panels = undefined
coordinateSystem = undefined
axis = undefined
}
coordinateSystem = undefined
axis = undefined
}
function initialize (pAxis, pCoordinateSystem) {
axis = pAxis
coordinateSystem = pCoordinateSystem
thisObject.autoMinScale = coordinateSystem.autoMinYScale
thisObject.autoMaxScale = coordinateSystem.autoMaxYScale
function initialize(pAxis, pCoordinateSystem) {
axis = pAxis
coordinateSystem = pCoordinateSystem
thisObject.autoMinScale = coordinateSystem.autoMinYScale
thisObject.autoMaxScale = coordinateSystem.autoMaxYScale
switch (axis) {
case 'X': {
thisObject.container.frame.width = ICON_SIZE
thisObject.container.frame.height = ICON_SIZE
switch (axis) {
case 'X': {
thisObject.container.frame.width = ICON_SIZE
thisObject.container.frame.height = ICON_SIZE
let position = {
x: thisObject.container.parentContainer.frame.width * 7 / 8,
y: thisObject.container.parentContainer.frame.height / 2
let position = {
x: thisObject.container.parentContainer.frame.width * 7 / 8,
y: thisObject.container.parentContainer.frame.height / 2
}
thisObject.container.frame.position = position
break
}
case 'Y': {
thisObject.container.frame.width = ICON_SIZE
thisObject.container.frame.height = ICON_SIZE
let position = {
x: thisObject.container.parentContainer.frame.width * 7 / 8,
y: thisObject.container.parentContainer.frame.height / 2
}
thisObject.container.frame.position = position
break
}
}
thisObject.container.frame.position = position
break
}
case 'Y': {
thisObject.container.frame.width = ICON_SIZE
thisObject.container.frame.height = ICON_SIZE
let position = {
x: thisObject.container.parentContainer.frame.width * 7 / 8,
y: thisObject.container.parentContainer.frame.height / 2
}
thisObject.container.frame.position = position
break
}
}
onMouseWheelEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel)
}
function setStatus (autoMinScale, autoMaxScale) {
thisObject.autoMinScale = autoMinScale
thisObject.autoMaxScale = autoMaxScale
if (thisObject.autoMinScale === false && thisObject.autoMaxScale === false) {
currentStatus = 1
}
if (thisObject.autoMinScale === true && thisObject.autoMaxScale === false) {
currentStatus = 2
}
if (thisObject.autoMinScale === false && thisObject.autoMaxScale === true) {
currentStatus = 4
}
if (thisObject.autoMinScale === true && thisObject.autoMaxScale === true) {
currentStatus = 6
}
}
function onMouseWheel (event) {
let factor
let delta = event.wheelDelta
if (delta < 0) {
delta = -1
} else {
delta = 1
}
currentStatus = currentStatus + delta
if (currentStatus === 7) { currentStatus = 1 }
if (currentStatus === 0) { currentStatus = 6 }
switch (currentStatus) {
case 1: {
thisObject.autoMinScale = false
thisObject.autoMaxScale = false
update()
return
}
case 2: {
thisObject.autoMinScale = true
thisObject.autoMaxScale = false
update()
return
}
case 3: {
thisObject.autoMinScale = false
thisObject.autoMaxScale = false
update()
return
}
case 4: {
thisObject.autoMinScale = false
thisObject.autoMaxScale = true
update()
return
}
case 5: {
thisObject.autoMinScale = false
thisObject.autoMaxScale = false
update()
return
}
case 6: {
thisObject.autoMinScale = true
thisObject.autoMaxScale = true
update()
return
}
onMouseWheelEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel)
}
function update () {
switch (axis) {
case 'X': {
coordinateSystem.autoMinXScale = thisObject.autoMinScale
coordinateSystem.autoMaxXScale = thisObject.autoMaxScale
break
}
case 'Y': {
coordinateSystem.autoMinYScale = thisObject.autoMinScale
coordinateSystem.autoMaxYScale = thisObject.autoMaxScale
break
}
}
function setStatus(autoMinScale, autoMaxScale) {
thisObject.autoMinScale = autoMinScale
thisObject.autoMaxScale = autoMaxScale
coordinateSystem.recalculateScale()
}
}
function getContainer (point, purpose) {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
return thisObject.container
}
}
function draw () {
let icon
switch (axis) {
case 'X': {
if (thisObject.autoMinScale === false && thisObject.autoMaxScale === false) {
icon = canvas.designSpace.iconCollection.get('toggle-auto-time-scale-manual')
currentStatus = 1
}
if (thisObject.autoMinScale === true && thisObject.autoMaxScale === false) {
icon = canvas.designSpace.iconCollection.get('toggle-auto-time-scale-auto-min')
currentStatus = 2
}
if (thisObject.autoMinScale === false && thisObject.autoMaxScale === true) {
icon = canvas.designSpace.iconCollection.get('toggle-auto-time-scale-auto-max')
currentStatus = 4
}
if (thisObject.autoMinScale === true && thisObject.autoMaxScale === true) {
icon = canvas.designSpace.iconCollection.get('toggle-auto-time-scale-auto-min-max')
currentStatus = 6
}
}
function onMouseWheel(event) {
let factor
let delta = event.wheelDelta
if (delta < 0) {
delta = -1
} else {
delta = 1
}
currentStatus = currentStatus + delta
if (currentStatus === 7) { currentStatus = 1 }
if (currentStatus === 0) { currentStatus = 6 }
switch (currentStatus) {
case 1: {
thisObject.autoMinScale = false
thisObject.autoMaxScale = false
update()
return
}
case 2: {
thisObject.autoMinScale = true
thisObject.autoMaxScale = false
update()
return
}
case 3: {
thisObject.autoMinScale = false
thisObject.autoMaxScale = false
update()
return
}
case 4: {
thisObject.autoMinScale = false
thisObject.autoMaxScale = true
update()
return
}
case 5: {
thisObject.autoMinScale = false
thisObject.autoMaxScale = false
update()
return
}
case 6: {
thisObject.autoMinScale = true
thisObject.autoMaxScale = true
update()
return
}
}
function update() {
switch (axis) {
case 'X': {
coordinateSystem.autoMinXScale = thisObject.autoMinScale
coordinateSystem.autoMaxXScale = thisObject.autoMaxScale
break
}
case 'Y': {
coordinateSystem.autoMinYScale = thisObject.autoMinScale
coordinateSystem.autoMaxYScale = thisObject.autoMaxScale
break
}
}
coordinateSystem.recalculateScale()
}
}
function getContainer(point, purpose) {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
return thisObject.container
}
}
function draw() {
let icon
switch (axis) {
case 'X': {
if (thisObject.autoMinScale === false && thisObject.autoMaxScale === false) {
icon = canvas.designSpace.iconCollection.get('toggle-auto-time-scale-manual')
}
if (thisObject.autoMinScale === true && thisObject.autoMaxScale === false) {
icon = canvas.designSpace.iconCollection.get('toggle-auto-time-scale-auto-min')
}
if (thisObject.autoMinScale === false && thisObject.autoMaxScale === true) {
icon = canvas.designSpace.iconCollection.get('toggle-auto-time-scale-auto-max')
}
if (thisObject.autoMinScale === true && thisObject.autoMaxScale === true) {
icon = canvas.designSpace.iconCollection.get('toggle-auto-time-scale-auto-min-max')
}
drawIcon(icon, 0, 0, 0, 0, ICON_SIZE, thisObject.container)
break
}
case 'Y': {
if (thisObject.autoMinScale === false && thisObject.autoMaxScale === false) {
icon = canvas.designSpace.iconCollection.get('toggle-auto-scale-manual')
}
if (thisObject.autoMinScale === true && thisObject.autoMaxScale === false) {
icon = canvas.designSpace.iconCollection.get('toggle-auto-scale-auto-min')
}
if (thisObject.autoMinScale === false && thisObject.autoMaxScale === true) {
icon = canvas.designSpace.iconCollection.get('toggle-auto-scale-auto-max')
}
if (thisObject.autoMinScale === true && thisObject.autoMaxScale === true) {
icon = canvas.designSpace.iconCollection.get('toggle-auto-scale-auto-min-max')
}
drawIcon(icon, 0, 0, 0, 0, ICON_SIZE, thisObject.container)
break
}
}
drawIcon(icon, 0, 0, 0, 0, ICON_SIZE, thisObject.container)
break
}
case 'Y': {
if (thisObject.autoMinScale === false && thisObject.autoMaxScale === false) {
icon = canvas.designSpace.iconCollection.get('toggle-auto-scale-manual')
}
if (thisObject.autoMinScale === true && thisObject.autoMaxScale === false) {
icon = canvas.designSpace.iconCollection.get('toggle-auto-scale-auto-min')
}
if (thisObject.autoMinScale === false && thisObject.autoMaxScale === true) {
icon = canvas.designSpace.iconCollection.get('toggle-auto-scale-auto-max')
}
if (thisObject.autoMinScale === true && thisObject.autoMaxScale === true) {
icon = canvas.designSpace.iconCollection.get('toggle-auto-scale-auto-min-max')
}
drawIcon(icon, 0, 0, 0, 0, ICON_SIZE, thisObject.container)
break
}
}
}
}
+33 -33
View File
@@ -1,45 +1,45 @@
function drawScaleDisplay (label1, label2, label3, xExtraOffSet1, xExtraOffSet2, xExtraOffSet3, icon1, icon2, container, backgroundColor) {
const RED_LINE_HIGHT = 4
const OPACITY = 1
function drawScaleDisplay(label1, label2, label3, xExtraOffSet1, xExtraOffSet2, xExtraOffSet3, icon1, icon2, container, backgroundColor) {
const RED_LINE_HIGHT = 4
const OPACITY = 1
let params = {
cornerRadius: 5,
lineWidth: 1,
container: container,
borderColor: UI_COLOR.RUSTED_RED,
castShadow: false,
backgroundColor: backgroundColor,
opacity: OPACITY
}
let params = {
cornerRadius: 5,
lineWidth: 1,
container: container,
borderColor: UI_COLOR.RUSTED_RED,
castShadow: false,
backgroundColor: backgroundColor,
opacity: OPACITY
}
roundedCornersBackground(params)
roundedCornersBackground(params)
/* Place the Text */
/* Place the Text */
label1 = label1.substring(0, 18)
label2 = label2.substring(0, 20)
label3 = label3.substring(0, 20)
label1 = label1.substring(0, 18)
label2 = label2.substring(0, 20)
label3 = label3.substring(0, 20)
drawLabel(label1, 1 / 2, 92 / 100, 0, 0, 9, container)
drawLabel(label2, 1 / 2, 42 / 100, 0, 0, 17, container)
drawLabel(label3, 1 / 2, 67 / 100, 0, 0, 9, container)
drawLabel(label1, 1 / 2, 92 / 100, 0, 0, 9, container)
drawLabel(label2, 1 / 2, 42 / 100, 0, 0, 17, container)
drawLabel(label3, 1 / 2, 67 / 100, 0, 0, 9, container)
drawIcon(icon1, 1 / 8, 1 / 2, 0, 0, 28, container)
drawIcon(icon2, 7 / 8, 1 / 2, 0, 0, 28, container)
drawIcon(icon1, 1 / 8, 1 / 2, 0, 0, 28, container)
drawIcon(icon2, 7 / 8, 1 / 2, 0, 0, 28, container)
}
function drawScaleDisplayCover (container) {
let params = {
cornerRadius: 5,
lineWidth: 1,
container: container,
borderColor: UI_COLOR.WHITE,
castShadow: false,
backgroundColor: UI_COLOR.WHITE,
opacity: '0.25'
}
function drawScaleDisplayCover(container) {
let params = {
cornerRadius: 5,
lineWidth: 1,
container: container,
borderColor: UI_COLOR.WHITE,
castShadow: false,
backgroundColor: UI_COLOR.WHITE,
opacity: '0.25'
}
roundedCornersBackground(params)
roundedCornersBackground(params)
}
+518 -518
View File
File diff suppressed because it is too large. Load diff
+354 -354
View File
@@ -1,389 +1,389 @@
function newTimeFrameScale () {
const MODULE_NAME = 'Time Frame Scale'
function newTimeFrameScale() {
const MODULE_NAME = 'Time Frame Scale'
let thisObject = {
timeFrame: undefined,
container: undefined,
fitFunction: undefined,
payload: undefined,
isVisible: true,
layersOn: undefined,
adjustTimeFrame: adjustTimeFrame,
onMouseOverSomeTimeMachineContainer: onMouseOverSomeTimeMachineContainer,
draw: draw,
drawForeground: drawForeground,
physics: physics,
getContainer: getContainer,
initialize: initialize,
finalize: finalize
}
const FILES_PERIOD_DEFAULT_VALUE = 0
const TIME_PERIOD_DEFAULT_VALUE = 0
const MIN_HEIGHT = 50
let displayingRealTimeFrame = true
let greyOutCoverLayer = false
let isMouseOver
let filePeriodIndex = FILES_PERIOD_DEFAULT_VALUE
let timeFrameIndex = TIME_PERIOD_DEFAULT_VALUE
let timeFramesMasterArray = [marketFilesPeriods, dailyFilePeriods]
let timeFrameLabel = '24-hs'
let onMouseWheelEventSubscriptionId
let onViewportZoomChangedEventSubscriptionId
let onMouseOverEventSubscriptionId
let onMouseNotOverEventSubscriptionId
let limitingContainer
setupContainer()
let wheelDeltaDirection
let wheelDeltaCounter = 0
return thisObject
function setupContainer () {
thisObject.container = newContainer()
thisObject.container.initialize(MODULE_NAME)
thisObject.container.isDraggeable = false
thisObject.container.isClickeable = false
thisObject.container.isWheelable = true
thisObject.container.detectMouseOver = true
thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL
thisObject.container.frame.height = 40
}
function finalize () {
thisObject.container.eventHandler.stopListening(onMouseWheelEventSubscriptionId)
canvas.chartingSpace.viewport.eventHandler.stopListening(onViewportZoomChangedEventSubscriptionId)
thisObject.container.eventHandler.stopListening(onMouseOverEventSubscriptionId)
thisObject.container.eventHandler.stopListening(onMouseNotOverEventSubscriptionId)
thisObject.container.finalize()
thisObject.container = undefined
thisObject.fitFunction = undefined
thisObject.payload = undefined
limitingContainer = undefined
}
function initialize (pLimitingContainer) {
limitingContainer = pLimitingContainer
readObjectState()
newTimeFrame()
onMouseWheelEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel)
onViewportZoomChangedEventSubscriptionId = canvas.chartingSpace.viewport.eventHandler.listenToEvent('Zoom Changed', onViewportZoomChanged)
onMouseOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver)
onMouseNotOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseNotOver', onMouseNotOver)
}
function onMouseOverSomeTimeMachineContainer (event) {
if (event.containerId === undefined) {
/* This happens when the mouse over was not at the instance of a certain scale, but anywhere else. */
greyOutCoverLayer = false
} else {
if (event.containerId === thisObject.container.id) {
greyOutCoverLayer = false
} else {
greyOutCoverLayer = true
turnOnCounter = 0
}
}
}
function onMouseOver (event) {
isMouseOver = true
event.containerId = thisObject.container.id
thisObject.container.eventHandler.raiseEvent('onMouseOverScale', event)
}
function onMouseNotOver () {
isMouseOver = false
}
function physics () {
readObjectState()
positioningPhysics()
}
function adjustTimeFrame (elementsPlotted) {
const ELEMENTS_PLOTTED_THREASHOLD = 500
if (
canvas.chartingSpace.viewport.zoomTargetLevel >= ZOOM_OUT_THRESHOLD_FOR_CHANGING_TIME_FRAME &&
displayingRealTimeFrame === false
) {
let event = {}
event.timeFrame = thisObject.timeFrame
thisObject.container.eventHandler.raiseEvent('Time Frame Value Changed', event)
displayingRealTimeFrame = true
}
if (
elementsPlotted > ELEMENTS_PLOTTED_THREASHOLD &&
canvas.chartingSpace.viewport.zoomTargetLevel < ZOOM_OUT_THRESHOLD_FOR_CHANGING_TIME_FRAME &&
displayingRealTimeFrame === true
) {
let event = {}
event.timeFrame = ONE_DAY_IN_MILISECONDS
thisObject.container.eventHandler.raiseEvent('Time Frame Value Changed', event)
displayingRealTimeFrame = false
}
}
function positioningPhysics () {
/* Container Limits */
let upCorner = {
x: 0,
y: 0
let thisObject = {
timeFrame: undefined,
container: undefined,
fitFunction: undefined,
payload: undefined,
isVisible: true,
layersOn: undefined,
adjustTimeFrame: adjustTimeFrame,
onMouseOverSomeTimeMachineContainer: onMouseOverSomeTimeMachineContainer,
draw: draw,
drawForeground: drawForeground,
physics: physics,
getContainer: getContainer,
initialize: initialize,
finalize: finalize
}
let bottonCorner = {
x: limitingContainer.frame.width,
y: limitingContainer.frame.height
const FILES_PERIOD_DEFAULT_VALUE = 0
const TIME_PERIOD_DEFAULT_VALUE = 0
const MIN_HEIGHT = 50
let displayingRealTimeFrame = true
let greyOutCoverLayer = false
let isMouseOver
let filePeriodIndex = FILES_PERIOD_DEFAULT_VALUE
let timeFrameIndex = TIME_PERIOD_DEFAULT_VALUE
let timeFramesMasterArray = [marketFilesPeriods, dailyFilePeriods]
let timeFrameLabel = '24-hs'
let onMouseWheelEventSubscriptionId
let onViewportZoomChangedEventSubscriptionId
let onMouseOverEventSubscriptionId
let onMouseNotOverEventSubscriptionId
let limitingContainer
setupContainer()
let wheelDeltaDirection
let wheelDeltaCounter = 0
return thisObject
function setupContainer() {
thisObject.container = newContainer()
thisObject.container.initialize(MODULE_NAME)
thisObject.container.isDraggeable = false
thisObject.container.isClickeable = false
thisObject.container.isWheelable = true
thisObject.container.detectMouseOver = true
thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL
thisObject.container.frame.height = 40
}
upCorner = transformThisPoint(upCorner, limitingContainer)
bottonCorner = transformThisPoint(bottonCorner, limitingContainer)
function finalize() {
thisObject.container.eventHandler.stopListening(onMouseWheelEventSubscriptionId)
canvas.chartingSpace.viewport.eventHandler.stopListening(onViewportZoomChangedEventSubscriptionId)
thisObject.container.eventHandler.stopListening(onMouseOverEventSubscriptionId)
thisObject.container.eventHandler.stopListening(onMouseNotOverEventSubscriptionId)
upCorner = limitingContainer.fitFunction(upCorner, true)
bottonCorner = limitingContainer.fitFunction(bottonCorner, true)
thisObject.container.finalize()
thisObject.container = undefined
thisObject.fitFunction = undefined
thisObject.payload = undefined
/* We will check if we need to change the bottom because of being one of many scales of the same type */
let displaceFactor = 0
if (thisObject.payload.parentNode === undefined) { return } // This happens when in the process of deleting the scale, timeline chart or time machine.
if (thisObject.payload.parentNode.type === 'Timeline Chart') {
if (thisObject.payload.parentNode.payload.parentNode !== undefined) {
if (thisObject.payload.parentNode.payload.parentNode.timeFrameScale !== undefined) {
if (thisObject.payload.parentNode.payload.parentNode.timeFrameScale.payload.isVisible === true) {
displaceFactor++
}
}
for (let i = 0; i < thisObject.payload.parentNode.payload.parentNode.timelineCharts.length; i++) {
let timelineChart = thisObject.payload.parentNode.payload.parentNode.timelineCharts[i]
if (timelineChart.timeFrameScale !== undefined) {
if (thisObject.payload.node.id !== timelineChart.timeFrameScale.id) {
if (timelineChart.timeFrameScale.payload.isVisible === true) {
displaceFactor++
}
limitingContainer = undefined
}
function initialize(pLimitingContainer) {
limitingContainer = pLimitingContainer
readObjectState()
newTimeFrame()
onMouseWheelEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel)
onViewportZoomChangedEventSubscriptionId = canvas.chartingSpace.viewport.eventHandler.listenToEvent('Zoom Changed', onViewportZoomChanged)
onMouseOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver)
onMouseNotOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseNotOver', onMouseNotOver)
}
function onMouseOverSomeTimeMachineContainer(event) {
if (event.containerId === undefined) {
/* This happens when the mouse over was not at the instance of a certain scale, but anywhere else. */
greyOutCoverLayer = false
} else {
if (event.containerId === thisObject.container.id) {
greyOutCoverLayer = false
} else {
break
greyOutCoverLayer = true
turnOnCounter = 0
}
}
}
}
}
bottonCorner.y = bottonCorner.y - thisObject.container.frame.height * displaceFactor
/* Positioning */
timePoint = {
x: 0,
y: limitingContainer.frame.height
}
timePoint = transformThisPoint(timePoint, limitingContainer.frame.container)
timePoint.x = canvas.mouse.position.x - thisObject.container.frame.width / 2
/* Checking against the container limits. */
if (timePoint.x < upCorner.x) { timePoint.x = upCorner.x }
if (timePoint.x + thisObject.container.frame.width > bottonCorner.x) { timePoint.x = bottonCorner.x - thisObject.container.frame.width }
if (timePoint.y < upCorner.y + thisObject.container.frame.height) { timePoint.y = upCorner.y + thisObject.container.frame.height }
if (timePoint.y > bottonCorner.y) { timePoint.y = bottonCorner.y }
thisObject.container.frame.position.x = timePoint.x
thisObject.container.frame.position.y = timePoint.y - thisObject.container.frame.height
thisObject.isVisible = true
thisObject.payload.isVisible = true
if (thisObject.container.frame.position.y + thisObject.container.frame.height > bottonCorner.y ||
thisObject.container.frame.position.y - thisObject.container.frame.height * 3 < upCorner.y ||
thisObject.container.frame.position.x < upCorner.x) {
thisObject.isVisible = false
thisObject.payload.isVisible = false
}
if (thisObject.layersOn === 0) {
thisObject.isVisible = false
thisObject.payload.isVisible = false
function onMouseOver(event) {
isMouseOver = true
event.containerId = thisObject.container.id
thisObject.container.eventHandler.raiseEvent('onMouseOverScale', event)
}
if (canvas.chartingSpace.viewport.zoomTargetLevel < ZOOM_OUT_THRESHOLD_FOR_DISPLAYING_SCALES) {
thisObject.isVisible = false
function onMouseNotOver() {
isMouseOver = false
}
}
function onViewportZoomChanged (event) {
if (event !== undefined) { // it is undefined when the level is just being animated.
if (event.shiftKey === false) { return } // with no shft key pressed, no automatic change in scale
let currentTimeFrame = thisObject.timeFrame
let timeFrame = recalculatePeriod(event.newLevel)
if (timeFrame !== currentTimeFrame) {
for (let i = 0; i < timeFramesMasterArray.length; i++) {
let timeFrameArray = timeFramesMasterArray[i]
for (let j = 0; j < timeFrameArray.length; j++) {
let record = timeFrameArray[j]
if (timeFrame === record[0]) {
filePeriodIndex = i
timeFrameIndex = j
function physics() {
readObjectState()
positioningPhysics()
}
function adjustTimeFrame(elementsPlotted) {
const ELEMENTS_PLOTTED_THREASHOLD = 500
if (
canvas.chartingSpace.viewport.zoomTargetLevel >= ZOOM_OUT_THRESHOLD_FOR_CHANGING_TIME_FRAME &&
displayingRealTimeFrame === false
) {
let event = {}
event.timeFrame = thisObject.timeFrame
thisObject.container.eventHandler.raiseEvent('Time Frame Value Changed', event)
displayingRealTimeFrame = true
}
if (
elementsPlotted > ELEMENTS_PLOTTED_THREASHOLD &&
canvas.chartingSpace.viewport.zoomTargetLevel < ZOOM_OUT_THRESHOLD_FOR_CHANGING_TIME_FRAME &&
displayingRealTimeFrame === true
) {
let event = {}
event.timeFrame = ONE_DAY_IN_MILISECONDS
thisObject.container.eventHandler.raiseEvent('Time Frame Value Changed', event)
displayingRealTimeFrame = false
}
}
function positioningPhysics() {
/* Container Limits */
let upCorner = {
x: 0,
y: 0
}
let bottonCorner = {
x: limitingContainer.frame.width,
y: limitingContainer.frame.height
}
upCorner = transformThisPoint(upCorner, limitingContainer)
bottonCorner = transformThisPoint(bottonCorner, limitingContainer)
upCorner = limitingContainer.fitFunction(upCorner, true)
bottonCorner = limitingContainer.fitFunction(bottonCorner, true)
/* We will check if we need to change the bottom because of being one of many scales of the same type */
let displaceFactor = 0
if (thisObject.payload.parentNode === undefined) { return } // This happens when in the process of deleting the scale, timeline chart or time machine.
if (thisObject.payload.parentNode.type === 'Timeline Chart') {
if (thisObject.payload.parentNode.payload.parentNode !== undefined) {
if (thisObject.payload.parentNode.payload.parentNode.timeFrameScale !== undefined) {
if (thisObject.payload.parentNode.payload.parentNode.timeFrameScale.payload.isVisible === true) {
displaceFactor++
}
}
for (let i = 0; i < thisObject.payload.parentNode.payload.parentNode.timelineCharts.length; i++) {
let timelineChart = thisObject.payload.parentNode.payload.parentNode.timelineCharts[i]
if (timelineChart.timeFrameScale !== undefined) {
if (thisObject.payload.node.id !== timelineChart.timeFrameScale.id) {
if (timelineChart.timeFrameScale.payload.isVisible === true) {
displaceFactor++
}
} else {
break
}
}
}
}
}
}
bottonCorner.y = bottonCorner.y - thisObject.container.frame.height * displaceFactor
/* Positioning */
timePoint = {
x: 0,
y: limitingContainer.frame.height
}
timePoint = transformThisPoint(timePoint, limitingContainer.frame.container)
timePoint.x = canvas.mouse.position.x - thisObject.container.frame.width / 2
/* Checking against the container limits. */
if (timePoint.x < upCorner.x) { timePoint.x = upCorner.x }
if (timePoint.x + thisObject.container.frame.width > bottonCorner.x) { timePoint.x = bottonCorner.x - thisObject.container.frame.width }
if (timePoint.y < upCorner.y + thisObject.container.frame.height) { timePoint.y = upCorner.y + thisObject.container.frame.height }
if (timePoint.y > bottonCorner.y) { timePoint.y = bottonCorner.y }
thisObject.container.frame.position.x = timePoint.x
thisObject.container.frame.position.y = timePoint.y - thisObject.container.frame.height
thisObject.isVisible = true
thisObject.payload.isVisible = true
if (thisObject.container.frame.position.y + thisObject.container.frame.height > bottonCorner.y ||
thisObject.container.frame.position.y - thisObject.container.frame.height * 3 < upCorner.y ||
thisObject.container.frame.position.x < upCorner.x) {
thisObject.isVisible = false
thisObject.payload.isVisible = false
}
if (thisObject.layersOn === 0) {
thisObject.isVisible = false
thisObject.payload.isVisible = false
}
if (canvas.chartingSpace.viewport.zoomTargetLevel < ZOOM_OUT_THRESHOLD_FOR_DISPLAYING_SCALES) {
thisObject.isVisible = false
}
}
function onViewportZoomChanged(event) {
if (event !== undefined) { // it is undefined when the level is just being animated.
if (event.shiftKey === false) { return } // with no shft key pressed, no automatic change in scale
let currentTimeFrame = thisObject.timeFrame
let timeFrame = recalculatePeriod(event.newLevel)
if (timeFrame !== currentTimeFrame) {
for (let i = 0; i < timeFramesMasterArray.length; i++) {
let timeFrameArray = timeFramesMasterArray[i]
for (let j = 0; j < timeFrameArray.length; j++) {
let record = timeFrameArray[j]
if (timeFrame === record[0]) {
filePeriodIndex = i
timeFrameIndex = j
}
}
}
newTimeFrame()
saveObjectState()
}
}
}
function onMouseWheel(event) {
if (IS_MAC) {
let sensitivity
if (event.wheelDelta < 0) {
if (event.shiftKey === true) {
sensitivity = 20
} else {
sensitivity = 5
}
if (wheelDeltaDirection === -1) {
wheelDeltaCounter++
if (wheelDeltaCounter < sensitivity) {
return
} else {
wheelDeltaCounter = 0
}
} else {
wheelDeltaCounter = 0
wheelDeltaDirection = -1
return
}
} else {
if (wheelDeltaDirection === 1) {
wheelDeltaCounter++
if (wheelDeltaCounter < sensitivity) {
return
} else {
wheelDeltaCounter = 0
}
} else {
wheelDeltaCounter = 0
wheelDeltaDirection = 1
return
}
}
}
let delta = event.wheelDelta
if (delta < 0) {
timeFrameIndex--
if (timeFrameIndex < 0) {
filePeriodIndex--
if (filePeriodIndex < 0) {
filePeriodIndex = 0
timeFrameIndex = 0
} else {
timeFrameIndex = timeFramesMasterArray[filePeriodIndex].length - 1
}
}
} else {
timeFrameIndex++
if (timeFrameIndex > timeFramesMasterArray[filePeriodIndex].length - 1) {
filePeriodIndex++
if (filePeriodIndex > timeFramesMasterArray.length - 1) {
filePeriodIndex = timeFramesMasterArray.length - 1
timeFrameIndex = timeFramesMasterArray[filePeriodIndex].length - 1
} else {
timeFrameIndex = 0
}
}
}
newTimeFrame()
saveObjectState()
}
}
}
function onMouseWheel (event) {
if (IS_MAC) {
let sensitivity
if (event.wheelDelta < 0) {
if (event.shiftKey === true) {
sensitivity = 20
} else {
sensitivity = 5
}
if (wheelDeltaDirection === -1) {
wheelDeltaCounter++
if (wheelDeltaCounter < sensitivity) {
return
} else {
wheelDeltaCounter = 0
}
} else {
wheelDeltaCounter = 0
wheelDeltaDirection = -1
return
}
} else {
if (wheelDeltaDirection === 1) {
wheelDeltaCounter++
if (wheelDeltaCounter < sensitivity) {
return
} else {
wheelDeltaCounter = 0
}
} else {
wheelDeltaCounter = 0
wheelDeltaDirection = 1
return
}
}
}
let delta = event.wheelDelta
if (delta < 0) {
timeFrameIndex--
if (timeFrameIndex < 0) {
filePeriodIndex--
if (filePeriodIndex < 0) {
filePeriodIndex = 0
timeFrameIndex = 0
} else {
timeFrameIndex = timeFramesMasterArray[filePeriodIndex].length - 1
function getContainer(point) {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
return thisObject.container
}
}
} else {
timeFrameIndex++
if (timeFrameIndex > timeFramesMasterArray[filePeriodIndex].length - 1) {
filePeriodIndex++
if (filePeriodIndex > timeFramesMasterArray.length - 1) {
filePeriodIndex = timeFramesMasterArray.length - 1
timeFrameIndex = timeFramesMasterArray[filePeriodIndex].length - 1
} else {
timeFrameIndex = 0
}
function saveObjectState() {
try {
let config = JSON.parse(thisObject.payload.node.config)
config.value = timeFrameLabel
thisObject.payload.node.config = JSON.stringify(config)
} catch (err) {
// we ignore errors here since most likely they will be parsing errors.
}
}
}
newTimeFrame()
saveObjectState()
}
function getContainer (point) {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
return thisObject.container
}
}
function saveObjectState () {
try {
let config = JSON.parse(thisObject.payload.node.config)
config.value = timeFrameLabel
thisObject.payload.node.config = JSON.stringify(config)
} catch (err) {
// we ignore errors here since most likely they will be parsing errors.
}
}
function readObjectState () {
try {
let config = JSON.parse(thisObject.payload.node.config)
if (config.value !== timeFrameLabel) {
let found = false
for (let i = 0; i < timeFramesMasterArray.length; i++) {
let timeFrameArray = timeFramesMasterArray[i]
for (let j = 0; j < timeFrameArray.length; j++) {
let record = timeFrameArray[j]
if (config.value === record[1]) {
filePeriodIndex = i
timeFrameIndex = j
found = true
function readObjectState() {
try {
let config = JSON.parse(thisObject.payload.node.config)
if (config.value !== timeFrameLabel) {
let found = false
for (let i = 0; i < timeFramesMasterArray.length; i++) {
let timeFrameArray = timeFramesMasterArray[i]
for (let j = 0; j < timeFrameArray.length; j++) {
let record = timeFrameArray[j]
if (config.value === record[1]) {
filePeriodIndex = i
timeFrameIndex = j
found = true
}
}
}
if (found === true) {
newTimeFrame()
} else {
saveObjectState()
}
}
}
} catch (err) {
// we ignore errors here since most likely they will be parsing errors.
}
if (found === true) {
newTimeFrame()
} else {
saveObjectState()
}
function newTimeFrame() {
let timeFrameArray = timeFramesMasterArray[filePeriodIndex]
thisObject.timeFrame = timeFrameArray[timeFrameIndex][0]
timeFrameLabel = timeFrameArray[timeFrameIndex][1]
// console.log('NEW TIME FRAME LABEL', timeFrameLabel)
let event = {}
event.timeFrame = thisObject.timeFrame
thisObject.container.eventHandler.raiseEvent('Time Frame Value Changed', event)
}
function draw() {
drawScaleBox()
if (greyOutCoverLayer === true) {
drawScaleDisplayCover(thisObject.container)
}
}
} catch (err) {
// we ignore errors here since most likely they will be parsing errors.
}
}
function newTimeFrame () {
let timeFrameArray = timeFramesMasterArray[filePeriodIndex]
thisObject.timeFrame = timeFrameArray[timeFrameIndex][0]
timeFrameLabel = timeFrameArray[timeFrameIndex][1]
// console.log('NEW TIME FRAME LABEL', timeFrameLabel)
let event = {}
event.timeFrame = thisObject.timeFrame
thisObject.container.eventHandler.raiseEvent('Time Frame Value Changed', event)
}
function draw () {
drawScaleBox()
if (greyOutCoverLayer === true) {
drawScaleDisplayCover(thisObject.container)
function drawForeground() {
if (isMouseOver === true) {
drawScaleBox()
}
}
}
function drawForeground () {
if (isMouseOver === true) {
drawScaleBox()
function drawScaleBox() {
if (timeFrameLabel === undefined) { return }
let label = timeFrameLabel.split('-')
let label1 = thisObject.payload.node.payload.parentNode.name
let label2 = label[0]
let label3 = label[1].toUpperCase()
let icon1 = canvas.designSpace.iconByUiObjectType.get(thisObject.payload.node.payload.parentNode.type)
let icon2 = canvas.designSpace.iconByUiObjectType.get(thisObject.payload.node.type)
let backgroundColor = UI_COLOR.BLACK
drawScaleDisplay(label1, label2, label3, 0, 0, 0, icon1, icon2, thisObject.container, backgroundColor)
}
}
function drawScaleBox () {
if (timeFrameLabel === undefined) { return }
let label = timeFrameLabel.split('-')
let label1 = thisObject.payload.node.payload.parentNode.name
let label2 = label[0]
let label3 = label[1].toUpperCase()
let icon1 = canvas.designSpace.iconByUiObjectType.get(thisObject.payload.node.payload.parentNode.type)
let icon2 = canvas.designSpace.iconByUiObjectType.get(thisObject.payload.node.type)
let backgroundColor = UI_COLOR.BLACK
drawScaleDisplay(label1, label2, label3, 0, 0, 0, icon1, icon2, thisObject.container, backgroundColor)
}
}
+325 -325
View File
@@ -1,359 +1,359 @@
function newTimeScale () {
const MODULE_NAME = 'Time Scale'
function newTimeScale() {
const MODULE_NAME = 'Time Scale'
let thisObject = {
container: undefined,
date: undefined,
fitFunction: undefined,
payload: undefined,
isVisible: true,
fromDate: undefined,
toDate: undefined,
onMouseOverSomeTimeMachineContainer: onMouseOverSomeTimeMachineContainer,
physics: physics,
draw: draw,
drawBackground: drawBackground,
drawForeground: drawForeground,
getContainer: getContainer,
initialize: initialize,
finalize: finalize
}
thisObject.container = newContainer()
thisObject.container.initialize(MODULE_NAME)
thisObject.container.isDraggeable = false
thisObject.container.isClickeable = false
thisObject.container.isWheelable = true
thisObject.container.detectMouseOver = true
thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL
thisObject.container.frame.height = 40
let visible = true
let autoScaleButton
let isMouseOver
let onMouseWheelEventSubscriptionId
let onMouseOverEventSubscriptionId
let onMouseNotOverEventSubscriptionId
let onScaleChangedEventSubscriptionId
let coordinateSystem
let limitingContainer
let wheelDeltaDirection
let wheelDeltaCounter = 0
return thisObject
function finalize () {
thisObject.container.eventHandler.stopListening(onMouseWheelEventSubscriptionId)
thisObject.container.eventHandler.stopListening(onMouseOverEventSubscriptionId)
thisObject.container.eventHandler.stopListening(onMouseNotOverEventSubscriptionId)
coordinateSystem.eventHandler.stopListening(onScaleChangedEventSubscriptionId)
thisObject.container.finalize()
thisObject.container = undefined
thisObject.fitFunction = undefined
thisObject.payload = undefined
coordinateSystem = undefined
limitingContainer = undefined
autoScaleButton.finalize()
autoScaleButton = undefined
}
function initialize (pCoordinateSystem, pLimitingContainer) {
coordinateSystem = pCoordinateSystem
limitingContainer = pLimitingContainer
onMouseWheelEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel)
onMouseOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver)
onMouseNotOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseNotOver', onMouseNotOver)
onScaleChangedEventSubscriptionId = coordinateSystem.eventHandler.listenToEvent('Scale Changed', onScaleChanged)
autoScaleButton = newAutoScaleButton()
autoScaleButton.container.connectToParent(thisObject.container)
autoScaleButton.initialize('X', coordinateSystem)
readObjectState()
}
function onMouseOverSomeTimeMachineContainer (event) {
if (event.containerId === undefined) {
/* This happens when the mouse over was not at the instance of a certain scale, but anywhere else. */
visible = true
} else {
if (event.containerId === thisObject.container.id) {
visible = true
} else {
visible = false
turnOnCounter = 0
}
let thisObject = {
container: undefined,
date: undefined,
fitFunction: undefined,
payload: undefined,
isVisible: true,
fromDate: undefined,
toDate: undefined,
onMouseOverSomeTimeMachineContainer: onMouseOverSomeTimeMachineContainer,
physics: physics,
draw: draw,
drawBackground: drawBackground,
drawForeground: drawForeground,
getContainer: getContainer,
initialize: initialize,
finalize: finalize
}
}
function onMouseOver (event) {
isMouseOver = true
event.containerId = thisObject.container.id
thisObject.container.eventHandler.raiseEvent('onMouseOverScale', event)
}
thisObject.container = newContainer()
thisObject.container.initialize(MODULE_NAME)
function onMouseNotOver () {
isMouseOver = false
}
thisObject.container.isDraggeable = false
thisObject.container.isClickeable = false
thisObject.container.isWheelable = true
thisObject.container.detectMouseOver = true
thisObject.container.frame.width = UI_PANEL.WIDTH.NORMAL
thisObject.container.frame.height = 40
let visible = true
let autoScaleButton
let isMouseOver
let onMouseWheelEventSubscriptionId
let onMouseOverEventSubscriptionId
let onMouseNotOverEventSubscriptionId
let onScaleChangedEventSubscriptionId
let coordinateSystem
let limitingContainer
let wheelDeltaDirection
let wheelDeltaCounter = 0
return thisObject
function finalize() {
thisObject.container.eventHandler.stopListening(onMouseWheelEventSubscriptionId)
thisObject.container.eventHandler.stopListening(onMouseOverEventSubscriptionId)
thisObject.container.eventHandler.stopListening(onMouseNotOverEventSubscriptionId)
coordinateSystem.eventHandler.stopListening(onScaleChangedEventSubscriptionId)
thisObject.container.finalize()
thisObject.container = undefined
thisObject.fitFunction = undefined
thisObject.payload = undefined
coordinateSystem = undefined
limitingContainer = undefined
autoScaleButton.finalize()
autoScaleButton = undefined
}
function initialize(pCoordinateSystem, pLimitingContainer) {
coordinateSystem = pCoordinateSystem
limitingContainer = pLimitingContainer
onMouseWheelEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel)
onMouseOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver)
onMouseNotOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseNotOver', onMouseNotOver)
onScaleChangedEventSubscriptionId = coordinateSystem.eventHandler.listenToEvent('Scale Changed', onScaleChanged)
autoScaleButton = newAutoScaleButton()
autoScaleButton.container.connectToParent(thisObject.container)
autoScaleButton.initialize('X', coordinateSystem)
readObjectState()
}
function onMouseOverSomeTimeMachineContainer(event) {
if (event.containerId === undefined) {
/* This happens when the mouse over was not at the instance of a certain scale, but anywhere else. */
visible = true
} else {
if (event.containerId === thisObject.container.id) {
visible = true
} else {
visible = false
turnOnCounter = 0
}
}
}
function onMouseOver(event) {
isMouseOver = true
event.containerId = thisObject.container.id
thisObject.container.eventHandler.raiseEvent('onMouseOverScale', event)
}
function onMouseNotOver() {
isMouseOver = false
}
function onMouseWheel(event) {
if (IS_MAC) {
let sensitivity
if (event.wheelDelta < 0) {
if (event.shiftKey === true) {
sensitivity = 20
} else {
sensitivity = 5
}
if (wheelDeltaDirection === -1) {
wheelDeltaCounter++
if (wheelDeltaCounter < sensitivity) {
return
} else {
wheelDeltaCounter = 0
}
} else {
wheelDeltaCounter = 0
wheelDeltaDirection = -1
return
}
} else {
if (wheelDeltaDirection === 1) {
wheelDeltaCounter++
if (wheelDeltaCounter < sensitivity) {
return
} else {
wheelDeltaCounter = 0
}
} else {
wheelDeltaCounter = 0
wheelDeltaDirection = 1
return
}
}
}
function onMouseWheel (event) {
if (IS_MAC) {
let sensitivity
if (event.wheelDelta < 0) {
if (event.shiftKey === true) {
sensitivity = 20
} else {
sensitivity = 5
}
if (wheelDeltaDirection === -1) {
wheelDeltaCounter++
if (wheelDeltaCounter < sensitivity) {
autoScaleButton.container.eventHandler.raiseEvent('onMouseWheel', event)
return
} else {
wheelDeltaCounter = 0
}
}
let factor
let morePower = 10
if (event.buttons === 4) { morePower = 1 } // Mouse wheel pressed.
let delta = event.wheelDelta
if (delta < 0) {
factor = -0.01 * morePower
} else {
wheelDeltaCounter = 0
wheelDeltaDirection = -1
return
factor = 0.01 * morePower
}
} else {
if (wheelDeltaDirection === 1) {
wheelDeltaCounter++
if (wheelDeltaCounter < sensitivity) {
return
} else {
wheelDeltaCounter = 0
}
} else {
wheelDeltaCounter = 0
wheelDeltaDirection = 1
return
coordinateSystem.zoomX(factor, event, limitingContainer, MODULE_NAME)
}
function onScaleChanged() {
saveObjectState()
}
function getContainer(point, purpose) {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
return thisObject.container
}
}
}
if (event.shiftKey === true) {
autoScaleButton.container.eventHandler.raiseEvent('onMouseWheel', event)
return
}
let factor
let morePower = 10
if (event.buttons === 4) { morePower = 1 } // Mouse wheel pressed.
let delta = event.wheelDelta
if (delta < 0) {
factor = -0.01 * morePower
} else {
factor = 0.01 * morePower
}
coordinateSystem.zoomX(factor, event, limitingContainer, MODULE_NAME)
}
function onScaleChanged () {
saveObjectState()
}
function getContainer (point, purpose) {
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
return thisObject.container
}
}
function saveObjectState () {
try {
let config = JSON.parse(thisObject.payload.node.config)
config.fromDate = (new Date(coordinateSystem.min.x)).toISOString()
config.toDate = (new Date(coordinateSystem.max.x)).toISOString()
config.autoMinScale = coordinateSystem.autoMinXScale
config.autoMaxScale = coordinateSystem.autoMaxXScale
thisObject.payload.node.config = JSON.stringify(config, null, 4)
} catch (err) {
// we ignore errors here since most likely they will be parsing errors.
}
}
function readObjectState () {
try {
let config = JSON.parse(thisObject.payload.node.config)
if (
(isNaN(Date.parse(config.fromDate)) || config.fromDate === null || config.fromDate === undefined) ||
(isNaN(Date.parse(config.toDate)) || config.toDate === null || config.toDate === undefined)
) {
// not using this value
} else {
if (thisObject.fromDate !== Date.parse(config.fromDate) || thisObject.toDate !== Date.parse(config.toDate)) {
thisObject.fromDate = Date.parse(config.fromDate)
thisObject.toDate = Date.parse(config.toDate)
coordinateSystem.min.x = thisObject.fromDate
coordinateSystem.max.x = thisObject.toDate
if (config.autoMinScale !== undefined && (config.autoMinScale === true || config.autoMinScale === false) && config.autoMaxScale !== undefined && (config.autoMaxScale === true || config.autoMaxScale === false)) {
coordinateSystem.autoMinXScale = config.autoMinScale
coordinateSystem.autoMaxXScale = config.autoMaxScale
autoScaleButton.setStatus(config.autoMinScale, config.autoMaxScale)
}
coordinateSystem.recalculateScale()
function saveObjectState() {
try {
let config = JSON.parse(thisObject.payload.node.config)
config.fromDate = (new Date(coordinateSystem.min.x)).toISOString()
config.toDate = (new Date(coordinateSystem.max.x)).toISOString()
config.autoMinScale = coordinateSystem.autoMinXScale
config.autoMaxScale = coordinateSystem.autoMaxXScale
thisObject.payload.node.config = JSON.stringify(config, null, 4)
} catch (err) {
// we ignore errors here since most likely they will be parsing errors.
}
}
saveObjectState() // this overrides any invalid value at the config.
} catch (err) {
// we ignore errors here since most likely they will be parsing errors.
}
}
function physics () {
readObjectState()
positioningPhysics()
}
function positioningPhysics () {
/* Container Limits */
let upCorner = {
x: 0,
y: 0
}
let bottonCorner = {
x: limitingContainer.frame.width,
y: limitingContainer.frame.height
function readObjectState() {
try {
let config = JSON.parse(thisObject.payload.node.config)
if (
(isNaN(Date.parse(config.fromDate)) || config.fromDate === null || config.fromDate === undefined) ||
(isNaN(Date.parse(config.toDate)) || config.toDate === null || config.toDate === undefined)
) {
// not using this value
} else {
if (thisObject.fromDate !== Date.parse(config.fromDate) || thisObject.toDate !== Date.parse(config.toDate)) {
thisObject.fromDate = Date.parse(config.fromDate)
thisObject.toDate = Date.parse(config.toDate)
coordinateSystem.min.x = thisObject.fromDate
coordinateSystem.max.x = thisObject.toDate
if (config.autoMinScale !== undefined && (config.autoMinScale === true || config.autoMinScale === false) && config.autoMaxScale !== undefined && (config.autoMaxScale === true || config.autoMaxScale === false)) {
coordinateSystem.autoMinXScale = config.autoMinScale
coordinateSystem.autoMaxXScale = config.autoMaxScale
autoScaleButton.setStatus(config.autoMinScale, config.autoMaxScale)
}
coordinateSystem.recalculateScale()
}
}
saveObjectState() // this overrides any invalid value at the config.
} catch (err) {
// we ignore errors here since most likely they will be parsing errors.
}
}
upCorner = transformThisPoint(upCorner, limitingContainer)
bottonCorner = transformThisPoint(bottonCorner, limitingContainer)
upCorner = limitingContainer.fitFunction(upCorner, true)
bottonCorner = limitingContainer.fitFunction(bottonCorner, true)
/* Mouse Position Date Calculation */
let timePoint = {
x: canvas.mouse.position.x,
y: 0
function physics() {
readObjectState()
positioningPhysics()
}
let mouseDate = getDateFromPointAtBrowserCanvas(timePoint, limitingContainer, coordinateSystem)
function positioningPhysics() {
/* Container Limits */
thisObject.date = new Date(mouseDate)
let upCorner = {
x: 0,
y: 0
}
/* timeScale Positioning */
timePoint = {
x: 0,
y: 0
let bottonCorner = {
x: limitingContainer.frame.width,
y: limitingContainer.frame.height
}
upCorner = transformThisPoint(upCorner, limitingContainer)
bottonCorner = transformThisPoint(bottonCorner, limitingContainer)
upCorner = limitingContainer.fitFunction(upCorner, true)
bottonCorner = limitingContainer.fitFunction(bottonCorner, true)
/* Mouse Position Date Calculation */
let timePoint = {
x: canvas.mouse.position.x,
y: 0
}
let mouseDate = getDateFromPointAtBrowserCanvas(timePoint, limitingContainer, coordinateSystem)
thisObject.date = new Date(mouseDate)
/* timeScale Positioning */
timePoint = {
x: 0,
y: 0
}
timePoint = transformThisPoint(timePoint, limitingContainer.frame.container)
timePoint.x = canvas.mouse.position.x - thisObject.container.frame.width / 2
/* Checking against the container limits. */
if (timePoint.x < upCorner.x) { timePoint.x = upCorner.x }
if (timePoint.x + thisObject.container.frame.width > bottonCorner.x) { timePoint.x = bottonCorner.x - thisObject.container.frame.width }
if (timePoint.y < upCorner.y) { timePoint.y = upCorner.y }
if (timePoint.y + thisObject.container.frame.height > bottonCorner.y) { timePoint.y = bottonCorner.y - thisObject.container.frame.height }
thisObject.container.frame.position.x = timePoint.x
thisObject.container.frame.position.y = timePoint.y
thisObject.isVisible = true
if (thisObject.container.frame.position.y + thisObject.container.frame.height * 4 > bottonCorner.y ||
thisObject.container.frame.position.y < upCorner.y ||
thisObject.container.frame.position.x < upCorner.x) {
thisObject.isVisible = false
}
if (canvas.chartingSpace.viewport.zoomTargetLevel < ZOOM_OUT_THRESHOLD_FOR_DISPLAYING_SCALES) {
thisObject.isVisible = false
}
}
timePoint = transformThisPoint(timePoint, limitingContainer.frame.container)
timePoint.x = canvas.mouse.position.x - thisObject.container.frame.width / 2
/* Checking against the container limits. */
if (timePoint.x < upCorner.x) { timePoint.x = upCorner.x }
if (timePoint.x + thisObject.container.frame.width > bottonCorner.x) { timePoint.x = bottonCorner.x - thisObject.container.frame.width }
if (timePoint.y < upCorner.y) { timePoint.y = upCorner.y }
if (timePoint.y + thisObject.container.frame.height > bottonCorner.y) { timePoint.y = bottonCorner.y - thisObject.container.frame.height }
thisObject.container.frame.position.x = timePoint.x
thisObject.container.frame.position.y = timePoint.y
thisObject.isVisible = true
if (thisObject.container.frame.position.y + thisObject.container.frame.height * 4 > bottonCorner.y ||
thisObject.container.frame.position.y < upCorner.y ||
thisObject.container.frame.position.x < upCorner.x) {
thisObject.isVisible = false
function drawBackground() {
drawScale()
}
if (canvas.chartingSpace.viewport.zoomTargetLevel < ZOOM_OUT_THRESHOLD_FOR_DISPLAYING_SCALES) {
thisObject.isVisible = false
}
}
function drawScale() {
const SEPARATION = 150
const NUMBER_OF_LABELS = Math.trunc(canvas.chartingSpace.viewport.width / SEPARATION)
const FONT_SIZE = 15
function drawBackground () {
drawScale()
}
for (let i = 0; i <= NUMBER_OF_LABELS; i++) {
let timePoint = {
x: SEPARATION * (i + 1),
y: 0
}
function drawScale () {
const SEPARATION = 150
const NUMBER_OF_LABELS = Math.trunc(canvas.chartingSpace.viewport.width / SEPARATION)
const FONT_SIZE = 15
let time = getDateFromPointAtBrowserCanvas(timePoint, limitingContainer, coordinateSystem)
let labels = scaleLabels(time, true)
let labelDisplace = labels[1].length * FONT_SIZE * FONT_ASPECT_RATIO
for (let i = 0; i <= NUMBER_OF_LABELS; i++) {
let timePoint = {
x: SEPARATION * (i + 1),
y: 0
}
let timePoint1 = {
x: SEPARATION * (i + 1) - labelDisplace,
y: 0
}
let timePoint2 = {
x: SEPARATION * (i + 1) + labelDisplace,
y: 0
}
let time = getDateFromPointAtBrowserCanvas(timePoint, limitingContainer, coordinateSystem)
let labels = scaleLabels(time, true)
let labelDisplace = labels[1].length * FONT_SIZE * FONT_ASPECT_RATIO
let fitPoint1 = thisObject.fitFunction(timePoint1)
let fitPoint2 = thisObject.fitFunction(timePoint2)
let timePoint1 = {
x: SEPARATION * (i + 1) - labelDisplace,
y: 0
}
let timePoint2 = {
x: SEPARATION * (i + 1) + labelDisplace,
y: 0
}
let fitPoint1 = thisObject.fitFunction(timePoint1)
let fitPoint2 = thisObject.fitFunction(timePoint2)
if (fitPoint1.x === timePoint1.x && fitPoint2.x === timePoint2.x) {
drawLabel(labels[1], 1 / 2, 0, 18, 17, FONT_SIZE, thisObject.container, UI_COLOR.GREY, timePoint1.x, undefined)
drawLabel(labels[2], 1 / 2, 0, 18, 30, 12, thisObject.container, UI_COLOR.GREY, timePoint1.x, undefined)
}
}
}
function draw () {
drawScaleBox()
autoScaleButton.draw()
if (visible === false) {
drawScaleDisplayCover(thisObject.container)
}
}
function drawForeground () {
if (isMouseOver === true) {
drawScaleBox()
autoScaleButton.draw()
}
}
function drawScaleBox () {
if (thisObject.date === undefined) { return }
let icon1 = canvas.designSpace.iconByUiObjectType.get(thisObject.payload.node.payload.parentNode.type)
let icon2 = canvas.designSpace.iconByUiObjectType.get(thisObject.payload.node.type)
let backgroundColor = UI_COLOR.BLACK
let labels = scaleLabels(thisObject.date)
drawScaleDisplay(labels[0], labels[1], labels[2], 0, 0, 0, icon1, icon2, thisObject.container, backgroundColor)
}
function scaleLabels (date, excludeYear) {
let label = date.toUTCString()
let labelArray = label.split(' ')
let label1 = thisObject.payload.node.payload.parentNode.name
let label2 = labelArray[1] + ' ' + labelArray[2] + ' ' + labelArray[3]
let label3 = labelArray[4]
if (excludeYear === true) {
label2 = labelArray[1] + ' ' + labelArray[2]
if (fitPoint1.x === timePoint1.x && fitPoint2.x === timePoint2.x) {
drawLabel(labels[1], 1 / 2, 0, 18, 17, FONT_SIZE, thisObject.container, UI_COLOR.GREY, timePoint1.x, undefined)
drawLabel(labels[2], 1 / 2, 0, 18, 30, 12, thisObject.container, UI_COLOR.GREY, timePoint1.x, undefined)
}
}
}
return [label1, label2, label3]
}
function draw() {
drawScaleBox()
autoScaleButton.draw()
if (visible === false) {
drawScaleDisplayCover(thisObject.container)
}
}
function drawForeground() {
if (isMouseOver === true) {
drawScaleBox()
autoScaleButton.draw()
}
}
function drawScaleBox() {
if (thisObject.date === undefined) { return }
let icon1 = canvas.designSpace.iconByUiObjectType.get(thisObject.payload.node.payload.parentNode.type)
let icon2 = canvas.designSpace.iconByUiObjectType.get(thisObject.payload.node.type)
let backgroundColor = UI_COLOR.BLACK
let labels = scaleLabels(thisObject.date)
drawScaleDisplay(labels[0], labels[1], labels[2], 0, 0, 0, icon1, icon2, thisObject.container, backgroundColor)
}
function scaleLabels(date, excludeYear) {
let label = date.toUTCString()
let labelArray = label.split(' ')
let label1 = thisObject.payload.node.payload.parentNode.name
let label2 = labelArray[1] + ' ' + labelArray[2] + ' ' + labelArray[3]
let label3 = labelArray[4]
if (excludeYear === true) {
label2 = labelArray[1] + ' ' + labelArray[2]
}
return [label1, label2, label3]
}
}