Commits

Ralph Bean committed 0a2e20e

Super useful utility functions.

  • Participants
  • Parent commits 5ab0692

Comments (0)

Files changed (2)

 
 setup(
     name='tw2.d3',
-    version='0.0.3',
+    version='0.0.4',
     description='toscawidgets2 wrapper for d3 (data-driven documents)',
     long_description=long_description,
     author='Ralph Bean',

tw2/d3/static/ext/bar.js

                     tw2.store[selector].data[i].value += Math.random() * 3;
                 }
             }, interval);
-        }
+        },
+        index_of: function(selector, key) {
+            var index = 0;
+            for (var i = 0; i < tw2.store[selector].data.length; i++) {
+                if (tw2.store[selector].data[i].key == key) {
+                    return i;
+                }
+            }
+            return null;
+        },
+        set_value: function(selector, key, value) {
+            var index = tw2.d3.util.index_of(selector, key);
+            tw2.store[selector].data[index].value = value;
+        },
+        bump_value: function(selector, key, value) {
+            var index = tw2.d3.util.index_of(selector, key);
+            if (index == null) {
+                tw2.store[selector].data.push({'key': key, 'value': +value});
+            } else {
+                tw2.store[selector].data[index].value =
+                tw2.store[selector].data[index].value + 1;
+            }
+        },
     },
 
     bar: {