Recalculating Datapoints only when really needed
This commit is contained in:
1 parent
ad7228d3fd
commit
111749f2f1
1 file changed
+32
-18
+32
-18
@@ -35,6 +35,7 @@ function newPlotter () {
|
||||
let slotCoordinateSystem // Needed to be able to plot on a slot over the timeline.
|
||||
let plotterModuleConfig
|
||||
let slotHeight = (viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topLeft.y) / 5 // This is the amount of slots available
|
||||
let mustRecalculateDataPoints = false
|
||||
|
||||
let timePeriod // This will hold the current Time Period the user is at.
|
||||
let datetime // This will hold the current Datetime the user is at.
|
||||
@@ -214,6 +215,7 @@ function newPlotter () {
|
||||
|
||||
function recalculate () {
|
||||
try {
|
||||
console.log('Recalculating...')
|
||||
if (timePeriod >= _1_HOUR_IN_MILISECONDS) {
|
||||
recalculateUsingMarketFiles()
|
||||
} else {
|
||||
@@ -516,44 +518,53 @@ function newPlotter () {
|
||||
if (productDefinition.referenceParent.shapes.chartPoints === undefined) { continue }
|
||||
|
||||
let dataPoints = new Map()
|
||||
|
||||
for (let j = 0; j < productDefinition.referenceParent.shapes.chartPoints.points.length; j++) {
|
||||
let point = productDefinition.referenceParent.shapes.chartPoints.points[j]
|
||||
if (point.pointFormula !== undefined) {
|
||||
let x = 0
|
||||
let y = 0
|
||||
eval(point.pointFormula.code)
|
||||
let dataPoint = {
|
||||
x: x,
|
||||
y: y
|
||||
}
|
||||
if (record.dataPoints !== undefined && mustRecalculateDataPoints === false) {
|
||||
/* We use the datapoints already calculated. */
|
||||
dataPoints = record.dataPoints
|
||||
} else {
|
||||
console.log('Recalculating Data Points...')
|
||||
/* Only calculate the datapoints for this record, if we have not calculate it before. */
|
||||
for (let j = 0; j < productDefinition.referenceParent.shapes.chartPoints.points.length; j++) {
|
||||
let point = productDefinition.referenceParent.shapes.chartPoints.points[j]
|
||||
if (point.pointFormula !== undefined) {
|
||||
let x = 0
|
||||
let y = 0
|
||||
eval(point.pointFormula.code)
|
||||
let dataPoint = {
|
||||
x: x,
|
||||
y: y
|
||||
}
|
||||
|
||||
/*
|
||||
The information we store in files is independent from the charing system and its coordinate systems.
|
||||
That means that the first thing we allways need to do is to trasform these points to the coordinate system of the timeline.
|
||||
*/
|
||||
dataPoint = timeLineCoordinateSystem.transformThisPoint(dataPoint)
|
||||
dataPoint = timeLineCoordinateSystem.transformThisPoint(dataPoint)
|
||||
|
||||
/*
|
||||
The browser canvas object does not care about our timeline and its coordinate system. In order to draw on a html canvas we
|
||||
need the points to be converted into the canvas coordinate system.
|
||||
Next we transform again to the screen coordinate system.
|
||||
*/
|
||||
dataPoint = transformThisPoint(dataPoint, thisObject.container)
|
||||
dataPoint = transformThisPoint(dataPoint, thisObject.container)
|
||||
|
||||
/* We make sure the points do not fall outside the viewport visible area. This step allways need to be done. */
|
||||
dataPoint = viewPort.fitIntoVisibleArea(dataPoint)
|
||||
dataPoint = viewPort.fitIntoVisibleArea(dataPoint)
|
||||
|
||||
/* Store the data point at the local map */
|
||||
dataPoints.set(point.id, dataPoint)
|
||||
dataPoints.set(point.id, dataPoint)
|
||||
|
||||
if (plotterModuleConfig !== undefined) {
|
||||
if (plotterModuleConfig.slot !== undefined) {
|
||||
if (plotterModuleConfig !== undefined) {
|
||||
if (plotterModuleConfig.slot !== undefined) {
|
||||
/* We reset the y coordinate since it will be transformed with another coordinate system to fit into a slot. */
|
||||
dataPoint.y = (-1) * y * slotCoordinateSystem.scale.y + (plotterModuleConfig.slot.number - 1) * slotHeight
|
||||
dataPoint.y = (-1) * y * slotCoordinateSystem.scale.y + (plotterModuleConfig.slot.number - 1) * slotHeight
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Remember this datapoints, so that we do not need to calculate them again. */
|
||||
record.dataPoints = dataPoints
|
||||
}
|
||||
|
||||
for (let j = 0; j < productDefinition.referenceParent.shapes.polygons.length; j++) {
|
||||
@@ -647,6 +658,8 @@ function newPlotter () {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mustRecalculateDataPoints = false
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] plotChart -> err = ' + err.stack) }
|
||||
}
|
||||
@@ -670,6 +683,7 @@ function newPlotter () {
|
||||
|
||||
function onOffsetChanged (event) {
|
||||
try {
|
||||
mustRecalculateDataPoints = true
|
||||
if (event !== undefined) {
|
||||
if (event.recalculate === true) {
|
||||
recalculate()
|
||||
|
||||
Reference in new issue
Block a user