MyNixOS website logo
Description

Calendar Layout Algorithm.

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

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.

Metadata

Version

0.1.0.2

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows