Autoscaling implementation finished

This commit is contained in:
Luis Fernando Molina committed 2020-02-13 19:19:36 +01:00
1 parent da3e8184de
commit 612c32204b
5 files changed
+67 -20

No files matched your search

+11
View File
@@ -119,6 +119,17 @@ function newAnimation () {
labelToPrint = key + ' ' + percentage.toFixed(1) + '%'
printLabel(labelToPrint, 300, 100 + row * 30, 1, 20, UI_COLOR.RED)
}
/* Other Variables */
row++
printLabel(DEBUG.variable1, 300, 100 + row * 30, 1, 20, UI_COLOR.RED)
row++
printLabel(DEBUG.variable2, 300, 100 + row * 30, 1, 20, UI_COLOR.RED)
row++
printLabel(DEBUG.variable3, 300, 100 + row * 30, 1, 20, UI_COLOR.RED)
row++
printLabel(DEBUG.variable4, 300, 100 + row * 30, 1, 20, UI_COLOR.RED)
console.log(DEBUG.variable4)
}
} else {
browserCanvas.width = 1
+32 -15
View File
@@ -15,7 +15,8 @@ function newCoordinateSystem () {
maxWidth: undefined,
scale: undefined,
eventHandler: undefined,
autosScale: true,
autoMinScale: true,
autoMaxScale: true,
physics: physics,
reportValue: reportValue,
zoomX: zoomX,
@@ -49,6 +50,7 @@ function newCoordinateSystem () {
let newMax = -VERY_LARGE_NUMBER
let newMin = VERY_LARGE_NUMBER
let notValueReported = true
return thisObject
@@ -59,11 +61,11 @@ function newCoordinateSystem () {
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.x = minValue.x
thisObject.max.x = maxValue.x
thisObject.min.y = minValue.y // * 0.999; // 0.1% less
thisObject.max.y = maxValue.y // * 1.001; // 0.1% more
thisObject.min.y = minValue.y
thisObject.max.y = maxValue.y
thisObject.maxWidth = pMaxWidth
thisObject.maxHeight = pMaxHeight
@@ -72,24 +74,39 @@ function newCoordinateSystem () {
}
function physics () {
if (thisObject.autosScale === true) {
if (thisObject.max.y !== newMax || thisObject.min.y !== newMin) {
thisObject.min.y = newMin
thisObject.max.y = newMax
if ((thisObject.autoMinScale === true || thisObject.autoMaxScale === true) && notValueReported === false) {
let mustRecalculate = false
thisObject.scale.x = thisObject.maxWidth / (thisObject.max.x - thisObject.min.x)
thisObject.scale.y = thisObject.maxHeight / (thisObject.max.y - thisObject.min.y)
if (thisObject.autoMaxScale === true && thisObject.max.y !== newMax) {
thisObject.max.y = newMax
newMax = -VERY_LARGE_NUMBER
mustRecalculate = true
}
newMax = -VERY_LARGE_NUMBER
newMin = VERY_LARGE_NUMBER
if (thisObject.autoMinScale === true && thisObject.min.y !== newMin) {
thisObject.min.y = newMin
newMin = VERY_LARGE_NUMBER
mustRecalculate = true
}
if (mustRecalculate === true) {
recalculateScale()
}
/* Reseting this to start over at each cycle. */
notValueReported = true
}
}
function reportValue (value) {
if (thisObject.autosScale === true) {
if (value > newMax) { newMax = value }
if (thisObject.autoMinScale === true) {
if (value < newMin) { newMin = value }
notValueReported = false
}
if (thisObject.autoMaxScale === true) {
if (value > newMax) { newMax = value }
notValueReported = false
}
}
+2 -1
View File
@@ -41,7 +41,8 @@ UI_FONT = {
SECONDARY: "Source Code Pro"
};
const ZOOM_OUT_THRESHOLD_FOR_HIDDING_PANELS = 10 // This regulates some behavious changes that happens when the user zoom out below this level.
const DEBUG = {}
const ZOOM_OUT_THRESHOLD_FOR_HIDDING_PANELS = 5 // This regulates some behavious changes that happens when the user zoom out below this level.
const ZOOM_OUT_THRESHOLD_FOR_CHANGING_TIME_FRAME = 5 // This help regulate when to change the Time Frame base on the level of zoom out.
let FONT_ASPECT_RATIO = 0.32;
+8 -2
View File
@@ -547,7 +547,6 @@ function newPlotter () {
if (productDefinition.referenceParent.shapes === undefined) { continue }
if (productDefinition.referenceParent.shapes.chartPoints === undefined) { continue }
let dataPoints = new Map()
if (record.dataPoints !== undefined && mustRecalculateDataPoints === false) {
/* We use the datapoints already calculated. */
@@ -569,6 +568,8 @@ function newPlotter () {
x: x,
y: y
}
/* Contributing to Auto-Scale */
coordinateSystem.reportValue(dataPoint.y)
/*
The information we store in files is independent from the charing system and its coordinate systems.
@@ -768,7 +769,12 @@ function newPlotter () {
}
}
mustRecalculateDataPoints = false
if (coordinateSystem.autoMinScale === true || coordinateSystem.autosMaxScale === true) {
mustRecalculateDataPoints = true
} else {
mustRecalculateDataPoints = false
}
logged = false
} catch (err) {
if (ERROR_LOG === true) { logger.write('[ERROR] plotChart -> err = ' + err.stack) }
+14 -2
View File
@@ -156,6 +156,8 @@ function newRateScale () {
let code = JSON.parse(thisObject.payload.node.code)
code.minValue = coordinateSystem.min.y
code.maxValue = coordinateSystem.max.y
code.autoMinScale = coordinateSystem.autoMinScale
code.autoMaxScale = coordinateSystem.autoMaxScale
thisObject.payload.node.code = JSON.stringify(code, null, 4)
} catch (err) {
// we ignore errors here since most likely they will be parsing errors.
@@ -163,7 +165,6 @@ function newRateScale () {
}
function readObjectState () {
return
try {
let code = JSON.parse(thisObject.payload.node.code)
@@ -173,11 +174,22 @@ function newRateScale () {
) {
// not using this value
} else {
if (thisObject.minValue !== code.minValue || thisObject.maxValue !== code.maxValue) {
if (
thisObject.minValue !== code.minValue ||
thisObject.maxValue !== code.maxValue ||
coordinateSystem.autoMinScale !== code.autoMinScale ||
coordinateSystem.autoMaxScale !== code.autoMaxScale
) {
thisObject.minValue = code.minValue
thisObject.maxValue = code.maxValue
coordinateSystem.min.y = thisObject.minValue
coordinateSystem.max.y = thisObject.maxValue
if (code.autoMinScale !== undefined && (code.autoMinScale === true || code.autoMinScale === false)) {
coordinateSystem.autoMinScale = code.autoMinScale
}
if (code.autoMaxScale !== undefined && (code.autoMaxScale === true || code.autoMaxScale === false)) {
coordinateSystem.autoMaxScale = code.autoMaxScale
}
coordinateSystem.recalculateScale()
}
}