1/*==================================================
2 *  Create timeline functions
3 *==================================================
4 */
5var tl;
6
7function plugin_eventline() {
8
9    var theme = Timeline.ClassicTheme.create();
10    var filepath;
11
12    filepath = plugin_eventline_filePath;
13    bubbleH = plugin_eventline_bubbleHeight;
14    bubbleW = plugin_eventline_bubbleWidth;
15    mouse = plugin_eventline_mouse;
16    center = plugin_eventline_center;
17    controls = plugin_eventline_controls;
18    bandPos = plugin_eventline_bandPos;
19    detailPart = plugin_eventline_detailPercent;
20    overPart = plugin_eventline_overPercent;
21    detailPixels = plugin_eventline_detailPixels;
22    overPixels = plugin_eventline_overPixels;
23    detailInterval = plugin_eventline_detailInterval;
24    overInterval   = plugin_eventline_overInterval;
25
26    hotzone   = plugin_eventline_hotzone;
27    hzStart   = plugin_eventline_hzStart;
28    hzEnd     = plugin_eventline_hzEnd;
29    hzMagnify = plugin_eventline_hzMagnify;
30    hzUnit    = plugin_eventline_hzUnit;
31
32    hzStart2   = plugin_eventline_hzStart2;
33    hzEnd2     = plugin_eventline_hzEnd2;
34    hzMagnify2 = plugin_eventline_hzMagnify2;
35    hzUnit2    = plugin_eventline_hzUnit2;
36
37    hzStart3   = plugin_eventline_hzStart3;
38    hzEnd3     = plugin_eventline_hzEnd3;
39    hzMagnify3 = plugin_eventline_hzMagnify3;
40    hzUnit3    = plugin_eventline_hzUnit3;
41
42   theme.mousewheel = mouse;
43   theme.event.label.width = 500;
44   theme.event.bubble.width = bubbleW;
45   theme.event.bubble.maxHeight = bubbleH;
46
47  var eventSource = new Timeline.DefaultEventSource();
48
49  if (hotzone == 1)
50    var bandInfos = [
51     Timeline.createHotZoneBandInfo({
52        zones: [
53         { start:   hzStart,
54           end:     hzEnd,
55           magnify: hzMagnify,
56           unit:    convertTime(hzUnit)
57         },
58         { start:   hzStart2,
59           end:     hzEnd2,
60           magnify: hzMagnify2,
61           unit:    convertTime(hzUnit2)
62         },
63         { start:   hzStart3,
64           end:     hzEnd3,
65           magnify: hzMagnify3,
66           unit:    convertTime(hzUnit3)
67         }
68        ],
69        eventSource:    eventSource,
70        date:           center,
71        width:          detailPart,
72        intervalUnit:   convertTime(detailInterval),
73        intervalPixels: detailPixels,
74        theme: theme
75      }),
76      Timeline.createBandInfo({
77        overview:       true,
78        showEventText:  false,
79        trackHeight:    0.5,
80        trackGap:       0.2,
81        eventSource:    eventSource,
82        date:           center,
83        width:          overPart,
84        intervalUnit:   convertTime(overInterval),
85        intervalPixels: overPixels
86      })
87    ];
88  else
89
90  if (bandPos == 'default')
91    var bandInfos = [
92      Timeline.createBandInfo({
93        eventSource:    eventSource,
94        date:           "Mar 8 999 00:00:00 GMT",
95        width:          detailPart,
96        intervalUnit:   convertTime(detailInterval),
97        intervalPixels: detailPixels,
98        theme: theme
99      }),
100      Timeline.createBandInfo({
101        overview:       true,
102        showEventText:  false,
103        trackHeight:    0.5,
104        trackGap:       0.2,
105        eventSource:    eventSource,
106        date:           "Mar 8 999 00:00:00 GMT",
107        width:          overPart,
108        intervalUnit:   convertTime(overInterval),
109        intervalPixels: overPixels
110      })
111    ];
112  else
113    var bandInfos = [
114      Timeline.createBandInfo({
115        overview:       true,
116        showEventText:  false,
117        trackHeight:    0.5,
118        trackGap:       0.2,
119        eventSource:    eventSource,
120        date:           "Mar 8 999 00:00:00 GMT",
121        width:          overPart,
122        intervalUnit:   convertTime(overInterval),
123        intervalPixels: overPixels
124      }),
125      Timeline.createBandInfo({
126        eventSource:    eventSource,
127        date:           "Mar 8 999 00:00:00 GMT",
128        width:          detailPart,
129        intervalUnit:   convertTime(detailInterval),
130        intervalPixels: detailPixels,
131        theme: theme
132      })
133    ];
134
135  bandInfos[1].syncWith = 0;
136  bandInfos[1].highlight = true;
137  bandInfos[1].eventPainter.Layout=bandInfos[0].eventPainter.Layout;
138
139  tl = Timeline.create(document.getElementById("eventlineplugin__timeline"), bandInfos, Timeline.HORIZONTAL);
140  Timeline.loadXML(filepath, function(xml, url) { eventSource.loadXML(xml, url); });
141  if (controls==1) setupFilterHighlightControls(document.getElementById("eventlineplugin__controls"), tl, [0,1], theme);
142  javascript:centerTimeline(center);
143}
144
145function centerTimeline(dateStr) {
146    tl.getBand(0).setCenterVisibleDate(new Date(dateStr));
147}
148
149var resizeTimerID = null;
150function plugin_eventline_onResize() {
151    if (resizeTimerID == null) {
152        resizeTimerID = window.setTimeout(function() {
153            resizeTimerID = null;
154            tl.layout();
155        }, 500);
156    }
157}
158
159function convertTime (timeframe) {
160    var result;
161      switch (timeframe) {
162          case 'MILLISECOND':
163            result=Timeline.DateTime.MILLISECOND;
164            break;
165          case 'SECOND':
166            result=Timeline.DateTime.SECOND;
167            break;
168          case 'MINUTE':
169            result=Timeline.DateTime.MINUTE;
170            break;
171          case 'HOUR':
172            result=Timeline.DateTime.HOUR;
173            break;
174          case 'DAY':
175            result=Timeline.DateTime.DAY;
176            break;
177          case 'WEEK':
178            result=Timeline.DateTime.WEEK;
179            break;
180          case 'MONTH':
181            result=Timeline.DateTime.MONTH;
182            break;
183          case 'YEAR':
184            result=Timeline.DateTime.YEAR;
185            break;
186          case 'DECADE':
187            result=Timeline.DateTime.DECADE;
188            break;
189          case 'CENTURY':
190            result=Timeline.DateTime.CENTURY;
191            break;
192          case 'MILLENNIUM':
193            result=Timeline.DateTime.MILLENNIUM;
194            break;
195          case 'EPOCH':
196            result=Timeline.DateTime.EPOCH;
197            break;
198          case 'ERA':
199            result=Timeline.DateTime.ERA;
200            break;
201          default:
202            result=Timeline.DateTime.YEAR;
203       }
204       return result;
205}
206