# cal-layout: Calendar Layout Algorithm

[ bsd3, library, math, program ] [ Propose Tags ]

This project demonstrates calculation of dimensions and positions for a list of events in a given calendar.

Versions [faq] 0.1.0.0, 0.1.0.1, 0.1.0.2 CHANGELOG.md base (==4.*), cal-layout, containers (==0.5.11.0) [details] BSD-3-Clause (c) 2019 Boro Sitnikovski Boro Sitnikovski buritomath@gmail.com Math https://github.com/bor0/cal-layout head: git clone https://github.com/bor0/cal-layoutthis: git clone https://github.com/bor0/cal-layout(tag 0.1.0.2) by bor0 at Thu Jan 3 22:06:19 UTC 2019 NixOS:0.1.0.2 bookings-test 788 total (89 in the last 30 days) (no votes yet) [estimated by Bayesian average] λ λ λ Docs available Last success reported on 2019-01-03

## Modules

[Index] [Quick Jump]

#### Maintainer's Corner

For package maintainers and hackage trustees

[back to package description]

# Calendar Layout Algorithm

This algorithm will calculate top, left, width and height for each event from a list of events so that they can be drawn on a canvas such that none of them overlap visually.

## Algorithm

The most complex bit in the algorithm is CalLayout.insertEventTree and CalLayout.insertEventForest, which, inserts an event into a tree or forest such that every parent overlaps the children. Afterwards given a list of events, CalLayout.mkIntersectionsForest will convert them to a forest by using the two functions above. This will produce a similar forest to:

> putStr $drawForest$ map (fmap show) forest
"P&P Leg Training"
|
- "Gym Tour"

"12 days of Christmas workout"

"12 days of Christmas workout"
|
- "12 days of Christmas workout"


Now that we have this structure, we need to calculate the depth and maxDepth of each node. CalLayout.populateDepths does exactly that. Viewed as a forest, it looks something like:

("P&P Leg Training", 1, 1)
|
- ("Gym Tour", 1, 0)

("12 days of Christmas workout", 0, 0)

("12 days of Christmas workout", 1, 1)
|
- ("12 days of Christmas workout", 1, 0)


Once we have this data, calculations are straight-forward:

top    = start e
left   = width * depth
width  = 100 / (1 + maxDepth)
height = end e - start e


As we can see, all this calculation is just for figuring out left and width, whereas top and height were easy.

## Prerequisites

Make sure you have stack installed.

## Running

1. Run stack init
2. Run stack run

For playground, you can use stack repl.

Example:

\$ stack run
("P&P Leg Training",Dimension {top = 600.0, left = 50.0, width = 50.0, height = 60.0})
("Gym Tour",Dimension {top = 600.0, left = 0.0, width = 50.0, height = 15.0})
("12 days of Christmas workout",Dimension {top = 720.0, left = 0.0, width = 100.0, height = 120.0})
("12 days of Christmas workout",Dimension {top = 840.0, left = 50.0, width = 50.0, height = 360.0})
("12 days of Christmas workout",Dimension {top = 1020.0, left = 0.0, width = 50.0, height = 120.0})