Event stack is missing event when selecting time range
fspoettel opened this issue · comments
When selecting a date in the timeline, the event stack is missing an element. in below example, 8 events are (correctly) displayed on the map while 7 events are displayed in the stack.
Digging a bit into this, I noticed that there might be a problem with how the selection range is determined in the Layout
component. handleSelect
receives a selected event and then calls this.findEventIdx
which performs a binary search. In the example screenshot above, the selected
event has id 208
while the binary search returns id 176
. The pointer then starts one id below 176 which leads to 176 being ignored for this time range - yet showing up on the map.
handleSelect(selected, axis) {
if (selected.length <= 0) {
this.props.actions.updateSelected([]);
return;
}
const matchedEvents = [];
const TIMELINE_AXIS = 0;
if (axis === TIMELINE_AXIS) {
matchedEvents.push(selected);
// find in events
const { events } = this.props.domain;
const idx = this.findEventIdx(selected);
// check events before
let ptr = idx - 1;
while (
ptr >= 0 &&
events[idx].datetime.getTime() === events[ptr].datetime.getTime()
) {
if (events[ptr].id !== selected.id) {
matchedEvents.push(events[ptr]);
}
ptr -= 1;
}
// check events after
ptr = idx + 1;
while (
ptr < events.length &&
events[idx].datetime.getTime() === events[ptr].datetime.getTime()
) {
if (events[ptr].id !== selected.id) {
matchedEvents.push(events[ptr]);
}
ptr += 1;
}
} else {
// Map..
const std = { ...selected };
delete std.sources;
Object.values(std).forEach((ev) => matchedEvents.push(ev));
}
this.props.actions.updateSelected(matchedEvents);
}
Very nice catch, I have found the issue and will push a fix soon.