Merge branch 'master' of https://github.com/raineth/dygraphs
authorDan Vanderkam <dan@dygraphs.com>
Mon, 14 Mar 2011 23:28:48 +0000 (19:28 -0400)
committerDan Vanderkam <dan@dygraphs.com>
Mon, 14 Mar 2011 23:28:48 +0000 (19:28 -0400)
docs/index.html
dygraph-canvas.js
dygraph.js
generate-combined.sh
generate-documentation.py [new file with mode: 0755]
push-to-web.sh
tests/independent-series.html [new file with mode: 0644]
tests/noise.html

index 8693bc9..772ab2c 100644 (file)
       <ul>
         <li>Plots time series without using an external server or Flash</li>
         <li>Works in Internet Explorer (using excanvas)</li>
-        <li>Lightweight (57kb) and responsive</li>
+        <li>Lightweight (69kb) and responsive</li>
         <li>Displays values on mouseover (this makes it easily discoverable)</li>
         <li>Supports error bands around data series</li>
         <li>Interactive zoom</li>
@@ -537,434 +537,9 @@ perl -ne 'BEGIN{print "Month,Nominal,Real\n"} chomp; ($m,$cpi,$low,$close,$high)
 
     <h2 id="options">Other Options</h2>
 
-    <p>These are the options that can be passed in through the optional third parameter of the Dygraph constructor. Under each option is a set of links to tests which demonstrate its use. While we attempt to keep this list up-to-date, a more complete list can be found in the <code>Dygraph.DEFAULT_ATTRS</code> map in <code>dygraph.js</code> and the <code>this.options</code> map in <code>dygraph-canvas.js</code>.</p>
-
-    <table class="thinborder" width="900">
-      <thead>
-        <tr>
-          <th width="150">Name</th>
-          <th width="200">Values</th>
-          <th width="150">Default</th>
-          <th>Description</th>
-        </tr>
-      </thead>
-      <tbody>
-        <tr>
-          <td><strong>includeZero</strong></td>
-          <td><code>boolean</code></td>
-          <td><code>false</code></td>
-        <td>Usually, dygraphs will use the range of the data plus some padding to set the range of the y-axis. If this option is set, the y-axis will always include zero, typically as the lowest value. This can be used to avoid exaggerating the variance in the data.
-        <div class="tests">Tests: <a href="tests/no-range.html">no-range</a> <a href="tests/numeric-gviz.html">numeric-gviz</a> <a href="tests/small-range-zero.html">small-range-zero</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>rollPeriod</strong></td>
-          <td><code>integer &gt;= 1</code></td>
-          <td><code>1</code></td>
-          <td>Number of days over which to average data. Discussed extensively above.
-        <div class="tests">Tests: <a href="tests/demo.html">demo</a> <a href="tests/two-series.html">two-series</a> <a href="tests/noise.html">noise</a> </div>
-        </td>
-        </tr>
-        <tr>
-          <td><strong>showRoller</strong></td>
-          <td><code>boolean</code></td>
-          <td><code>false</code></td>
-          <td>If the rolling average period text box should be shown.
-          <div class="tests">Tests: <a href="tests/callback.html">callback</a> <a href="tests/crosshair.html">crosshair</a> <a href="tests/fractions.html">fractions</a> <a href="tests/isolated-points.html">isolated-points</a> <a href="tests/numeric-gviz.html">numeric-gviz</a> <a href="tests/underlay-callback.html">underlay-callback</a> <a href="tests/highlighted-region.html">highlighted-region</a></div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>colors</strong></td>
-          <td><code>['red', '#00FF00']</code></td>
-          <td><code></code></td>
-          <td>List of colors for the data series. These can be of the form "#AABBCC" or "rgb(255,100,200)" or "yellow", etc. If not specified, equally-spaced points around a color wheel are used.
-          <div class="tests">Tests: <a href="tests/color-visibility.html">color-visibility</a> <a href="tests/demo.html">demo</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>fillGraph</strong></td>
-          <td><code>boolean<br/></code></td>
-          <td><code>false</code></td>
-          <td>Should the area underneath the graph be filled? This option is not
-          compatible with error bars.
-          <div class="tests">Tests: <a href="tests/fillGraph.html">fillGraph</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>visibility</strong></td>
-          <td><code>Array of booleans<br/></code></td>
-          <td><code>[true, true, ...]</code></td>
-          <td>Which series should initially be visible? Once the Dygraph has
-          been constructed, you can access and modify the visibility of each
-          series using the <code>visibility</code> and
-          <code>setVisibility</code> methods.
-          <div class="tests">Tests: <a href="tests/visibility.html">visibility</a> <a href="tests/color-visibility.html">color-visibility</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>colorSaturation</strong></td>
-          <td><code>0.0 - 1.0</code></td>
-          <td><code>1.0</code></td>
-          <td>If <strong>colors</strong> is not specified, saturation of the automatically-generated data series colors.
-          <div class="tests">Tests: <font color=red>none</font></div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>colorValue</strong></td>
-          <td><code>float (0.0 &mdash; 1.0)</code></td>
-          <td><code>1.0</code></td>
-          <td>If colors is not specified, value of the data series colors, as in hue/saturation/value. (0.0-1.0, default 0.5)
-          <div class="tests">Tests: <font color=red>none</font></div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>clickCallback</strong></td>
-          <td><code>function(e, date){<br>&nbsp;&nbsp;&nbsp;&nbsp;alert(date);<br>}</code></td>
-          <td><code>null</code></td>
-          <td>A function to call when a data point is clicked. The function should take two arguments, the event object for the click and the date that was clicked. (default null)
-          <div class="tests">Tests: <a href="tests/callback.html">callback</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>zoomCallback</strong></td>
-          <td><code>function(minDate,<br/>maxDate,<br/>yRanges){}</code></td>
-          <td><code>null</code></td>
-          <td>A function to call when the zoom window is changed (either by zooming in or out). minDate and maxDate are milliseconds since epoch. yRanges is an array of [bottom, top] pairs, one for each y-axis.
-          <div class="tests">Tests: <a href="tests/callback.html">callback</a> <a href="tests/zoom.html">zoom</a></div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>strokeWidth</strong></td>
-          <td><code>integer</code></td>
-          <td><code>1</code></td>
-          <td>Width of the data lines. This can be used to increase the contrast or some graphs.
-          <div class="tests">Tests: <font color=red>none</font></div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>dateWindow</strong></td>
-          <td><code>[<br>&nbsp;&nbsp;Date.parse('2006-01-01'),<br>&nbsp;&nbsp;(new Date()).valueOf()<br>]</code></td>
-          <td rowspan="2"><code>Full range of the<br/> input is shown</code></td>
-          <td>Initially zoom in on a section of the graph. Is of the form [earliest, latest], where earliest/latest are milliseconds since epoch.
-          <div class="tests">Tests: <a href="tests/dateWindow.html">dateWindow</a> <a href="tests/link-interaction.html">link-interaction</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>valueRange</strong></td>
-          <td><code>[10, 110]</code></td>
-          <td>Explicitly set the vertical range of the graph to [low, high].
-          <div class="tests">Tests: <font color=red>none</font></div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>labelsSeparateLines</strong></td>
-          <td><code>boolean</code></td>
-          <td><code>false</code></td>
-          <td>Put <code>&lt;br/&gt;</code> between lines in the label string. Often used in conjunction with <strong>labelsDiv</strong>.
-          <div class="tests">Tests: <a href="tests/customLabel.html">customLabel</a> <a href="tests/demo.html">demo</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>labelsDiv</strong></td>
-          <td><code style="font-size: small">document.getElementById('foo')</code><br/>or<br/><code>'foo'</code></td>
-          <td><code>null</code></td>
-          <td style="vertical-align:top">Show data labels in an external div, rather than on the graph.  This value can either be a div element or a div id.
-          <div class="tests">Tests: <a href="tests/label-div.html">label-div</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>labelsShowZeroValues</strong></td>
-          <td><code>boolean</code></td>
-          <td><code>true</code></td>
-          <td>Show zero value labels in the labelsDiv.
-          <div class="tests">Tests: <a href="tests/label-div.html">label-div</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>labelsKMB</strong></td>
-          <td><code>true</code></td>
-          <td><code>false</code></td>
-          <td>Show K/M/B for thousands/millions/billions on y-axis.
-          <div class="tests">Tests: <a href="tests/demo.html">demo</a> <a href="tests/labelsKMB.html">labelsKMB</a> <a href="tests/no-range.html">no-range</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>labelsKMG2</strong></td>
-          <td><code>true</code></td>
-          <td><code>false</code></td>
-          <td>Show k/M/G for kilo/Mega/Giga on y-axis. This is different than
-          <code>labelsKMB</code> in that it uses base 2, not 10.
-          <div class="tests">Tests: <a href="tests/labelsKMB.html">labelsKMB</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>labelsDivWidth</strong></td>
-          <td><code>250</code></td>
-          <td><code></code></td>
-          <td>Width (in pixels) of the div which shows information on the currently-highlighted points.
-          <div class="tests">Tests: <a href="tests/customLabel.html">customLabel</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>labelsDivStyles</strong></td>
-          <td><code>{}</code></td>
-          <td><code>null</code></td>
-          <td>Additional styles to apply to the currently-highlighted points div. For example, { 'font-weight': 'bold' } will make the labels bold.
-          <div class="tests">Tests: <a href="tests/border.html">border</a> <a href="tests/customLabel.html">customLabel</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>highlightCircleSize</strong></td>
-          <td><code>integer</code></td>
-          <td><code>3</code></td>
-          <td>The size in pixels of the dot drawn over highlighted points.
-          <div class="tests">Tests: <a href="tests/grid_dot.html">grid_dot</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>drawPoints</strong></td>
-          <td><code>boolean</code></td>
-          <td><code>false</code></td>
-          <td>Draw a small dot at each point, in addition to a line going through the point. This makes the individual data points easier to see, but can increase visual clutter in the chart.
-          <div class="tests">Tests: <a href="tests/draw-points.html">draw-points</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>pointSize</strong></td>
-          <td><code>integer</code></td>
-          <td><code>1</code></td>
-          <td>The size of the dot to draw on each point in pixels (see drawPoints). A dot is always drawn when a point is "isolated", i.e. there is a missing point on either side of it. This also controls the size of those dots.
-          <div class="tests">Tests: <font color=red>none</font></div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>pixelsPerXLabel</strong></td>
-          <td rowspan="2"><code>integer</code></td>
-          <td><code>60</code></td>
-          <td rowspan="2">Number of pixels to require between each x- and y-label. Larger values will yield a sparser axis with fewer ticks.
-          <div class="tests">Tests: <a href="tests/spacing.html">spacing</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>pixelsPerYLabel</strong></td>
-          <td><code>30</code></td>
-        </tr>
-        <tr>
-          <td><strong>xAxisLabelWidth</strong></td>
-          <td rowspan="2"><code>integer</code></td>
-          <td><code></code></td>
-          <td rowspan="2">Width (in pixels) of the x- and y-axis labels.
-          <div class="tests">Tests: <a href="tests/customLabel.html">customLabel</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>yAxisLabelWidth</strong></td>
-          <td><code></code></td>
-        </tr>
-        <tr>
-          <td><strong>axisLabelFontSize</strong></td>
-          <td><code>integer</code></td>
-          <td><code>14</code></td>
-          <td>Size of the font (in pixels) to use in the axis labels, both x- and y-axis.
-          <div class="tests">Tests: <font color=red>none</font></div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>xAxisLabelFormatter</strong></td>
-          <td><code>function(date, granularity)</code></td>
-          <td><code>Dygraph.dateAxisFormatter</code></td>
-          <td>Function to call to format values along the x axis.
-            <div class="tests">Tests: <a href="tests/x-axis-formatter.html">xAxisLabelFormatter</a></div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>yAxisLabelFormatter</strong></td>
-          <td><code>function(x)</code></td>
-          <td><code>yValueFormatter</code></td>
-          <td>
-            Function used to format values along the Y axis. By default it uses the same as the <code>yValueFormatter</code> unless specified.
-            <div class="tests">Tests: <a href="tests/y-axis-formatter.html">yAxisLabelFormatter</a></div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>rightGap</strong></td>
-          <td><code>integer</code></td>
-          <td><code></code></td>
-          <td>Number of pixels to leave blank at the right edge of the Dygraph. This makes it easier to highlight the right-most data point.
-          <div class="tests">Tests: <font color=red>none</font></div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>errorBars</strong></td>
-          <td><code>boolean</code></td>
-          <td><code>false</code></td>
-          <td>Does the data contain standard deviations? Setting this to true alters the input format (see above).
-          <div class="tests">Tests: <a href="tests/noise.html">noise</a> <a href="tests/customLabel.html">customLabel</a> <a href="tests/draw-points.html">draw-points</a> <a href="tests/fillGraph.html">fillGraph</a> <a href="tests/fractions.html">fractions</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>sigma</strong></td>
-          <td><code>integer</code></td>
-          <td><code></code></td>
-          <td>When errorBars is set, shade this many standard deviations above/below each point.
-          <div class="tests">Tests: <font color=red>none</font></div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>fractions</strong></td>
-          <td><code>boolean</code></td>
-          <td><code>false</code></td>
-          <td>When set, attempt to parse each cell in the CSV file as "a/b", where a and b are integers. The ratio will be plotted. This allows computation of Wilson confidence intervals (see below).
-          <div class="tests">Tests: <a href="tests/fractions.html">fractions</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>wilsonInterval</strong></td>
-          <td><code>boolean</code></td>
-          <td><code>true</code></td>
-          <td>Use in conjunction with the "fractions" option. Instead of plotting +/- N standard deviations, dygraphs will compute a Wilson confidence interval and plot that. This has more reasonable behavior for ratios close to 0 or 1.
-          <div class="tests">Tests: <font color=red>none</font></div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>customBars</strong></td>
-          <td><code>boolean</code></td>
-          <td><code>false</code></td>
-          <td>When set, parse each CSV cell as "low;middle;high". Error bars will be drawn for each point between low and high, with the series itself going through middle.
-          <div class="tests">Tests: <a href="tests/custom-bars.html">custom-bars</a> <a href="tests/zero-series.html">zero-series</a> </div>
-          </td>
-        </tr>
-
-        <tr>
-          <td><strong>drawCallback</strong></td>
-          <td><code>function(dygraph, is_initial)</code></td>
-          <td><code>null</code></td>
-          <td>When set, this callback gets called every time the dygraph is drawn. This includes the initial draw, after zooming and repeatedly while panning. The first parameter is the dygraph being drawn. The second is a boolean value indicating whether this is the initial draw.
-          <div class="tests">Tests: <a href="tests/callback.html">callback</a> <a href="tests/synchronize.html">synchronize</a> </div>
-          </td>
-        </tr>
-
-        <tr>
-          <td><strong>gridLineColor</strong></td>
-          <td><code>red, blue</code></td>
-          <td><code>rgb(128,128,128)</code></td>
-          <td>The color of the gridlines.
-          <div class="tests">Tests: <a href="tests/grid_dot.html">grid_dot</a> </div>
-          </td>
-        </tr>
-
-        <tr>
-          <td><strong>highlightCallback</strong></td>
-          <td><code>function(event, x, points,row)</code></td>
-          <td><code>null</code></td>
-          <td>When set, this callback gets called every time a new point is highlighted. The parameters are the JavaScript mousemove event, the x-coordinate of the highlighted points and an array of highlighted points: <code>[ {name: 'series', yval: y-value}, &hellip; ]</code>
-          <div class="tests">Tests: <a href="tests/callback.html">callback</a> <a href="tests/crosshair.html">crosshair</a> </div>
-          </td>
-        </tr>
-
-        <tr>
-          <td><strong>unhighlightCallback</strong></td>
-          <td><code>function(event)</code></td>
-          <td><code>null</code></td>
-          <td>When set, this callback gets called every time the user stops highlighting any point by mousing out of the graph.  The parameter is the mouseout event.
-            <div class="tests">Tests: <a href="tests/callback.html">callback</a> <a href="tests/crosshair.html">crosshair</a> </div>
-          </td>
-        </tr>
-
-        <tr>
-          <td><strong>underlayCallback</strong></td>
-          <td><code>function(canvas, area, dygraph)</code></td>
-          <td><code>null</code></td>
-          <td>When set, this callback gets called before the chart is drawn. It
-            allows you to draw underneath the chart. See the tests for more
-            details on how to use this.
-            <div class="tests">Tests:
-              <a href="tests/underlay-callback.html">underlay-callback</a>
-              <a href="tests/highlighted-region.html">highlighted-region</a>
-            </div>
-          </td>
-        </tr>
-
-        <tr>
-          <td><strong>strokeWidth</strong></td>
-          <td><code>0.5, 2.0</code></td>
-          <td><code>1.0</code></td>
-          <td>The width of the lines connecting data points.
-          <div class="tests">Tests: <a href="tests/grid_dot.html">grid_dot</a> </div>
-          </td>
-        </tr>
-
-        <tr>
-          <td><strong>width</strong></td>
-          <td rowspan="2"><code>integer</code></td>
-          <td><code>480</code></td>
-          <td rowspan="2">Width/Height (in pixels) of the chart. If the container div has been explicitly sized, these attributes will be ignored.
-          <div class="tests">Tests: <a href="tests/demo.html">demo</a> <a href="tests/link-interaction.html">link-interaction</a> <a href="tests/no-range.html">no-range</a> </div>
-          </td>
-        </tr>
-        <tr>
-          <td><strong>height</strong></td>
-          <td><code>320</code></td>
-        </tr>
-
-        <tr>
-          <td><strong>stepPlot</strong></td>
-          <td><code>boolean</code></td>
-          <td><code>false</code></td>
-          <td>
-            When set, display the graph as a step plot instead of a line plot.
-            <div class="tests">Tests: <a href="tests/steps.html">steps</a></div>
-          </td>
-        </tr>
-
-        <tr>
-          <td><strong>xValueFormatter</strong></td>
-          <td><code>function(x)</code></td>
-          <td></td>
-          <td>
-            Function to provide a custom display format the X value for mouseover.
-          </td>
-        </tr>
-
-        <tr>
-          <td><strong>yValueFormatter</strong></td>
-          <td><code>function(x)</code></td>
-          <td>(Round to 2 decimal places)</td>
-          <td>
-            Function to provide a custom display format for the Y value for mouseover.
-            <div class="tests">Tests: <a href="tests/y-axis-formatter.html">yAxisLabelFormatter</a></div>
-          </td>
-        </tr>
-
-        <tr>
-          <td><strong>avoidMinZero</strong></td>
-          <td><code>boolean</code></td>
-          <td><code>false</code></td>
-          <td>
-            When set, the heuristic that fixes the Y axis at zero for a data set with the minimum Y value of zero is disabled.
-            This is particularly useful for data sets that contain many zero values, especially for step plots which may otherwise have lines not visible running along the bottom axis.
-            <div class="tests">Tests: <a href="tests/avoidMinZero.html">avoidMinZero</a></div>
-          </td>
-        </tr>
-
-        <tr>
-          <td><strong>logscale</strong></td>
-          <td><code>boolean</code></td>
-          <td><code>false</code></td>
-          <td>
-            When set for a y-axis, the graph shows that axis in y-scale. Any values less than or equal
-            to zero are not displayed.</p>
-
-           Not compatible with showZero, and ignores connectSeparatedPoints. Also, showing log scale
-           with valueRanges that are less than zero will result in an unviewable graph.<br/>
-
-            <div class="tests">Tests: <a href="tests/logscale.html">logscale</a>,
-            <a href="tests/stock.html"> stock</div>
-          </td>
-        </tr>
-
-      </tbody>
-    </table>
+    <p>In addition to the options mentioned above (<code>showRoller</code>, <code>rollPeriod</code>, <code>errorBars</code>, <code>valueRange</code>), there are <i>many</i> others.</p>
+
+    <p>For a full list, see the <a href="options.html">Dygraphs Options Reference</a> page.</p>
 
     <h2>Common Gotchas</h2>
 
