59 |
70 |
60 var sortedTopics = data.topics.filter(function(t) { |
71 var sortedTopics = data.topics.filter(function(t) { |
61 return pageParams.visibletopics.indexOf(t.index.toString()) !==-1 && t.index !== topicPoubelle; |
72 return pageParams.visibletopics.indexOf(t.index.toString()) !==-1 && t.index !== topicPoubelle; |
62 }); |
73 }); |
63 |
74 |
|
75 function hasTopics(mmso, topics) { |
|
76 for (var j = 0; j < mmso.topics.length; j++) { |
|
77 if (topics.indexOf(mmso.topics[j].topic) !== -1) { |
|
78 return true; |
|
79 } |
|
80 } |
|
81 return false; |
|
82 } |
|
83 |
|
84 function checkOrGoNext() { |
|
85 var topics = Array.prototype.slice.call( |
|
86 $(".topic.selected").map(function() { |
|
87 return parseInt($(this).attr("data-topic-id")) |
|
88 }) |
|
89 ); |
|
90 var currentMmso = _(data.segments).find(function(s) { |
|
91 return s.start <= player.currentTime && s.end > player.currentTime; |
|
92 }); |
|
93 |
|
94 if (hasTopics(currentMmso, topics)) { |
|
95 throttledShowLocal(); |
|
96 } else { |
|
97 goToNext(); |
|
98 } |
|
99 |
|
100 } |
64 |
101 |
65 function goToNext() { |
102 function goToNext() { |
66 var topics = Array.prototype.slice.call($(".topic.selected").map(function(){return $(this).attr("data-topic-id")})); |
103 var topics = Array.prototype.slice.call( |
|
104 $(".topic.selected").map(function() { |
|
105 return parseInt($(this).attr("data-topic-id")); |
|
106 }) |
|
107 ); |
67 for (var i = 0; i < data.segments.length; i++) { |
108 for (var i = 0; i < data.segments.length; i++) { |
68 var mmso = data.segments[i]; |
109 var mmso = data.segments[i]; |
69 if (mmso.start >= localpos) { |
110 if (mmso.start >= player.currentTime && hasTopics(mmso, topics)) { |
70 for (var j = 0; j < mmso.topics.length; j++) { |
111 player.setCurrentTime(mmso.start); |
71 if (topics.indexOf(mmso.topics[j].topic.toString()) !== -1) { |
112 throttledShowLocal(); |
72 localpos = mmso.start; |
113 return; |
73 showLocal(); |
|
74 return; |
|
75 } |
|
76 } |
|
77 } |
114 } |
78 } |
115 } |
79 console.log("We haven't found a segment"); |
|
80 } |
116 } |
81 |
117 |
82 function showTopics(topiclist) { |
118 function showTopics(topiclist) { |
83 var tbhtml = topiclist.reduce(function(mem, topic) { |
119 var tbhtml = topiclist.reduce(function(mem, topic) { |
84 var wordsToShow = topic.words.slice(0,3), |
120 var wordsToShow = topic.words.slice(0,3), |
205 localTimeR = (localL + localW) + globL, |
241 localTimeR = (localL + localW) + globL, |
206 globR = (globW + globL), |
242 globR = (globW + globL), |
207 yscale = ph / data.duration, |
243 yscale = ph / data.duration, |
208 mx = Math.max.apply(Math, data.minutes.map(function(s) { return s.count})), |
244 mx = Math.max.apply(Math, data.minutes.map(function(s) { return s.count})), |
209 xscale = globW/mx; |
245 xscale = globW/mx; |
210 |
|
211 var segmentrects = data.segments.map(function(mmso) { |
246 var segmentrects = data.segments.map(function(mmso) { |
212 var rect = paper.rect(globL, yscale * mmso.start, globW, yscale * mmso.duration); |
247 var rect = paper.rect(globL, yscale * mmso.start, globW, yscale * mmso.duration); |
213 rect.attr({stroke: "none"}); |
248 rect.attr({stroke: "none"}); |
214 return rect; |
249 return rect; |
215 }); |
250 }); |
291 + betweenx + "," + Math.max(ph - curve, betweenyb) +"L" + betweenx + "," + Math.min(globbottom + curve, betweenyb) |
330 + betweenx + "," + Math.max(ph - curve, betweenyb) +"L" + betweenx + "," + Math.min(globbottom + curve, betweenyb) |
292 + "Q" + betweenx + "," + globbottom + "," + globR + "," + globbottom + "L0," + globbottom, |
331 + "Q" + betweenx + "," + globbottom + "," + globR + "," + globbottom + "L0," + globbottom, |
293 localkeywords = {}; |
332 localkeywords = {}; |
294 |
333 |
295 entonnoir.attr("path",entonnoird); |
334 entonnoir.attr("path",entonnoird); |
|
335 localIndic.css("top",(player.currentTime - localstart) * localyscale); |
296 localTimes.forEach(function(t) { |
336 localTimes.forEach(function(t) { |
297 t.text.remove(); |
337 t.text.remove(); |
298 t.line.remove(); |
338 t.line.remove(); |
299 }); |
339 }); |
300 localMmsos.forEach(function(t) { |
340 localMmsos.forEach(function(t) { |
674 $(".topic[data-topic-id=" + id + "]").addClass("selected").attr("data-timestamp",++ordertag); |
714 $(".topic[data-topic-id=" + id + "]").addClass("selected").attr("data-timestamp",++ordertag); |
675 }); |
715 }); |
676 |
716 |
677 var localpos = 300, |
717 var localpos = 300, |
678 localduration = 600; |
718 localduration = 600; |
679 |
719 |
680 goToNext(); |
720 var player = new Player(); |
|
721 |
|
722 player.duration = data.duration; |
|
723 |
|
724 player.on("play", function() { |
|
725 $(".play-button").html("▐ ▌"); |
|
726 }); |
|
727 player.on("pause", function() { |
|
728 $(".play-button").text("▶"); |
|
729 }); |
|
730 player.on("timeupdate", function(t) { |
|
731 playTime.text(secsToString(t)); |
|
732 globalIndic.css("top", yscale * t); |
|
733 if (localyscale) { |
|
734 var localy = (+t - localpos + localduration / 2) * localyscale; |
|
735 localIndic.css("top", localy); |
|
736 } |
|
737 if (syncVideo) { |
|
738 localpos = Math.max(localduration / 2, Math.min(data.duration - localduration / 2, t)); |
|
739 throttledShowLocal(); |
|
740 } |
|
741 }); |
|
742 |
|
743 $(".play-button").click(function() { |
|
744 if (player.paused) { |
|
745 player.play(); |
|
746 } else { |
|
747 player.pause(); |
|
748 } |
|
749 }); |
|
750 |
|
751 $(".next-button").click(goToNext); |
681 |
752 |
682 $(".topics-block").on("mouseenter", ".topic", function() { |
753 $(".topics-block").on("mouseenter", ".topic", function() { |
683 var el = $(this); |
754 var el = $(this); |
684 el.addClass("hover"); |
755 el.addClass("hover"); |
685 showTopicViz(); |
756 showTopicViz(); |
690 var el = $(this); |
761 var el = $(this); |
691 $(this).toggleClass("selected"); |
762 $(this).toggleClass("selected"); |
692 el.attr("data-timestamp", el.hasClass("selected") ? ++ordertag : 999999); |
763 el.attr("data-timestamp", el.hasClass("selected") ? ++ordertag : 999999); |
693 showTopicViz(); |
764 showTopicViz(); |
694 }); |
765 }); |
695 |
766 |
696 var mouseIsDown, isDragging, startY, startT, startPos, scrollGlobal, speedscale, slowiterations; |
767 var h = Hammer($(".play-bottom")[0]); |
697 |
768 |
698 $(document).mouseup(function() { mouseIsDown = false; isDragging = false; }); |
769 var scrollGlobal, isDragging, startPos, startLevel, scaleStep = 1/Math.log(Math.sqrt(2)); |
699 |
770 |
700 $(".play-dataviz").mousedown(function(e) { |
771 h.on("tap", function(e) { |
701 var l = $(this).offset().left, |
772 var _o = $(this).offset(), |
702 scrollLimit = l + 380; |
773 posX = e.gesture.center.pageX - _o.left, |
703 if (e.pageX < scrollLimit) { |
774 posY = e.gesture.center.pageY - _o.top; |
704 mouseIsDown = true; |
775 if (posX < 140) { |
705 startY = e.pageY; |
776 deSync(); |
706 startT = new Date(); |
777 localpos = Math.max(localduration / 2, Math.min(data.duration - localduration / 2, Math.floor(posY / yscale))); |
707 startPos = localpos; |
778 throttledShowLocal(); |
708 scrollGlobal = e.pageX < (l + 140); |
779 } |
709 e.preventDefault(); |
780 }) |
710 } |
781 .on("dragstart", function(e) { |
711 }).mousemove(function(e) { |
782 startPos = localpos; |
712 if (mouseIsDown) { |
783 var x = e.gesture.center.pageX - $(this).offset().left; |
713 if (isDragging) { |
784 isDragging = (x < 380); |
714 var deltaY = e.pageY - startY, |
785 scrollGlobal = (x < 140); |
715 delta = Math.floor(deltaY / (scrollGlobal ? yscale : - localyscale)); |
786 }) |
716 localpos = Math.max(localduration / 2, Math.min(data.duration - localduration / 2, startPos + delta)); |
787 .on("drag", function(e) { |
717 throttledShowLocal(); |
788 if (isDragging && e.gesture) { |
718 } else { |
789 var delta = Math.floor(e.gesture.deltaY / (scrollGlobal ? yscale : - localyscale)); |
719 isDragging = true; |
790 deSync(); |
720 } |
791 localpos = Math.max(localduration / 2, Math.min(data.duration - localduration / 2, startPos + delta)); |
721 } |
792 throttledShowLocal(); |
722 }).mouseup(function(e) { |
793 } |
723 if (scrollGlobal && !isDragging) { |
794 }) |
724 var _o = $(this).offset(), |
795 .on("touch", function(e) { |
725 posX = e.pageX - _o.left, |
796 startLevel = currentlevel; |
726 posY = e.pageY - _o.top; |
797 }) |
727 if (posX < 140) { |
798 .on("pinchin", function(e) { |
728 localpos = Math.max(localduration / 2, Math.min(data.duration - localduration / 2, Math.floor(posY / yscale))); |
799 var newlevel = Math.max(0, Math.min(zoomlevels.length - 1, startLevel + Math.round(Math.log(e.gesture.scale)*scaleStep))); |
729 throttledShowLocal(); |
800 if (newlevel !== currentlevel) { |
730 } |
801 currentlevel = newlevel; |
731 } |
802 localduration = zoomlevels[currentlevel]; |
732 }); |
803 localpos = Math.max(localduration / 2, Math.min(data.duration - localduration / 2, localpos)); |
733 |
804 throttledShowLocal(); |
|
805 } |
|
806 }); |
|
807 |
734 var totalScroll = 0, zoomlevels = [ 1800, 900, 600, 300, 120, 60 ], currentlevel = 2; |
808 var totalScroll = 0, zoomlevels = [ 1800, 900, 600, 300, 120, 60 ], currentlevel = 2; |
735 |
809 |
736 $(".play-dataviz").mousewheel(function(_event, _scrolldelta) { |
810 $(".play-bottom") |
|
811 .mousedown(function(_e) { |
|
812 _e.preventDefault(); |
|
813 }) |
|
814 .on("touchstart", function(_e) { |
|
815 _e.preventDefault(); |
|
816 }) |
|
817 .mousewheel(function(_event, _scrolldelta) { |
737 totalScroll += _scrolldelta; |
818 totalScroll += _scrolldelta; |
738 if (Math.abs(totalScroll) >= 1) { |
819 if (Math.abs(totalScroll) >= 1) { |
739 var d = (totalScroll > 0 ? 1 : -1), |
820 var d = (totalScroll > 0 ? 1 : -1), |
740 newlevel = Math.max(0, Math.min(zoomlevels.length - 1, currentlevel + d)); |
821 newlevel = Math.max(0, Math.min(zoomlevels.length - 1, currentlevel + d)); |
741 if (newlevel !== currentlevel) { |
822 if (newlevel !== currentlevel) { |
744 localpos = Math.max(localduration / 2, Math.min(data.duration - localduration / 2, localpos)); |
825 localpos = Math.max(localduration / 2, Math.min(data.duration - localduration / 2, localpos)); |
745 throttledShowLocal(); |
826 throttledShowLocal(); |
746 } |
827 } |
747 totalScroll = 0; |
828 totalScroll = 0; |
748 } |
829 } |
|
830 _event.preventDefault(); |
749 }); |
831 }); |
750 |
832 |
751 if (pageParams.keywords && pageParams.keywords.length) { |
833 if (pageParams.keywords && pageParams.keywords.length) { |
752 $(".keyword-search a").removeClass("placeholder").text(pageParams.keywords.join(", ")); |
834 $(".keyword-search a").removeClass("placeholder").text(pageParams.keywords.join(", ")); |
753 } |
835 } |
754 |
836 |
|
837 checkOrGoNext(); |
755 } |
838 } |
756 |
839 |
757 var data = { duration: 10200, topics: [] }, |
840 var data = { duration: 10200, topics: [] }, |
758 colorset = ["#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", "#A65628", "#F781BF"]; |
841 colorset = ["#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", "#A65628", "#F781BF"]; |
759 |
842 |