Skip to content

Commit

Permalink
don't calculate all dates when max frames exceeded
Browse files Browse the repository at this point in the history
  • Loading branch information
jasontk19 committed Dec 8, 2021
1 parent d8b6203 commit 6f18245
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
5 changes: 3 additions & 2 deletions web/js/containers/animation-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
getQueueLength,
getMaxQueueLength,
snapToIntervalDelta,
getNumberOfSteps,
} from '../modules/animation/util';
import {
subdailyLayersActive,
Expand Down Expand Up @@ -685,7 +686,7 @@ function mapStateToProps(state) {
const useInterval = customSelected ? customInterval || 3 : interval;
const subDailyInterval = useInterval > 3;
const subDailyMode = subDailyInterval && hasSubdailyLayers;
const numberOfFrames = util.getNumberOfSteps(
const numberOfFrames = getNumberOfSteps(
startDate,
endDate,
TIME_SCALE_FROM_NUMBER[useInterval],
Expand All @@ -696,7 +697,7 @@ function mapStateToProps(state) {
const visibleLayersForProj = lodashFilter(activeLayersForProj, 'visible');
const currentDate = getSelectedDate(state);
let snappedCurrentDate;
if (numberOfFrames <= maxFrames) {
if (numberOfFrames < maxFrames) {
snappedCurrentDate = snapToIntervalDelta(
currentDate,
startDate,
Expand Down
5 changes: 2 additions & 3 deletions web/js/containers/gif.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import GifStream from '../modules/animation/gifstream';
import GifPanel from '../components/animation-widget/gif-panel';
import util from '../util/util';

import Crop from '../components/util/image-crop';
import {
resolutionsGeo,
Expand All @@ -23,7 +22,7 @@ import {
import { TIME_SCALE_FROM_NUMBER } from '../modules/date/constants';
import GifResults from '../components/animation-widget/gif-post-creation';
import getImageArray from '../modules/animation/selectors';
import { getStampProps, svgToPng } from '../modules/animation/util';
import { getStampProps, svgToPng, getNumberOfSteps } from '../modules/animation/util';
import { changeCropBounds } from '../modules/animation/actions';
import { subdailyLayersActive } from '../modules/layers/selectors';
import { formatDisplayDate } from '../modules/date/util';
Expand Down Expand Up @@ -410,7 +409,7 @@ function mapStateToProps(state) {
speed,
map,
url,
numberOfFrames: util.getNumberOfSteps(
numberOfFrames: getNumberOfSteps(
startDate,
endDate,
customSelected
Expand Down
14 changes: 14 additions & 0 deletions web/js/modules/animation/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ export function snapToIntervalDelta(currDate, startDate, endDate, interval, delt
return currentDate || startDate;
}

export function getNumberOfSteps(start, end, interval, delta = 1, maxToCheck) {
let i = 1;
let currentDate = start;
while (currentDate < end) {
i += 1;
currentDate = util.dateAdd(currentDate, interval, delta);
// if checking for a max number limit, break out after reaching it
if (maxToCheck && i >= maxToCheck) {
return i;
}
}
return i;
}

export function getStampProps(
stampWidthRatio,
breakPoint,
Expand Down
14 changes: 0 additions & 14 deletions web/js/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,20 +323,6 @@ export default (function(self) {
return newDate;
};

self.getNumberOfSteps = function(start, end, interval, delta = 1, maxToCheck) {
let i = 1;
let currentDate = start;
while (currentDate < end) {
i += 1;
currentDate = self.dateAdd(currentDate, interval, delta);
// if checking for a max number limit, break out after reaching it
if (maxToCheck && i >= maxToCheck) {
return i;
}
}
return i;
};

self.daysInYear = function(date) {
const jStart = self.parseDateUTC(`${date.getUTCFullYear()}-01-01`);
const jDate = `00${Math.ceil((date.getTime() - jStart) / 86400000) + 1}`;
Expand Down

0 comments on commit 6f18245

Please sign in to comment.