3 # Generate docs/options.html
11 # Set this to the path to a test file to get debug output for just that test
12 # file. Can be helpful to figure out why a test is not being shown for a
14 debug_tests
= [] # [ 'tests/zoom.html' ]
16 # Pull options reference JSON out of dygraph.js
19 for line
in file('dygraph-options-reference.js'):
22 elif '</JSON>' in line
:
27 # TODO(danvk): better errors here.
31 # Go through the tests and find uses of each option.
33 docs
[opt
]['tests'] = []
34 docs
[opt
]['gallery'] = []
36 # This is helpful for differentiating uses of options like 'width' and 'height'
37 # from appearances of identically-named options in CSS.
39 """Really primitive method to find text inside of {..} braces.
40 Doesn't work if there's an unmatched brace in a string, e.g. '{'. """
52 def search_files(type, files
):
53 # Find text followed by a colon. These won't all be options, but those that
54 # have the same name as a Dygraph option probably will be.
55 prop_re
= re
.compile(r
'\b([a-zA-Z0-9]+) *:')
56 for test_file
in files
:
57 if os
.path
.isfile(test_file
): # Basically skips directories
58 text
= file(test_file
).read()
60 # Hack for slipping past gallery demos that have title in their attributes
61 # so they don't appear as reasons for the demo to have 'title' options.
63 idx
= text
.find("function(")
66 braced_html
= find_braces(text
)
70 ms
= re
.findall(prop_re
, braced_html
)
72 if debug_tests
: print '\n'.join(ms
)
73 if opt
in docs
and test_file
not in docs
[opt
][type]:
74 docs
[opt
][type].append(test_file
)
76 search_files("tests", glob
.glob("tests/*.html"))
77 search_files("gallery", glob
.glob("gallery/*.js")) #TODO add grep "Gallery.register\("
79 if debug_tests
: sys
.exit(0)
81 # Extract a labels list.
83 for nu
, opt
in docs
.iteritems():
84 for label
in opt
['labels']:
85 if label
not in labels
:
88 print """<!DOCTYPE HTML>
91 <title>Dygraphs Options Reference</title>
92 <link rel="stylesheet" href="style.css">
93 <style type="text/css">
115 <li><a href="index.html">Home</a>
116 <li><a href="data.html">Data Formats</a></li>
117 <li><a href="annotations.html">Annotations</a></li>
119 <h2>Options Reference</h2>
121 <li><a href="#usage">Usage</a>
123 for label
in sorted(labels
):
124 print ' <li><a href="#%s">%s</a>\n' %
(label
, label
)
125 print '</ul>\n</div>\n\n'
129 <h2>Options Reference</h2>
130 <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>
132 <a name="usage"></a><h3>Usage</h3>
133 <p>You specify options in the third parameter to the dygraphs constructor:</p>
134 <pre>g = new Dygraph(div,
143 <p>After you've created a Dygraph, you can change an option by calling the <code>updateOptions</code> method:</p>
144 <pre>g.updateOptions({
149 <p>And, without further ado, here's the complete list of options:</p>
153 """Takes 'tests/demo.html' -> 'demo'"""
154 return f
.replace('tests/', '').replace('.html', '')
157 """Takes 'gallery/demo.js' -> 'demo'"""
158 return f
.replace('gallery/', '').replace('.js', '')
160 def urlify_gallery(f
):
161 """Takes 'gallery/demo.js' -> 'demo'"""
162 return f
.replace('gallery/', 'gallery/#g/').replace('.js', '')
165 for label
in sorted(labels
):
166 print '<a name="%s"><h3>%s</h3>\n' %
(label
, label
)
168 for opt_name
in sorted(docs
.keys()):
170 if label
not in opt
['labels']: continue
173 examples_html
= '<font color=red>NONE</font>'
175 examples_html
= ' '.join(
176 '<a href="%s">%s</a>' %
(f
, test_name(f
)) for f
in tests
)
178 gallery
= opt
['gallery']
180 gallery_html
= '<font color=red>NONE</font>'
182 gallery_html
= ' '.join(
183 '<a href="%s">%s</a>' %
(urlify_gallery(f
), gallery_name(f
)) for f
in gallery
)
185 if 'parameters' in opt
:
186 parameters
= opt
['parameters']
187 parameters_html
= '\n'.join("<i>%s</i>: %s<br/>" %
(p
[0], p
[1]) for p
in parameters
)
188 parameters_html
= "\n <div class='parameters'>\n%s</div>" %
(parameters_html
);
192 if not opt
['type']: opt
['type'] = '(missing)'
193 if not opt
['default']: opt
['default'] = '(missing)'
194 if not opt
['description']: opt
['description'] = '(missing)'
197 <div class='option'><a name="%(name)s"></a><b>%(name)s</b><br/>
199 <i>Type: %(type)s</i><br/>%(parameters)s
200 <i>Default: %(default)s</i></p>
201 Gallery Samples: %(gallery_html)s<br/>
202 Other Examples: %(examples_html)s<br/>
204 """ %
{ 'name': opt_name
,
206 'parameters': parameters_html
,
207 'default': opt
['default'],
208 'desc': opt
['description'],
209 'examples_html': examples_html
,
210 'gallery_html': gallery_html
}
214 <a name="point_properties"></a><h3>Point Properties</h3>
215 Some callbacks take a point argument. Its properties are:<br/>
217 <li>xval/yval: The data coordinates of the point (with dates/times as millis since epoch)</li>
218 <li>canvasx/canvasy: The canvas coordinates at which the point is drawn.</li>
219 <li>name: The name of the data series to which the point belongs</li>
226 # This page was super-helpful:
227 # http://jsbeautifier.org/