3 # Generate docs/options.html
10 # Set this to the path to a test file to get debug output for just that test
11 # file. Can be helpful to figure out why a test is not being shown for a
13 debug_tests
= [] # [ 'tests/zoom.html' ]
15 # Pull options reference JSON out of dygraph.js
18 for line
in file('dygraph-options-reference.js'):
21 elif '</JSON>' in line
:
26 # TODO(danvk): better errors here.
30 # Go through the tests and find uses of each option.
32 docs
[opt
]['tests'] = []
33 docs
[opt
]['gallery'] = []
35 # This is helpful for differentiating uses of options like 'width' and 'height'
36 # from appearances of identically-named options in CSS.
38 """Really primitive method to find text inside of {..} braces.
39 Doesn't work if there's an unmatched brace in a string, e.g. '{'. """
51 def search_files(type, files
):
52 # Find text followed by a colon. These won't all be options, but those that
53 # have the same name as a Dygraph option probably will be.
54 prop_re
= re
.compile(r
'\b([a-zA-Z0-9]+) *:')
55 for test_file
in files
:
56 text
= file(test_file
).read()
57 # Hack for slipping past gallery demos that have title in their attributes
58 # so they don't appear as reasons for the demo to have 'title' options.
60 idx
= text
.find("function(")
63 braced_html
= find_braces(text
)
67 ms
= re
.findall(prop_re
, braced_html
)
69 if debug_tests
: print '\n'.join(ms
)
70 if opt
in docs
and test_file
not in docs
[opt
][type]:
71 docs
[opt
][type].append(test_file
)
73 search_files("tests", glob
.glob("tests/*.html"))
74 search_files("gallery", glob
.glob("gallery/*.js")) #TODO add grep "Gallery.register\("
76 if debug_tests
: sys
.exit(0)
78 # Extract a labels list.
80 for nu
, opt
in docs
.iteritems():
81 for label
in opt
['labels']:
82 if label
not in labels
:
85 print """<!DOCTYPE HTML>
88 <title>Dygraphs Options Reference</title>
89 <link rel="stylesheet" href="style.css">
90 <style type="text/css">
112 <li><a href="index.html">Home</a>
113 <li><a href="data.html">Data Formats</a></li>
114 <li><a href="annotations.html">Annotations</a></li>
116 <h2>Options Reference</h2>
118 <li><a href="#usage">Usage</a>
120 for label
in sorted(labels
):
121 print ' <li><a href="#%s">%s</a>\n' %
(label
, label
)
122 print '</ul>\n</div>\n\n'
126 <h2>Options Reference</h2>
127 <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>
129 <a name="usage"></a><h3>Usage</h3>
130 <p>You specify options in the third parameter to the dygraphs constructor:</p>
131 <pre>g = new Dygraph(div,
140 <p>After you've created a Dygraph, you can change an option by calling the <code>updateOptions</code> method:</p>
141 <pre>g.updateOptions({
146 <p>And, without further ado, here's the complete list of options:</p>
150 """Takes 'tests/demo.html' -> 'demo'"""
151 return f
.replace('tests/', '').replace('.html', '')
154 """Takes 'gallery/demo.js' -> 'demo'"""
155 return f
.replace('gallery/', '').replace('.js', '')
157 def urlify_gallery(f
):
158 """Takes 'gallery/demo.js' -> 'demo'"""
159 return f
.replace('gallery/', 'gallery/#g/').replace('.js', '')
162 for label
in sorted(labels
):
163 print '<a name="%s"><h3>%s</h3>\n' %
(label
, label
)
165 for opt_name
in sorted(docs
.keys()):
167 if label
not in opt
['labels']: continue
170 examples_html
= '<font color=red>NONE</font>'
172 examples_html
= ' '.join(
173 '<a href="%s">%s</a>' %
(f
, test_name(f
)) for f
in tests
)
175 gallery
= opt
['gallery']
177 gallery_html
= '<font color=red>NONE</font>'
179 gallery_html
= ' '.join(
180 '<a href="%s">%s</a>' %
(urlify_gallery(f
), gallery_name(f
)) for f
in gallery
)
182 if 'parameters' in opt
:
183 parameters
= opt
['parameters']
184 parameters_html
= '\n'.join("<i>%s</i>: %s<br/>" %
(p
[0], p
[1]) for p
in parameters
)
185 parameters_html
= "\n <div class='parameters'>\n%s</div>" %
(parameters_html
);
189 if not opt
['type']: opt
['type'] = '(missing)'
190 if not opt
['default']: opt
['default'] = '(missing)'
191 if not opt
['description']: opt
['description'] = '(missing)'
194 <div class='option'><a name="%(name)s"></a><b>%(name)s</b><br/>
196 <i>Type: %(type)s</i><br/>%(parameters)s
197 <i>Default: %(default)s</i></p>
198 Gallery Samples: %(gallery_html)s<br/>
199 Other Examples: %(examples_html)s<br/>
201 """ %
{ 'name': opt_name
,
203 'parameters': parameters_html
,
204 'default': opt
['default'],
205 'desc': opt
['description'],
206 'examples_html': examples_html
,
207 'gallery_html': gallery_html
}
211 <a name="point_properties"></a><h3>Point Properties</h3>
212 Some callbacks take a point argument. Its properties are:<br/>
214 <li>xval/yval: The data coordinates of the point (with dates/times as millis since epoch)</li>
215 <li>canvasx/canvasy: The canvas coordinates at which the point is drawn.</li>
216 <li>name: The name of the data series to which the point belongs</li>
223 # This page was super-helpful:
224 # http://jsbeautifier.org/