6 # Pull options reference JSON out of dygraph.js
9 for line
in file('dygraph.js'):
12 elif '</JSON>' in line
:
17 # TODO(danvk): better errors here.
21 # Go through the tests and find uses of each option.
23 docs
[opt
]['tests'] = []
25 # This is helpful for differentiating uses of options like 'width' and 'height'
26 # from appearances of identically-named options in CSS.
28 """Really primitive method to find text inside of {..} braces.
29 Doesn't work if there's an unmatched brace in a string, e.g. '{'. """
41 # Find text followed by a colon. These won't all be options, but those that
42 # have the same name as a Dygraph option probably will be.
43 prop_re
= re
.compile(r
'\b([a-zA-Z0-9]+):')
44 for test_file
in glob
.glob('tests/*.html'):
45 braced_html
= find_braces(file(test_file
).read())
46 ms
= re
.findall(prop_re
, braced_html
)
48 if opt
in docs
and test_file
not in docs
[opt
]['tests']:
49 docs
[opt
]['tests'].append(test_file
)
51 # Extract a labels list.
53 for nu
, opt
in docs
.iteritems():
54 for label
in opt
['labels']:
55 if label
not in labels
:
61 <title>Dygraphs Options Reference</title>
62 <link rel="stylesheet" href="style.css">
63 <style type="text/css">
82 <li><a href="index.html">Home</a>
83 <li><a href="data.html">Data Formats</a></li>
84 <li><a href="annotations.html">Annotations</a></li>
86 <h2>Options Reference</h2>
88 <li><a href="#usage">Usage</a>
90 for label
in sorted(labels
):
91 print ' <li><a href="#%s">%s</a>\n' %
(label
, label
)
92 print '</ul>\n</div>\n\n'
95 """Takes 'tests/demo.html' -> 'demo'"""
96 return f
.replace('tests/', '').replace('.html', '')
100 <h2>Options Reference</h2>
101 <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>
103 <a name="usage"><h3>Usage</h3>
104 <p>You specify options in the third parameter to the dygraphs constructor:
105 <pre>g = new Dygraph(div,
114 After you've created a Dygraph, you can change an option by calling the <code>updateOptions</code> method:
115 <pre>g.updateOptions({
121 <p>And, without further ado, here's the complete list of options:</p>
123 for label
in sorted(labels
):
124 print '<a name="%s"><h3>%s</h3>\n' %
(label
, label
)
126 for opt_name
in sorted(docs
.keys()):
128 if label
not in opt
['labels']: continue
131 examples_html
= '<font color=red>NONE</font>'
133 examples_html
= ' '.join(
134 '<a href="%s">%s</a>' %
(f
, name(f
)) for f
in tests
)
136 if not opt
['type']: opt
['type'] = '(missing)'
137 if not opt
['default']: opt
['default'] = '(missing)'
138 if not opt
['description']: opt
['description'] = '(missing)'
141 <p class='option'><b>%(name)s</b><br/>
143 <i>Type: %(type)s<br/>
144 Default: %(default)s</i><br/>
145 Examples: %(examples_html)s<br/>
147 """ %
{ 'name': opt_name
,
149 'default': opt
['default'],
150 'desc': opt
['description'],
151 'examples_html': examples_html
}
160 # This page was super-helpful:
161 # http://jsbeautifier.org/