Friday, November 20, 2009

Visualize your Twitter Timeline with jQuery and SIMILE

Since my last post I wondering if there was a better way to visualize my tweets. The Word Cloud was a nice feature, but I wanted more. I thought about using the Google Annotated Time Line chart, but it didn’t quite give me what I was looking for. Well, it turns out there is a really cool JavaScript plug-in called Simile Timeline that provides the functionality I was looking for.

So, I threw the following together to display my tweets. After completing it, I realized how much I actually tweet! A lot of exciting stuff was going on after being on vacation, having PDC 2009 going on, and watching the jQuery Summit.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" xml:lang="en" lang="en">
   <title>Visualize your Twitter Timiline with jQuery and SIMILE</title>
   <script src="" type="text/javascript"></script>  
   <script src="" type="text/javascript"></script>      
   <style type="text/css" media="screen">
   body { background-color: #000; font: 14px Helvetica, Arial; color: #fff; }
   #my-timeline, #source { margin-top: 15px; }
   #criteria, #my-timeline, #source { margin-bottom: 15px; }

   .timeline-band-layer-inner { font-size: 10px; }
   .timeline-event-bubble-title, .timeline-event-bubble-body { color: black; }
   .timeline-event-bubble-time { padding-top: 5px; color: #ccccc; font-size: 9px; }
   <script type="text/javascript">   
   $(function() {
      $('#getTwitterTimeline').click(function() {
   var timeLine;
   function getTwitterTimeline(userName) {
      var eventSource = new Timeline.DefaultEventSource();
      var url = '' + userName + '.json?count=200&callback=?';       
      $.getJSON(url, function(data) { 
         var mostRecentTweetDate = new Date(1);
         $.each(data, function(i, item) {   
            var dateEvent = Date.parse(item.created_at); 
            mostRecentTweetDate = (dateEvent > mostRecentTweetDate) ? dateEvent : mostRecentTweetDate;
            var html = replaceUrlWithHtmlLinks(item.text);
            var evt = new Timeline.DefaultEventSource.Event(
               new Date(dateEvent), //start
               null, //end
               null, //latestStart
               null, //earliestEnd
               true, //instant
               item.text.substr(0, 47) + '...', //text
               html //description
         var bandInfos = [
               trackGap: 0.2,
               width: "80%", 
               intervalUnit: Timeline.DateTime.HOUR, 
               intervalPixels: 500,
               eventSource: eventSource,
               timeZone: new Date().getTimezoneOffset() / 60,
               date: new Date(mostRecentTweetDate).toGMTString()
               showEventText:  false,
               trackHeight: 0.5,
               trackGap: 0.2,
               width: "20%", 
               intervalUnit: Timeline.DateTime.DAY, 
               intervalPixels: 300,
               eventSource: eventSource,
               timeZone: new Date().getTimezoneOffset() / 60,
               date: new Date(mostRecentTweetDate).toGMTString()
         bandInfos[1].syncWith = 0;
         bandInfos[1].highlight = true;
         timeLine = Timeline.create($("#my-timeline")[0], bandInfos);                  

   var resizeTimerID = null;   
   $('body').resize(function() {
      if (resizeTimerID == null) {
         resizeTimerID = window.setTimeout(function() {
            resizeTimerID = null;
         }, 500);
   function replaceUrlWithHtmlLinks(text) {    
      var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;    
      return text.replace(exp,"<a href='$1'>$1</a>"); 
      <h3>Visualize your Twitter Timeline with jQuery and SIMILE</h3>
      <div id="criteria">
         <span>Twitter Username: </span>
         <input id="userName" type="text" value="elijahmanor" /> 
         <button id="getTwitterTimeline">Twitter Timeline</button>
      <div id="my-timeline" style="height: 200px;"></div>
      <a id="source" href="" target="_blank">View, Run, & Edit Source Code</a>      

cooltext439924738 cooltext439924698


No comments:

Post a Comment