author | veltr |
Wed, 04 Jul 2012 16:13:49 +0200 | |
changeset 73 | 642ef9139fad |
parent 72 | a000f6a29dfa |
child 74 | e107c77600e8 |
permissions | -rw-r--r-- |
65 | 1 |
/* |
2 |
* Main Timeline code |
|
3 |
*/ |
|
4 |
||
5 |
window.Tlns = { |
|
6 |
Utils : {}, |
|
7 |
Defaults : {}, |
|
8 |
Templates : {}, |
|
9 |
Classes : {} |
|
10 |
}; |
|
11 |
||
12 |
/* Utility Functions */ |
|
13 |
||
14 |
Tlns.Utils.SetDefaults = function(_object, _defaults, _options) { |
|
15 |
var _options = _options || {}; |
|
16 |
_(_defaults).each(function(_v, _k) { |
|
17 |
if(/^m(in|ax)_/.test(_k)) { |
|
18 |
var _tab = _k.split('_') |
|
19 |
if( typeof _object[_tab[1]] !== "undefined") { |
|
20 |
var _fn = (_tab[0] === "min" ? Math.max : Math.min); |
|
21 |
_object[_tab[1]] = _fn(_object[_tab[1]], _v); |
|
22 |
} |
|
23 |
} else { |
|
24 |
if( typeof _options[_k] !== "undefined") { |
|
25 |
_object[_k] = _options[_k]; |
|
26 |
} else { |
|
27 |
_object[_k] = _v; |
|
28 |
} |
|
29 |
} |
|
30 |
}); |
|
31 |
} |
|
32 |
||
33 |
Tlns.Utils.dateFormat = function(_date, _template) { |
|
34 |
if (typeof _data !== "object") { |
|
35 |
_date = new Date(_date); |
|
36 |
} |
|
37 |
function zeroPad(_n) { |
|
38 |
return (_n < 10 ? "0" : "") + _n |
|
39 |
} |
|
40 |
var _params = { |
|
41 |
hours: _date.getHours(), |
|
42 |
"0hours": zeroPad(_date.getHours()), |
|
43 |
minutes: _date.getMinutes(), |
|
44 |
"0minutes": zeroPad(_date.getMinutes()), |
|
45 |
seconds: _date.getSeconds(), |
|
46 |
"0seconds": zeroPad(_date.getSeconds()), |
|
47 |
dayOfWeek: ["dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi"][_date.getDay()], |
|
48 |
shortDayOfWeek: ["Dim","Lun","Mar","Mer","Jeu","Ven","Sam"][_date.getDay()], |
|
49 |
dayOfMonth: _date.getDate(), |
|
50 |
"0dayOfMonth": zeroPad(_date.getDate()), |
|
51 |
monthNumber: 1+_date.getMonth(), |
|
52 |
"0monthNumber": zeroPad(1+_date.getMonth()), |
|
53 |
monthName: ["janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre"][_date.getMonth()], |
|
54 |
shortMonthName: ["jan","fev","mar","avr","mai","jun","jul","aou","sep","oct","nov","dec"][_date.getMonth()], |
|
55 |
year: _date.getFullYear() |
|
56 |
} |
|
57 |
return Mustache.to_html(_template, _params); |
|
58 |
} |
|
59 |
||
71 | 60 |
Tlns.Utils.guid = function() { |
61 |
return 'xxxx-xxxx-xxxx-xxxx'.replace(/x/g,function() { |
|
62 |
return Math.floor(Math.random()*16).toString(16); |
|
63 |
}); |
|
64 |
} |
|
65 |
||
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
66 |
Tlns.Utils.drawArrow = function(_ctx, _color, _x1, _y1, _x2, _y2) { |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
67 |
_ctx.strokeStyle = _color; |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
68 |
_ctx.fillStyle = _color; |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
69 |
_ctx.beginPath(); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
70 |
_ctx.moveTo(_x1,_y1); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
71 |
_ctx.lineTo(_x2,_y2); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
72 |
_ctx.stroke(); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
73 |
var _mod = Math.sqrt(Math.pow(_x2 - _x1, 2) + Math.pow(_y2 - _y1, 2)), |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
74 |
_xu = (_x2 - _x1) / _mod, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
75 |
_yu = (_y2 - _y1) / _mod, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
76 |
_xm = (_x1 + _x2) / 2, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
77 |
_ym = (_y1 + _y2) / 2, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
78 |
_arrowWidth = 4, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
79 |
_arrowLength = 8, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
80 |
_x3 = _xm - _arrowLength * _xu + _arrowWidth * _yu, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
81 |
_y3 = _ym - _arrowLength * _yu - _arrowWidth * _xu, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
82 |
_x4 = _xm - _arrowLength * _xu - _arrowWidth * _yu, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
83 |
_y4 = _ym - _arrowLength * _yu + _arrowWidth * _xu; |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
84 |
_ctx.beginPath(); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
85 |
_ctx.moveTo(_x3, _y3); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
86 |
_ctx.lineTo(_xm, _ym); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
87 |
_ctx.lineTo(_x4, _y4); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
88 |
_ctx.fill(); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
89 |
_ctx.stroke(); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
90 |
} |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
91 |
|
65 | 92 |
/* Defaults */ |
93 |
||
94 |
Tlns.Defaults.Timeline = { |
|
95 |
container : "timeline", |
|
96 |
width : 950, |
|
97 |
height : 200, |
|
98 |
url_univers : '', |
|
99 |
min_width : 400, |
|
100 |
min_height : 100, |
|
101 |
main_width : 800, |
|
102 |
timescales : [{ |
|
103 |
label : "Mois", |
|
104 |
span : 32 * 86400 * 1000, |
|
105 |
grid_interval : 5 * 86400 * 1000, |
|
106 |
grid_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
107 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
108 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}} {{year}}' |
|
109 |
}, { |
|
110 |
label : "Semaine", |
|
111 |
span : 8 * 86400 * 1000, |
|
112 |
grid_interval : 86400 * 1000, |
|
113 |
grid_date_format : '{{shortDayOfWeek}} {{0dayOfMonth}}/{{0monthNumber}}', |
|
114 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
115 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}}' |
|
116 |
}, { |
|
117 |
label : "2 jours", |
|
118 |
span : 2 * 86400 * 1000, |
|
119 |
grid_interval : 8 * 3600 * 1000, |
|
120 |
grid_date_format : '{{shortDayOfWeek}} {{0dayOfMonth}}/{{0monthNumber}} {{hours}}h', |
|
121 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
122 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}}' |
|
123 |
}, { |
|
124 |
label : "Demi-Journée", |
|
125 |
span : 12 * 3600 * 1000, |
|
126 |
grid_interval : 2 * 3600 * 1000, |
|
127 |
grid_date_format : '{{hours}}h', |
|
128 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}} {{hours}}h', |
|
129 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}} {{hours}}h' |
|
130 |
}, { |
|
131 |
label : "3 Heures", |
|
132 |
span : 3 * 3600 * 1000, |
|
133 |
grid_interval : 30 * 60 * 1000, |
|
134 |
grid_date_format : '{{0hours}}:{{0minutes}}', |
|
135 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}} {{0hours}}:{{0minutes}}', |
|
136 |
end_date_format : '{{0hours}}:{{0minutes}}' |
|
137 |
}, { |
|
138 |
label : "1 Heure", |
|
66 | 139 |
span : 60 * 60 * 1000, |
65 | 140 |
grid_interval : 15 * 60 * 1000, |
141 |
grid_date_format : '{{0hours}}:{{0minutes}}', |
|
142 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}} {{0hours}}:{{0minutes}}', |
|
143 |
end_date_format : '{{0hours}}:{{0minutes}}' |
|
144 |
}], |
|
145 |
level: 0, |
|
146 |
central_time: 0, |
|
147 |
sync_now: true, |
|
148 |
url_occurrences: '', |
|
66 | 149 |
occurrences: [], |
70 | 150 |
cluster_spacing: 10, |
151 |
tooltip_date_format: '{{dayOfMonth}} {{shortMonthName}} {{year}} {{0hours}}:{{0minutes}}' |
|
65 | 152 |
} |
153 |
||
154 |
for (var _i = 0; _i < Tlns.Defaults.Timeline.timescales.length; _i++) { |
|
155 |
Tlns.Defaults.Timeline.timescales[_i].level = _i; |
|
156 |
} |
|
157 |
||
158 |
/* Templates */ |
|
159 |
||
160 |
Tlns.Templates.Timeline = '<div class="Tl-TopBar"><div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-AddButton"></div></div><div class="Tl-TopBar-Spacer Tl-Border-Right"></div>' |
|
161 |
+ '<div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-PreviousButton"></div></div><div class="Tl-TopBar-TimeSpan Tl-TopBar-TextBtn Tl-Border-Right">--/--</div>' |
|
162 |
+ '<div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-SyncButton"></div></div><div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-NextButton"></div></div><div class="Tl-TopBar-Spacer Tl-Border-Right"></div>' |
|
163 |
+ '<div class="Tl-TopBar-Timescales">{{#timescales}}<div class="Tl-TopBar-Button Tl-TopBar-TextBtn Tl-Border-Right" data-level="{{level}}">{{label}}</div>{{/timescales}}</div></div>' |
|
71 | 164 |
+ '<div class="Tl-BottomPart"><ul class="Tl-UniversLabels"></ul>' |
165 |
+ '<div class="Tl-MainPart"><div class="Tl-Layer Tl-Grid"></div><canvas class="Tl-Layer Tl-Canvas"></canvas><canvas class="Tl-Layer Tl-Linking-Canvas"></canvas><div class="Tl-Layer Tl-Occurrences"></div>' |
|
166 |
+ '<ul class="Tl-Adding"><li class="Tl-AddingTitle">Ajout d\'une occurrence</li><li><span>Narrative</span><div class="Tl-AddOccurrence Tl-Occnarrative" occurrence-type="narrative" title="Glisser sur la frise chronologique pour ajouter"></div></li>' |
|
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
167 |
+ '<li><span>De Publication</span><div class="Tl-AddOccurrence Tl-Occpublication" occurrence-type="publication" title="Glisser sur la frise chronologique pour ajouter"></div></li></ul></div>' |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
168 |
+ '<div class="Tl-Overlay-Container"><div class="Tl-Overlay-Box"><div class="Tl-Overlay"><div class="Tl-Overlay-Tip-Top"></div><div class="Tl-Overlay-Main"></div><div class="Tl-Overlay-Tip-Bottom"></div></div></div></div></div>'; |
65 | 169 |
|
66 | 170 |
Tlns.Templates.Univers = '<span class="Tl-UniversText">{{title}}</span>'; |
171 |
||
70 | 172 |
Tlns.Templates.Occurrence = '{{#clusters}}<div class="Tl-Cluster Tl-Occ{{type}}" style="left: {{x}}px; top: {{y}}px;" cluster-contents="{{contents}}">' |
173 |
+ '<div class="Tl-ClusterCount">{{occurrences.length}}</div></div>{{/clusters}}' |
|
72 | 174 |
+ '{{#occurrences}}<div class="Tl-Occurrence Tl-OccOnGrid Tl-Occ{{type}}{{#editing}} Tl-Editing{{/editing}}" occurrence-id="{{id}}" style="left: {{x}}px; top: {{y}}px;">' |
70 | 175 |
+ '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}<div class="Tl-Link"{{#editing}} style="display: block"{{/editing}}></div></div>{{/occurrences}}{{#open_cluster}}<div class="Tl-ClusterOverlay" style="left: {{x}}px; top: {{y}}px;">' |
72 | 176 |
+ '{{#occurrences}}<div class="Tl-Occurrence Tl-OccInCluster Tl-Occ{{type}}{{#editing}} Tl-Editing{{/editing}}" occurrence-id="{{id}}">' |
70 | 177 |
+ '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}<div class="Tl-Link"{{#editing}} style="display: block"{{/editing}}></div></div>{{/occurrences}}</div>{{/open_cluster}}'; |
178 |
|
|
179 |
Tlns.Templates.OccurrenceTooltip = '<h3 class="Tl-Tooltip-Title">{{title}}</h3><p class="Tl-Tooltip-Date">{{formatted_date}}</p>' |
|
180 |
+ '<p class="Tl-Tooltip-Description">{{description}}</p><p class="Tl-Tooltip-Characters">{{univers.mainCharacter}}{{#characters}}, {{.}}{{/characters}}</p>' |
|
65 | 181 |
|
182 |
/* Classes */ |
|
183 |
||
184 |
Tlns.Classes.Timeline = function(_options) { |
|
185 |
||
186 |
/* Setting Defaults */ |
|
187 |
Tlns.Utils.SetDefaults(this, Tlns.Defaults.Timeline, _options); |
|
188 |
||
189 |
/* Setting container CSS */ |
|
190 |
this.$ = $('#' + this.container); |
|
191 |
this.$.addClass('Tl-Main'); |
|
192 |
this.$.css({ |
|
193 |
width : this.width + "px", |
|
194 |
height : this.height + "px" |
|
195 |
}); |
|
196 |
this.$.html(Mustache.to_html(Tlns.Templates.Timeline, this)); |
|
197 |
|
|
198 |
this.main_height = this.height - this.$.find('.Tl-TopBar').outerHeight(); |
|
199 |
this.$.find('.Tl-BottomPart').css("height", this.main_height + "px"); |
|
200 |
this.$.find('.Tl-MainPart').css("width", this.main_width + "px"); |
|
67 | 201 |
this.$.find('.Tl-Overlay-Container').css("left", (this.$.find('.Tl-BottomPart').outerWidth() - this.main_width) + "px"); |
70 | 202 |
this.$.find('canvas.Tl-Layer').attr({ |
67 | 203 |
width: this.main_width, |
204 |
height: this.main_height |
|
205 |
}); |
|
65 | 206 |
var _o = this.$.find('.Tl-MainPart').offset(); |
207 |
this.dragging_bounds = { |
|
208 |
left: _o.left, |
|
209 |
top: _o.top, |
|
210 |
right: _o.left + this.$.find('.Tl-MainPart').outerWidth(), |
|
211 |
bottom: _o.top + this.$.find('.Tl-MainPart').outerHeight(), |
|
212 |
}; |
|
213 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
214 |
var _this = this; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
215 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
216 |
this.throttledDrawGrid = _.throttle(function() { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
217 |
_this.drawGrid(); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
218 |
}, 150); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
219 |
|
65 | 220 |
this.setLevel(this.level); |
221 |
|
|
222 |
this.$.find('.Tl-TopBar-Timescales>div').click(function() { |
|
223 |
_this.setLevel($(this).attr("data-level")); |
|
224 |
}); |
|
225 |
|
|
226 |
this.$.find('.Tl-TopBar-SyncButton').click(function() { |
|
227 |
_this.sync_now = !_this.sync_now; |
|
228 |
_this.drawGrid(); |
|
229 |
}) |
|
230 |
|
|
231 |
this.$.find('.Tl-TopBar-PreviousButton').click(function() { |
|
232 |
_this.offsetTime(-_this.timescales[_this.level].span / 4); |
|
233 |
}); |
|
234 |
|
|
235 |
this.$.find('.Tl-TopBar-NextButton').click(function() { |
|
236 |
_this.offsetTime(_this.timescales[_this.level].span / 4); |
|
237 |
}); |
|
238 |
|
|
239 |
this.$.find('.Tl-MainPart').mousedown(function(_event) { |
|
240 |
_this.onMouseDown(_event); |
|
241 |
return false; |
|
242 |
}); |
|
243 |
|
|
244 |
this.$.find('.Tl-MainPart').mousemove(function(_event) { |
|
245 |
_this.onMouseMove(_event); |
|
246 |
return false; |
|
247 |
}); |
|
248 |
|
|
249 |
this.$.find('.Tl-MainPart').mouseup(function(_event) { |
|
250 |
_this.onMouseUp(_event); |
|
251 |
return false; |
|
252 |
}); |
|
253 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
254 |
this.$.find('.Tl-MainPart').mousewheel(function(_event, _delta) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
255 |
var _newLevel = Math.max(0,Math.min(_this.timescales.length-1, (_delta < 0 ? -1 : 1) + parseInt(_this.level))); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
256 |
if (_newLevel != _this.level) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
257 |
_this.hideTooltip(); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
258 |
var _deltaX = _event.pageX - _this.dragging_bounds.left, |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
259 |
_tAtMouse = _this.timeFromMouse(_event.pageX), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
260 |
_newScale = _this.main_width / (_this.timescales[_newLevel].span), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
261 |
_newStart = _tAtMouse - _deltaX / _newScale; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
262 |
_this.central_time = _newStart + _this.timescales[_newLevel].span / 2; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
263 |
_this.setLevel(_newLevel); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
264 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
265 |
return false; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
266 |
}); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
267 |
|
66 | 268 |
this.$.find('.Tl-Overlay-Box').mouseover(function(_event) { |
269 |
$(this).show(); |
|
270 |
}).mouseout(function(_event) { |
|
271 |
$(this).hide(); |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
272 |
}); |
65 | 273 |
|
71 | 274 |
this.$.find('.Tl-TopBar-AddButton').click(function() { |
275 |
$(this).toggleClass('active'); |
|
276 |
_this.$.find('.Tl-Adding').toggle(); |
|
277 |
}); |
|
278 |
|
|
279 |
this.$.find('.Tl-AddOccurrence').mousedown(function(_event) { |
|
280 |
var _el = $(this), |
|
281 |
_type = _el.attr("occurrence-type"), |
|
282 |
_d = _this.timeFromMouse(_event.pageX), |
|
283 |
_u = _this.universFromMouse(_event.pageY), |
|
284 |
_occ = _this.createOrUpdateOccurrence( |
|
285 |
_type, |
|
286 |
{ |
|
287 |
date: _d, |
|
288 |
titre: '<Nouvelle occurrence>', |
|
289 |
univers: _this.univers[_u].id, |
|
290 |
publie: true |
|
291 |
} |
|
292 |
); |
|
293 |
_occ.just_created = true; |
|
294 |
_occ.editing = true; |
|
295 |
_this.editing_occurrence = _occ; |
|
296 |
_this.dragging_type = "occurrence"; |
|
297 |
window.setTimeout(function () { |
|
298 |
_this.$.find('.Tl-TopBar-AddButton').removeClass('active'); |
|
299 |
_this.$.find('.Tl-Adding').hide(); |
|
300 |
}, 200); |
|
301 |
_this.throttledDrawGrid(); |
|
302 |
}).mouseup(function(_event) { |
|
303 |
_this.onMouseUp(_event); |
|
304 |
return false; |
|
305 |
}); |
|
306 |
|
|
65 | 307 |
/* Loading Univers */ |
308 |
$.getJSON(this.url_univers, function(_data) { |
|
309 |
_this.onUniversLoaded(_data); |
|
310 |
}); |
|
311 |
} |
|
312 |
||
313 |
Tlns.Classes.Timeline.prototype.onMouseDown = function(_event) { |
|
314 |
this.mouse_down = true; |
|
315 |
this.is_dragging = false; |
|
316 |
this.start_pos = { |
|
317 |
x: _event.pageX, |
|
318 |
y: _event.pageY |
|
319 |
}; |
|
66 | 320 |
if (typeof this.dragging_type === "undefined") { |
67 | 321 |
this.time_at_start = this.central_time; |
66 | 322 |
this.dragging_type = "timeline"; |
65 | 323 |
} |
324 |
} |
|
325 |
||
326 |
Tlns.Classes.Timeline.prototype.onMouseUp = function(_event) { |
|
67 | 327 |
if (this.is_dragging) { |
328 |
switch (this.dragging_type) { |
|
329 |
case "occurrence": |
|
330 |
this.editing_occurrence.editing = false; |
|
71 | 331 |
this.editing_occurrence.just_created = false; |
67 | 332 |
this.throttledDrawGrid(); |
333 |
break; |
|
70 | 334 |
case "link": |
335 |
this.editing_occurrence.editing = false; |
|
336 |
this.throttledDrawGrid(); |
|
337 |
var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
338 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
339 |
break; |
|
67 | 340 |
} |
71 | 341 |
} else { |
342 |
if (this.dragging_type == "occurrence" && this.editing_occurrence.just_created) { |
|
343 |
this.deleteOccurrence(this.editing_occurrence.type, this.editing_occurrence.id); |
|
344 |
this.throttledDrawGrid(); |
|
345 |
} |
|
67 | 346 |
} |
65 | 347 |
this.mouse_down = false; |
348 |
this.is_dragging = false; |
|
66 | 349 |
this.dragging_type = undefined; |
65 | 350 |
} |
351 |
||
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
352 |
Tlns.Classes.Timeline.prototype.timeFromX = function(_x) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
353 |
return Math.max(this.start_time,Math.min(this.end_time, this.start_time + _x / this.current_scale)); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
354 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
355 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
356 |
Tlns.Classes.Timeline.prototype.timeFromMouse = function(_pageX) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
357 |
return this.timeFromX(_pageX - this.dragging_bounds.left); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
358 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
359 |
|
71 | 360 |
Tlns.Classes.Timeline.prototype.universFromY = function(_y) { |
361 |
return Math.max(0,Math.min(this.univers.length, Math.floor(_y / this.univers_height))) |
|
362 |
} |
|
363 |
||
364 |
Tlns.Classes.Timeline.prototype.universFromMouse = function(_pageY) { |
|
365 |
return this.universFromY(_pageY - this.dragging_bounds.top); |
|
366 |
} |
|
367 |
||
65 | 368 |
Tlns.Classes.Timeline.prototype.onMouseMove = function(_event) { |
369 |
if (this.mouse_down) { |
|
370 |
this.is_dragging = true; |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
371 |
this.hideTooltip(); |
69 | 372 |
switch (this.dragging_type) { |
373 |
case "occurrence": |
|
374 |
var _d = this.timeFromMouse(_event.pageX); |
|
375 |
this.editing_occurrence.date = _d; |
|
71 | 376 |
var _u = this.universFromMouse(_event.pageY); |
69 | 377 |
this.editing_occurrence.univers = this.univers[_u]; |
378 |
this.editing_occurrence.univers_id = this.univers[_u].id; |
|
379 |
this.throttledDrawGrid(); |
|
380 |
break; |
|
381 |
case "timeline": |
|
382 |
this.setTime(this.time_at_start + Math.floor(( this.start_pos.x - _event.pageX ) / this.current_scale)); |
|
383 |
break; |
|
70 | 384 |
case "link": |
385 |
var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
386 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
387 |
Tlns.Utils.drawArrow( |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
388 |
_ctx, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
389 |
'#800080', |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
390 |
this.editing_occurrence.x, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
391 |
this.editing_occurrence.y + Math.floor(this.univers_height / 2), |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
392 |
_event.pageX - this.dragging_bounds.left, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
393 |
_event.pageY - this.dragging_bounds.top |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
394 |
); |
70 | 395 |
break; |
65 | 396 |
} |
397 |
} |
|
398 |
} |
|
399 |
||
400 |
Tlns.Classes.Timeline.prototype.onUniversLoaded = function(_data) { |
|
401 |
this.univers = []; |
|
402 |
if(_data.length) { |
|
403 |
this.univers_height = Math.floor(this.main_height / _data.length); |
|
404 |
} |
|
405 |
for(var _i = 0; _i < _data.length; _i++) { |
|
406 |
this.univers.push(new Tlns.Classes.Univers(_data[_i], this, _i)); |
|
407 |
} |
|
66 | 408 |
this.loadOccurrences(); |
65 | 409 |
} |
410 |
||
411 |
Tlns.Classes.Timeline.prototype.offsetTime = function(_timeOffset) { |
|
412 |
this.setTime(this.central_time + _timeOffset); |
|
413 |
} |
|
414 |
||
415 |
Tlns.Classes.Timeline.prototype.setTime = function(_centralTime) { |
|
416 |
this.sync_now = false; |
|
417 |
this.central_time = _centralTime; |
|
67 | 418 |
this.throttledDrawGrid(); |
65 | 419 |
} |
420 |
||
421 |
Tlns.Classes.Timeline.prototype.setLevel = function(_level) { |
|
422 |
if (_level >= 0 && _level < this.timescales.length) { |
|
423 |
this.$.find('.Tl-TopBar-Timescales>div').each(function() { |
|
424 |
var _el = $(this); |
|
425 |
if (_el.attr("data-level") == _level) { |
|
426 |
_el.addClass("active"); |
|
427 |
} else { |
|
428 |
_el.removeClass("active"); |
|
429 |
} |
|
430 |
}); |
|
431 |
this.level = _level; |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
432 |
this.throttledDrawGrid(); |
65 | 433 |
} |
434 |
} |
|
435 |
||
436 |
Tlns.Classes.Timeline.prototype.drawGrid = function() { |
|
437 |
var _now = new Date().valueOf(); |
|
438 |
if (this.sync_now) { |
|
439 |
this.central_time = _now; |
|
440 |
this.$.find('.Tl-TopBar-SyncButton').addClass("active"); |
|
441 |
} else { |
|
442 |
this.$.find('.Tl-TopBar-SyncButton').removeClass("active"); |
|
443 |
} |
|
444 |
var _timescale = this.timescales[this.level], |
|
445 |
_offset = new Date().getTimezoneOffset() * 60000; |
|
66 | 446 |
this.current_scale = this.main_width / (_timescale.span) |
447 |
this.start_time = this.central_time - (_timescale.span / 2); |
|
448 |
this.end_time = this.central_time + (_timescale.span / 2); |
|
449 |
var _grid_width = Math.floor(_timescale.grid_interval * this.current_scale), |
|
450 |
_roundstart = Math.floor((this.start_time - _offset) / _timescale.grid_interval) * _timescale.grid_interval + _offset, |
|
65 | 451 |
_html = ''; |
66 | 452 |
this.$.find('.Tl-TopBar-TimeSpan').html(Tlns.Utils.dateFormat(this.start_time, _timescale.start_date_format) + ' - ' + Tlns.Utils.dateFormat(this.end_time, _timescale.end_date_format)); |
453 |
for (var _t = _roundstart; _t < this.end_time; _t += _timescale.grid_interval) { |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
454 |
var _x = this.current_scale * (_t - this.start_time); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
455 |
if (_x > 0) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
456 |
_html += '<div class="Tl-Grid-Column" style="width:' + _grid_width + 'px; left: ' + _x + 'px">' |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
457 |
+ '<div class="Tl-Grid-Label">' + Tlns.Utils.dateFormat(_t, _timescale.grid_date_format) + '</div></div>'; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
458 |
} |
65 | 459 |
} |
460 |
/* |
|
461 |
|
|
462 |
for (var _t = _roundstart; _t < _tmax; _t += _timescale.grid_interval) { |
|
463 |
var _isMajor = !(Math.floor((_t - _offset) / _timescale.grid_interval) % _timescale.major_interval); |
|
67 | 464 |
_html += '<div class="Tl-Grid-Column' + ( _isMajor ? ' Tl-Grid-Major' : '' ) + '" style="width:' + _grid_width + 'px; left: ' + _scale * (_t - this.start_time) + 'px">' |
65 | 465 |
+ ( _isMajor ? '<div class="Tl-Grid-Label">' + Tlns.Utils.dateFormat(_t, _timescale.date_format) + '</div>' : '' ) + '</div>'; |
466 |
} |
|
467 |
*/ |
|
66 | 468 |
if (this.start_time <= _now && this.end_time >= _now) { |
67 | 469 |
_html += '<div class="Tl-Grid-Now" style="left: ' + this.current_scale * (_now - this.start_time) + 'px"></div>' |
65 | 470 |
} |
471 |
this.$.find('.Tl-Grid').html(_html); |
|
66 | 472 |
this.drawOccurrences(); |
473 |
} |
|
474 |
||
475 |
Tlns.Classes.Timeline.prototype.loadOccurrences = function() { |
|
476 |
var _url = Mustache.to_html(this.url_occurrences, { |
|
477 |
from_time: this.start_time, |
|
478 |
to_time: this.end_time |
|
479 |
}), |
|
480 |
_this = this; |
|
481 |
$.getJSON(_url, function(_data) { |
|
482 |
_this.onOccurrencesLoaded(_data); |
|
483 |
}); |
|
484 |
} |
|
485 |
||
486 |
Tlns.Classes.Timeline.prototype.onOccurrencesLoaded = function(_data) { |
|
487 |
if (typeof _data.occurrencesNarratives === "object" && _data.occurrencesNarratives !== null) { |
|
488 |
for (var _i = 0; _i < _data.occurrencesNarratives.length; _i++) { |
|
489 |
this.createOrUpdateOccurrence("narrative", _data.occurrencesNarratives[_i]); |
|
490 |
} |
|
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
491 |
for (var _i = 0; _i < _data.occurrencesPublication.length; _i++) { |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
492 |
this.createOrUpdateOccurrence("publication", _data.occurrencesPublication[_i]); |
66 | 493 |
} |
494 |
} |
|
495 |
if (!this.mouse_down) { |
|
496 |
this.drawOccurrences(); |
|
497 |
} |
|
498 |
} |
|
499 |
||
72 | 500 |
Tlns.Classes.Timeline.prototype.deleteOccurrence = function(_id) { |
71 | 501 |
this.occurrences = _(this.occurrences).reject(function(_occ) { |
72 | 502 |
return occ.id == _id; |
71 | 503 |
}); |
504 |
} |
|
505 |
||
72 | 506 |
Tlns.Classes.Timeline.prototype.getOccurrence = function(_id) { |
66 | 507 |
return _(this.occurrences).find(function(_occ) { |
72 | 508 |
return _occ.id == _id; |
66 | 509 |
}); |
510 |
} |
|
511 |
||
512 |
Tlns.Classes.Timeline.prototype.createOrUpdateOccurrence = function(_type, _data) { |
|
72 | 513 |
var _id = _type + "_" + _data.id, |
514 |
_occurrence = this.getOccurrence(_id); |
|
66 | 515 |
if (typeof _occurrence === "undefined") { |
516 |
_occurrence = new Tlns.Classes.Occurrence(this); |
|
517 |
this.occurrences.push(_occurrence); |
|
518 |
} |
|
519 |
_occurrence.update(_type, _data); |
|
71 | 520 |
return _occurrence; |
66 | 521 |
} |
522 |
||
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
523 |
Tlns.Classes.Timeline.prototype.showTooltip = function(_x, _y, _html, _isUp) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
524 |
this.$.find('.Tl-Overlay-Box') |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
525 |
.removeClass(_isUp ? 'Tl-Overlay-Down' : 'Tl-Overlay-Up') |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
526 |
.addClass(_isUp ? 'Tl-Overlay-Up' : 'Tl-Overlay-Down') |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
527 |
.show() |
66 | 528 |
.css({ |
529 |
left: _x + "px", |
|
530 |
top: _y + "px" |
|
531 |
}); |
|
532 |
this.$.find('.Tl-Overlay-Main').html(_html); |
|
533 |
} |
|
534 |
||
535 |
Tlns.Classes.Timeline.prototype.hideTooltip = function() { |
|
536 |
this.$.find('.Tl-Overlay-Box').hide(); |
|
65 | 537 |
} |
538 |
||
539 |
Tlns.Classes.Timeline.prototype.drawOccurrences = function() { |
|
66 | 540 |
var _this = this, |
541 |
_visible = _(this.occurrences).filter(function(_occ) { |
|
542 |
return (_occ.date >= _this.start_time && _occ.date <= _this.end_time && _occ.published); |
|
543 |
}); |
|
544 |
_(_visible).each(function(_occ) { |
|
67 | 545 |
_occ.x = _this.current_scale * (_occ.date - _this.start_time); |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
546 |
_occ.y = _occ.univers.y; |
66 | 547 |
_occ.in_cluster = false; |
548 |
}); |
|
65 | 549 |
|
66 | 550 |
var _moved = true; |
551 |
while (_moved) { |
|
552 |
_moved = false; |
|
553 |
for (var _i = 0; _i < _visible.length; _i++) { |
|
554 |
for (var _j = 0; _j < _i; _j++) { |
|
555 |
if (_visible[_j].univers_id == _visible[_i].univers_id |
|
556 |
&& _visible[_j].x != _visible[_i].x |
|
557 |
&& Math.abs(_visible[_j].x-_visible[_i].x) < this.cluster_spacing |
|
558 |
) { |
|
559 |
_moved = true; |
|
560 |
_visible[_i].x = this.cluster_spacing * Math.round(_visible[_i].x / this.cluster_spacing); |
|
561 |
_visible[_j].x = this.cluster_spacing * Math.round(_visible[_j].x / this.cluster_spacing); |
|
562 |
} |
|
563 |
} |
|
564 |
} |
|
565 |
} |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
566 |
var _clusters = [], |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
567 |
_openCluster = false; |
66 | 568 |
for (var _i = 0; _i < _visible.length; _i++) { |
569 |
for (var _j = 0; _j < _i; _j++) { |
|
570 |
if (_visible[_j].univers_id == _visible[_i].univers_id && _visible[_j].x == _visible[_i].x) { |
|
571 |
_visible[_j].in_cluster = true; |
|
572 |
_visible[_i].in_cluster = true; |
|
573 |
var _x = _visible[_j].x, |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
574 |
_y = _visible[_j].y; |
66 | 575 |
_cluster = _(_clusters).find(function(_c) { return _c.x == _x && _c.y == _y }); |
576 |
if (typeof _cluster === "undefined") { |
|
577 |
_cluster = { x: _x, y: _y, occurrences: [] }; |
|
578 |
_clusters.push(_cluster); |
|
579 |
} |
|
580 |
if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { |
|
581 |
return _o.type == _visible[_j].type && _o.id == _visible[_j].id; |
|
582 |
})) { |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
583 |
_cluster.occurrences.push(_visible[_j]); |
66 | 584 |
} |
585 |
if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { |
|
586 |
return _o.type == _visible[_i].type && _o.id == _visible[_i].id; |
|
587 |
})) { |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
588 |
_cluster.occurrences.push(_visible[_i]); |
66 | 589 |
} |
590 |
} |
|
591 |
} |
|
592 |
} |
|
593 |
_(_clusters).each(function(_cluster) { |
|
70 | 594 |
_cluster.occurrences = _(_cluster.occurrences).sortBy(function(_o) { |
595 |
return _o.date; |
|
596 |
}); |
|
66 | 597 |
_cluster.type = _cluster.occurrences[0].type; |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
598 |
_cluster.contents = _cluster.occurrences.map(function(_o) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
599 |
return _o.type + ":" + _o.id; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
600 |
}).join("|"); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
601 |
if (_cluster.contents == _this.open_cluster) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
602 |
_openCluster = _cluster; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
603 |
} |
66 | 604 |
for (var _i = 1; _i < _cluster.occurrences.length; _i++) { |
605 |
if (_cluster.occurrences[_i].type !== _cluster.type) { |
|
606 |
_cluster.type = "both"; |
|
607 |
break; |
|
608 |
} |
|
609 |
} |
|
610 |
}); |
|
611 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
612 |
|
67 | 613 |
var _links = []; |
614 |
|
|
615 |
_(_visible).each(function(_occurrence) { |
|
616 |
_(_occurrence.dependsOn).each(function(_dependance) { |
|
617 |
var _parent = _(_visible).find(function(_o) { |
|
72 | 618 |
return _o.id == _dependance; |
67 | 619 |
}); |
620 |
if (typeof _parent !== "undefined") { |
|
621 |
_links.push({ |
|
622 |
from_x: _occurrence.x, |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
623 |
from_y: _occurrence.y + Math.floor(_this.univers_height / 2), |
67 | 624 |
to_x: _parent.x, |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
625 |
to_y: _parent.y + Math.floor(_this.univers_height / 2) |
67 | 626 |
}); |
627 |
} |
|
628 |
}); |
|
629 |
}); |
|
630 |
|
|
631 |
var _ctx = this.$.find('.Tl-Canvas')[0].getContext('2d'); |
|
632 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
633 |
_(_links).each(function(_link) { |
|
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
634 |
Tlns.Utils.drawArrow(_ctx, "#505050", _link.from_x,_link.from_y, _link.to_x,_link.to_y); |
70 | 635 |
}); |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
636 |
|
66 | 637 |
var _html = Mustache.to_html(Tlns.Templates.Occurrence, { |
638 |
occurrences:_(_visible).reject(function(_o) {return _o.in_cluster}), |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
639 |
clusters: _clusters, |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
640 |
open_cluster: _openCluster |
66 | 641 |
}); |
642 |
this.$.find('.Tl-Occurrences').html(_html); |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
643 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
644 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
645 |
if (_openCluster) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
646 |
var _w = this.$.find('.Tl-Occurrence').width(), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
647 |
_ww = _w * _openCluster.occurrences.length; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
648 |
this.$.find('.Tl-ClusterOverlay').css({ |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
649 |
"margin-left": - Math.floor(_ww/2) + "px", |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
650 |
width: _ww |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
651 |
}); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
652 |
_(_openCluster.occurrences).each(function(_o, _i) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
653 |
_o.y = _o.y - 20; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
654 |
_o.x = _o.x - (_ww / 2) + ((_i + .5) * _w); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
655 |
}); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
656 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
657 |
|
66 | 658 |
this.$.find('.Tl-Occurrence').mousedown(function() { |
71 | 659 |
var _el = $(this), |
660 |
_id = _el.attr("occurrence-id"); |
|
72 | 661 |
if (typeof _id !== "undefined") { |
662 |
_this.editing_occurrence = _this.getOccurrence(_id); |
|
71 | 663 |
if (typeof _this.dragging_type === "undefined" && typeof _this.editing_occurrence !== "undefined" && !_this.editing_occurrence.locked) { |
664 |
_this.dragging_type = "occurrence"; |
|
665 |
_this.editing_occurrence.editing = true; |
|
666 |
} |
|
67 | 667 |
} |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
668 |
}).mouseover(function(_event) { |
66 | 669 |
var _el = $(this), |
71 | 670 |
_id = _el.attr("occurrence-id"); |
72 | 671 |
if (typeof _id !== "undefined") { |
672 |
var _occurrence = _this.getOccurrence(_id); |
|
71 | 673 |
if (!_occurrence.locked) { |
674 |
_el.find('.Tl-Link').show(); |
|
675 |
} |
|
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
676 |
if (!_this.is_dragging) { |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
677 |
_occurrence.formatted_date = Tlns.Utils.dateFormat(_occurrence.date,_this.tooltip_date_format); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
678 |
var _html = Mustache.to_html(Tlns.Templates.OccurrenceTooltip, _occurrence); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
679 |
_this.showTooltip(_occurrence.x, _occurrence.y, _html, (_event.pageY - _this.dragging_bounds.top) >= (.4 * _this.main_height) ); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
680 |
} |
70 | 681 |
} |
66 | 682 |
}).mouseout(function() { |
70 | 683 |
var _el = $(this), |
71 | 684 |
_id = _el.attr("occurrence-id"); |
72 | 685 |
if (typeof _id !== "undefined") { |
686 |
var _occurrence = _this.getOccurrence(_id); |
|
71 | 687 |
_this.hideTooltip(); |
688 |
if (!_occurrence.editing) { |
|
689 |
$(this).find('.Tl-Link').hide(); |
|
690 |
} |
|
70 | 691 |
} |
692 |
}).mouseup(function() { |
|
693 |
var _el = $(this); |
|
72 | 694 |
if (_this.dragging_type == "link") { |
70 | 695 |
_this.editing_occurrence.addDependency(_el.attr("occurrence-id")); |
696 |
} |
|
66 | 697 |
}); |
70 | 698 |
|
699 |
this.$.find('.Tl-Link').mousedown(function() { |
|
72 | 700 |
var _el = $(this).parent(), |
701 |
_id = _el.attr("occurrence-id"); |
|
702 |
_this.editing_occurrence = _this.getOccurrence(_id); |
|
70 | 703 |
if (typeof _this.editing_occurrence !== "undefined" && !_this.editing_occurrence.locked) { |
704 |
_this.dragging_type = "link"; |
|
705 |
_this.editing_occurrence.editing = true; |
|
706 |
} |
|
707 |
}) |
|
708 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
709 |
this.$.find('.Tl-Cluster').click(function() { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
710 |
var _el = $(this), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
711 |
_contents = _el.attr("cluster-contents"); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
712 |
if (_this.open_cluster == _contents) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
713 |
_this.open_cluster = false; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
714 |
} else { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
715 |
_this.open_cluster = _contents; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
716 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
717 |
_this.throttledDrawGrid(); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
718 |
}) |
65 | 719 |
} |
720 |
||
66 | 721 |
Tlns.Classes.Timeline.prototype.getUnivers = function(_id) { |
722 |
return _(this.univers).find(function(_univ) { |
|
723 |
return (_univ.id == _id); |
|
724 |
}); |
|
725 |
} |
|
726 |
||
727 |
/* |
|
728 |
* Univers |
|
729 |
*/ |
|
730 |
||
65 | 731 |
Tlns.Classes.Univers = function(_data, _timeline, _index) { |
732 |
this.id = _data.id; |
|
733 |
this.index = _index; |
|
734 |
this.title = _data.nom; |
|
735 |
this.mainCharacter = _data.personnage; |
|
66 | 736 |
this.y = (_timeline.univers_height * _index); |
65 | 737 |
|
738 |
this.$label = $('<li>').css({ |
|
739 |
height : _timeline.univers_height + "px" |
|
740 |
}).html(Mustache.to_html(Tlns.Templates.Univers, this)) |
|
66 | 741 |
.addClass((_index % 2) ? 'Tl-Line-Odd' : 'Tl-Line-Even'); |
65 | 742 |
|
743 |
_timeline.$.find('.Tl-UniversLabels').append(this.$label); |
|
744 |
var _txt = _data.nom, |
|
745 |
_span = this.$label.find('span'); |
|
746 |
||
747 |
while (_span.outerWidth() > (_timeline.width - _timeline.main_width) && _txt) { |
|
748 |
_txt = _txt.substr(0, _txt.length - 1); |
|
749 |
_span.html(_txt + '…'); |
|
750 |
} |
|
751 |
} |
|
66 | 752 |
|
753 |
/* |
|
754 |
* Occurrence |
|
755 |
*/ |
|
756 |
||
757 |
Tlns.Classes.Occurrence = function(_timeline) { |
|
758 |
this.timeline = _timeline; |
|
759 |
} |
|
760 |
||
761 |
Tlns.Classes.Occurrence.prototype.update = function(_type, _data) { |
|
762 |
this.type = _type; |
|
72 | 763 |
this.original_id = _data.id || Tlns.Utils.guid(); |
764 |
this.id = _type + "_" + this.original_id; |
|
66 | 765 |
this.date = _data.date || _data.datePublication; |
766 |
this.title = _data.titre || "<untitled>"; |
|
767 |
this.univers_id = _data.univers; |
|
768 |
this.univers = this.timeline.getUnivers(this.univers_id); |
|
769 |
this.status = _data.statut; |
|
770 |
this.published = _data.publie || false; |
|
771 |
this.locked = _data.verrouille || false; |
|
772 |
this.characters = _data.personnagesSecondaires || []; |
|
72 | 773 |
this.dependsOn = _(_data.dependDe || []).map(function(_id) { |
774 |
return "narrative_" + _id; |
|
775 |
}); |
|
70 | 776 |
this.description = _data.description || ""; |
777 |
} |
|
778 |
||
779 |
Tlns.Classes.Occurrence.prototype.addDependency = function(_id) { |
|
780 |
if (_(this.dependsOn).indexOf(_id) == -1) { |
|
781 |
this.dependsOn.push(_id); |
|
782 |
} |
|
66 | 783 |
} |
784 |
||
785 |
Tlns.Classes.Occurrence.prototype.toString = function() { |
|
786 |
return "Occurrence " + this.type + ': "' + this.title + '"'; |
|
787 |
} |