+ * Find the row number corresponding to the given x-value.
+ * Returns null if there is no such x-value in the data.
+ * If there are multiple rows with the same x-value, this will return the
+ * first one.
+ * @param {number} xVal The x-value to look for (e.g. millis since epoch).
+ * @return {?number} The row number, which you can pass to getValue(), or null.
+ */
+Dygraph.prototype.getRowForX = function(xVal) {
+ var low = 0,
+ high = this.numRows() - 1;
+
+ while (low <= high) {
+ var idx = (high + low) >> 1;
+ var x = this.getValue(idx, 0);
+ if (x < xVal) {
+ low = idx + 1;
+ } else if (x > xVal) {
+ high = idx - 1;
+ } else if (low != idx) { // equal, but there may be an earlier match.
+ high = idx;
+ } else {
+ return idx;
+ }
+ }
+
+ return null;
+};
+
+/**