author | veltr |
Fri, 06 Jul 2012 18:57:20 +0200 | |
changeset 74 | e107c77600e8 |
parent 73 | 642ef9139fad |
child 75 | ef3377d7a4f7 |
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>'; |
74 | 169 |
|
170 |
Tlns.Templates.List = '<div class="Ls-Main"><h2>Filtres :</h2><h3>Titre</h3><p><input class="Ls-Search" type="search" placeholder="Rechercher" /></p><h3>Univers :</h3><ul class="Ls-Univers"></ul>' |
|
171 |
+ '<h3>Type d\'occurrence</h3><ul class="Ls-Occtypes"><li><input type="checkbox" value="narrative" checked>Narratives</li><li><input type="checkbox" value="publication" checked>de Publication</li></ul></p>' |
|
172 |
+ '<h2>Occurrences :</h2><ul class="Ls-Occurrences"></ul></div>'; |
|
65 | 173 |
|
66 | 174 |
Tlns.Templates.Univers = '<span class="Tl-UniversText">{{title}}</span>'; |
175 |
||
74 | 176 |
Tlns.Templates.Univers_List = '{{#univers}}<li><input type="checkbox" value="{{id}}" checked>{{title}}</li>{{/univers}}'; |
177 |
||
70 | 178 |
Tlns.Templates.Occurrence = '{{#clusters}}<div class="Tl-Cluster Tl-Occ{{type}}" style="left: {{x}}px; top: {{y}}px;" cluster-contents="{{contents}}">' |
179 |
+ '<div class="Tl-ClusterCount">{{occurrences.length}}</div></div>{{/clusters}}' |
|
72 | 180 |
+ '{{#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 | 181 |
+ '{{#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 | 182 |
+ '{{#occurrences}}<div class="Tl-Occurrence Tl-OccInCluster Tl-Occ{{type}}{{#editing}} Tl-Editing{{/editing}}" occurrence-id="{{id}}">' |
70 | 183 |
+ '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}<div class="Tl-Link"{{#editing}} style="display: block"{{/editing}}></div></div>{{/occurrences}}</div>{{/open_cluster}}'; |
74 | 184 |
|
185 |
Tlns.Templates.Occurrence_List = '{{#occurrences}}<li><h3>{{title}}</h3><p><b>Type d\'occurrence :</b> {{type}}</p><p>' |
|
186 |
+ '<b>Univers :</b> {{univers.title}}</p><p><b>Date :</b> {{formatted_date}}</p><p>{{description}}</p></li>{{/occurrences}}'; |
|
187 |
||
70 | 188 |
Tlns.Templates.OccurrenceTooltip = '<h3 class="Tl-Tooltip-Title">{{title}}</h3><p class="Tl-Tooltip-Date">{{formatted_date}}</p>' |
189 |
+ '<p class="Tl-Tooltip-Description">{{description}}</p><p class="Tl-Tooltip-Characters">{{univers.mainCharacter}}{{#characters}}, {{.}}{{/characters}}</p>' |
|
65 | 190 |
|
191 |
/* Classes */ |
|
192 |
||
193 |
Tlns.Classes.Timeline = function(_options) { |
|
194 |
||
195 |
/* Setting Defaults */ |
|
196 |
Tlns.Utils.SetDefaults(this, Tlns.Defaults.Timeline, _options); |
|
197 |
||
198 |
/* Setting container CSS */ |
|
199 |
this.$ = $('#' + this.container); |
|
200 |
this.$.addClass('Tl-Main'); |
|
201 |
this.$.css({ |
|
202 |
width : this.width + "px", |
|
203 |
height : this.height + "px" |
|
204 |
}); |
|
205 |
this.$.html(Mustache.to_html(Tlns.Templates.Timeline, this)); |
|
206 |
|
|
207 |
this.main_height = this.height - this.$.find('.Tl-TopBar').outerHeight(); |
|
208 |
this.$.find('.Tl-BottomPart').css("height", this.main_height + "px"); |
|
209 |
this.$.find('.Tl-MainPart').css("width", this.main_width + "px"); |
|
67 | 210 |
this.$.find('.Tl-Overlay-Container').css("left", (this.$.find('.Tl-BottomPart').outerWidth() - this.main_width) + "px"); |
70 | 211 |
this.$.find('canvas.Tl-Layer').attr({ |
67 | 212 |
width: this.main_width, |
213 |
height: this.main_height |
|
214 |
}); |
|
65 | 215 |
var _o = this.$.find('.Tl-MainPart').offset(); |
216 |
this.dragging_bounds = { |
|
217 |
left: _o.left, |
|
218 |
top: _o.top, |
|
219 |
right: _o.left + this.$.find('.Tl-MainPart').outerWidth(), |
|
220 |
bottom: _o.top + this.$.find('.Tl-MainPart').outerHeight(), |
|
221 |
}; |
|
222 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
223 |
var _this = this; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
224 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
225 |
this.throttledDrawGrid = _.throttle(function() { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
226 |
_this.drawGrid(); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
227 |
}, 150); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
228 |
|
65 | 229 |
this.setLevel(this.level); |
230 |
|
|
231 |
this.$.find('.Tl-TopBar-Timescales>div').click(function() { |
|
232 |
_this.setLevel($(this).attr("data-level")); |
|
233 |
}); |
|
234 |
|
|
235 |
this.$.find('.Tl-TopBar-SyncButton').click(function() { |
|
236 |
_this.sync_now = !_this.sync_now; |
|
237 |
_this.drawGrid(); |
|
238 |
}) |
|
239 |
|
|
240 |
this.$.find('.Tl-TopBar-PreviousButton').click(function() { |
|
241 |
_this.offsetTime(-_this.timescales[_this.level].span / 4); |
|
242 |
}); |
|
243 |
|
|
244 |
this.$.find('.Tl-TopBar-NextButton').click(function() { |
|
245 |
_this.offsetTime(_this.timescales[_this.level].span / 4); |
|
246 |
}); |
|
247 |
|
|
248 |
this.$.find('.Tl-MainPart').mousedown(function(_event) { |
|
249 |
_this.onMouseDown(_event); |
|
250 |
return false; |
|
251 |
}); |
|
252 |
|
|
253 |
this.$.find('.Tl-MainPart').mousemove(function(_event) { |
|
254 |
_this.onMouseMove(_event); |
|
255 |
return false; |
|
256 |
}); |
|
257 |
|
|
258 |
this.$.find('.Tl-MainPart').mouseup(function(_event) { |
|
259 |
_this.onMouseUp(_event); |
|
260 |
return false; |
|
261 |
}); |
|
262 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
263 |
this.$.find('.Tl-MainPart').mousewheel(function(_event, _delta) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
264 |
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
|
265 |
if (_newLevel != _this.level) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
266 |
_this.hideTooltip(); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
267 |
var _deltaX = _event.pageX - _this.dragging_bounds.left, |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
268 |
_tAtMouse = _this.timeFromMouse(_event.pageX), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
269 |
_newScale = _this.main_width / (_this.timescales[_newLevel].span), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
270 |
_newStart = _tAtMouse - _deltaX / _newScale; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
271 |
_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
|
272 |
_this.setLevel(_newLevel); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
273 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
274 |
return false; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
275 |
}); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
276 |
|
66 | 277 |
this.$.find('.Tl-Overlay-Box').mouseover(function(_event) { |
278 |
$(this).show(); |
|
279 |
}).mouseout(function(_event) { |
|
280 |
$(this).hide(); |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
281 |
}); |
65 | 282 |
|
71 | 283 |
this.$.find('.Tl-TopBar-AddButton').click(function() { |
284 |
$(this).toggleClass('active'); |
|
285 |
_this.$.find('.Tl-Adding').toggle(); |
|
286 |
}); |
|
287 |
|
|
288 |
this.$.find('.Tl-AddOccurrence').mousedown(function(_event) { |
|
289 |
var _el = $(this), |
|
290 |
_type = _el.attr("occurrence-type"), |
|
291 |
_d = _this.timeFromMouse(_event.pageX), |
|
292 |
_u = _this.universFromMouse(_event.pageY), |
|
293 |
_occ = _this.createOrUpdateOccurrence( |
|
294 |
_type, |
|
295 |
{ |
|
296 |
date: _d, |
|
297 |
titre: '<Nouvelle occurrence>', |
|
298 |
univers: _this.univers[_u].id, |
|
299 |
publie: true |
|
300 |
} |
|
301 |
); |
|
302 |
_occ.just_created = true; |
|
303 |
_occ.editing = true; |
|
304 |
_this.editing_occurrence = _occ; |
|
305 |
_this.dragging_type = "occurrence"; |
|
306 |
window.setTimeout(function () { |
|
307 |
_this.$.find('.Tl-TopBar-AddButton').removeClass('active'); |
|
308 |
_this.$.find('.Tl-Adding').hide(); |
|
309 |
}, 200); |
|
310 |
_this.throttledDrawGrid(); |
|
311 |
}).mouseup(function(_event) { |
|
312 |
_this.onMouseUp(_event); |
|
313 |
return false; |
|
314 |
}); |
|
315 |
|
|
65 | 316 |
/* Loading Univers */ |
317 |
$.getJSON(this.url_univers, function(_data) { |
|
318 |
_this.onUniversLoaded(_data); |
|
319 |
}); |
|
74 | 320 |
|
321 |
|
|
322 |
|
|
323 |
/* LIST */ |
|
324 |
||
325 |
$("body").append(Mustache.to_html(Tlns.Templates.List, this)); |
|
326 |
|
|
327 |
$(".Ls-Main input").bind("click change keyup", function() { |
|
328 |
_this.drawList(); |
|
329 |
}); |
|
330 |
|
|
65 | 331 |
} |
332 |
||
333 |
Tlns.Classes.Timeline.prototype.onMouseDown = function(_event) { |
|
334 |
this.mouse_down = true; |
|
335 |
this.is_dragging = false; |
|
336 |
this.start_pos = { |
|
337 |
x: _event.pageX, |
|
338 |
y: _event.pageY |
|
339 |
}; |
|
66 | 340 |
if (typeof this.dragging_type === "undefined") { |
67 | 341 |
this.time_at_start = this.central_time; |
66 | 342 |
this.dragging_type = "timeline"; |
65 | 343 |
} |
344 |
} |
|
345 |
||
346 |
Tlns.Classes.Timeline.prototype.onMouseUp = function(_event) { |
|
67 | 347 |
if (this.is_dragging) { |
348 |
switch (this.dragging_type) { |
|
349 |
case "occurrence": |
|
350 |
this.editing_occurrence.editing = false; |
|
71 | 351 |
this.editing_occurrence.just_created = false; |
67 | 352 |
this.throttledDrawGrid(); |
353 |
break; |
|
70 | 354 |
case "link": |
355 |
this.editing_occurrence.editing = false; |
|
356 |
this.throttledDrawGrid(); |
|
357 |
var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
358 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
359 |
break; |
|
67 | 360 |
} |
71 | 361 |
} else { |
362 |
if (this.dragging_type == "occurrence" && this.editing_occurrence.just_created) { |
|
363 |
this.deleteOccurrence(this.editing_occurrence.type, this.editing_occurrence.id); |
|
364 |
this.throttledDrawGrid(); |
|
365 |
} |
|
67 | 366 |
} |
65 | 367 |
this.mouse_down = false; |
368 |
this.is_dragging = false; |
|
66 | 369 |
this.dragging_type = undefined; |
65 | 370 |
} |
371 |
||
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
372 |
Tlns.Classes.Timeline.prototype.timeFromX = function(_x) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
373 |
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
|
374 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
375 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
376 |
Tlns.Classes.Timeline.prototype.timeFromMouse = function(_pageX) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
377 |
return this.timeFromX(_pageX - this.dragging_bounds.left); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
378 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
379 |
|
71 | 380 |
Tlns.Classes.Timeline.prototype.universFromY = function(_y) { |
381 |
return Math.max(0,Math.min(this.univers.length, Math.floor(_y / this.univers_height))) |
|
382 |
} |
|
383 |
||
384 |
Tlns.Classes.Timeline.prototype.universFromMouse = function(_pageY) { |
|
385 |
return this.universFromY(_pageY - this.dragging_bounds.top); |
|
386 |
} |
|
387 |
||
65 | 388 |
Tlns.Classes.Timeline.prototype.onMouseMove = function(_event) { |
389 |
if (this.mouse_down) { |
|
390 |
this.is_dragging = true; |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
391 |
this.hideTooltip(); |
69 | 392 |
switch (this.dragging_type) { |
393 |
case "occurrence": |
|
394 |
var _d = this.timeFromMouse(_event.pageX); |
|
395 |
this.editing_occurrence.date = _d; |
|
74 | 396 |
this.editing_occurrence.formatted_date = Tlns.Utils.dateFormat(this.editing_occurrence.date,this.tooltip_date_format); |
71 | 397 |
var _u = this.universFromMouse(_event.pageY); |
69 | 398 |
this.editing_occurrence.univers = this.univers[_u]; |
399 |
this.editing_occurrence.univers_id = this.univers[_u].id; |
|
400 |
this.throttledDrawGrid(); |
|
401 |
break; |
|
402 |
case "timeline": |
|
403 |
this.setTime(this.time_at_start + Math.floor(( this.start_pos.x - _event.pageX ) / this.current_scale)); |
|
404 |
break; |
|
70 | 405 |
case "link": |
406 |
var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
407 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
408 |
Tlns.Utils.drawArrow( |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
409 |
_ctx, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
410 |
'#800080', |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
411 |
this.editing_occurrence.x, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
412 |
this.editing_occurrence.y + Math.floor(this.univers_height / 2), |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
413 |
_event.pageX - this.dragging_bounds.left, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
414 |
_event.pageY - this.dragging_bounds.top |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
415 |
); |
70 | 416 |
break; |
65 | 417 |
} |
418 |
} |
|
419 |
} |
|
420 |
||
421 |
Tlns.Classes.Timeline.prototype.onUniversLoaded = function(_data) { |
|
422 |
this.univers = []; |
|
423 |
if(_data.length) { |
|
424 |
this.univers_height = Math.floor(this.main_height / _data.length); |
|
425 |
} |
|
426 |
for(var _i = 0; _i < _data.length; _i++) { |
|
427 |
this.univers.push(new Tlns.Classes.Univers(_data[_i], this, _i)); |
|
428 |
} |
|
74 | 429 |
|
430 |
$(".Ls-Univers").html(Mustache.to_html(Tlns.Templates.Univers_List, this)); |
|
431 |
var _this = this; |
|
432 |
$(".Ls-Univers input").bind("click change keyup", function() { |
|
433 |
_this.drawList(); |
|
434 |
}); |
|
66 | 435 |
this.loadOccurrences(); |
65 | 436 |
} |
437 |
||
438 |
Tlns.Classes.Timeline.prototype.offsetTime = function(_timeOffset) { |
|
439 |
this.setTime(this.central_time + _timeOffset); |
|
440 |
} |
|
441 |
||
442 |
Tlns.Classes.Timeline.prototype.setTime = function(_centralTime) { |
|
443 |
this.sync_now = false; |
|
444 |
this.central_time = _centralTime; |
|
67 | 445 |
this.throttledDrawGrid(); |
65 | 446 |
} |
447 |
||
448 |
Tlns.Classes.Timeline.prototype.setLevel = function(_level) { |
|
449 |
if (_level >= 0 && _level < this.timescales.length) { |
|
450 |
this.$.find('.Tl-TopBar-Timescales>div').each(function() { |
|
451 |
var _el = $(this); |
|
452 |
if (_el.attr("data-level") == _level) { |
|
453 |
_el.addClass("active"); |
|
454 |
} else { |
|
455 |
_el.removeClass("active"); |
|
456 |
} |
|
457 |
}); |
|
458 |
this.level = _level; |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
459 |
this.throttledDrawGrid(); |
65 | 460 |
} |
461 |
} |
|
462 |
||
463 |
Tlns.Classes.Timeline.prototype.drawGrid = function() { |
|
464 |
var _now = new Date().valueOf(); |
|
465 |
if (this.sync_now) { |
|
466 |
this.central_time = _now; |
|
467 |
this.$.find('.Tl-TopBar-SyncButton').addClass("active"); |
|
468 |
} else { |
|
469 |
this.$.find('.Tl-TopBar-SyncButton').removeClass("active"); |
|
470 |
} |
|
471 |
var _timescale = this.timescales[this.level], |
|
472 |
_offset = new Date().getTimezoneOffset() * 60000; |
|
66 | 473 |
this.current_scale = this.main_width / (_timescale.span) |
474 |
this.start_time = this.central_time - (_timescale.span / 2); |
|
475 |
this.end_time = this.central_time + (_timescale.span / 2); |
|
476 |
var _grid_width = Math.floor(_timescale.grid_interval * this.current_scale), |
|
477 |
_roundstart = Math.floor((this.start_time - _offset) / _timescale.grid_interval) * _timescale.grid_interval + _offset, |
|
65 | 478 |
_html = ''; |
66 | 479 |
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)); |
480 |
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
|
481 |
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
|
482 |
if (_x > 0) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
483 |
_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
|
484 |
+ '<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
|
485 |
} |
65 | 486 |
} |
66 | 487 |
if (this.start_time <= _now && this.end_time >= _now) { |
67 | 488 |
_html += '<div class="Tl-Grid-Now" style="left: ' + this.current_scale * (_now - this.start_time) + 'px"></div>' |
65 | 489 |
} |
490 |
this.$.find('.Tl-Grid').html(_html); |
|
66 | 491 |
this.drawOccurrences(); |
492 |
} |
|
493 |
||
494 |
Tlns.Classes.Timeline.prototype.loadOccurrences = function() { |
|
495 |
var _url = Mustache.to_html(this.url_occurrences, { |
|
496 |
from_time: this.start_time, |
|
497 |
to_time: this.end_time |
|
498 |
}), |
|
499 |
_this = this; |
|
500 |
$.getJSON(_url, function(_data) { |
|
501 |
_this.onOccurrencesLoaded(_data); |
|
502 |
}); |
|
503 |
} |
|
504 |
||
505 |
Tlns.Classes.Timeline.prototype.onOccurrencesLoaded = function(_data) { |
|
506 |
if (typeof _data.occurrencesNarratives === "object" && _data.occurrencesNarratives !== null) { |
|
507 |
for (var _i = 0; _i < _data.occurrencesNarratives.length; _i++) { |
|
508 |
this.createOrUpdateOccurrence("narrative", _data.occurrencesNarratives[_i]); |
|
509 |
} |
|
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
510 |
for (var _i = 0; _i < _data.occurrencesPublication.length; _i++) { |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
511 |
this.createOrUpdateOccurrence("publication", _data.occurrencesPublication[_i]); |
66 | 512 |
} |
513 |
} |
|
514 |
if (!this.mouse_down) { |
|
515 |
this.drawOccurrences(); |
|
516 |
} |
|
74 | 517 |
this.drawList(); |
66 | 518 |
} |
519 |
||
72 | 520 |
Tlns.Classes.Timeline.prototype.deleteOccurrence = function(_id) { |
71 | 521 |
this.occurrences = _(this.occurrences).reject(function(_occ) { |
72 | 522 |
return occ.id == _id; |
71 | 523 |
}); |
524 |
} |
|
525 |
||
72 | 526 |
Tlns.Classes.Timeline.prototype.getOccurrence = function(_id) { |
66 | 527 |
return _(this.occurrences).find(function(_occ) { |
72 | 528 |
return _occ.id == _id; |
66 | 529 |
}); |
530 |
} |
|
531 |
||
532 |
Tlns.Classes.Timeline.prototype.createOrUpdateOccurrence = function(_type, _data) { |
|
72 | 533 |
var _id = _type + "_" + _data.id, |
534 |
_occurrence = this.getOccurrence(_id); |
|
66 | 535 |
if (typeof _occurrence === "undefined") { |
536 |
_occurrence = new Tlns.Classes.Occurrence(this); |
|
537 |
this.occurrences.push(_occurrence); |
|
538 |
} |
|
539 |
_occurrence.update(_type, _data); |
|
71 | 540 |
return _occurrence; |
66 | 541 |
} |
542 |
||
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
543 |
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
|
544 |
this.$.find('.Tl-Overlay-Box') |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
545 |
.removeClass(_isUp ? 'Tl-Overlay-Down' : 'Tl-Overlay-Up') |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
546 |
.addClass(_isUp ? 'Tl-Overlay-Up' : 'Tl-Overlay-Down') |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
547 |
.show() |
66 | 548 |
.css({ |
549 |
left: _x + "px", |
|
550 |
top: _y + "px" |
|
551 |
}); |
|
552 |
this.$.find('.Tl-Overlay-Main').html(_html); |
|
553 |
} |
|
554 |
||
555 |
Tlns.Classes.Timeline.prototype.hideTooltip = function() { |
|
556 |
this.$.find('.Tl-Overlay-Box').hide(); |
|
65 | 557 |
} |
558 |
||
559 |
Tlns.Classes.Timeline.prototype.drawOccurrences = function() { |
|
66 | 560 |
var _this = this, |
561 |
_visible = _(this.occurrences).filter(function(_occ) { |
|
562 |
return (_occ.date >= _this.start_time && _occ.date <= _this.end_time && _occ.published); |
|
563 |
}); |
|
564 |
_(_visible).each(function(_occ) { |
|
67 | 565 |
_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
|
566 |
_occ.y = _occ.univers.y; |
66 | 567 |
_occ.in_cluster = false; |
568 |
}); |
|
65 | 569 |
|
66 | 570 |
var _moved = true; |
571 |
while (_moved) { |
|
572 |
_moved = false; |
|
573 |
for (var _i = 0; _i < _visible.length; _i++) { |
|
574 |
for (var _j = 0; _j < _i; _j++) { |
|
575 |
if (_visible[_j].univers_id == _visible[_i].univers_id |
|
576 |
&& _visible[_j].x != _visible[_i].x |
|
577 |
&& Math.abs(_visible[_j].x-_visible[_i].x) < this.cluster_spacing |
|
578 |
) { |
|
579 |
_moved = true; |
|
580 |
_visible[_i].x = this.cluster_spacing * Math.round(_visible[_i].x / this.cluster_spacing); |
|
581 |
_visible[_j].x = this.cluster_spacing * Math.round(_visible[_j].x / this.cluster_spacing); |
|
582 |
} |
|
583 |
} |
|
584 |
} |
|
585 |
} |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
586 |
var _clusters = [], |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
587 |
_openCluster = false; |
66 | 588 |
for (var _i = 0; _i < _visible.length; _i++) { |
589 |
for (var _j = 0; _j < _i; _j++) { |
|
590 |
if (_visible[_j].univers_id == _visible[_i].univers_id && _visible[_j].x == _visible[_i].x) { |
|
591 |
_visible[_j].in_cluster = true; |
|
592 |
_visible[_i].in_cluster = true; |
|
593 |
var _x = _visible[_j].x, |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
594 |
_y = _visible[_j].y; |
66 | 595 |
_cluster = _(_clusters).find(function(_c) { return _c.x == _x && _c.y == _y }); |
596 |
if (typeof _cluster === "undefined") { |
|
597 |
_cluster = { x: _x, y: _y, occurrences: [] }; |
|
598 |
_clusters.push(_cluster); |
|
599 |
} |
|
600 |
if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { |
|
601 |
return _o.type == _visible[_j].type && _o.id == _visible[_j].id; |
|
602 |
})) { |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
603 |
_cluster.occurrences.push(_visible[_j]); |
66 | 604 |
} |
605 |
if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { |
|
606 |
return _o.type == _visible[_i].type && _o.id == _visible[_i].id; |
|
607 |
})) { |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
608 |
_cluster.occurrences.push(_visible[_i]); |
66 | 609 |
} |
610 |
} |
|
611 |
} |
|
612 |
} |
|
613 |
_(_clusters).each(function(_cluster) { |
|
70 | 614 |
_cluster.occurrences = _(_cluster.occurrences).sortBy(function(_o) { |
615 |
return _o.date; |
|
616 |
}); |
|
66 | 617 |
_cluster.type = _cluster.occurrences[0].type; |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
618 |
_cluster.contents = _cluster.occurrences.map(function(_o) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
619 |
return _o.type + ":" + _o.id; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
620 |
}).join("|"); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
621 |
if (_cluster.contents == _this.open_cluster) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
622 |
_openCluster = _cluster; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
623 |
} |
66 | 624 |
for (var _i = 1; _i < _cluster.occurrences.length; _i++) { |
625 |
if (_cluster.occurrences[_i].type !== _cluster.type) { |
|
626 |
_cluster.type = "both"; |
|
627 |
break; |
|
628 |
} |
|
629 |
} |
|
630 |
}); |
|
631 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
632 |
|
67 | 633 |
var _links = []; |
634 |
|
|
635 |
_(_visible).each(function(_occurrence) { |
|
636 |
_(_occurrence.dependsOn).each(function(_dependance) { |
|
637 |
var _parent = _(_visible).find(function(_o) { |
|
72 | 638 |
return _o.id == _dependance; |
67 | 639 |
}); |
640 |
if (typeof _parent !== "undefined") { |
|
641 |
_links.push({ |
|
642 |
from_x: _occurrence.x, |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
643 |
from_y: _occurrence.y + Math.floor(_this.univers_height / 2), |
67 | 644 |
to_x: _parent.x, |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
645 |
to_y: _parent.y + Math.floor(_this.univers_height / 2) |
67 | 646 |
}); |
647 |
} |
|
648 |
}); |
|
649 |
}); |
|
650 |
|
|
651 |
var _ctx = this.$.find('.Tl-Canvas')[0].getContext('2d'); |
|
652 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
653 |
_(_links).each(function(_link) { |
|
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
654 |
Tlns.Utils.drawArrow(_ctx, "#505050", _link.from_x,_link.from_y, _link.to_x,_link.to_y); |
70 | 655 |
}); |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
656 |
|
66 | 657 |
var _html = Mustache.to_html(Tlns.Templates.Occurrence, { |
658 |
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
|
659 |
clusters: _clusters, |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
660 |
open_cluster: _openCluster |
66 | 661 |
}); |
662 |
this.$.find('.Tl-Occurrences').html(_html); |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
663 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
664 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
665 |
if (_openCluster) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
666 |
var _w = this.$.find('.Tl-Occurrence').width(), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
667 |
_ww = _w * _openCluster.occurrences.length; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
668 |
this.$.find('.Tl-ClusterOverlay').css({ |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
669 |
"margin-left": - Math.floor(_ww/2) + "px", |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
670 |
width: _ww |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
671 |
}); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
672 |
_(_openCluster.occurrences).each(function(_o, _i) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
673 |
_o.y = _o.y - 20; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
674 |
_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
|
675 |
}); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
676 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
677 |
|
66 | 678 |
this.$.find('.Tl-Occurrence').mousedown(function() { |
71 | 679 |
var _el = $(this), |
680 |
_id = _el.attr("occurrence-id"); |
|
72 | 681 |
if (typeof _id !== "undefined") { |
682 |
_this.editing_occurrence = _this.getOccurrence(_id); |
|
71 | 683 |
if (typeof _this.dragging_type === "undefined" && typeof _this.editing_occurrence !== "undefined" && !_this.editing_occurrence.locked) { |
684 |
_this.dragging_type = "occurrence"; |
|
685 |
_this.editing_occurrence.editing = true; |
|
686 |
} |
|
67 | 687 |
} |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
688 |
}).mouseover(function(_event) { |
66 | 689 |
var _el = $(this), |
71 | 690 |
_id = _el.attr("occurrence-id"); |
72 | 691 |
if (typeof _id !== "undefined") { |
692 |
var _occurrence = _this.getOccurrence(_id); |
|
71 | 693 |
if (!_occurrence.locked) { |
694 |
_el.find('.Tl-Link').show(); |
|
695 |
} |
|
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
696 |
if (!_this.is_dragging) { |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
697 |
var _html = Mustache.to_html(Tlns.Templates.OccurrenceTooltip, _occurrence); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
698 |
_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
|
699 |
} |
70 | 700 |
} |
66 | 701 |
}).mouseout(function() { |
70 | 702 |
var _el = $(this), |
71 | 703 |
_id = _el.attr("occurrence-id"); |
72 | 704 |
if (typeof _id !== "undefined") { |
705 |
var _occurrence = _this.getOccurrence(_id); |
|
71 | 706 |
_this.hideTooltip(); |
707 |
if (!_occurrence.editing) { |
|
708 |
$(this).find('.Tl-Link').hide(); |
|
709 |
} |
|
70 | 710 |
} |
711 |
}).mouseup(function() { |
|
712 |
var _el = $(this); |
|
72 | 713 |
if (_this.dragging_type == "link") { |
70 | 714 |
_this.editing_occurrence.addDependency(_el.attr("occurrence-id")); |
715 |
} |
|
66 | 716 |
}); |
70 | 717 |
|
718 |
this.$.find('.Tl-Link').mousedown(function() { |
|
72 | 719 |
var _el = $(this).parent(), |
720 |
_id = _el.attr("occurrence-id"); |
|
721 |
_this.editing_occurrence = _this.getOccurrence(_id); |
|
70 | 722 |
if (typeof _this.editing_occurrence !== "undefined" && !_this.editing_occurrence.locked) { |
723 |
_this.dragging_type = "link"; |
|
724 |
_this.editing_occurrence.editing = true; |
|
725 |
} |
|
726 |
}) |
|
727 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
728 |
this.$.find('.Tl-Cluster').click(function() { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
729 |
var _el = $(this), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
730 |
_contents = _el.attr("cluster-contents"); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
731 |
if (_this.open_cluster == _contents) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
732 |
_this.open_cluster = false; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
733 |
} else { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
734 |
_this.open_cluster = _contents; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
735 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
736 |
_this.throttledDrawGrid(); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
737 |
}) |
65 | 738 |
} |
739 |
||
74 | 740 |
Tlns.Classes.Timeline.prototype.drawList = function() { |
741 |
var _universfilter = $(".Ls-Univers input:checked").map(function(){return this.value}), |
|
742 |
_occtypefilter = $(".Ls-Occtypes input:checked").map(function(){return this.value}), |
|
743 |
_title = $(".Ls-Search").val(), |
|
744 |
_titleregexp = new RegExp( "(" + _title.replace(/(\W)/gm, "\\$1") + ")", "gim" ); |
|
745 |
$(".Ls-Occurrences").html( |
|
746 |
Mustache.to_html( |
|
747 |
Tlns.Templates.Occurrence_List, |
|
748 |
{ |
|
749 |
occurrences: this.occurrences.filter(function(_occ) { |
|
750 |
var _titletest = (!!_occ.title.match(_titleregexp)), |
|
751 |
_keep = ( |
|
752 |
( !_title || _titletest ) |
|
753 |
&& (_(_occtypefilter).indexOf(_occ.type) !== -1) |
|
754 |
&& (_(_universfilter).indexOf(_occ.univers_id) !== -1) |
|
755 |
); |
|
756 |
return _keep; |
|
757 |
}) |
|
758 |
} |
|
759 |
) |
|
760 |
); |
|
761 |
if (_title) { |
|
762 |
$(".Ls-Occurrences h3").each(function() { |
|
763 |
$(this).html($(this).text().replace(_titleregexp, "<span style='background:yellow'>$1</span>")); |
|
764 |
}); |
|
765 |
} |
|
766 |
} |
|
767 |
||
66 | 768 |
Tlns.Classes.Timeline.prototype.getUnivers = function(_id) { |
769 |
return _(this.univers).find(function(_univ) { |
|
770 |
return (_univ.id == _id); |
|
771 |
}); |
|
772 |
} |
|
773 |
||
774 |
/* |
|
775 |
* Univers |
|
776 |
*/ |
|
777 |
||
65 | 778 |
Tlns.Classes.Univers = function(_data, _timeline, _index) { |
779 |
this.id = _data.id; |
|
780 |
this.index = _index; |
|
781 |
this.title = _data.nom; |
|
782 |
this.mainCharacter = _data.personnage; |
|
66 | 783 |
this.y = (_timeline.univers_height * _index); |
65 | 784 |
|
785 |
this.$label = $('<li>').css({ |
|
786 |
height : _timeline.univers_height + "px" |
|
787 |
}).html(Mustache.to_html(Tlns.Templates.Univers, this)) |
|
66 | 788 |
.addClass((_index % 2) ? 'Tl-Line-Odd' : 'Tl-Line-Even'); |
65 | 789 |
|
790 |
_timeline.$.find('.Tl-UniversLabels').append(this.$label); |
|
791 |
var _txt = _data.nom, |
|
792 |
_span = this.$label.find('span'); |
|
793 |
||
794 |
while (_span.outerWidth() > (_timeline.width - _timeline.main_width) && _txt) { |
|
795 |
_txt = _txt.substr(0, _txt.length - 1); |
|
796 |
_span.html(_txt + '…'); |
|
797 |
} |
|
798 |
} |
|
66 | 799 |
|
800 |
/* |
|
801 |
* Occurrence |
|
802 |
*/ |
|
803 |
||
804 |
Tlns.Classes.Occurrence = function(_timeline) { |
|
805 |
this.timeline = _timeline; |
|
806 |
} |
|
807 |
||
808 |
Tlns.Classes.Occurrence.prototype.update = function(_type, _data) { |
|
809 |
this.type = _type; |
|
72 | 810 |
this.original_id = _data.id || Tlns.Utils.guid(); |
811 |
this.id = _type + "_" + this.original_id; |
|
66 | 812 |
this.date = _data.date || _data.datePublication; |
74 | 813 |
this.formatted_date = Tlns.Utils.dateFormat(this.date,Tlns.Defaults.Timeline.tooltip_date_format); |
66 | 814 |
this.title = _data.titre || "<untitled>"; |
815 |
this.univers_id = _data.univers; |
|
816 |
this.univers = this.timeline.getUnivers(this.univers_id); |
|
817 |
this.status = _data.statut; |
|
818 |
this.published = _data.publie || false; |
|
819 |
this.locked = _data.verrouille || false; |
|
820 |
this.characters = _data.personnagesSecondaires || []; |
|
72 | 821 |
this.dependsOn = _(_data.dependDe || []).map(function(_id) { |
822 |
return "narrative_" + _id; |
|
823 |
}); |
|
70 | 824 |
this.description = _data.description || ""; |
825 |
} |
|
826 |
||
827 |
Tlns.Classes.Occurrence.prototype.addDependency = function(_id) { |
|
828 |
if (_(this.dependsOn).indexOf(_id) == -1) { |
|
829 |
this.dependsOn.push(_id); |
|
830 |
} |
|
66 | 831 |
} |
832 |
||
833 |
Tlns.Classes.Occurrence.prototype.toString = function() { |
|
834 |
return "Occurrence " + this.type + ': "' + this.title + '"'; |
|
835 |
} |