# how to make graphic timelines in mathematica

Hi does anyone know how to make timelines with mathematica?

http://images.nationmaster.com/images/motw/atlas_middle_east/turkey_timeline.jpg

something like that would be great! thanks

-
What have you tried so far? –  Mr.Wizard Jun 14 '12 at 13:15
@belisarius I think it's a reasonable task for Mathematica with some potentially interesting solutions. –  Mr.Wizard Jun 14 '12 at 13:17
This is clearly doable, and not very difficult, but it's a lot of work. It's much more likely that you'll get an answer if you first try to implement it on your own, show us what you have, and ask about the specific point you got stuck at. –  Szabolcs Jun 14 '12 at 13:34
In agreement with Szabolcs I would suggest you try out on your own first. Look up the documentation for Graphics, Line and Text, it's really just a task of combining these depending on your input list. –  jVincent Jun 14 '12 at 13:38
This presentation, Dynamic Timeline Plots, by Daniel G Martinez, may be of interest. –  TomD Jun 14 '12 at 14:40

I tried to do something similar a few months ago

The easiest way is to write several functions:

EventFrame function creates event lables

EventFrame[str_, {date_, height_}, OptionsPattern[FontSize -> 14]] :=
Graphics[{
Black, Thick, Line[{{date, height}, {date, 0}}],
Text[Framed[Style[str, FontSize -> OptionValue[FontSize]],
{Background -> White, FrameStyle -> Black,FrameMargins -> Automatic}], {date, height}]
}]


DateConv converts date {yr,mon,day} into single real number

Needs["Calendar"]
LeapYearQ[year_] := DateQ[{year, 2, 29}]
DateConv[y_, m_, d_]:=y+(DateDifference[{y},{y, m, d}]+1)/If[LeapYearQ[y], 366, 365]
DateConv[{y_, m_, d_}]:=y+(DateDifference[{y},{y, m, d}]+1)/If[LeapYearQ[y], 366, 365]


TimeLine function creates timeline

TimeLine[min_, max_] :=
Graphics[{
(* TimeLine *)
Black, Thick, Line[{{min, 0}, {max, 0}}],
(* year ticks *)
Thin, Table[Line[{{x, 0.5}, {x, 0}}], {x, min, max}],
(* year labels *)
Table[Text[Framed[Style[x, FontSize -> 20],
{Background -> White, FrameStyle -> White}], {x, 1}], {x, min, max}]
}]


Now all we need is a Show function. Use Pane for for easier viewing

Pane[Show[
EventFrame["Event 1", {DateConv[1988, 6, 2], 4}],
EventFrame["Event 2", {DateConv[1990, 8, 15], -2}],
(************************)
TimeLine[1985, 1995],
(************************)
AspectRatio -> 1/6, ImageSize -> {1400, 280}],
(************************)
ImageSize -> {550, 280}, Scrollbars -> {True, False}]


Output without Pane

Edit

EventFrame2 function

EventFrame2[str_, {date_, height_}, OptionsPattern[{FontSize -> 14, offsets -> {0, 0}}]] :=
Graphics[{
Thick,Line[{{date, height}, {date, 0}}],
Text[Framed[Style[Column@{Style[ToString[Floor[date]],
Bold,TextAlignment -> Left], str},
FontSize -> OptionValue[FontSize]],
{Background -> White, FrameStyle -> Black,FrameMargins -> Automatic}],
{date, height},OptionValue[offsets]]
} ]


Example

EventFrame2["Event 1", {DateConv[1988, 6, 2], 4}, offsets -> {-0.97, -0.5}]


-
Does this handle leap years? The division by 365 in DateConv makes me wonder. –  Verbeia Jun 14 '12 at 22:25
Thanks, I forgot about that. Added LeapYearQ function –  FDSg Jun 15 '12 at 0:43
Instead of DateConv[], you might consider the use of AbsoluteTime[]... –  Ｊ. Ｍ. Jun 17 '12 at 3:12
this is fantastic. some ideas i'm going to try to implement: tooltip for difference between dates, title and eventually tagging. my original idea was to have certain events with tags like : event 1 - green tag, red tag, yellow tag; event 2 - green tag; event 3 - red tag; when red tag is selected only events 1 and 2 are displayed. in that vein. will begin work and modifications tonight –  user582 Jun 19 '12 at 23:40
what exactly does the second DateConv[] function do? DateConv[{y_, m_, d_}]:=y+(DateDifference[{y},{y, m, d}]+1)/If[LeapYearQ[y], 366, 365]` –  user582 Jun 19 '12 at 23:53
show 1 more comment