# HG changeset patch # User veltr # Date 1376405198 -7200 # Node ID 50e3c4ba168a5c0f5f5c0853365a44212dbca5e2 # Parent 6b1a038edbf755219be5a546efe00f958f829901 Remove clusters diff -r 6b1a038edbf7 -r 50e3c4ba168a timeline/js/timeline.js --- a/timeline/js/timeline.js Tue Aug 13 16:22:32 2013 +0200 +++ b/timeline/js/timeline.js Tue Aug 13 16:46:38 2013 +0200 @@ -156,7 +156,7 @@ api_endpoint: "", api_method: "searchForTimelineEdito", occurrences: [], - cluster_spacing: 12, + grid_spacing: 12, tooltip_date_format: '{{dayOfMonth}} {{shortMonthName}} {{year}} {{0hours}}:{{0minutes}}', statuses: { "valide": "Validée", @@ -179,13 +179,8 @@ Tlns.Templates.Univers = '
{{formatted_date}} — {{translated_status}} — {{#jt}}Au JT{{/jt}}{{^jt}}Hors JT{{/jt}}{{#format}} — {{format}}{{/format}}
' + '{{description}}
' @@ -454,88 +449,36 @@ _(this.occurrences).each(function(_occ) { _occ.x = _this.current_scale * (_occ.date - _this.start_time); _occ.y = _occ.univers.y; - _occ.in_cluster = false; }); var _visible = _(this.occurrences).filter(function(_occ) { return (_occ.date >= _this.start_time && _occ.date <= _this.end_time && _occ.status); }); - var _moved = true; - while (_moved) { + var _moved = true, l = 0; + while (_moved && l < 200) { + l++; _moved = false; for (var _i = 0; _i < _visible.length; _i++) { for (var _j = 0; _j < _i; _j++) { + var delta = Math.abs(_visible[_j].x-_visible[_i].x); if (_visible[_j].univers_id == _visible[_i].univers_id - && _visible[_j].x != _visible[_i].x - && Math.abs(_visible[_j].x-_visible[_i].x) < this.cluster_spacing + && delta < this.grid_spacing ) { + var sign = _visible[_i].x < _visible[_j].x ? 1 : -1, + add = sign * (this.cluster_spacing - delta) / 2; _moved = true; - _visible[_i].x = this.cluster_spacing * Math.round(_visible[_i].x / this.cluster_spacing); - _visible[_j].x = this.cluster_spacing * Math.round(_visible[_j].x / this.cluster_spacing); + _visible[_i].x -= add; + _visible[_j].x += add; } } } } - var _clusters = [], - _openCluster = false; - for (var _i = 0; _i < _visible.length; _i++) { - for (var _j = 0; _j < _i; _j++) { - if (_visible[_j].univers_id == _visible[_i].univers_id && _visible[_j].x == _visible[_i].x) { - _visible[_j].in_cluster = true; - _visible[_i].in_cluster = true; - var _x = _visible[_j].x, - _y = _visible[_j].y; - _cluster = _(_clusters).find(function(_c) { return _c.x == _x && _c.y == _y }); - if (typeof _cluster === "undefined") { - _cluster = { x: _x, y: _y, occurrences: [] }; - _clusters.push(_cluster); - } - if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { - return _o.type == _visible[_j].type && _o.id == _visible[_j].id; - })) { - _cluster.occurrences.push(_visible[_j]); - } - if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { - return _o.type == _visible[_i].type && _o.id == _visible[_i].id; - })) { - _cluster.occurrences.push(_visible[_i]); - } - } - } - } - _(_clusters).each(function(_cluster) { - _cluster.occurrences = _(_cluster.occurrences).sortBy(function(_o) { - return _o.date; - }); - _cluster.contents = _cluster.occurrences.map(function(_o) { - return _o.id; - }).join("|"); - if (_cluster.contents == _this.open_cluster) { - _openCluster = _cluster; - } - }); var _html = Mustache.to_html(Tlns.Templates.Occurrence, { - occurrences:_(_visible).reject(function(_o) {return _o.in_cluster}), - clusters: _clusters, - open_cluster: _openCluster + occurrences: _visible }); this.$.find('.Tl-Occurrences').html(_html); - - - if (_openCluster) { - var _w = this.$.find('.Tl-Occurrence').width(), - _ww = _w * _openCluster.occurrences.length; - this.$.find('.Tl-ClusterOverlay').css({ - "margin-left": - Math.floor(_ww/2) + "px", - width: _ww - }); - _(_openCluster.occurrences).each(function(_o, _i) { - _o.y = _o.y - 20; - _o.x = _o.x - (_ww / 2) + ((_i + .5) * _w); - }); - } - + this.$.find('.Tl-Occurrence').mousedown(function() { var _el = $(this), _id = _el.attr("occurrence-id"); @@ -570,17 +513,7 @@ _this.hideTooltip(); } }); - - this.$.find('.Tl-Cluster').click(function() { - var _el = $(this), - _contents = _el.attr("cluster-contents"); - if (_this.open_cluster == _contents) { - _this.open_cluster = false; - } else { - _this.open_cluster = _contents; - } - _this.throttledDrawGrid(); - }) + } Tlns.Classes.Timeline.prototype.getUnivers = function(_id) { @@ -624,7 +557,7 @@ this.date = new Date(1000 * (_data.dateFirstPublication || _data.dateCreate) || Date.now); this.formatted_date = Tlns.Utils.dateFormat(this.date,Tlns.Defaults.Timeline.tooltip_date_format); this.title = _data.title; - this.univers_id = this.timeline.univers[Math.floor(this.timeline.univers.length * Math.random())].id; + this.univers_id = this.timeline.univers[0].id; this.univers = this.timeline.getUnivers(this.univers_id); this.type = "publication"; if (typeof _data.statut !== "undefined" || typeof this.status === "undefined") {