I found this question where someone put some code to graphic a timeline based on a certain number of events. In that code in particular, the events are hard coded one by one, I want to modify it, so it can get the events from an array. This is the link to that question:
how to make graphic timelines in mathematica
What I have is an array of events, like so:
{{0,arrival ,1,1},{0.35749,departure ,1},{6,arrival ,2,3}}
Where the first position is the time of the event, the second position stores the type of the event (arrival or departure) and the other fields are not necessary in the graphic.
I'll post the code from the link so it is easier for you to look at it, as I said, it creates the graphic, but the events don't come from an array. This block of code creates the event frames:
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}]
}]
This creates the graphic for the 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}]
}]
And this wraps all of the above, here is where the events are hardcoded
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}]
I won't use the function that converts the date because my events are based on seconds, not by dates.
I tried using a for loop within the last block of code, instead of creating the events individually, but it doesn't give the Show function a proper argument, like this:
For[i = 1, i < Length[events],
EventFrame[events[[i]][[2]],{events[[i]][[1]], -1}]
, i++]
What would be the best approach to accomplish this? Thanks!