Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
5  
What have you tried so far? –  Mr.Wizard Jun 14 '12 at 13:15
3  
@belisarius I think it's a reasonable task for Mathematica with some potentially interesting solutions. –  Mr.Wizard Jun 14 '12 at 13:17
3  
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
3  
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
3  
This presentation, Dynamic Timeline Plots, by Daniel G Martinez, may be of interest. –  TomD Jun 14 '12 at 14:40

1 Answer 1

up vote 11 down vote accepted

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 enter image description here

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}]

enter image description here

share|improve this answer
1  
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
1  
Instead of DateConv[], you might consider the use of AbsoluteTime[]... –  J. M. 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.