7 # Set this to the path to a test file to get debug output for just that test
8 # file. Can be helpful to figure out why a test is not being shown for a
10 debug_tests
= [] # [ 'tests/zoom.html' ]
12 # Pull options reference JSON out of dygraph.js
15 for line
in file('dygraph.js'):
18 elif '</JSON>' in line
:
23 # TODO(danvk): better errors here.
27 # Go through the tests and find uses of each option.
29 docs
[opt
]['tests'] = []
31 # This is helpful for differentiating uses of options like 'width' and 'height'
32 # from appearances of identically-named options in CSS.
34 """Really primitive method to find text inside of {..} braces.
35 Doesn't work if there's an unmatched brace in a string, e.g. '{'. """
47 # Find text followed by a colon. These won't all be options, but those that
48 # have the same name as a Dygraph option probably will be.
49 prop_re
= re
.compile(r
'\b([a-zA-Z0-9]+) *:')
50 tests
= debug_tests
or glob
.glob('tests/*.html')
51 for test_file
in tests
:
52 braced_html
= find_braces(file(test_file
).read())
56 ms
= re
.findall(prop_re
, braced_html
)
58 if debug_tests
: print '\n'.join(ms
)
59 if opt
in docs
and test_file
not in docs
[opt
]['tests']:
60 docs
[opt
]['tests'].append(test_file
)
62 if debug_tests
: sys
.exit(0)
64 # Extract a labels list.
66 for nu
, opt
in docs
.iteritems():
67 for label
in opt
['labels']:
68 if label
not in labels
:
74 <title>Dygraphs Options Reference</title>
75 <link rel="stylesheet" href="style.css">
76 <style type="text/css">
95 <li><a href="index.html">Home</a>
96 <li><a href="data.html">Data Formats</a></li>
97 <li><a href="annotations.html">Annotations</a></li>
99 <h2>Options Reference</h2>
101 <li><a href="#usage">Usage</a>
103 for label
in sorted(labels
):
104 print ' <li><a href="#%s">%s</a>\n' %
(label
, label
)
105 print '</ul>\n</div>\n\n'
108 """Takes 'tests/demo.html' -> 'demo'"""
109 return f
.replace('tests/', '').replace('.html', '')
113 <h2>Options Reference</h2>
114 <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>
116 <a name="usage"><h3>Usage</h3>
117 <p>You specify options in the third parameter to the dygraphs constructor:
118 <pre>g = new Dygraph(div,
127 After you've created a Dygraph, you can change an option by calling the <code>updateOptions</code> method:
128 <pre>g.updateOptions({
134 <p>And, without further ado, here's the complete list of options:</p>
136 for label
in sorted(labels
):
137 print '<a name="%s"><h3>%s</h3>\n' %
(label
, label
)
139 for opt_name
in sorted(docs
.keys()):
141 if label
not in opt
['labels']: continue
144 examples_html
= '<font color=red>NONE</font>'
146 examples_html
= ' '.join(
147 '<a href="%s">%s</a>' %
(f
, name(f
)) for f
in tests
)
149 if not opt
['type']: opt
['type'] = '(missing)'
150 if not opt
['default']: opt
['default'] = '(missing)'
151 if not opt
['description']: opt
['description'] = '(missing)'
154 <p class='option'><a name="%(name)s"/><b>%(name)s</b><br/>
156 <i>Type: %(type)s<br/>
157 Default: %(default)s</i><br/>
158 Examples: %(examples_html)s<br/>
160 """ %
{ 'name': opt_name
,
162 'default': opt
['default'],
163 'desc': opt
['description'],
164 'examples_html': examples_html
}
173 # This page was super-helpful:
174 # http://jsbeautifier.org/