Skip to content

Instantly share code, notes, and snippets.

@dimaShin
Last active February 1, 2017 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimaShin/7a5ca2c759b0cbafafb76d793ef26603 to your computer and use it in GitHub Desktop.
Save dimaShin/7a5ca2c759b0cbafafb76d793ef26603 to your computer and use it in GitHub Desktop.
static calculateEventsWidth(groupedEvents) {
groupedEvents.forEach((group: EventModel[]) => {
const interactions = [];
let topRange = group[0].data.end;
let currentInteractionStart = 0;
let currentInteractionCount = 0;
group.forEach((event: EventModel, idx: number) => {
let nextEvent = group[idx +1];
if (!nextEvent) {
return;
}
if (topRange > nextEvent.data.start) {
currentInteractionCount++;
if (nextEvent.data.end > topRange) {
topRange = nextEvent.data.end;
}
for (let i = currentInteractionStart; i <= idx + 1; i++) {
interactions[i] = {
count: currentInteractionCount,
offset: i - currentInteractionStart
}
}
} else {
currentInteractionStart = idx+1;
topRange = group[idx + 1].data.end;
currentInteractionCount = 0;
}
});
interactions.forEach((value, idx) => {
group[idx].interactions = value;
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment