Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change date range immediately and only debounce chart updates #1025

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 44 additions & 21 deletions src/actions/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { updateFrequencyDataDebounced } from "./frequencies";
import { calendarToNumeric } from "../util/dateHelpers";
import { applyToChildren } from "../components/tree/phyloTree/helpers";
import { constructVisibleTipLookupBetweenTrees } from "../util/treeTangleHelpers";
import {timerEnd, timerStart} from "../util/perf";


export const applyInViewNodesToTree = (idx, tree) => {
Expand Down Expand Up @@ -156,6 +157,7 @@ export const updateVisibleTipsAndBranchThicknesses = (
* @param {string|false} newMax optional
* @return {null} side-effects: a single action
*/
let timeout;
export const changeDateFilter = ({newMin = false, newMax = false, quickdraw = false}) => {
return (dispatch, getState) => {
const { tree, treeToo, controls, frequencies } = getState();
Expand All @@ -164,35 +166,56 @@ export const changeDateFilter = ({newMin = false, newMax = false, quickdraw = fa
dateMinNumeric: newMin ? calendarToNumeric(newMin) : controls.dateMinNumeric,
dateMaxNumeric: newMax ? calendarToNumeric(newMax) : controls.dateMaxNumeric
};
const data = calculateVisiblityAndBranchThickness(tree, controls, dates);
const dispatchObj = {
type: types.CHANGE_DATES_VISIBILITY_THICKNESS,
const changeDateAction = {
type: types.CHANGE_DATES_MIN_MAX,
quickdraw,
dateMin: newMin ? newMin : controls.dateMin,
dateMax: newMax ? newMax : controls.dateMax,
dateMinNumeric: dates.dateMinNumeric,
dateMaxNumeric: dates.dateMaxNumeric,
visibility: data.visibility,
visibilityVersion: data.visibilityVersion,
branchThickness: data.branchThickness,
branchThicknessVersion: data.branchThicknessVersion,
idxOfInViewRootNode: tree.idxOfInViewRootNode,
stateCountAttrs: Object.keys(controls.filters)
};
if (controls.showTreeToo) {
const dataToo = calculateVisiblityAndBranchThickness(treeToo, controls, dates);
dispatchObj.tangleTipLookup = constructVisibleTipLookupBetweenTrees(tree.nodes, treeToo.nodes, data.visibility, dataToo.visibility);
dispatchObj.visibilityToo = dataToo.visibility;
dispatchObj.visibilityVersionToo = dataToo.visibilityVersion;
dispatchObj.branchThicknessToo = dataToo.branchThickness;
dispatchObj.branchThicknessVersionToo = dataToo.branchThicknessVersion;
dispatch(changeDateAction);

const changeVisibilityAndThickness = () => {
const data = calculateVisiblityAndBranchThickness(tree, controls, dates);
const changeVisibilityThicknessAction = {
type: types.CHANGE_DATES_VISIBILITY_THICKNESS,
quickdraw,
dateMin: newMin ? newMin : controls.dateMin,
dateMax: newMax ? newMax : controls.dateMax,
dateMinNumeric: dates.dateMinNumeric,
dateMaxNumeric: dates.dateMaxNumeric,
visibility: data.visibility,
visibilityVersion: data.visibilityVersion,
branchThickness: data.branchThickness,
branchThicknessVersion: data.branchThicknessVersion,
idxOfInViewRootNode: tree.idxOfInViewRootNode,
stateCountAttrs: Object.keys(controls.filters)
};
if (controls.showTreeToo) {
const dataToo = calculateVisiblityAndBranchThickness(treeToo, controls, dates);
changeVisibilityThicknessAction.tangleTipLookup =
constructVisibleTipLookupBetweenTrees(tree.nodes, treeToo.nodes, data.visibility, dataToo.visibility);
changeVisibilityThicknessAction.visibilityToo = dataToo.visibility;
changeVisibilityThicknessAction.visibilityVersionToo = dataToo.visibilityVersion;
changeVisibilityThicknessAction.branchThicknessToo = dataToo.branchThickness;
changeVisibilityThicknessAction.branchThicknessVersionToo = dataToo.branchThicknessVersion;
}
/* D I S P A T C H */
dispatch(changeVisibilityThicknessAction)
updateEntropyVisibility(dispatch, getState);
if (frequencies.loaded) {
updateFrequencyDataDebounced(dispatch, getState);
}
}

/* D I S P A T C H */
dispatch(dispatchObj);
updateEntropyVisibility(dispatch, getState);
if (frequencies.loaded) {
updateFrequencyDataDebounced(dispatch, getState);
clearTimeout(timeout)
// Quickdraw also means debounce in this context, but better change it.
// TODO: Refactor to two seperate variables for quickdraw and debounce
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avin-kavish Definitely agree with the TODO here, I think it would make this more readable. Could you add that refactor here please? Thanks!

if (quickdraw) {
timeout = setTimeout(() => changeVisibilityAndThickness(), 100)
} else {
changeVisibilityAndThickness()
}
};
};
Expand Down
2 changes: 2 additions & 0 deletions src/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export const SEARCH_INPUT_CHANGE = "SEARCH_INPUT_CHANGE";
export const CHANGE_LAYOUT = "CHANGE_LAYOUT";
export const CHANGE_BRANCH_LABEL = "CHANGE_BRANCH_LABEL";
export const CHANGE_DISTANCE_MEASURE = "CHANGE_DISTANCE_MEASURE";
export const CHANGE_DATES_MIN_MAX = "CHANGE_DATES_MIN_MAX";
export const CHANGE_VISIBILITY_THICKNESS = "CHANGE_VISIBILITY_THICKNESS";
export const CHANGE_DATES_VISIBILITY_THICKNESS = "CHANGE_DATES_VISIBILITY_THICKNESS";
export const CHANGE_ABSOLUTE_DATE_MIN = "CHANGE_ABSOLUTE_DATE_MIN";
export const CHANGE_ABSOLUTE_DATE_MAX = "CHANGE_ABSOLUTE_DATE_MAX";
Expand Down
9 changes: 0 additions & 9 deletions src/components/controls/date-range-inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ class DateRangeInputs extends React.Component {
/* debounce: boolean. TRUE: both debounce and quickdraw. */
this.maybeClearMapAnimationInterval();

if (debounce) {
// simple debounce @ 100ms
const currentTime = Date.now();
if (currentTime < this.state.lastSliderUpdateTime + 100) {
return null;
}
// console.log("UPDATING", currentTime, this.state.lastSliderUpdateTime)
this.setState({lastSliderUpdateTime: currentTime});
}
// {numDateValues} is an array of numDates received from Slider
// [numDateStart, numDateEnd]
const newRange = {min: numericToCalendar(numDateValues[0]),
Expand Down
1 change: 1 addition & 0 deletions src/reducers/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const Controls = (state = getDefaultControlsState(), action) => {
distanceMeasure: action.data,
branchLengthsToDisplay: state.branchLengthsToDisplay
});
case types.CHANGE_DATES_MIN_MAX:
case types.CHANGE_DATES_VISIBILITY_THICKNESS: {
const newDates = {quickdraw: action.quickdraw};
if (action.dateMin) {
Expand Down