ongyiren1994 / mermaid-hs

MIT License
5 stars 2 forks source link

Parse gantt chart #5

Open srid opened 3 years ago

srid commented 3 years ago

https://mermaid-js.github.io/mermaid/#/gantt?id=syntax

Add support for mermaid's gantt format.

This is something I actually have an usecase for The book Deep Work talks about scheduling one's day ahead in terms of 'blocks', and I currently do this using mermaid-js in Emanote. It'd be great to write a CLI program that parses this diagram, so I can display the 'current' block in KDE desktop, as well send a reminder if that 'active' block reaches the end of its time (reminding me to adjust the gantt chart).
srid commented 3 years ago

It should not fail to parse this format:

gantt
    title Today's Plan
    dateFormat  HH:mm
    axisFormat %H:%M

    section Hacking
    TT Mermaid     : done, mm, 11:00, 38m
    TT Finish : active, tt, after mm, 2h
    Emanote concurrent load : after tt, 2h

    section Reading
    Deep Work      :crit, after bell  , 1h
    Mailbrew      :20:30, 1h

    section Errands
    Family call :done, 10:30, 45m
    Bell installation : bell, 12:00, 5h
    Eat :18:00, 1h
srid commented 3 years ago

What datastructure to use?

The data structure should be designed such that it should be possible to write code to query blocks by time interval. I suppose that means that at minimum it should have a notion of 'time interval' - which, in a naive way, can be implemented as "start" and "end" LocalTime or "start" and "duration" (LocalTime & NominalDiffTime), depending on how the user specifies it.

EDIT: Or maybe we should just map the syntax to type 1-on-1, and avoid calculating time duration based on after dependencies. And let the library user worry about that all. This would simplify our implementation. Okay, let's do that.

srid commented 3 years ago

It would also be good to maintain the order of blocks, so that when we serialize the data structure back to the original string syntax, it will be more or less the same (except for whitespace difference, I guess) to the parsed string.

Also, for version 1, we can assume that all diagrams will use the following date format:

    dateFormat  HH:mm