cal-layout: Calendar Layout Algorithm

[ bsd3, library, math, program ] [ Propose Tags ] [ Report a vulnerability ]

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


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2
Change log CHANGELOG.md
Dependencies base (>=4 && <5), cal-layout, containers (==0.5.11.0) [details]
License BSD-3-Clause
Copyright (c) 2019 Boro Sitnikovski
Author Boro Sitnikovski
Maintainer buritomath@gmail.com
Category Math
Home page https://github.com/bor0/cal-layout
Source repo head: git clone https://github.com/bor0/cal-layout
this: git clone https://github.com/bor0/cal-layout(tag 0.1.0.2)
Uploaded by bor0 at 2019-01-03T22:06:19Z
Distributions
Executables bookings-test
Downloads 1680 total (1 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-01-03 [all 1 reports]

Readme for cal-layout-0.1.0.2

[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})

Copyright 2019, Boro Sitnikovski. All rights reserved.