Permalink
Browse files

refactor beginnings. bb

  • Loading branch information...
1 parent a914a57 commit d636e676ec8ebab366f6e13ace636c34b6c077f1 @iros iros committed Apr 18, 2012
Showing with 20,301 additions and 418 deletions.
  1. +30 −0 app/config.js
  2. +112 −0 app/main.js
  3. +44 −0 app/modules/example.js
  4. 0 Icon → app/modules/treemap.js
  5. +55 −0 app/namespace.js
  6. +1 −0 app/templates/chart.html
  7. +2 −0 app/templates/container.html
  8. +22 −0 app/templates/header.html
  9. +1 −0 assets/css/index.css
  10. +342 −0 assets/css/style.css
  11. BIN assets/img/backbone.png
  12. +277 −0 assets/js/libs/almond.js
  13. +1,431 −0 assets/js/libs/backbone.js
  14. +9,266 −0 assets/js/libs/jquery.js
  15. +2,053 −0 assets/js/libs/require.js
  16. +999 −0 assets/js/libs/underscore.js
  17. +102 −0 assets/js/plugins/use.js
  18. BIN favicon.ico
  19. +139 −0 grunt.js
  20. +22 −109 index.html
  21. +0 −309 js/main.js
  22. 0 old/Icon
  23. 0 { → old}/data/cabinet_office_spend_data.csv
  24. +34 −0 old/index.html
  25. +17 −0 old/js/application.js
  26. +38 −0 old/js/backbone.js
  27. 0 { → old}/js/d3.v2.min.js
  28. 0 { → old}/js/jquery-1.7.js
  29. +328 −0 old/js/main.js
  30. 0 { → old}/js/miso.ds.deps.js
  31. +68 −0 old/styles/main.css
  32. 0 { → old}/test/chroma.min.js
  33. 0 { → old}/test/hackday.js
  34. 0 { → old}/test/main.longer.js
  35. 0 { → old}/test/miso.ds.deps.min.js
  36. 0 { → old}/test/nebulos-min.js
  37. 0 { → old}/test/raphaelboth.js
  38. 0 { → old}/test/spain.js
  39. +31 −0 readme.md
  40. +44 −0 test/jasmine/index.html
  41. +73 −0 test/jasmine/spec/example.js
  42. +20 −0 test/jasmine/vendor/MIT.LICENSE
  43. +190 −0 test/jasmine/vendor/jasmine-html.js
  44. +166 −0 test/jasmine/vendor/jasmine.css
  45. +2,476 −0 test/jasmine/vendor/jasmine.js
  46. BIN test/jasmine/vendor/jasmine_favicon.png
  47. +47 −0 test/qunit/index.html
  48. +54 −0 test/qunit/tests/example.js
  49. +228 −0 test/qunit/vendor/qunit.css
  50. +1,589 −0 test/qunit/vendor/qunit.js
