Last active
February 1, 2017 22:51
-
-
Save dimaShin/7a5ca2c759b0cbafafb76d793ef26603 to your computer and use it in GitHub Desktop.
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
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