Coordinate System raising events when scale changes
This commit is contained in:
1 parent
58cfd502e2
commit
9cc7e1ccd9
6 files changed
+49
-13
No files matched your search
@@ -14,6 +14,7 @@ function newCoordinateSystem () {
|
||||
maxHeight: undefined,
|
||||
maxWidth: undefined,
|
||||
scale: undefined,
|
||||
eventHandler: undefined,
|
||||
recalculateScale: recalculateScale,
|
||||
transformThisPoint: transformThisPoint,
|
||||
transformThisPoint2: transformThisPoint2,
|
||||
@@ -21,7 +22,8 @@ function newCoordinateSystem () {
|
||||
inverseTransformUncappedY: inverseTransformUncappedY,
|
||||
initializeX: initializeX,
|
||||
initializeY: initializeY,
|
||||
initialize: initialize
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
thisObject.min = {
|
||||
@@ -37,8 +39,16 @@ function newCoordinateSystem () {
|
||||
y: 0
|
||||
}
|
||||
|
||||
thisObject.eventHandler = newEventHandler()
|
||||
thisObject.eventHandler.name = 'Coordinate System'
|
||||
|
||||
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 // * 0.999; // 0.1% less
|
||||
@@ -57,6 +67,9 @@ function newCoordinateSystem () {
|
||||
/* Defines the initial Zoom level at center position. */
|
||||
thisObject.scale.x = thisObject.maxWidth / (thisObject.max.x - thisObject.min.x)
|
||||
thisObject.scale.y = thisObject.maxHeight / (thisObject.max.y - thisObject.min.y)
|
||||
|
||||
thisObject.eventHandler.raiseEvent('Scale Changed')
|
||||
console.log('Scale Changed')
|
||||
}
|
||||
|
||||
function initializeX (minValue, maxValue, maxWidth) {
|
||||
|
||||
@@ -104,6 +104,8 @@ function newTimeMachine () {
|
||||
|
||||
mouse = undefined
|
||||
timelineChartsMap = undefined
|
||||
|
||||
timeMachineCoordinateSystem.finalize()
|
||||
timeMachineCoordinateSystem = undefined
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ function newTimelineChart () {
|
||||
logger = undefined
|
||||
|
||||
timeMachineCoordinateSystem = undefined
|
||||
timelineChartCoordinateSystem.finalize()
|
||||
timelineChartCoordinateSystem = undefined
|
||||
coordinateSystem = undefined
|
||||
layersPanel = undefined
|
||||
|
||||
+18
@@ -52,6 +52,7 @@ function newPlotter () {
|
||||
let marketFilesUpdatedEventSubscriptionId
|
||||
let dailyFilesUpdatedEventSubscriptionId
|
||||
let onDisplaceEventSubscriptionId
|
||||
let scaleChangedEventSubscriptionId
|
||||
|
||||
let logged = false
|
||||
return thisObject
|
||||
@@ -78,6 +79,7 @@ function newPlotter () {
|
||||
marketFile = undefined
|
||||
fileCursor = undefined
|
||||
|
||||
finalizeCoordinateSystem()
|
||||
coordinateSystem = undefined
|
||||
slotCoordinateSystem = undefined
|
||||
plotterModuleConfig = undefined
|
||||
@@ -99,6 +101,7 @@ function newPlotter () {
|
||||
datetime = pDatetime
|
||||
timeFrame = pTimeFrame
|
||||
coordinateSystem = pCoordinateSystem
|
||||
initializeCoordinateSystem()
|
||||
|
||||
productDefinition = pProductDefinition
|
||||
|
||||
@@ -131,6 +134,19 @@ function newPlotter () {
|
||||
}
|
||||
}
|
||||
|
||||
function initializeCoordinateSystem () {
|
||||
scaleChangedEventSubscriptionId = coordinateSystem.eventHandler.listenToEvent('Scale Changed', onScaleChanged)
|
||||
}
|
||||
|
||||
function finalizeCoordinateSystem () {
|
||||
coordinateSystem.eventHandler.stopListening(scaleChangedEventSubscriptionId)
|
||||
}
|
||||
|
||||
function onScaleChanged () {
|
||||
mustRecalculateDataPoints = true
|
||||
recalculate()
|
||||
}
|
||||
|
||||
function onMouseOver (event) {
|
||||
let userPosition = getDateFromPoint(event, thisObject.container, coordinateSystem)
|
||||
userPositionDate = userPosition.valueOf()
|
||||
@@ -208,7 +224,9 @@ function newPlotter () {
|
||||
}
|
||||
|
||||
function setCoordinateSystem (pCoordinateSystem) {
|
||||
finalizeCoordinateSystem()
|
||||
coordinateSystem = pCoordinateSystem
|
||||
initializeCoordinateSystem()
|
||||
}
|
||||
|
||||
function onDailyFileLoaded (event) {
|
||||
|
||||
+7
-7
@@ -277,11 +277,13 @@ function newRateScale () {
|
||||
) {
|
||||
// not using this value
|
||||
} else {
|
||||
thisObject.minValue = code.minValue
|
||||
thisObject.maxValue = code.maxValue
|
||||
coordinateSystem.min.y = thisObject.minValue
|
||||
coordinateSystem.max.y = thisObject.maxValue
|
||||
coordinateSystem.recalculateScale()
|
||||
if (thisObject.minValue !== code.minValue || thisObject.maxValue !== code.maxValue) {
|
||||
thisObject.minValue = code.minValue
|
||||
thisObject.maxValue = code.maxValue
|
||||
coordinateSystem.min.y = thisObject.minValue
|
||||
coordinateSystem.max.y = thisObject.maxValue
|
||||
coordinateSystem.recalculateScale()
|
||||
}
|
||||
}
|
||||
saveObjectState() // this overrides any invalid value at the config.
|
||||
} catch (err) {
|
||||
@@ -393,11 +395,9 @@ function newRateScale () {
|
||||
|
||||
if (rate < coordinateSystem.min.y) {
|
||||
rate = coordinateSystem.min.y
|
||||
coordinateSystem.recalculateScale()
|
||||
}
|
||||
if (rate > coordinateSystem.max.y) {
|
||||
rate = coordinateSystem.max.y
|
||||
coordinateSystem.recalculateScale()
|
||||
}
|
||||
|
||||
let label = (rate - Math.trunc(rate)).toFixed(2)
|
||||
|
||||
+7
-5
@@ -200,11 +200,13 @@ function newTimeScale () {
|
||||
) {
|
||||
// not using this value
|
||||
} else {
|
||||
thisObject.fromDate = Date.parse(code.fromDate)
|
||||
thisObject.toDate = Date.parse(code.toDate)
|
||||
coordinateSystem.min.x = thisObject.fromDate
|
||||
coordinateSystem.max.x = thisObject.toDate
|
||||
coordinateSystem.recalculateScale()
|
||||
if (thisObject.fromDate !== Date.parse(code.fromDate) || thisObject.toDate !== Date.parse(code.toDate)) {
|
||||
thisObject.fromDate = Date.parse(code.fromDate)
|
||||
thisObject.toDate = Date.parse(code.toDate)
|
||||
coordinateSystem.min.x = thisObject.fromDate
|
||||
coordinateSystem.max.x = thisObject.toDate
|
||||
coordinateSystem.recalculateScale()
|
||||
}
|
||||
}
|
||||
saveObjectState() // this overrides any invalid value at the config.
|
||||
} catch (err) {
|
||||
|
||||
Reference in new issue
Block a user