Philippe Luickx avatar Philippe Luickx committed bbaa004

Different types get different color schemes. New prerequisite now: at
least as many arrays in the definition of the box_color[] as there are
types. Might be an issue if you do not know upfront how many types you
have.

Comments (0)

Files changed (2)

+// Define colors
+var text_color = '#333333';
+// For every type, a new array
+// You can have more arrays than types
+var box_color = [['#95ec00', '#80B12C',] , ['#009999', '#006363',], ['#6D0F03', '#E62F17',], ['#330349', '#711599',], ['#6D3803', '#E67F17',],] ;
+
+// Define source
 // Prerequisites:
 // Sorted by start date
+// Make sure that every type has an array in box_color with color schemes (e.g. shades of blue)
 
 timeline_source =  [{
 		"type": "type1",
 		"end_date": "2003-02-01",
 		"summary": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum",
 	}, {
-	"type": "type1",
+		"type": "type1",
 		"title": "Title 2",
 		"subtitle": "Location 2",
 		"start_date": "2003-09-01",
 		"end_date": "2012-02-01",
 		"summary": "",
 	}, {
-		"type": "type2",
+		"type": "type3",
 		"title": "A moderatly long title",
 		"subtitle": "Location 5",
 		"start_date": "2011-03-01",
 		"end_date": "2011-09-01",
 		"summary": "At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.",
 	}, {
-		"type": "type1",
+		"type": "type3",
 		"title": "Title 6",
 		"subtitle": "Location 6",
 		"start_date": "2011-10-26",
-// Define colors
-var text_color = '#333333';
-var box_color = ['#95ec00', '#80B12C', '#009999', '#006363'] ;
 
 window.onload = function() {
 	draw_timeline(timeline_source);
 // draw the timeline
 draw_timeline = function (source) {
 	
-
 	
 	// Define some parameters
 	// width and height of the timeline (= paper)
 	var paper_width = 900;
-	var paper_height = 200;
+	var paper_height = 240;
 	
 	var timeline_padding = 200;
 	var timeline_width = paper_width - timeline_padding;
-	var timeline_height = paper_height - 50;
+	var timeline_height = paper_height - 100;
 	
 	// Current day
 	var current_date = new Date();
     	today = paper.circle((current_date_diff_pixels + (timeline_padding / 2)), timeline_height, 5)
     );
     
-
 	today.attr({
 		fill: '#444444',
 		stroke: 'none',
-
 	});
 	
 	// Blocks
 	
 	// Initiate array to capture the end dates of the set
     var end_dates_collection = [];
+    // Keep an array of all used types, to be combined with color schemes.
+    var types = [];
     
 	for (var i = 0; i < timeline_source.length; ++i) {
 		
 	    console.log(timeline_source[i]);
 	    
+	    // Check if the type exists already
+	    if (!(contains(types, timeline_source[i].type))) {
+	    	// Push it to the array so we can find it next time
+	    	types.push(timeline_source[i].type);
+	    	// Deifne height
+	    	var height = timeline_height + 40 + types.length * 12;
+	    	// Draw an indicative block with the correct color
+	    	type = paper.rect((timeline_padding / 2), height, 10, 10);
+	    	type.attr({
+	    		fill: box_color[types.length - 1][0],
+	    		stroke: 'none',
+	    	});
+	    	// Draw the text fitting for the box
+	    	paper.text((timeline_padding / 2) + 30, height + 5, timeline_source[i].type);
+	    }
+	    color_index = types.length - 1;
+	    
 	    // Define start and end date.
 	    // Dates can not be in the future.
 	    var start_date = new Date(Math.min(new Date(timeline_source[i].start_date), current_date));
 	    var box = paper.rect(((timeline_padding / 2) + start_date_diff_pixels), (timeline_height - height), (end_date_diff_pixels - start_date_diff_pixels), height);
 	    
 	    box.attr({  
-            fill: box_color[i % box_color.length],
+            fill: box_color[color_index][i % box_color[color_index].length],
             stroke: 'none',
             opacity: 0.6, 
 		});
 	    	fill: text_color,
 	    });
 	    
-
-	    
 	    // Animate the box when hovering over the box or label
 	    box.hover(
 	    	function(){
 	}
 	
 }
+
+function contains(a, obj) {
+    for (var i = 0; i < a.length; i++) {
+        if (a[i] === obj) {
+            return true;
+        }
+    }
+    return false;
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.