Index: ow/static/js/ow.js
===================================================================
--- ow/static/js/ow.js	(revision dbfab702456d2155b486ca7069b1ed674bf8a92a)
+++ ow/static/js/ow.js	(revision 5cf5787d1c21f5eedd38c23d588cc1906e4bef1d)
@@ -236,7 +236,11 @@
     var chart_selector = spec.chart_selector,
         filters_selector = spec.filters_selector,
-        url = spec.url,
+        switcher_selector = spec.switcher_selector,
+        urls = spec.urls,
         current_month = spec.current_month,
-        y_axis_labels = spec.y_axis_labels;
+        current_week = spec.current_week,
+        y_axis_labels = spec.y_axis_labels,
+        filter_by = spec.filter_by,
+        url = spec.url;
 
     // Helpers
@@ -256,17 +260,35 @@
     };
 
+    function get_name_for_x(d) {
+        if (d.week == undefined || d.week == 0) {
+            return d.name;
+        }
+        else {
+            return d.id.split('-')[2];
+        }
+    }
+
     // Methods
     var filters_setup = function filters_setup() {
         $(filters_selector).on('click', function(e) {
-            var filter_by = 'distance';
             e.preventDefault();
             filter_by = $(this).attr('class').split('-')[1]
             var chart = d3.select(chart_selector);
             chart.selectAll("*").remove();
-            render(filter_by);
-        });
-    };
-
-    var render = function render(filter_by) {
+            render(filter_by, url);
+        });
+    };
+
+    var switcher_setup = function switcher_setup() {
+        $(switcher_selector).on('click', function(e) {
+            e.preventDefault();
+            url = $(this).attr('class').split('-')[1]
+            var chart = d3.select(chart_selector);
+            chart.selectAll("*").remove();
+            render(filter_by, url);
+        });
+    };
+
+    var render = function render(filter_by, url) {
         /*
           Build a d3 bar chart, populated with data from the given url.
@@ -280,7 +302,8 @@
             y = d3.scaleLinear().rangeRound([height, 0]);
 
-        d3.json(url).then(function (data) {
+        d3.json(urls[url]).then(function (data) {
 	    x.domain(data.map(function (d) {
-	        return d.name;
+                return get_name_for_x(d);
+	        // return d.name;
 	    }));
 
@@ -308,14 +331,29 @@
 	        .enter().append("rect")
                 .attr("class", function(d) {
-                    if (d.id == current_month){
+                    var sel_week = current_month + '-' + current_week;
+                    if (d.id == current_month || d.id == sel_week){
+                        /* Bar for the currently selected month or week */
                         select_x_axis_label(d).attr('style', "font-weight: bold;");
-                        return 'bar current'
+                        return 'bar current';
                     }
                     else {
-                        return 'bar'
+                        if (!current_week && d.id.indexOf(current_month) >=0 ) {
+                            /*
+                               User selected a month, then switched to weekly
+                               view, we do highlight all the bars for weeks in
+                               that month
+                            */
+                            select_x_axis_label(d).attr('style', "font-weight: bold;");
+                            return 'bar current';
+                        }
+                        else {
+                            /* Non-selected bar */
+                            return 'bar';
+                        }
+
                     }
                 })
 	        .attr("x", function (d) {
-		    return x(d.name);
+		    return x(get_name_for_x(d));
 	        })
 	        .attr("y", function (d) {
@@ -340,30 +378,46 @@
                 });
 
-            g.selectAll(".text")
-                .data(data)
-                .enter()
-                .append("text")
-                .attr("class","label")
-	        .attr("x", function (d) {
-		    return x(d.name) + x.bandwidth()/2;
-	        })
-	        .attr("y", function (d) {
-                    /*
-                      Get the value for the current bar, then get the maximum
-                      value to be displayed in the bar, which is used to
-                      calculate the proper position of the label for this bar,
-                      relatively to its height (1% above the bar)
-                     */
-                    var value = get_y_value(d, filter_by);
-                    var max = y.domain()[1];
-                    return y(value + y.domain()[1] * 0.01);
-	        })
-                .text(function(d) {
-                    var value = get_y_value(d, filter_by)
-                    if ( value > 0) {
-                        return value;
-                    }
-                });
-
+            if (url == 'monthly') {
+                g.selectAll(".text")
+                    .data(data)
+                    .enter()
+                    .append("text")
+                    .attr("class","label")
+	            .attr("x", function (d) {
+		        return x(get_name_for_x(d)) + x.bandwidth()/2;
+	            })
+	            .attr("y", function (d) {
+                        /*
+                          Get the value for the current bar, then get the maximum
+                          value to be displayed in the bar, which is used to
+                          calculate the proper position of the label for this bar,
+                          relatively to its height (1% above the bar)
+                        */
+                        var value = get_y_value(d, filter_by);
+                        var max = y.domain()[1];
+                        return y(value + y.domain()[1] * 0.01);
+	            })
+                    .text(function(d) {
+                        var value = get_y_value(d, filter_by)
+                        if ( value > 0) {
+                            return value;
+                        }
+                    });
+            }
+
+            if (url == 'weekly') {
+                g.selectAll(".tick")
+                    .each(function (d, i) {
+                        /*
+                          Remove from the x-axis tickets those without letters
+                          on them (useful for the weekly chart)
+                        */
+                        if (d !== parseInt(d, 10)) {
+                            if(!d.match(/[a-z]/i)) {
+                                this.remove();
+                            }
+                        }
+                    });
+            }
         });
     };
@@ -371,4 +425,5 @@
     var that = {}
     that.filters_setup = filters_setup;
+    that.switcher_setup = switcher_setup;
     that.render = render;
     return that
