This is a bit of a hard one for me to explain, but here goes...
I am storing calendar appointments in a database for multiple people and I need to draw these together in a group view programmatically..
I am drawing the appointments on a page where time is from top to bottom.. eg. 8am is up the top and 8pm is down the bottom...
I have no trouble in calculating the y positions, the issue comes with the x positions if there are multiple appointments at the same time... I am drawing a separate box for each appointment...
The issue is such, when two or more appointments overlap how do I calculate (a) the width of the appointment box, and (b) it's starting x position.
The calculations I am currently doing work in the following scenarios
1) there are no overlapping of appointment times
2) there is only one overlap
3) there are any number of overlaps, but if there are more than one, then the others also overlap with all the ones currently overlapping and not just one of them.
Basically what I am doing at the moment is as follows:
1) Calculate the number of appointments an appointment intersects with
2) Divide the width specified for a day by this number to determine the single width for an appointment.
3) Keep a count of which number this appointment is relative to all the intersections to determine its starting x position.
This works perfectly fine for any number of appointments and "a certain type of intersection"
To explain my problem better I have attached 3 pictures...
The first two are generated by my code, and the last one has been modified in paint on how i want it to work...
The first picture explains what I mean that it works the way I want if the intersecting appointments intersect with all the other appointments in the same "section".
The second picture explains the problem I am having when I introduce an appointment that only intersects with one other appointment that is part of the section of intersections... it throws off the width of the existing appointments, the width of the new appointment is wrong, and the x position of the new appointment is way off.. [the appointment is being drawn with not the width i want and two days off to the right.. this is the flaw with my algorithm :)]
The following picture has been modified by me in a paint program. This is how I want the second picture to look.
Basically I want to know if there are any algorithms out there that will calculate the correct position no matter the type of intersections...
Outlook 2007 does it quite well, so there must be a way :)