coordinateSystem going down to Plotters
This commit is contained in:
1 parent
addfff4585
commit
09309d6e9c
5 files changed
+110
-104
No files matched your search
@@ -12,6 +12,7 @@ function newCoordinateSystem () {
|
||||
min: undefined,
|
||||
max: undefined,
|
||||
scale: undefined,
|
||||
recalculateScale: recalculateScale,
|
||||
transformThisPoint: transformThisPoint,
|
||||
transformThisPoint2: transformThisPoint2,
|
||||
unInverseTransform: unInverseTransform,
|
||||
@@ -21,44 +22,42 @@ function newCoordinateSystem () {
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
var min = {
|
||||
thisObject.min = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
|
||||
var max = {
|
||||
thisObject.max = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
|
||||
var scale = {
|
||||
thisObject.scale = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
|
||||
thisObject.min = min
|
||||
thisObject.max = max
|
||||
thisObject.scale = scale
|
||||
|
||||
let maxHeight
|
||||
let maxWidth
|
||||
|
||||
return thisObject
|
||||
|
||||
function initialize (minValue, maxValue, maxWidth, pMaxHeight) {
|
||||
/* Defines the min and max value of rate that we are going to transport to the available screen at the center position. */
|
||||
|
||||
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
|
||||
thisObject.max.x = maxValue.x // * 1.001; // 0.1% more
|
||||
|
||||
thisObject.min.y = minValue.y // * 0.999; // 0.1% less
|
||||
thisObject.max.y = maxValue.y // * 1.001; // 0.1% more
|
||||
|
||||
/* Defines the initial Zoom level at center position. */
|
||||
|
||||
thisObject.scale.x = maxWidth / (thisObject.max.x - thisObject.min.x)
|
||||
thisObject.scale.y = pMaxHeight / (thisObject.max.y - thisObject.min.y)
|
||||
|
||||
maxWidth = pMaxWidth
|
||||
maxHeight = pMaxHeight
|
||||
|
||||
recalculateScale()
|
||||
}
|
||||
|
||||
function recalculateScale () {
|
||||
/* Defines the initial Zoom level at center position. */
|
||||
thisObject.scale.x = maxWidth / (thisObject.max.x - thisObject.min.x)
|
||||
thisObject.scale.y = maxHeight / (thisObject.max.y - thisObject.min.y)
|
||||
}
|
||||
|
||||
function initializeX (minValue, maxValue, maxWidth) {
|
||||
|
||||
@@ -15,6 +15,7 @@ function newPlottersManager () {
|
||||
payload: undefined,
|
||||
setDatetime: setDatetime,
|
||||
setTimeFrame: setTimeFrame,
|
||||
setCoordinateSystem: setCoordinateSystem,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize,
|
||||
@@ -22,10 +23,9 @@ function newPlottersManager () {
|
||||
}
|
||||
|
||||
let initializationReady = false
|
||||
|
||||
let layersPanel
|
||||
|
||||
let onLayerStatusChangedEventSuscriptionId
|
||||
let coordinateSystem
|
||||
|
||||
setupContainer()
|
||||
return thisObject
|
||||
@@ -37,6 +37,7 @@ function newPlottersManager () {
|
||||
|
||||
function finalize () {
|
||||
layersPanel.container.eventHandler.stopListening(onLayerStatusChangedEventSuscriptionId)
|
||||
layersPanel = undefined
|
||||
|
||||
for (let i = 0; i < connectors.length; i++) {
|
||||
let connector = connectors[i]
|
||||
@@ -61,12 +62,10 @@ function newPlottersManager () {
|
||||
connector = undefined
|
||||
}
|
||||
connectors = []
|
||||
|
||||
layersPanel = undefined
|
||||
coordinateSystem = undefined
|
||||
|
||||
thisObject.container.finalize()
|
||||
thisObject.container = undefined
|
||||
|
||||
thisObject.payload = undefined
|
||||
}
|
||||
|
||||
@@ -80,15 +79,11 @@ function newPlottersManager () {
|
||||
}
|
||||
|
||||
function initialize (pLayersPanel) {
|
||||
try {
|
||||
/* Remember the Layers Panel */
|
||||
layersPanel = pLayersPanel
|
||||
/* Remember the Layers Panel */
|
||||
layersPanel = pLayersPanel
|
||||
|
||||
/* Listen to the event of change of status */
|
||||
onLayerStatusChangedEventSuscriptionId = layersPanel.container.eventHandler.listenToEvent('Layer Status Changed', onLayerStatusChanged)
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err.stack) }
|
||||
}
|
||||
/* Listen to the event of change of status */
|
||||
onLayerStatusChangedEventSuscriptionId = layersPanel.container.eventHandler.listenToEvent('Layer Status Changed', onLayerStatusChanged)
|
||||
}
|
||||
|
||||
function initializePlotter (layer) {
|
||||
@@ -178,7 +173,7 @@ function newPlottersManager () {
|
||||
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, onPlotterInizialized, product)
|
||||
plotter.initialize(storage, datetime, timeFrame, coordinateSystem, onPlotterInizialized, product)
|
||||
|
||||
function onPlotterInizialized () {
|
||||
try {
|
||||
@@ -291,6 +286,14 @@ function newPlottersManager () {
|
||||
}
|
||||
}
|
||||
|
||||
function setCoordinateSystem (pCoordinateSystem) {
|
||||
coordinateSystem = pCoordinateSystem
|
||||
for (let i = 0; i < connectors.length; i++) {
|
||||
let connector = connectors[i]
|
||||
connector.plotter.setCoordinateSystem(coordinateSystem)
|
||||
}
|
||||
}
|
||||
|
||||
function getContainer (point) {
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ function newTimelineChart () {
|
||||
|
||||
let timeMachineCoordinateSystem
|
||||
let timelineChartCoordinateSystem = newCoordinateSystem()
|
||||
let coordinateSystem
|
||||
|
||||
let layersPanel
|
||||
let layersPanelHandle
|
||||
@@ -89,6 +90,7 @@ function newTimelineChart () {
|
||||
|
||||
timeMachineCoordinateSystem = undefined
|
||||
timelineChartCoordinateSystem = undefined
|
||||
coordinateSystem = undefined
|
||||
layersPanel = undefined
|
||||
layersPanelHandle = undefined
|
||||
}
|
||||
@@ -140,6 +142,7 @@ function newTimelineChart () {
|
||||
/* We load the logow we will need for the background. */
|
||||
|
||||
timeMachineCoordinateSystem = pTimeMachineCoordinateSystem
|
||||
coordinateSystem = timeMachineCoordinateSystem
|
||||
|
||||
timeFrame = INITIAL_TIME_PERIOD
|
||||
recalculateCurrentDatetime()
|
||||
@@ -172,6 +175,7 @@ function newTimelineChart () {
|
||||
thisObject.plotterManager.initialize(thisObject.layersManager)
|
||||
thisObject.plotterManager.setTimeFrame(timeFrame)
|
||||
thisObject.plotterManager.setDatetime(datetime)
|
||||
thisObject.plotterManager.setCoordinateSystem(coordinateSystem)
|
||||
}
|
||||
|
||||
function initializeRateScale () {
|
||||
@@ -371,9 +375,11 @@ function newTimelineChart () {
|
||||
}
|
||||
if (thisObject.payload.node.rateScale === undefined && thisObject.rateScale !== undefined) {
|
||||
finalizeRateScale()
|
||||
coordinateSystem = timeMachineCoordinateSystem
|
||||
}
|
||||
if (thisObject.payload.node.rateScale !== undefined && thisObject.rateScale === undefined) {
|
||||
initializeRateScale()
|
||||
coordinateSystem = timelineChartCoordinateSystem
|
||||
}
|
||||
if (thisObject.payload.node.timeFrameScale === undefined && thisObject.timeFrameScale !== undefined) {
|
||||
finalizeTimeFrameScale()
|
||||
|
||||
+11
-18
@@ -6,32 +6,23 @@ function newPlotter () {
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
let thisObject = {
|
||||
|
||||
/* Events declared outside the plotter. */
|
||||
|
||||
currentRecord: undefined,
|
||||
container: undefined,
|
||||
onDailyFileLoaded: onDailyFileLoaded,
|
||||
|
||||
// Main functions and properties.
|
||||
|
||||
initialize: initialize,
|
||||
finalize: finalize,
|
||||
container: undefined,
|
||||
getContainer: getContainer,
|
||||
setTimeFrame: setTimeFrame,
|
||||
setDatetime: setDatetime,
|
||||
recalculateScale: recalculateScale,
|
||||
draw: draw,
|
||||
|
||||
// Secondary functions and properties.
|
||||
|
||||
currentRecord: undefined // ---> Check Here
|
||||
setCoordinateSystem: setCoordinateSystem,
|
||||
draw: draw
|
||||
}
|
||||
|
||||
let container = newContainer()
|
||||
container.initialize()
|
||||
thisObject.container = container
|
||||
|
||||
let coordinateSystem = newCoordinateSystem() // Needed to be able to plot on the timeline.
|
||||
let coordinateSystem
|
||||
let slotCoordinateSystem // Needed to be able to plot on a slot over the timeline.
|
||||
let plotterModuleConfig
|
||||
let slotHeight = (canvas.chartSpace.viewport.visibleArea.bottomRight.y - canvas.chartSpace.viewport.visibleArea.topLeft.y) / 10 // This is the amount of slots available
|
||||
@@ -96,7 +87,7 @@ function newPlotter () {
|
||||
}
|
||||
}
|
||||
|
||||
function initialize (pStorage, pDatetime, pTimeFrame, callBackFunction, pProductDefinition) {
|
||||
function initialize (pStorage, pDatetime, pTimeFrame, pCoordinateSystem, callBackFunction, pProductDefinition) {
|
||||
try {
|
||||
/* Store the information received. */
|
||||
marketFiles = pStorage.marketFiles[0]
|
||||
@@ -104,14 +95,13 @@ function newPlotter () {
|
||||
|
||||
datetime = pDatetime
|
||||
timeFrame = pTimeFrame
|
||||
coordinateSystem = pCoordinateSystem
|
||||
|
||||
productDefinition = pProductDefinition
|
||||
|
||||
/* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */
|
||||
marketFile = marketFiles.getFile(ONE_DAY_IN_MILISECONDS) // This file is the one processed faster.
|
||||
|
||||
recalculateScale()
|
||||
|
||||
/* Now we set the right files according to current Period. */
|
||||
marketFile = marketFiles.getFile(pTimeFrame)
|
||||
fileCursor = dailyFiles.getFileCursor(pTimeFrame)
|
||||
@@ -127,7 +117,6 @@ function newPlotter () {
|
||||
/* Get ready for plotting. */
|
||||
recalculate()
|
||||
dimmensionsChangedEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () {
|
||||
recalculateScale()
|
||||
recalculate()
|
||||
})
|
||||
|
||||
@@ -209,6 +198,10 @@ function newPlotter () {
|
||||
datetime = pDatetime
|
||||
}
|
||||
|
||||
function setCoordinateSystem (pCoordinateSystem) {
|
||||
coordinateSystem = pCoordinateSystem
|
||||
}
|
||||
|
||||
function onDailyFileLoaded (event) {
|
||||
try {
|
||||
if (event.currentValue === event.totalValue) {
|
||||
|
||||
+60
-55
@@ -89,6 +89,9 @@ function newRateScale () {
|
||||
limitingContainer = pLimitingContainer
|
||||
rateCalculationsContainer = pRateCalculationsContainer
|
||||
|
||||
thisObject.minValue = coordinateSystem.min.y
|
||||
thisObject.maxValue = coordinateSystem.max.y
|
||||
|
||||
onMouseWheelEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel)
|
||||
onMouseOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver)
|
||||
onMouseNotOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseNotOver', onMouseNotOver)
|
||||
@@ -222,6 +225,8 @@ function newRateScale () {
|
||||
code.scale = thisObject.scale / MAX_SCALE * 100
|
||||
code.scale = code.scale.toFixed(0)
|
||||
code.offset = thisObject.offset
|
||||
code.minValue = thisObject.minValue
|
||||
code.maxValue = thisObject.maxValue
|
||||
thisObject.payload.node.code = JSON.stringify(code)
|
||||
} catch (err) {
|
||||
// we ignore errors here since most likely they will be parsing errors.
|
||||
@@ -233,67 +238,61 @@ function newRateScale () {
|
||||
let code = JSON.parse(thisObject.payload.node.code)
|
||||
|
||||
if (isNaN(code.scale) || code.scale === null || code.scale === undefined) {
|
||||
saveObjectState()
|
||||
return
|
||||
}
|
||||
|
||||
code.scale = code.scale / 100 * MAX_SCALE
|
||||
if (code.scale < MIN_SCALE) { code.scale = MIN_SCALE }
|
||||
if (code.scale > MAX_SCALE) { code.scale = MAX_SCALE }
|
||||
|
||||
if (code.scale !== thisObject.scale) {
|
||||
thisObject.scale = code.scale
|
||||
let event = {}
|
||||
if (
|
||||
thisObject.scale <= DEFAULT_SCALE + SNAP_THRESHOLD_SCALE &&
|
||||
thisObject.scale >= DEFAULT_SCALE - SNAP_THRESHOLD_SCALE
|
||||
) {
|
||||
event.scale = DEFAULT_SCALE
|
||||
} else {
|
||||
event.scale = thisObject.scale
|
||||
}
|
||||
thisObject.container.eventHandler.raiseEvent('Rate Scale Value Changed', event)
|
||||
// not using this value
|
||||
} else {
|
||||
saveObjectState()
|
||||
return
|
||||
code.scale = code.scale / 100 * MAX_SCALE
|
||||
if (code.scale < MIN_SCALE) { code.scale = MIN_SCALE }
|
||||
if (code.scale > MAX_SCALE) { code.scale = MAX_SCALE }
|
||||
|
||||
if (code.scale !== thisObject.scale) {
|
||||
thisObject.scale = code.scale
|
||||
let event = {}
|
||||
if (
|
||||
thisObject.scale <= DEFAULT_SCALE + SNAP_THRESHOLD_SCALE &&
|
||||
thisObject.scale >= DEFAULT_SCALE - SNAP_THRESHOLD_SCALE
|
||||
) {
|
||||
event.scale = DEFAULT_SCALE
|
||||
} else {
|
||||
event.scale = thisObject.scale
|
||||
}
|
||||
thisObject.container.eventHandler.raiseEvent('Rate Scale Value Changed', event)
|
||||
}
|
||||
}
|
||||
|
||||
if (isNaN(code.offset) || code.offset === null || code.offset === undefined) {
|
||||
saveObjectState()
|
||||
return
|
||||
}
|
||||
|
||||
if (code.offset < MIN_OFFSET) { code.offset = MIN_OFFSET }
|
||||
if (code.offset > MAX_OFFSET) { code.offset = MAX_OFFSET }
|
||||
|
||||
if (code.offset !== thisObject.offset) {
|
||||
thisObject.offset = code.offset
|
||||
let event = {}
|
||||
if (
|
||||
thisObject.offset <= DEFAULT_OFFSET + SNAP_THRESHOLD_OFFSET &&
|
||||
thisObject.offset >= DEFAULT_OFFSET - SNAP_THRESHOLD_OFFSET
|
||||
) {
|
||||
event.offset = 0
|
||||
} else {
|
||||
event.offset = -thisObject.offset
|
||||
}
|
||||
thisObject.container.eventHandler.raiseEvent('Rate Scale Offset Changed', event)
|
||||
// not using this value
|
||||
} else {
|
||||
saveObjectState()
|
||||
return
|
||||
if (code.offset < MIN_OFFSET) { code.offset = MIN_OFFSET }
|
||||
if (code.offset > MAX_OFFSET) { code.offset = MAX_OFFSET }
|
||||
|
||||
if (code.offset !== thisObject.offset) {
|
||||
thisObject.offset = code.offset
|
||||
let event = {}
|
||||
if (
|
||||
thisObject.offset <= DEFAULT_OFFSET + SNAP_THRESHOLD_OFFSET &&
|
||||
thisObject.offset >= DEFAULT_OFFSET - SNAP_THRESHOLD_OFFSET
|
||||
) {
|
||||
event.offset = 0
|
||||
} else {
|
||||
event.offset = -thisObject.offset
|
||||
}
|
||||
thisObject.container.eventHandler.raiseEvent('Rate Scale Offset Changed', event)
|
||||
}
|
||||
}
|
||||
|
||||
if (isNaN(code.minValue) || code.minValue === null || code.minValue === undefined) {
|
||||
saveObjectState()
|
||||
return
|
||||
if (
|
||||
(isNaN(code.minValue) || code.minValue === null || code.minValue === undefined) ||
|
||||
(isNaN(code.maxValue) || code.maxValue === null || code.maxValue === undefined)
|
||||
) {
|
||||
// not using this value
|
||||
} else {
|
||||
thisObject.minValue = code.minValue
|
||||
thisObject.maxValue = code.maxValue
|
||||
coordinateSystem.min.y = code.minValue
|
||||
coordinateSystem.max.y = code.maxValue
|
||||
coordinateSystem.recalculateScale()
|
||||
}
|
||||
if (isNaN(code.maxValue) || code.maxValue === null || code.maxValue === undefined) {
|
||||
saveObjectState()
|
||||
return
|
||||
}
|
||||
|
||||
coordinateSystem.min.y = code.minValue
|
||||
coordinateSystem.max.y = code.maxValue
|
||||
saveObjectState() // this overrides any invalid value at the config.
|
||||
} catch (err) {
|
||||
// we ignore errors here since most likely they will be parsing errors.
|
||||
}
|
||||
@@ -401,8 +400,14 @@ function newRateScale () {
|
||||
|
||||
let rate = thisObject.rate
|
||||
|
||||
if (rate < coordinateSystem.min.y) { rate = coordinateSystem.min.y }
|
||||
if (rate > coordinateSystem.max.y) { rate = coordinateSystem.max.y }
|
||||
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)
|
||||
let labelArray = label.split('.')
|
||||
|
||||
Reference in new issue
Block a user