diff --git a/ChartingSpace/PlottersManager.js b/ChartingSpace/PlottersManager.js index 3b245cf99..848f5cf1a 100644 --- a/ChartingSpace/PlottersManager.js +++ b/ChartingSpace/PlottersManager.js @@ -301,9 +301,16 @@ function newPlottersManager () { function draw () { if (thisObject.connectors === undefined) { return } // We need to wait /* First the Product Plotters. */ + let maxElementsPlotted = 0 for (let i = 0; i < thisObject.connectors.length; i++) { let connector = thisObject.connectors[thisObject.connectors.length - i - 1] - connector.plotter.draw() + let elementsPlotted = connector.plotter.draw() + if (elementsPlotted !== undefined) { + if (elementsPlotted > maxElementsPlotted) { + maxElementsPlotted = elementsPlotted + } + } } + return maxElementsPlotted } } diff --git a/ChartingSpace/TimeMachine.js b/ChartingSpace/TimeMachine.js index 8bf908946..2f62f9c5f 100644 --- a/ChartingSpace/TimeMachine.js +++ b/ChartingSpace/TimeMachine.js @@ -529,9 +529,18 @@ function newTimeMachine () { function drawBackground () { drawChartsBackground() if (thisObject.container.frame.isInViewPort()) { + let maxElementsPlotted = 0 for (let i = 0; i < thisObject.timelineCharts.length; i++) { let timelineChart = thisObject.timelineCharts[thisObject.timelineCharts.length - i - 1] - timelineChart.drawBackground() + let elementsPlotted = timelineChart.drawBackground() + if (elementsPlotted !== undefined) { + if (elementsPlotted > maxElementsPlotted) { + maxElementsPlotted = elementsPlotted + } + } + } + if (thisObject.timeFrameScale !== undefined) { + thisObject.timeFrameScale.adjustTimeFrame(maxElementsPlotted) } } } diff --git a/ChartingSpace/TimelineChart.js b/ChartingSpace/TimelineChart.js index ce9e7ede5..5ae735f80 100644 --- a/ChartingSpace/TimelineChart.js +++ b/ChartingSpace/TimelineChart.js @@ -380,7 +380,12 @@ function newTimelineChart () { if (thisObject.container.frame.isInViewPort()) { drawChartsBackground() if (thisObject.plotterManager !== undefined) { - thisObject.plotterManager.draw() + let elementsPlotted = thisObject.plotterManager.draw() + if (thisObject.timeFrameScale !== undefined) { + thisObject.timeFrameScale.adjustTimeFrame(elementsPlotted) + } else { + return elementsPlotted + } } } } diff --git a/Globals.js b/Globals.js index 5b4aa5751..1a1c76a6b 100644 --- a/Globals.js +++ b/Globals.js @@ -43,7 +43,7 @@ UI_FONT = { 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. +const ZOOM_OUT_THRESHOLD_FOR_CHANGING_TIME_FRAME = 3 // This help regulate when to change the Time Frame base on the level of zoom out. const ZOOM_OUT_THRESHOLD_FOR_PACKING_OBJECTS_AT_THE_BOTTOM_OR_TOP_OF_VIEWPORT = 2 const ZOOM_OUT_THRESHOLD_FOR_PLOTTING_IN_LOW_RESOLUTION = 3 const ZOOM_OUT_THRESHOLD_FOR_DISPLAYING_TIME_MACHINES_ICONIZED = 5 diff --git a/Scales/TimeFrameScale.js b/Scales/TimeFrameScale.js index 05f6fbb38..856a1e15f 100644 --- a/Scales/TimeFrameScale.js +++ b/Scales/TimeFrameScale.js @@ -8,6 +8,7 @@ function newTimeFrameScale () { payload: undefined, isVisible: true, layersOn: undefined, + adjustTimeFrame: adjustTimeFrame, onMouseOverSomeTimeMachineContainer: onMouseOverSomeTimeMachineContainer, draw: draw, drawForeground: drawForeground, @@ -21,7 +22,7 @@ function newTimeFrameScale () { const TIME_PERIOD_DEFAULT_VALUE = 0 const MIN_HEIGHT = 50 - let previousIsVisible = true + let displayingRealTimeFrame = true let greyOutCoverLayer = false let isMouseOver @@ -119,21 +120,28 @@ function newTimeFrameScale () { function physics () { readObjectState() positioningPhysics() - zoomOutPhysics() } - function zoomOutPhysics () { - if ((thisObject.isVisible === true && previousIsVisible === false) && (canvas.chartingSpace.viewport.zoomTargetLevel >= ZOOM_OUT_THRESHOLD_FOR_CHANGING_TIME_FRAME)) { + function adjustTimeFrame (elementsPlotted) { + const ELEMENTS_PLOTTED_THREASHOLD = 500 + if ( + canvas.chartingSpace.viewport.zoomTargetLevel >= ZOOM_OUT_THRESHOLD_FOR_CHANGING_TIME_FRAME && + displayingRealTimeFrame === false + ) { let event = {} event.timeFrame = thisObject.timeFrame thisObject.container.eventHandler.raiseEvent('Time Frame Value Changed', event) - previousIsVisible = true + displayingRealTimeFrame = true } - if ((thisObject.isVisible === false && previousIsVisible === true) || (canvas.chartingSpace.viewport.zoomTargetLevel < ZOOM_OUT_THRESHOLD_FOR_CHANGING_TIME_FRAME)) { + if ( + elementsPlotted > ELEMENTS_PLOTTED_THREASHOLD && + canvas.chartingSpace.viewport.zoomTargetLevel < ZOOM_OUT_THRESHOLD_FOR_CHANGING_TIME_FRAME && + displayingRealTimeFrame === true + ) { let event = {} event.timeFrame = ONE_DAY_IN_MILISECONDS thisObject.container.eventHandler.raiseEvent('Time Frame Value Changed', event) - previousIsVisible = false + displayingRealTimeFrame = false } }