From: Dan Vanderkam <danvdk@gmail.com>
Date: Thu, 16 Sep 2010 00:30:32 +0000 (-0400)
Subject: data access API
X-Git-Tag: v1.0.0~653
X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=e99fde0585bfc07ff26c9dc3a5ca30ea339cc81f;p=dygraphs.git

data access API
---

diff --git a/dygraph.js b/dygraph.js
index b53dccf..4adb716 100644
--- a/dygraph.js
+++ b/dygraph.js
@@ -352,6 +352,32 @@ Dygraph.prototype.toDataCoords = function(x, y) {
   return ret;
 };
 
+/**
+ * Returns the number of columns (including the independent variable).
+ */
+Dygraph.prototype.numColumns = function() {
+  return this.rawData_[0].length;
+};
+
+/**
+ * Returns the number of rows (excluding any header/label row).
+ */
+Dygraph.prototype.numRows = function() {
+  return this.rawData_.length;
+};
+
+/**
+ * Returns the value in the given row and column. If the row and column exceed
+ * the bounds on the data, returns null. Also returns null if the value is
+ * missing.
+ */
+Dygraph.prototype.getValue = function(row, col) {
+  if (row < 0 || row > this.rawData_.length) return null;
+  if (col < 0 || col > this.rawData_[row].length) return null;
+
+  return this.rawData_[row][col];
+};
+
 Dygraph.addEvent = function(el, evt, fn) {
   var normed_fn = function(e) {
     if (!e) var e = window.event;