-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86fc99d
commit 94adaa2
Showing
5 changed files
with
158 additions
and
89 deletions.
There are no files selected for viewing
38 changes: 0 additions & 38 deletions
38
webapp/javascript/components/TimelineChart/SyncTimelines/checkSelectionInRange.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
webapp/javascript/components/TimelineChart/SyncTimelines/useSync.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// import { areIntervalsOverlapping } from 'date-fns'; | ||
import { | ||
centerTimelineData, | ||
TimelineData, | ||
} from '@webapp/components/TimelineChart/centerTimelineData'; | ||
import { actions } from '@webapp/redux/reducers/continuous'; | ||
import { useAppDispatch } from '@webapp/redux/hooks'; | ||
import { markingsFromSelection, Selection } from '../markings'; | ||
|
||
type UseSyncParams = { | ||
timeline: TimelineData; | ||
selection: { | ||
left: { | ||
from: Selection['from']; | ||
to: Selection['to']; | ||
}; | ||
right: { | ||
from: Selection['from']; | ||
to: Selection['to']; | ||
}; | ||
}; | ||
}; | ||
|
||
export function useSync({ timeline, selection }: UseSyncParams) { | ||
const dispatch = useAppDispatch(); | ||
const centeredData = centerTimelineData(timeline); | ||
|
||
const leftSelectionMarkings = markingsFromSelection( | ||
'single', | ||
selection.left as Selection | ||
); | ||
const rightSelectionMarkings = markingsFromSelection( | ||
'single', | ||
selection.right as Selection | ||
); | ||
|
||
const timelineFrom = centeredData?.[0]?.[0]; | ||
const timelineTo = centeredData?.[centeredData?.length - 1]?.[0]; | ||
|
||
console.log('timelineFrom', timelineFrom); | ||
console.log('timelineTo', timelineTo); | ||
|
||
const leftSelectionFrom = leftSelectionMarkings?.[0]?.xaxis?.from; | ||
const leftSelectionTo = leftSelectionMarkings?.[0]?.xaxis?.to; | ||
|
||
const rightSelectionFrom = rightSelectionMarkings?.[0]?.xaxis?.from; | ||
const rightSelectionTo = rightSelectionMarkings?.[0]?.xaxis?.to; | ||
|
||
const fullRange = { | ||
start: new Date(timelineFrom), | ||
end: new Date(timelineTo), | ||
}; | ||
|
||
console.log('fullRange', fullRange); | ||
|
||
// const leftSelectionRange = { | ||
// start: new Date(leftSelectionFrom), | ||
// end: new Date(leftSelectionTo), | ||
// }; | ||
|
||
const selectionsLimits = [ | ||
leftSelectionFrom, | ||
leftSelectionTo, | ||
rightSelectionFrom, | ||
rightSelectionTo, | ||
]; | ||
|
||
const min = Math.min(...selectionsLimits); | ||
const max = Math.max(...selectionsLimits); | ||
|
||
// console.log('min', min); | ||
// console.log('max', max); | ||
|
||
const selectionRange = { | ||
start: new Date(min), | ||
end: new Date(max), | ||
}; | ||
|
||
console.log('selectionRange', selectionRange); | ||
|
||
// console.log('selectionRange', selectionRange); | ||
|
||
const isLeftOut = min + 5000 < timelineFrom; | ||
const isRightOut = max - 5000 > timelineTo; | ||
|
||
console.log('isLeftOut', isLeftOut); | ||
console.log('isRightOut', isRightOut); | ||
|
||
return { | ||
isSelectionInRange: !(isLeftOut || isRightOut), | ||
onSync: () => { | ||
dispatch( | ||
actions.setFromAndUntil({ | ||
from: String(min - 5000), | ||
until: String(max + 5000), | ||
}) | ||
); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters