diff --git a/Animation.js b/Animation.js index 4042960c6..02182b246 100644 --- a/Animation.js +++ b/Animation.js @@ -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 diff --git a/ChartsSpace/CoordinateSystem.js b/ChartsSpace/CoordinateSystem.js index d302b080e..ed6996e5e 100644 --- a/ChartsSpace/CoordinateSystem.js +++ b/ChartsSpace/CoordinateSystem.js @@ -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 } } diff --git a/Globals.js b/Globals.js index 8ec77286f..1f38f538a 100644 --- a/Globals.js +++ b/Globals.js @@ -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; diff --git a/Plotter.js b/Plotter.js index 32a4f3ff4..095b1d6f5 100644 --- a/Plotter.js +++ b/Plotter.js @@ -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) } diff --git a/Scales/RateScale.js b/Scales/RateScale.js index 150a65fc3..ee6c4ab88 100644 --- a/Scales/RateScale.js +++ b/Scales/RateScale.js @@ -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() } }