index f463e39..2f8821e 100644 (file)
@@ -739,8 +739,6 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() {
   }
 
   // create paths
-  var isOK = function(x) { return x && !isNaN(x); };
-
   var ctx = context;
   if (errorBars) {
     if (fillGraph) {
@@ -768,7 +766,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() {
       for (var j = 0; j < this.layout.points.length; j++) {
         var point = this.layout.points[j];
         if (point.name == setName) {
-          if (!isOK(point.y)) {
+          if (!Dygraph.isOK(point.y)) {
             prevX = NaN;
             continue;
           }
@@ -833,7 +831,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() {
       for (var j = 0; j < this.layout.points.length; j++) {
         var point = this.layout.points[j];
         if (point.name == setName) {
-          if (!isOK(point.y)) {
+          if (!Dygraph.isOK(point.y)) {
             prevX = NaN;
             continue;
           }
@@ -880,7 +878,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() {
     for (var j = 0; j < points.length; j++) {
       var point = points[j];
       if (point.name == setName) {
-        if (!isOK(point.canvasy)) {
+        if (!Dygraph.isOK(point.canvasy)) {
           if (stepPlot && prevX != null) {
             // Draw a horizontal line to the start of the missing data
             ctx.beginPath();
@@ -896,7 +894,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() {
           // A point is "isolated" if it is non-null but both the previous
           // and next points are null.
           var isIsolated = (!prevX && (j == points.length - 1 ||
-                                       !isOK(points[j+1].canvasy)));
+                                       !Dygraph.isOK(points[j+1].canvasy)));
 
           if (!prevX) {
             prevX = point.canvasx;
index 7f312b6..5380f26 100644 (file)
@@ -187,6 +187,9 @@ Dygraph.DEFAULT_ATTRS = {
   stackedGraph: false,
   hideOverlayOnMouseOut: true,
 
+  // TODO(danvk): support 'onmouseover' and 'never', and remove synonyms.
+  legend: 'onmouseover',  // the only relevant value at the moment is 'always'.
+
   stepPlot: false,
   avoidMinZero: false,
 
@@ -338,6 +341,16 @@ Dygraph.prototype.toString = function() {
 }
 
 Dygraph.prototype.attr_ = function(name, seriesName) {
+// <REMOVE_FOR_COMBINED>
+  if (typeof(Dygraph.OPTIONS_REFERENCE) === 'undefined') {
+    this.error('Must include options reference JS for testing');
+  } else if (!Dygraph.OPTIONS_REFERENCE.hasOwnProperty(name)) {
+    this.error('Dygraphs is using property ' + name + ', which has no entry ' +
+               'in the Dygraphs.OPTIONS_REFERENCE listing.');
+    // Only log this error once.
+    Dygraph.OPTIONS_REFERENCE[name] = true;
+  }
+// </REMOVE_FOR_COMBINED>
   if (seriesName &&
       typeof(this.user_attrs_[seriesName]) != 'undefined' &&
       this.user_attrs_[seriesName] != null &&
@@ -1553,6 +1566,52 @@ Dygraph.prototype.idxToRow_ = function(idx) {
   return -1;
 };
 
+// TODO(danvk): rename this function to something like 'isNonZeroNan'.
+Dygraph.isOK = function(x) {
+  return x && !isNaN(x);
+};
+
+Dygraph.prototype.generateLegendHTML_ = function(x, sel_points) {
+  // If no points are selected, we display a default legend. Traditionally,
+  // this has been blank. But a better default would be a conventional legend,
+  // which provides essential information for a non-interactive chart.
+  if (typeof(x) === 'undefined') {
+    if (this.attr_('legend') != 'always') return '';
+
+    var sepLines = this.attr_('labelsSeparateLines');
+    var labels = this.attr_('labels');
+    var html = '';
+    for (var i = 1; i < labels.length; i++) {
+      var c = new RGBColor(this.plotter_.colors[labels[i]]);
+      if (i > 1) html += (sepLines ? '<br/>' : ' ');
+      html += "<b><font color='" + c.toHex() + "'>&mdash;" + labels[i] +
+        "</font></b>";
+    }
+    return html;
+  }
+
+  var displayDigits = this.numXDigits_ + this.numExtraDigits_;
+  var html = this.attr_('xValueFormatter')(x, displayDigits) + ":";
+
+  var fmtFunc = this.attr_('yValueFormatter');
+  var showZeros = this.attr_("labelsShowZeroValues");
+  var sepLines = this.attr_("labelsSeparateLines");
+  for (var i = 0; i < this.selPoints_.length; i++) {
+    var pt = this.selPoints_[i];
+    if (pt.yval == 0 && !showZeros) continue;
+    if (!Dygraph.isOK(pt.canvasy)) continue;
+    if (sepLines) html += "<br/>";
+
+    var c = new RGBColor(this.plotter_.colors[pt.name]);
+    var yval = fmtFunc(pt.yval, displayDigits);
+    // TODO(danvk): use a template string here and make it an attribute.
+    html += " <b><font color='" + c.toHex() + "'>"
+      + pt.name + "</font></b>:"
+      + yval;
+  }
+  return html;
+};
+
 /**
  * Draw dots over the selectied points in the data series. This function
  * takes care of cleanup of previously-drawn dots.
@@ -1574,46 +1633,24 @@ Dygraph.prototype.updateSelection_ = function() {
                   2 * maxCircleSize + 2, this.height_);
   }
 
-  var isOK = function(x) { return x && !isNaN(x); };
-
   if (this.selPoints_.length > 0) {
-    var canvasx = this.selPoints_[0].canvasx;
-
     // Set the status message to indicate the selected point(s)
-    var replace = this.attr_('xValueFormatter')(
-          this.lastx_, this.numXDigits_ + this.numExtraDigits_) + ":";
-    var fmtFunc = this.attr_('yValueFormatter');
-    var clen = this.colors_.length;
-
     if (this.attr_('showLabelsOnHighlight')) {
-      // Set the status message to indicate the selected point(s)
-      for (var i = 0; i < this.selPoints_.length; i++) {
-        if (!this.attr_("labelsShowZeroValues") && this.selPoints_[i].yval == 0) continue;
-        if (!isOK(this.selPoints_[i].canvasy)) continue;
-        if (this.attr_("labelsSeparateLines")) {
-          replace += "<br/>";
-        }
-        var point = this.selPoints_[i];
-        var c = new RGBColor(this.plotter_.colors[point.name]);
-        var yval = fmtFunc(point.yval, this.numYDigits_ + this.numExtraDigits_);
-        replace += " <b><font color='" + c.toHex() + "'>"
-                + point.name + "</font></b>:"
-                + yval;
-      }
-
-      this.attr_("labelsDiv").innerHTML = replace;
+      var html = this.generateLegendHTML_(this.lastx_, this.selPoints_);
+      this.attr_("labelsDiv").innerHTML = html;
     }
 
     // Draw colored circles over the center of each selected point
+    var canvasx = this.selPoints_[0].canvasx;
     ctx.save();
     for (var i = 0; i < this.selPoints_.length; i++) {
-      if (!isOK(this.selPoints_[i].canvasy)) continue;
-      var circleSize =
-        this.attr_('highlightCircleSize', this.selPoints_[i].name);
+      var pt = this.selPoints_[i];
+      if (!Dygraph.isOK(pt.canvasy)) continue;
+
+      var circleSize = this.attr_('highlightCircleSize', pt.name);
       ctx.beginPath();
-      ctx.fillStyle = this.plotter_.colors[this.selPoints_[i].name];
-      ctx.arc(canvasx, this.selPoints_[i].canvasy, circleSize,
-              0, 2 * Math.PI, false);
+      ctx.fillStyle = this.plotter_.colors[pt.name];
+      ctx.arc(canvasx, pt.canvasy, circleSize, 0, 2 * Math.PI, false);
       ctx.fill();
     }
     ctx.restore();
@@ -1685,7 +1722,7 @@ Dygraph.prototype.clearSelection = function() {
   // Get rid of the overlay data
   var ctx = this.canvas_.getContext("2d");
   ctx.clearRect(0, 0, this.width_, this.height_);
-  this.attr_("labelsDiv").innerHTML = "";
+  this.attr_('labelsDiv').innerHTML = this.generateLegendHTML_();
   this.selPoints_ = [];
   this.lastx_ = -1;
 }
@@ -2470,6 +2507,11 @@ Dygraph.prototype.drawGraph_ = function() {
   this.canvas_.getContext('2d').clearRect(0, 0, this.canvas_.width,
                                           this.canvas_.height);
 
+  if (is_initial_draw) {
+    // Generate a static legend before any particular point is selected.
+    this.attr_('labelsDiv').innerHTML = this.generateLegendHTML_();
+  }
+
   if (this.attr_("drawCallback") !== null) {
     this.attr_("drawCallback")(this, is_initial_draw);
   }
@@ -2878,6 +2920,40 @@ Dygraph.prototype.detectTypeFromString_ = function(str) {
 };
 
 /**
+ * Parses the value as a floating point number. This is like the parseFloat()
+ * built-in, but with a few differences:
+ * - the empty string is parsed as null, rather than NaN.
+ * - if the string cannot be parsed at all, an error is logged.
+ * If the string can't be parsed, this method returns null.
+ * @param {String} x The string to be parsed
+ * @param {Number} opt_line_no The line number from which the string comes.
+ * @param {String} opt_line The text of the line from which the string comes.
+ * @private
+ */
+
+// Parse the x as a float or return null if it's not a number.
+Dygraph.prototype.parseFloat_ = function(x, opt_line_no, opt_line) {
+  var val = parseFloat(x);
+  if (!isNaN(val)) return val;
+
+  // Try to figure out what happeend.
+  // If the value is the empty string, parse it as null.
+  if (/^ *$/.test(x)) return null;
+
+  // If it was actually "NaN", return it as NaN.
+  if (/^ *nan *$/i.test(x)) return NaN;
+
+  // Looks like a parsing error.
+  var msg = "Unable to parse '" + x + "' as a number";
+  if (opt_line !== null && opt_line_no !== null) {
+    msg += " on line " + (1+opt_line_no) + " ('" + opt_line + "') of CSV.";
+  }
+  this.error(msg);
+
+  return null;
+};
+
+/**
  * Parses a string in a special csv format.  We expect a csv file where each
  * line is a date point, and the first field in each line is the date string.
  * We also expect that all remaining fields represent series.
@@ -2909,13 +2985,7 @@ Dygraph.prototype.parseCSV_ = function(data) {
     start = 1;
     this.attrs_.labels = lines[0].split(delim);
   }
-
-  // Parse the x as a float or return null if it's not a number.
-  var parseFloatOrNull = function(x) {
-    var val = parseFloat(x);
-    // isFinite() returns false for NaN and +/-Infinity.
-    return isFinite(val) ? val : null;
-  };
+  var line_no = 0;
 
   var xParser;
   var defaultParserSet = false;  // attempt to auto-detect x value type
@@ -2923,6 +2993,7 @@ Dygraph.prototype.parseCSV_ = function(data) {
   var outOfOrder = false;
   for (var i = start; i < lines.length; i++) {
     var line = lines[i];
+    line_no = i;
     if (line.length == 0) continue;  // skip blank lines
     if (line[0] == '#') continue;    // skip comment lines
     var inFields = line.split(delim);
@@ -2941,37 +3012,68 @@ Dygraph.prototype.parseCSV_ = function(data) {
       for (var j = 1; j < inFields.length; j++) {
         // TODO(danvk): figure out an appropriate way to flag parse errors.
         var vals = inFields[j].split("/");
-        fields[j] = [parseFloatOrNull(vals[0]), parseFloatOrNull(vals[1])];
+        if (vals.length != 2) {
+          this.error('Expected fractional "num/den" values in CSV data ' +
+                     "but found a value '" + inFields[j] + "' on line " +
+                     (1 + i) + " ('" + line + "') which is not of this form.");
+          fields[j] = [0, 0];
+        } else {
+          fields[j] = [this.parseFloat_(vals[0], i, line),
+                       this.parseFloat_(vals[1], i, line)];
+        }
       }
     } else if (this.attr_("errorBars")) {
       // If there are error bars, values are (value, stddev) pairs
-      for (var j = 1; j < inFields.length; j += 2)
-        fields[(j + 1) / 2] = [parseFloatOrNull(inFields[j]),
-                               parseFloatOrNull(inFields[j + 1])];
+      if (inFields.length % 2 != 1) {
+        this.error('Expected alternating (value, stdev.) pairs in CSV data ' +
+                   'but line ' + (1 + i) + ' has an odd number of values (' +
+                   (inFields.length - 1) + "): '" + line + "'");
+      }
+      for (var j = 1; j < inFields.length; j += 2) {
+        fields[(j + 1) / 2] = [this.parseFloat_(inFields[j], i, line),
+                               this.parseFloat_(inFields[j + 1], i, line)];
+      }
     } else if (this.attr_("customBars")) {
       // Bars are a low;center;high tuple
       for (var j = 1; j < inFields.length; j++) {
         var vals = inFields[j].split(";");
-        fields[j] = [ parseFloatOrNull(vals[0]),
-                      parseFloatOrNull(vals[1]),
-                      parseFloatOrNull(vals[2]) ];
+        fields[j] = [ this.parseFloat_(vals[0], i, line),
+                      this.parseFloat_(vals[1], i, line),
+                      this.parseFloat_(vals[2], i, line) ];
       }
     } else {
       // Values are just numbers
       for (var j = 1; j < inFields.length; j++) {
-        fields[j] = parseFloatOrNull(inFields[j]);
+        fields[j] = this.parseFloat_(inFields[j], i, line);
       }
     }
     if (ret.length > 0 && fields[0] < ret[ret.length - 1][0]) {
       outOfOrder = true;
     }
-    ret.push(fields);
 
     if (fields.length != expectedCols) {
       this.error("Number of columns in line " + i + " (" + fields.length +
                  ") does not agree with number of labels (" + expectedCols +
                  ") " + line);
     }
+
+    // If the user specified the 'labels' option and none of the cells of the
+    // first row parsed correctly, then they probably double-specified the
+    // labels. We go with the values set in the option, discard this row and
+    // log a warning to the JS console.
+    if (i == 0 && this.attr_('labels')) {
+      var all_null = true;
+      for (var j = 0; all_null && j < fields.length; j++) {
+        if (fields[j]) all_null = false;
+      }
+      if (all_null) {
+        this.warn("The dygraphs 'labels' option is set, but the first row of " +
+                  "CSV data ('" + line + "') appears to also contain labels. " +
+                  "Will drop the CSV labels and use the option labels.");
+        continue;
+      }
+    }
+    ret.push(fields);
   }
 
   if (outOfOrder) {
@@ -3513,3 +3615,460 @@ Dygraph.GVizChart.prototype.getSelection = function() {
 
 // Older pages may still use this name.
 DateGraph = Dygraph;
+
+// <REMOVE_FOR_COMBINED>
+Dygraph.OPTIONS_REFERENCE =  // <JSON>
+{
+  "xValueParser": {
+    "default": "parseFloat() or Date.parse()*",
+    "labels": ["CSV parsing"],
+    "type": "function(str) -> number",
+    "description": "A function which parses x-values (i.e. the dependent series). Must return a number, even when the values are dates. In this case, millis since epoch are used. This is used primarily for parsing CSV data. *=Dygraphs is slightly more accepting in the dates which it will parse. See code for details."
+  },
+  "stackedGraph": {
+    "default": "false",
+    "labels": ["Data Line display"],
+    "type": "boolean",
+    "description": "If set, stack series on top of one another rather than drawing them independently."
+  },
+  "pointSize": {
+    "default": "1",
+    "labels": ["Data Line display"],
+    "type": "integer",
+    "description": "The size of the dot to draw on each point in pixels (see drawPoints). A dot is always drawn when a point is \"isolated\", i.e. there is a missing point on either side of it. This also controls the size of those dots."
+  },
+  "labelsDivStyles": {
+    "default": "null",
+    "labels": ["Legend"],
+    "type": "{}",
+    "description": "Additional styles to apply to the currently-highlighted points div. For example, { 'font-weight': 'bold' } will make the labels bold."
+  },
+  "drawPoints": {
+    "default": "false",
+    "labels": ["Data Line display"],
+    "type": "boolean",
+    "description": "Draw a small dot at each point, in addition to a line going through the point. This makes the individual data points easier to see, but can increase visual clutter in the chart."
+  },
+  "height": {
+    "default": "320",
+    "labels": ["Overall display"],
+    "type": "integer",
+    "description": "Height, in pixels, of the chart. If the container div has been explicitly sized, this will be ignored."
+  },
+  "zoomCallback": {
+    "default": "null",
+    "labels": ["Callbacks"],
+    "type": "function(minDate, maxDate, yRanges)",
+    "description": "A function to call when the zoom window is changed (either by zooming in or out). minDate and maxDate are milliseconds since epoch. yRanges is an array of [bottom, top] pairs, one for each y-axis."
+  },
+  "pointClickCallback": {
+    "default": "",
+    "labels": ["Callbacks", "Interactive Elements"],
+    "type": "",
+    "description": ""
+  },
+  "colors": {
+    "default": "(see description)",
+    "labels": ["Data Series Colors"],
+    "type": "array<string>",
+    "example": "['red', '#00FF00']",
+    "description": "List of colors for the data series. These can be of the form \"#AABBCC\" or \"rgb(255,100,200)\" or \"yellow\", etc. If not specified, equally-spaced points around a color wheel are used."
+  },
+  "connectSeparatedPoints": {
+    "default": "false",
+    "labels": ["Data Line display"],
+    "type": "boolean",
+    "description": "Usually, when Dygraphs encounters a missing value in a data series, it interprets this as a gap and draws it as such. If, instead, the missing values represents an x-value for which only a different series has data, then you'll want to connect the dots by setting this to true. To explicitly include a gap with this option set, use a value of NaN."
+  },
+  "highlightCallback": {
+    "default": "null",
+    "labels": ["Callbacks"],
+    "type": "function(event, x, points,row)",
+    "description": "When set, this callback gets called every time a new point is highlighted. The parameters are the JavaScript mousemove event, the x-coordinate of the highlighted points and an array of highlighted points: <code>[ {name: 'series', yval: y-value}, &hellip; ]</code>"
+  },
+  "includeZero": {
+    "default": "false",
+    "labels": ["Axis display"],
+    "type": "boolean",
+    "description": "Usually, dygraphs will use the range of the data plus some padding to set the range of the y-axis. If this option is set, the y-axis will always include zero, typically as the lowest value. This can be used to avoid exaggerating the variance in the data"
+  },
+  "rollPeriod": {
+    "default": "1",
+    "labels": ["Error Bars", "Rolling Averages"],
+    "type": "integer &gt;= 1",
+    "description": "Number of days over which to average data. Discussed extensively above."
+  },
+  "unhighlightCallback": {
+    "default": "null",
+    "labels": ["Callbacks"],
+    "type": "function(event)",
+    "description": "When set, this callback gets called every time the user stops highlighting any point by mousing out of the graph.  The parameter is the mouseout event."
+  },
+  "axisTickSize": {
+    "default": "3.0",
+    "labels": ["Axis display"],
+    "type": "number",
+    "description": "The size of the line to display next to each tick mark on x- or y-axes."
+  },
+  "labelsSeparateLines": {
+    "default": "false",
+    "labels": ["Legend"],
+    "type": "boolean",
+    "description": "Put <code>&lt;br/&gt;</code> between lines in the label string. Often used in conjunction with <strong>labelsDiv</strong>."
+  },
+  "xValueFormatter": {
+    "default": "(Round to 2 decimal places)",
+    "labels": ["Axis display"],
+    "type": "function(x)",
+    "description": "Function to provide a custom display format for the X value for mouseover."
+  },
+  "pixelsPerYLabel": {
+    "default": "30",
+    "labels": ["Axis display", "Grid"],
+    "type": "integer",
+    "description": "Number of pixels to require between each x- and y-label. Larger values will yield a sparser axis with fewer ticks."
+  },
+  "annotationMouseOverHandler": {
+    "default": "null",
+    "labels": ["Annotations"],
+    "type": "function(annotation, point, dygraph, event)",
+    "description": "If provided, this function is called whenever the user mouses over an annotation."
+  },
+  "annotationMouseOutHandler": {
+    "default": "null",
+    "labels": ["Annotations"],
+    "type": "function(annotation, point, dygraph, event)",
+    "description": "If provided, this function is called whenever the user mouses out of an annotation."
+  },
+  "annotationClickHandler": {
+    "default": "null",
+    "labels": ["Annotations"],
+    "type": "function(annotation, point, dygraph, event)",
+    "description": "If provided, this function is called whenever the user clicks on an annotation."
+  },
+  "annotationDblClickHandler": {
+    "default": "null",
+    "labels": ["Annotations"],
+    "type": "function(annotation, point, dygraph, event)",
+    "description": "If provided, this function is called whenever the user double-clicks on an annotation."
+  },
+  "drawCallback": {
+    "default": "null",
+    "labels": ["Callbacks"],
+    "type": "function(dygraph, is_initial)",
+    "description": "When set, this callback gets called every time the dygraph is drawn. This includes the initial draw, after zooming and repeatedly while panning. The first parameter is the dygraph being drawn. The second is a boolean value indicating whether this is the initial draw."
+  },
+  "labelsKMG2": {
+    "default": "false",
+    "labels": ["Value display/formatting"],
+    "type": "boolean",
+    "description": "Show k/M/G for kilo/Mega/Giga on y-axis. This is different than <code>labelsKMB</code> in that it uses base 2, not 10."
+  },
+  "delimiter": {
+    "default": ",",
+    "labels": ["CSV parsing"],
+    "type": "string",
+    "description": "The delimiter to look for when separating fields of a CSV file. Setting this to a tab is not usually necessary, since tab-delimited data is auto-detected."
+  },
+  "axisLabelFontSize": {
+    "default": "14",
+    "labels": ["Axis display"],
+    "type": "integer",
+    "description": "Size of the font (in pixels) to use in the axis labels, both x- and y-axis."
+  },
+  "underlayCallback": {
+    "default": "null",
+    "labels": ["Callbacks"],
+    "type": "function(canvas, area, dygraph)",
+    "description": "When set, this callback gets called before the chart is drawn. It details on how to use this."
+  },
+  "width": {
+    "default": "480",
+    "labels": ["Overall display"],
+    "type": "integer",
+    "description": "Width, in pixels, of the chart. If the container div has been explicitly sized, this will be ignored."
+  },
+  "interactionModel": {
+    "default": "...",
+    "labels": ["Interactive Elements"],
+    "type": "Object",
+    "description": "TODO(konigsberg): document this"
+  },
+  "xTicker": {
+    "default": "Dygraph.dateTicker or Dygraph.numericTicks",
+    "labels": ["Axis display"],
+    "type": "function(min, max, dygraph) -> [{v: ..., label: ...}, ...]",
+    "description": "This lets you specify an arbitrary function to generate tick marks on an axis. The tick marks are an array of (value, label) pairs. The built-in functions go to great lengths to choose good tick marks so, if you set this option, you'll most likely want to call one of them and modify the result."
+  },
+  "xAxisLabelWidth": {
+    "default": "50",
+    "labels": ["Axis display"],
+    "type": "integer",
+    "description": "Width, in pixels, of the x-axis labels."
+  },
+  "showLabelsOnHighlight": {
+    "default": "true",
+    "labels": ["Interactive Elements", "Legend"],
+    "type": "boolean",
+    "description": "Whether to show the legend upon mouseover."
+  },
+  "axis": {
+    "default": "(none)",
+    "labels": ["Axis display"],
+    "type": "string or object",
+    "description": "Set to either an object ({}) filled with options for this axis or to the name of an existing data series with its own axis to re-use that axis. See tests for usage."
+  },
+  "pixelsPerXLabel": {
+    "default": "60",
+    "labels": ["Axis display", "Grid"],
+    "type": "integer",
+    "description": "Number of pixels to require between each x- and y-label. Larger values will yield a sparser axis with fewer ticks."
+  },
+  "labelsDiv": {
+    "default": "null",
+    "labels": ["Legend"],
+    "type": "DOM element or string",
+    "example": "<code style='font-size: small'>document.getElementById('foo')</code>or<code>'foo'",
+    "description": "Show data labels in an external div, rather than on the graph.  This value can either be a div element or a div id."
+  },
+  "fractions": {
+    "default": "false",
+    "labels": ["CSV parsing", "Error Bars"],
+    "type": "boolean",
+    "description": "When set, attempt to parse each cell in the CSV file as \"a/b\", where a and b are integers. The ratio will be plotted. This allows computation of Wilson confidence intervals (see below)."
+  },
+  "logscale": {
+    "default": "false",
+    "labels": ["Axis display"],
+    "type": "boolean",
+    "description": "When set for a y-axis, the graph shows that axis in y-scale. Any values less than or equal to zero are not displayed.\n\nNot compatible with showZero, and ignores connectSeparatedPoints. Also, showing log scale with valueRanges that are less than zero will result in an unviewable graph."
+  },
+  "strokeWidth": {
+    "default": "1.0",
+    "labels": ["Data Line display"],
+    "type": "integer",
+    "example": "0.5, 2.0",
+    "description": "The width of the lines connecting data points. This can be used to increase the contrast or some graphs."
+  },
+  "wilsonInterval": {
+    "default": "true",
+    "labels": ["Error Bars"],
+    "type": "boolean",
+    "description": "Use in conjunction with the \"fractions\" option. Instead of plotting +/- N standard deviations, dygraphs will compute a Wilson confidence interval and plot that. This has more reasonable behavior for ratios close to 0 or 1."
+  },
+  "fillGraph": {
+    "default": "false",
+    "labels": ["Data Line display"],
+    "type": "boolean",
+    "description": "Should the area underneath the graph be filled? This option is not compatible with error bars."
+  },
+  "highlightCircleSize": {
+    "default": "3",
+    "labels": ["Interactive Elements"],
+    "type": "integer",
+    "description": "The size in pixels of the dot drawn over highlighted points."
+  },
+  "gridLineColor": {
+    "default": "rgb(128,128,128)",
+    "labels": ["Grid"],
+    "type": "red, blue",
+    "description": "The color of the gridlines."
+  },
+  "visibility": {
+    "default": "[true, true, ...]",
+    "labels": ["Data Line display"],
+    "type": "Array of booleans",
+    "description": "Which series should initially be visible? Once the Dygraph has been constructed, you can access and modify the visibility of each series using the <code>visibility</code> and <code>setVisibility</code> methods."
+  },
+  "valueRange": {
+    "default": "Full range of the input is shown",
+    "labels": ["Axis display"],
+    "type": "Array of two numbers",
+    "example": "[10, 110]",
+    "description": "Explicitly set the vertical range of the graph to [low, high]."
+  },
+  "labelsDivWidth": {
+    "default": "250",
+    "labels": ["Legend"],
+    "type": "integer",
+    "description": "Width (in pixels) of the div which shows information on the currently-highlighted points."
+  },
+  "colorSaturation": {
+    "default": "1.0",
+    "labels": ["Data Series Colors"],
+    "type": "0.0 - 1.0",
+    "description": "If <strong>colors</strong> is not specified, saturation of the automatically-generated data series colors."
+  },
+  "yAxisLabelWidth": {
+    "default": "50",
+    "labels": ["Axis display"],
+    "type": "integer",
+    "description": "Width, in pixels, of the y-axis labels."
+  },
+  "hideOverlayOnMouseOut": {
+    "default": "true",
+    "labels": ["Interactive Elements", "Legend"],
+    "type": "boolean",
+    "description": "Whether to hide the legend when the mouse leaves the chart area."
+  },
+  "yValueFormatter": {
+    "default": "(Round to 2 decimal places)",
+    "labels": ["Axis display"],
+    "type": "function(x)",
+    "description": "Function to provide a custom display format for the Y value for mouseover."
+  },
+  "legend": {
+    "default": "onmouseover",
+    "labels": ["Legend"],
+    "type": "string",
+    "description": "When to display the legend. By default, it only appears when a user mouses over the chart. Set it to \"always\" to always display a legend of some sort."
+  },
+  "labelsShowZeroValues": {
+    "default": "true",
+    "labels": ["Legend"],
+    "type": "boolean",
+    "description": "Show zero value labels in the labelsDiv."
+  },
+  "stepPlot": {
+    "default": "false",
+    "labels": ["Data Line display"],
+    "type": "boolean",
+    "description": "When set, display the graph as a step plot instead of a line plot."
+  },
+  "labelsKMB": {
+    "default": "false",
+    "labels": ["Value display/formatting"],
+    "type": "boolean",
+    "description": "Show K/M/B for thousands/millions/billions on y-axis."
+  },
+  "rightGap": {
+    "default": "5",
+    "labels": ["Overall display"],
+    "type": "integer",
+    "description": "Number of pixels to leave blank at the right edge of the Dygraph. This makes it easier to highlight the right-most data point."
+  },
+  "avoidMinZero": {
+    "default": "false",
+    "labels": ["Axis display"],
+    "type": "boolean",
+    "description": "When set, the heuristic that fixes the Y axis at zero for a data set with the minimum Y value of zero is disabled. \nThis is particularly useful for data sets that contain many zero values, especially for step plots which may otherwise have lines not visible running along the bottom axis."
+  },
+  "xAxisLabelFormatter": {
+    "default": "Dygraph.dateAxisFormatter",
+    "labels": ["Axis display", "Value display/formatting"],
+    "type": "function(date, granularity)",
+    "description": "Function to call to format values along the x axis."
+  },
+  "clickCallback": {
+    "snippet": "function(e, date){<br>&nbsp;&nbsp;alert(date);<br>}",
+    "default": "null",
+    "labels": ["Callbacks"],
+    "type": "function(e, date)",
+    "description": "A function to call when a data point is clicked. The function should take two arguments, the event object for the click and the date that was clicked."
+  },
+  "yAxisLabelFormatter": {
+    "default": "yValueFormatter",
+    "labels": ["Axis display", "Value display/formatting"],
+    "type": "function(x)",
+    "description": "Function used to format values along the Y axis. By default it uses the same as the <code>yValueFormatter</code> unless specified."
+  },
+  "labels": {
+    "default": "[\"X\", \"Y1\", \"Y2\", ...]*",
+    "labels": ["Legend"],
+    "type": "array<string>",
+    "description": "A name for each data series, including the independent (X) series. For CSV files and DataTable objections, this is determined by context. For raw data, this must be specified. If it is not, default values are supplied and a warning is logged."
+  },
+  "dateWindow": {
+    "default": "Full range of the input is shown",
+    "labels": ["Axis display"],
+    "type": "Array of two Dates or numbers",
+    "example": "[<br>&nbsp;&nbsp;Date.parse('2006-01-01'),<br>&nbsp;&nbsp;(new Date()).valueOf()<br>]",
+    "description": "Initially zoom in on a section of the graph. Is of the form [earliest, latest], where earliest/latest are milliseconds since epoch. If the data for the x-axis is numeric, the values in dateWindow must also be numbers."
+  },
+  "showRoller": {
+    "default": "false",
+    "labels": ["Interactive Elements", "Rolling Averages"],
+    "type": "boolean",
+    "description": "If the rolling average period text box should be shown."
+  },
+  "sigma": {
+    "default": "2.0",
+    "labels": ["Error Bars"],
+    "type": "integer",
+    "description": "When errorBars is set, shade this many standard deviations above/below each point."
+  },
+  "customBars": {
+    "default": "false",
+    "labels": ["CSV parsing", "Error Bars"],
+    "type": "boolean",
+    "description": "When set, parse each CSV cell as \"low;middle;high\". Error bars will be drawn for each point between low and high, with the series itself going through middle."
+  },
+  "colorValue": {
+    "default": "1.0",
+    "labels": ["Data Series Colors"],
+    "type": "float (0.0 - 1.0)",
+    "description": "If colors is not specified, value of the data series colors, as in hue/saturation/value. (0.0-1.0, default 0.5)"
+  },
+  "errorBars": {
+    "default": "false",
+    "labels": ["CSV parsing", "Error Bars"],
+    "type": "boolean",
+    "description": "Does the data contain standard deviations? Setting this to true alters the input format (see above)."
+  },
+  "displayAnnotations": {
+    "default": "false",
+    "labels": ["Annotations"],
+    "type": "boolean",
+    "description": "Only applies when Dygraphs is used as a GViz chart. Causes string columns following a data series to be interpreted as annotations on points in that series. This is the same format used by Google's AnnotatedTimeLine chart."
+  }
+}
+;  // </JSON>
+// NOTE: in addition to parsing as JS, this snippet is expected to be valid
+// JSON. This assumption cannot be checked in JS, but it will be checked when
+// documentation is generated by the generate-documentation.py script.
+
+// Do a quick sanity check on the options reference.
+(function() {
+  var warn = function(msg) { if (console) console.warn(msg); };
+  var flds = ['type', 'default', 'description'];
+  var valid_cats = [ 
+   'Annotations',
+   'Axis display',
+   'CSV parsing',
+   'Callbacks',
+   'Data Line display',
+   'Data Series Colors',
+   'Error Bars',
+   'Grid',
+   'Interactive Elements',
+   'Legend',
+   'Overall display',
+   'Rolling Averages',
+   'Value display/formatting'
+  ];
+  var cats = {};
+  for (var i = 0; i < valid_cats.length; i++) cats[valid_cats[i]] = true;
+
+  for (var k in Dygraph.OPTIONS_REFERENCE) {
+    if (!Dygraph.OPTIONS_REFERENCE.hasOwnProperty(k)) continue;
+    var op = Dygraph.OPTIONS_REFERENCE[k];
+    for (var i = 0; i < flds.length; i++) {
+      if (!op.hasOwnProperty(flds[i])) {
+        warn('Option ' + k + ' missing "' + flds[i] + '" property');
+      } else if (typeof(op[flds[i]]) != 'string') {
+        warn(k + '.' + flds[i] + ' must be of type string');
+      }
+    }
+    var labels = op['labels'];
+    if (typeof(labels) !== 'object') {
+      warn('Option "' + k + '" is missing a "labels": [...] option');
+      for (var i = 0; i < labels.length; i++) {
+        if (!cats.hasOwnProperty(labels[i])) {
+          warn('Option "' + k + '" has label "' + labels[i] +
+               '", which is invalid.');
+        }
+      }
+    }
+  }
+})();
+// </REMOVE_FOR_COMBINED>
index 5694425..2b81f75 100755 (executable)
@@ -7,6 +7,7 @@ dygraph-canvas.js \
 dygraph.js \
 rgbcolor/rgbcolor.js \
 strftime/strftime-min.js \
+| perl -ne 'print unless m,REMOVE_FOR_COMBINED,..m,/REMOVE_FOR_COMBINED,' \
 > /tmp/dygraph.js
 
 java -jar yuicompressor-2.4.2.jar /tmp/dygraph.js \
diff --git a/generate-documentation.py b/generate-documentation.py
new file mode 100755 (executable)
index 0000000..3e88088
--- /dev/null
@@ -0,0 +1,161 @@
+#!/usr/bin/python
+import json
+import glob
+import re
+
+# Pull options reference JSON out of dygraph.js
+js = ''
+in_json = False
+for line in file('dygraph.js'):
+  if '<JSON>' in line:
+    in_json = True
+  elif '</JSON>' in line:
+    in_json = False
+  elif in_json:
+    js += line
+
+# TODO(danvk): better errors here.
+assert js
+docs = json.loads(js)
+
+# Go through the tests and find uses of each option.
+for opt in docs:
+  docs[opt]['tests'] = []
+
+# This is helpful for differentiating uses of options like 'width' and 'height'
+# from appearances of identically-named options in CSS.
+def find_braces(txt):
+  """Really primitive method to find text inside of {..} braces.
+  Doesn't work if there's an unmatched brace in a string, e.g. '{'. """
+  out = ''
+  level = 0
+  for char in txt:
+    if char == '{':
+      level += 1
+    if level >= 1:
+      out += char
+    if char == '}':
+      level -= 1
+  return out
+
+# Find text followed by a colon. These won't all be options, but those that
+# have the same name as a Dygraph option probably will be.
+prop_re = re.compile(r'\b([a-zA-Z0-9]+):')
+for test_file in glob.glob('tests/*.html'):
+  braced_html = find_braces(file(test_file).read())
+  ms = re.findall(prop_re, braced_html)
+  for opt in ms:
+    if opt in docs and test_file not in docs[opt]['tests']:
+      docs[opt]['tests'].append(test_file)
+
+# Extract a labels list.
+labels = []
+for nu, opt in docs.iteritems():
+  for label in opt['labels']:
+    if label not in labels:
+      labels.append(label)
+
+print """
+<html>
+<head>
+  <title>Dygraphs Options Reference</title>
+  <link rel="stylesheet" href="style.css">
+  <style type="text/css">
+    p.option {
+      padding-left: 25px;
+    }
+    #nav {
+      position: fixed;
+    }
+    #content {
+      max-width: 800px;
+    }
+  </style>
+</head>
+<body>
+"""
+
+print """
+<div id=nav>
+<h2>Dygraphs</h2>
+<ul>
+  <li><a href="index.html">Home</a>
+  <li><a href="data.html">Data Formats</a></li>
+  <li><a href="annotations.html">Annotations</a></li>
+</ul>
+<h2>Options Reference</h2>
+<ul>
+  <li><a href="#usage">Usage</a>
+"""
+for label in sorted(labels):
+  print '  <li><a href="#%s">%s</a>\n' % (label, label)
+print '</ul>\n</div>\n\n'
+
+def name(f):
+  """Takes 'tests/demo.html' -> 'demo'"""
+  return f.replace('tests/', '').replace('.html', '')
+
+print """
+<div id=content>
+<h2>Options Reference</h2>
+<p>Dygraphs tries to do a good job of displaying your data without any further configuration. But inevitably, you're going to want to tinker. Dygraphs provides a rich set of options for configuring its display and behavior.</p>
+
+<a name="usage"><h3>Usage</h3>
+<p>You specify options in the third parameter to the dygraphs constructor:
+<pre>g = new Dygraph(div,
+                data,
+                {
+                  option1: value1,
+                  option2: value2,
+                  ...
+                });
+</pre>
+
+After you've created a Dygraph, you can change an option by calling the <code>updateOptions</code> method:
+<pre>g.updateOptions({
+                  new_option1: value1,
+                  new_option2: value2
+                });
+</pre>
+
+<p>And, without further ado, here's the complete list of options:</p>
+"""
+for label in sorted(labels):
+  print '<a name="%s"><h3>%s</h3>\n' % (label, label)
+
+  for opt_name in sorted(docs.keys()):
+    opt = docs[opt_name]
+    if label not in opt['labels']: continue
+    tests = opt['tests']
+    if not tests:
+      examples_html = '<font color=red>NONE</font>'
+    else:
+      examples_html = ' '.join(
+        '<a href="%s">%s</a>' % (f, name(f)) for f in tests)
+
+    if not opt['type']: opt['type'] = '(missing)'
+    if not opt['default']: opt['default'] = '(missing)'
+    if not opt['description']: opt['description'] = '(missing)'
+
+    print """
+  <p class='option'><b>%(name)s</b><br/>
+  %(desc)s<br/>
+  <i>Type: %(type)s<br/>
+  Default: %(default)s</i><br/>
+  Examples: %(examples_html)s<br/>
+  <br/>
+  """ % { 'name': opt_name,
+          'type': opt['type'],
+          'default': opt['default'],
+          'desc': opt['description'],
+          'examples_html': examples_html}
+
+
+print """
+</div>
+</body>
+</html>
+"""
+
+# This page was super-helpful:
+# http://jsbeautifier.org/
index aaf18bd..7aca0f4 100755 (executable)
@@ -7,10 +7,14 @@ site=$1
 # Produce dygraph-combined.js.
 ./generate-combined.sh
 
+# Generate documentation.
+./generate-documentation.py > docs/options.html
+
 # Copy everything to the site.
 scp tests/*.html tests/*.js tests/*.png $site/tests/ \
 && \
 scp dygraph*.js gadget.xml excanvas.js thumbnail.png screenshot.png docs/* $site/
 
-# Revert changes to dygraph-combined.js
+# Revert changes to dygraph-combined.js and docs/options.html
 git checkout dygraph-combined.js
+rm docs/options.html
diff --git a/tests/independent-series.html b/tests/independent-series.html
new file mode 100644 (file)
index 0000000..543f51f
--- /dev/null
@@ -0,0 +1,176 @@
+<html>
+  <head>
+    <title>Independent Series</title>
+    <!--[if IE]>
+    <script type="text/javascript" src="../excanvas.js"></script>
+    <![endif]-->
+    <script type="text/javascript" src="../strftime/strftime-min.js"></script>
+    <script type="text/javascript" src="../rgbcolor/rgbcolor.js"></script>
+    <script type="text/javascript" src="../dygraph-canvas.js"></script>
+    <script type="text/javascript" src="../dygraph.js"></script>
+    <style type="text/css">
+      .thinborder {
+        border-width: 1px;
+        border-spacing: 0px;
+        border-style: solid;
+        border-color: black;
+        border-collapse: collapse;
+      }
+
+      .thinborder td,
+      .thinborder th {
+        border-width: 1px;
+        padding: 5px;
+        border-style: solid;
+        border-color: black;
+      }
+    </style>
+  </head>
+  <body>
+    <h3>Independent Series</h3>
+    <p>By using the connectSeparated attribute, it's possible to display a chart of several time series with completely independent x-values.</p>
+
+    <p>The trick is to specify values for the series at the union of the x-values of all series. For one series' x values, specify <code>null</code> for each of the other series.</p>
+
+    <div id="graph" style="float: right; margin-right: 50px; width: 400px; height: 300px;"></div>
+    <p>For example, say you had two series:</p>
+    <table><tr>
+    <td valign=top>
+    <table>
+      <table class=thinborder>
+        <tr><th>x</th><th>A</th></tr>
+        <tr><td>2</td><td>2</td></tr>
+        <tr><td>4</td><td>6</td></tr>
+        <tr><td>6</td><td>4</td></tr>
+      </table>
+    </td>
+    <td valign=top style="padding-left:25px;">
+      <table class=thinborder>
+        <tr><th>x</th><th>B</th></tr>
+        <tr><td>1</td><td>3</td></tr>
+        <tr><td>3</td><td>7</td></tr>
+        <tr><td>5</td><td>5</td></tr>
+      </table>
+    </td>
+    </tr></table>
+
+    <p>Then you would specify the following CSV or native data:</p>
+    <table><tr>
+    <td valign=top>
+    (CSV)
+    <pre>X,A,B
+1,,3
+2,2,
+3,,7
+4,6,
+5,,5
+6,4,</pre>
+    </td>
+    <td valign=top style="padding-left: 25px;">
+    (native)
+    <pre>[
+[1, null, 3],
+[2, 2, null],
+[3, null, 7],
+[4, 6, null],
+[5, null, 5],
+[6, 4, null] ]</pre>
+    </td>
+    </tr></table>
+
+    <script type="text/javascript">
+    new Dygraph(
+      document.getElementById("graph"),
+      [
+        [1, null, 3],
+        [2, 2, null],
+        [3, null, 7],
+        [4, 5, null],
+        [5, null, 5],
+        [6, 3, null]
+      ],
+      {
+        labels: ["x", "A", "B" ],
+        connectSeparatedPoints: true,
+        drawPoints: true
+      }
+    );
+    </script>
+
+    <h3>Encoding a gap</h3>
+    <p>There's one extra wrinkle. What if one of the series has a missing
+    value, i.e. what if your series are something like </p>
+
+    <table><tr>
+    <td valign=top>
+    <table>
+      <table class=thinborder>
+        <tr><th>x</th><th>A</th></tr>
+        <tr><td>2</td><td>2</td></tr>
+        <tr><td>4</td><td>4</td></tr>
+        <tr><td>6</td><td>(gap)</td></tr>
+        <tr><td>8</td><td>8</td></tr>
+        <tr><td>10</td><td>10</td></tr>
+      </table>
+    </td>
+    <td valign=top style="padding-left:25px;">
+      <table class=thinborder>
+        <tr><th>x</th><th>B</th></tr>
+        <tr><td>1</td><td>3</td></tr>
+        <tr><td>3</td><td>5</td></tr>
+        <tr><td>5</td><td>7</td></tr>
+      </table>
+    </td>
+    </tr></table>
+
+    <div id="graph2" style="float: right; margin-right: 50px; width: 400px; height: 300px;"></div>
+    <p>The gap would normally be encoded as a null, or missing value. But when you use <code>connectSeparatedPoints</code>, that has a special meaning. Instead, you have to use <code>NaN</code>. This is a bit of a hack, but it gets the job done.</p> 
+
+    <script type="text/javascript">
+    g2 = new Dygraph(
+      document.getElementById("graph2"),
+"x,A,B  \n" +
+"1,,3   \n" +
+"2,2,   \n" +
+"3,,5   \n" +
+"4,4,   \n" +
+"5,,7   \n" +
+"6,NaN, \n" +
+"8,8,   \n" +
+"10,10, \n"
+      , {
+        labels: ["x", "A", "B" ],
+        connectSeparatedPoints: true,
+        drawPoints: true
+      }
+    );
+    </script>
+
+    <table><tr>
+    <td valign=top>
+    (CSV)
+    <pre>x,A,B
+1,,3
+2,2,
+3,,5
+4,4,
+5,,7
+6,NaN,
+8,8,
+10,10,</pre>
+    </td>
+    <td valign=top style="padding-left: 25px;">
+    (native)
+    <pre>[ [1, null, 3],
+  [2, 2, null],
+  [3, null, 5],
+  [4, 4, null],
+  [5, null, 7],
+  [6, NaN, null],
+  [8, 8, null],
+  [10, 10, null] ]</pre>
+    </td>
+    </tr></table>
+
+  </body>
+</html>
index bdec05f..7a666bf 100644 (file)
             document.getElementById("div_g"),
             NoisyData, {
               rollPeriod: 7,
-              errorBars: true
+              errorBars: true,
+              legend: 'always'
             }
           );
       g30 = new Dygraph(
             document.getElementById("div_g30"),
             NoisyData().replace(/,/g, "\t"), {
               rollPeriod: 14,
-              errorBars: true
+              errorBars: true,
+              legend: 'always',
+              labelsDivStyles: {
+                'text-align': 'right',
+              },
+              labelsDivWidth: 170
             }
           );
     </script>