From 6b2e5432d1529b63793ea32a20068d441f2dc193 Mon Sep 17 00:00:00 2001 From: Freeyorp Date: Sat, 23 Mar 2013 13:51:35 +1300 Subject: Add libraries - d3, crossfilter, dc --- .gitmodules | 9 +++++++++ js/crossfilter | 1 + js/d3 | 1 + js/dc | 1 + js/util/memoize.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 .gitmodules create mode 160000 js/crossfilter create mode 160000 js/d3 create mode 160000 js/dc create mode 100644 js/util/memoize.js diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c10d45c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "js/crossfilter"] + path = js/crossfilter + url = https://github.com/square/crossfilter.git +[submodule "js/d3"] + path = js/d3 + url = https://github.com/mbostock/d3.git +[submodule "js/dc"] + path = js/dc + url = https://github.com/NickQiZhu/dc.js.git diff --git a/js/crossfilter b/js/crossfilter new file mode 160000 index 0000000..ae994e8 --- /dev/null +++ b/js/crossfilter @@ -0,0 +1 @@ +Subproject commit ae994e8f8014ad4304e0575973bb23c1fb1ac0b7 diff --git a/js/d3 b/js/d3 new file mode 160000 index 0000000..91d35b4 --- /dev/null +++ b/js/d3 @@ -0,0 +1 @@ +Subproject commit 91d35b4205d4ef150c61c415b7379404bced7267 diff --git a/js/dc b/js/dc new file mode 160000 index 0000000..517c488 --- /dev/null +++ b/js/dc @@ -0,0 +1 @@ +Subproject commit 517c4887dac9dffa08494d31c7a54321861d53e0 diff --git a/js/util/memoize.js b/js/util/memoize.js new file mode 100644 index 0000000..796c060 --- /dev/null +++ b/js/util/memoize.js @@ -0,0 +1,45 @@ +/* + * Helper function for memoization + * + * The passed labeller function must generate unique and exact names for entries that are naturally equal. + * IDs are persistent. + * + * names, idByName, and entries are accessible fields from the memoizer. + * Behaviour on external modification of these fields is undefined. + * + * An entry object passed to the memoizer has its field "id" set to the memoized id by default. + * The name of the ID field can be modified by calling the getter/setter idField() from the memoizer. + * Behaviour on changing the ID field used while the memoizer has already performed memoization is undefined. + */ +function memoize(labeller) { + var idField = "id"; + var names = []; + var idByName = {}; + var entries = []; + var _memoizer = function(entry) { + var name = labeller(entry); + if (name in idByName) { + /* We already have a suitable entry. */ + var id = idByName[name]; + return entries[id]; + } + /* New entry. */ + /* Set the entry's ID. */ + entry[idField] = entries.length; + /* Index the new entry. */ + idByName[name] = entry[idField]; + names[entry[idField]] = name; + entries.push(entry); + + return entry; + } + _memoizer.names = function() { return names; }; + _memoizer.idByName = function() { return idByName; }; + _memoizer.entries = function() { return entries; }; + _memoizer.idField = function(x) { + if (!arguments.length) return idField; + idField = x; + return _memoizer; + }; + return _memoizer; +} -- cgit v1.2.3-60-g2f50