View
@@ -0,0 +1,30 @@
+// Set the require.js configuration for your application.
+require.config({
+ // Initialize the application with the main application file
+ deps: ["main"],
+
+ paths: {
+ // JavaScript folders
+ libs: "../assets/js/libs",
+ plugins: "../assets/js/plugins",
+
+ // Libraries
+ jquery: "../assets/js/libs/jquery",
+ underscore: "../assets/js/libs/underscore",
+ backbone: "../assets/js/libs/backbone",
+
+ // Shim Plugin
+ use: "../assets/js/plugins/use"
+ },
+
+ use: {
+ backbone: {
+ deps: ["use!underscore", "jquery"],
+ attach: "Backbone"
+ },
+
+ underscore: {
+ attach: "_"
+ }
+ }
+});
View
@@ -0,0 +1,112 @@
+require([
+ "TM",
+
+ // Libs
+ "jquery",
+ "use!backbone",
+
+ // Modules
+ "modules/example"
+],
+
+function(TM, $, Backbone, Example) {
+
+ // Defining the application router, you can attach sub routers here.
+ var Router = Backbone.Router.extend({
+ routes: {
+ "": "index",
+ ":hash": "index"
+ },
+
+ index : function(hash) {
+ // Define the columns in the underlying dataset
+ TM.columns = [
+ { name: "Description", type: "string" },
+ { name: "Supplier", type: "string" },
+ { name: "URL", type: "string" },
+ { name: "Entity", type: "string" },
+ { name: "Expense Type", type: "string" },
+ { name: "Transaction Number", type: "string" },
+ { name: "Amount", type: "number",
+
+ // Define a helper for pre-processing numeric values -
+ // ensures empty cells are set to 0 and the rest are
+ // stripped of commas and turned to floats
+ before: function(v) {
+ return (_.isUndefined(v) || _.isNull(v)) ?
+ 0 :
+ parseFloat(v.replace(/\,/g, ''));
+ }
+ },
+
+ { name: "Expense Area", type: "string" },
+ { name: "Date", type: "time", format: "DD/MM/YYYY" },
+ { name: "Departmental Family", type: "string" }
+ ];
+
+ // Define the underlying dataset for this interactive, a CSV file containing
+ // every item of Cabinet Office spending above £25k during the 2010/2011 period.
+ // (source = )
+ TM.data = new Miso.Dataset({
+ url: "data/cabinet_office_spend_data.csv",
+ delimiter: ",",
+ columns: columns
+ });
+
+ TM.data.fetch({
+
+ success: function(){
+ setupGrouping(groupings);
+ setupDateRanges(data);
+
+ showFilters();
+ showExpenses(wholeRange, currentGrouping, maxGroups);
+ },
+
+ error: function(){
+ setTitle("Failed to load data from " + data.url);
+ }
+
+ });
+ })
+ }
+ });
+
+ // Shorthand the application namespace
+ var app = TM.app;
+
+ // Treat the jQuery ready function as the entry point to the application.
+ // Inside this function, kick-off all initialization, everything up to this
+ // point should be definitions.
+ $(function() {
+ // Define your master router on the application namespace and trigger all
+ // navigation from this instance.
+ app.router = new Router();
+
+ // Trigger the initial route and enable HTML5 History API support
+ Backbone.history.start({ pushState: true });
+ });
+
+ // All navigation that is relative should be passed through the navigate
+ // method, to be processed by the router. If the link has a data-bypass
+ // attribute, bypass the delegation completely.
+ $(document).on("click", "a:not([data-bypass])", function(evt) {
+ // Get the anchor href and protcol
+ var href = $(this).attr("href");
+ var protocol = this.protocol + "//";
+
+ // Ensure the protocol is not part of URL, meaning its relative.
+ if (href && href.slice(0, protocol.length) !== protocol &&
+ href.indexOf("javascript:") !== 0) {
+ // Stop the default event to ensure the link will not cause a page
+ // refresh.
+ evt.preventDefault();
+
+ // `Backbone.history.navigate` is sufficient for all Routers and will
+ // trigger the correct events. The Router's internal `navigate` method
+ // calls this anyways.
+ Backbone.history.navigate(href, true);
+ }
+ });
+
+});
View
@@ -0,0 +1,44 @@
+define([
+ "namespace",
+
+ // Libs
+ "use!backbone"
+
+ // Modules
+
+ // Plugins
+],
+
+function(namespace, Backbone) {
+
+ // Create a new module
+ var Example = namespace.module();
+
+ // Example extendings
+ Example.Model = Backbone.Model.extend({ /* ... */ });
+ Example.Collection = Backbone.Collection.extend({ /* ... */ });
+ Example.Router = Backbone.Router.extend({ /* ... */ });
+
+ // This will fetch the tutorial template and render it.
+ Example.Views.Tutorial = Backbone.View.extend({
+ template: "app/templates/example.html",
+
+ render: function(done) {
+ var view = this;
+
+ // Fetch the template, render it to the View element and call done.
+ namespace.fetchTemplate(this.template, function(tmpl) {
+ view.el.innerHTML = tmpl();
+
+ // If a done function is passed, call it with the element
+ if (_.isFunction(done)) {
+ done(view.el);
+ }
+ });
+ }
+ });
+
+ // Required, return the module for AMD compliance
+ return Example;
+
+});
File renamed without changes.
View
@@ -0,0 +1,55 @@
+define([
+ // Libs
+ "jquery",
+ "use!underscore",
+ "use!backbone"
+],
+
+function($, _, Backbone) {
+ // Put application wide code here
+
+ return {
+ // This is useful when developing if you don't want to use a
+ // build process every time you change a template.
+ //
+ // Delete if you are using a different template loading method.
+ fetchTemplate: function(path, done) {
+ var JST = window.JST = window.JST || {};
+ var def = new $.Deferred();
+
+ // Should be an instant synchronous way of getting the template, if it
+ // exists in the JST object.
+ if (JST[path]) {
+ if (_.isFunction(done)) {
+ done(JST[path]);
+ }
+
+ return def.resolve(JST[path]);
+ }
+
+ // Fetch it asynchronously if not available from JST
+ $.get(path, function(contents) {
+ JST[path] = _.template(contents);
+
+ // Set the global JST cache and return the template
+ if (_.isFunction(done)) {
+ done(JST[path]);
+ }
+
+ // Resolve the template deferred
+ def.resolve(JST[path]);
+ }, "text");
+
+ // Ensure a normalized return value (Promise)
+ return def.promise();
+ },
+
+ // Create a custom object with a nested Views object
+ module: function(additionalProps) {
+ return _.extend({ Views: {} }, additionalProps);
+ },
+
+ // Keep active application instances namespaced under an app object.
+ app: _.extend({}, Backbone.Events)
+ };
+});
View
@@ -0,0 +1 @@
+<div id="chart"></div>
@@ -0,0 +1,2 @@
+<div id="container">
+</div>
View
@@ -0,0 +1,22 @@
+<div id="header">
+
+ <div id="legend">
+ Loading spending data
+ </div>
+
+ <div id="daterange">
+ <label for="range">
+ in period:
+ </label>
+ <select name="id" id="range"></select>
+ </div>
+
+ <div id="grouping">
+ <label for="groupby">
+ grouped by:
+ </label>
+ <select name="id" id="groupby"></select>
+ </div>
+
+</div>
+
View
@@ -0,0 +1 @@
+@import "style.css";
Oops, something went wrong.

0 comments on commit d636e67

Please sign in to comment.