blob: e7bf372a2bf61d6af6d7317748fb4e6a1b3e393c [file] [log] [blame]
bungeman@google.com85669f92011-06-17 13:58:14 +00001'''
2Created on May 16, 2011
3
4@author: bungeman
5'''
6import sys
7import getopt
8import re
9import os
10import bench_util
11import json
12import xml.sax.saxutils
13
14def usage():
15 """Prints simple usage information."""
16
17 print '-d <dir> a directory containing bench_r<revision>_<scalar> files.'
18 print '-b <bench> the bench to show.'
19 print '-c <config> the config to show (GPU, 8888, 565, etc).'
20 print '-t <time> the time to show (w, c, g, etc).'
21 print '-s <setting>[=<value>] a setting to show (alpha, scalar, etc).'
22 print '-r <revision>[:<revision>] the revisions to show.'
23 print '-f <revision>[:<revision>] the revisions to use for fitting.'
24 print '-x <int> the desired width of the svg.'
25 print '-y <int> the desired height of the svg.'
26 print '--default-setting <setting>[=<value>] setting for those without.'
27
28
29class Label:
30 """The information in a label.
31
32 (str, str, str, str, {str:str})"""
33 def __init__(self, bench, config, time_type, settings):
34 self.bench = bench
35 self.config = config
36 self.time_type = time_type
37 self.settings = settings
38
39 def __repr__(self):
40 return "Label(%s, %s, %s, %s)" % (
41 str(self.bench),
42 str(self.config),
43 str(self.time_type),
44 str(self.settings),
45 )
46
47 def __str__(self):
48 return "%s_%s_%s_%s" % (
49 str(self.bench),
50 str(self.config),
51 str(self.time_type),
52 str(self.settings),
53 )
54
55 def __eq__(self, other):
56 return (self.bench == other.bench and
57 self.config == other.config and
58 self.time_type == other.time_type and
59 self.settings == other.settings)
60
61 def __hash__(self):
62 return (hash(self.bench) ^
63 hash(self.config) ^
64 hash(self.time_type) ^
65 hash(frozenset(self.settings.iteritems())))
66
67def parse_dir(directory, default_settings, oldest_revision, newest_revision):
68 """Parses bench data from files like bench_r<revision>_<scalar>.
69
70 (str, {str, str}, Number, Number) -> {int:[BenchDataPoints]}"""
71 revision_data_points = {} # {revision : [BenchDataPoints]}
72 for bench_file in os.listdir(directory):
73 file_name_match = re.match('bench_r(\d+)_(\S+)', bench_file)
74 if (file_name_match is None):
75 continue
76
77 revision = int(file_name_match.group(1))
78 scalar_type = file_name_match.group(2)
79
80 if (revision < oldest_revision or revision > newest_revision):
81 continue
82
83 file_handle = open(directory + '/' + bench_file, 'r')
84
85 if (revision not in revision_data_points):
86 revision_data_points[revision] = []
87 default_settings['scalar'] = scalar_type
88 revision_data_points[revision].extend(
89 bench_util.parse(default_settings, file_handle))
90 file_handle.close()
91 return revision_data_points
92
93def create_lines(revision_data_points, settings
94 , bench_of_interest, config_of_interest, time_of_interest):
95 """Convert revision data into sorted line data.
96
97 ({int:[BenchDataPoints]}, {str:str}, str?, str?, str?)
98 -> {Label:[(x,y)] | [n].x <= [n+1].x}"""
99 revisions = revision_data_points.keys()
100 revisions.sort()
101 lines = {} # {Label:[(x,y)] | x[n] <= x[n+1]}
102 for revision in revisions:
103 for point in revision_data_points[revision]:
104 if (bench_of_interest is not None and
105 not bench_of_interest == point.bench):
106 continue
107
108 if (config_of_interest is not None and
109 not config_of_interest == point.config):
110 continue
111
112 if (time_of_interest is not None and
113 not time_of_interest == point.time_type):
114 continue
115
116 skip = False
117 for key, value in settings.items():
118 if key in point.settings and point.settings[key] != value:
119 skip = True
120 break
121 if skip:
122 continue
123
124 line_name = Label(point.bench
125 , point.config
126 , point.time_type
127 , point.settings)
128
129 if line_name not in lines:
130 lines[line_name] = []
131
132 lines[line_name].append((revision, point.time))
133
134 return lines
135
136def bounds(lines):
137 """Finds the bounding rectangle for the lines.
138
139 {Label:[(x,y)]} -> ((min_x, min_y),(max_x,max_y))"""
140 min_x = bench_util.Max
141 min_y = bench_util.Max
142 max_x = bench_util.Min
143 max_y = bench_util.Min
144
145 for line in lines.itervalues():
146 for x, y in line:
147 min_x = min(min_x, x)
148 min_y = min(min_y, y)
149 max_x = max(max_x, x)
150 max_y = max(max_y, y)
151
152 return ((min_x, min_y), (max_x, max_y))
153
154def create_regressions(lines, start_x, end_x):
155 """Creates regression data from line segments.
156
157 ({Label:[(x,y)] | [n].x <= [n+1].x}, Number, Number)
158 -> {Label:LinearRegression}"""
159 regressions = {} # {Label : LinearRegression}
160
161 for label, line in lines.iteritems():
162 regression_line = [p for p in line if start_x <= p[0] <= end_x]
163
164 if (len(regression_line) < 2):
165 continue
166 regression = bench_util.LinearRegression(regression_line)
167 regressions[label] = regression
168
169 return regressions
170
171def bounds_slope(regressions):
172 """Finds the extreme up and down slopes of a set of linear regressions.
173
174 ({Label:LinearRegression}) -> (max_up_slope, min_down_slope)"""
175 max_up_slope = 0
176 min_down_slope = 0
177 for regression in regressions.itervalues():
178 min_slope = regression.find_min_slope()
179 max_up_slope = max(max_up_slope, min_slope)
180 min_down_slope = min(min_down_slope, min_slope)
181
182 return (max_up_slope, min_down_slope)
183
184def main():
185 """Parses command line and writes output."""
186
187 try:
188 opts, _ = getopt.getopt(sys.argv[1:]
189 , "d:b:c:t:s:r:f:x:y:"
190 , "default-setting=")
191 except getopt.GetoptError, err:
192 print str(err)
193 usage()
194 sys.exit(2)
195
196 directory = None
197 config_of_interest = None
198 bench_of_interest = None
199 time_of_interest = None
200 oldest_revision = 0
201 newest_revision = bench_util.Max
202 oldest_regression = 0
203 newest_regression = bench_util.Max
204 requested_height = None
205 requested_width = None
206 settings = {}
207 default_settings = {}
208
209 def parse_range(revision_range):
210 """Takes <old>[:<new>] returns (old, new) or (old, Max)."""
211 old, _, new = revision_range.partition(":")
212 if not new:
213 return (int(old), bench_util.Max)
214 return (int(old), int(new))
215
216 def add_setting(settings, setting):
217 """Takes <key>[=<value>] adds {key:value} or {key:True} to settings."""
218 name, _, value = setting.partition('=')
219 if not value:
220 settings[name] = True
221 else:
222 settings[name] = value
223
224 try:
225 for option, value in opts:
226 if option == "-d":
227 directory = value
228 elif option == "-b":
229 bench_of_interest = value
230 elif option == "-c":
231 config_of_interest = value
232 elif option == "-t":
233 time_of_interest = value
234 elif option == "-s":
235 add_setting(settings, value)
236 elif option == "-r":
237 oldest_revision, newest_revision = parse_range(value)
238 elif option == "-f":
239 oldest_regression, newest_regression = parse_range(value)
240 elif option == "-x":
241 requested_width = int(value)
242 elif option == "-y":
243 requested_height = int(value)
244 elif option == "--default-setting":
245 add_setting(default_settings, value)
246 else:
247 usage()
248 assert False, "unhandled option"
249 except ValueError:
250 usage()
251 sys.exit(2)
epoger@google.comc71174d2011-08-08 17:19:23 +0000252
bungeman@google.com85669f92011-06-17 13:58:14 +0000253 if directory is None:
254 usage()
255 sys.exit(2)
epoger@google.comc71174d2011-08-08 17:19:23 +0000256
bungeman@google.com85669f92011-06-17 13:58:14 +0000257 revision_data_points = parse_dir(directory
258 , default_settings
259 , oldest_revision
260 , newest_revision)
epoger@google.comc71174d2011-08-08 17:19:23 +0000261
262 # Update oldest_revision and newest_revision based on the data we could find
263 all_revision_numbers = revision_data_points.keys()
264 oldest_revision = min(all_revision_numbers)
265 newest_revision = max(all_revision_numbers)
266
bungeman@google.com85669f92011-06-17 13:58:14 +0000267 lines = create_lines(revision_data_points
268 , settings
269 , bench_of_interest
270 , config_of_interest
271 , time_of_interest)
epoger@google.comc71174d2011-08-08 17:19:23 +0000272
bungeman@google.com85669f92011-06-17 13:58:14 +0000273 regressions = create_regressions(lines
274 , oldest_regression
275 , newest_regression)
epoger@google.comc71174d2011-08-08 17:19:23 +0000276
277 output_xhtml(lines, oldest_revision, newest_revision,
278 regressions, requested_width, requested_height)
bungeman@google.com85669f92011-06-17 13:58:14 +0000279
280def qa(out):
281 """Stringify input and quote as an xml attribute."""
282 return xml.sax.saxutils.quoteattr(str(out))
283def qe(out):
284 """Stringify input and escape as xml data."""
285 return xml.sax.saxutils.escape(str(out))
286
287def create_select(qualifier, lines, select_id=None):
288 """Output select with options showing lines which qualifier maps to it.
289
290 ((Label) -> str, {Label:_}, str?) -> _"""
291 options = {} #{ option : [Label]}
292 for label in lines.keys():
293 option = qualifier(label)
294 if (option not in options):
295 options[option] = []
296 options[option].append(label)
297 option_list = list(options.keys())
298 option_list.sort()
299 print '<select class="lines"',
300 if select_id is not None:
301 print 'id=%s' % qa(select_id)
302 print 'multiple="true" size="10" onchange="updateSvg();">'
303 for option in option_list:
304 print '<option value=' + qa('[' +
305 reduce(lambda x,y:x+json.dumps(str(y))+',',options[option],"")[0:-1]
306 + ']') + '>'+qe(option)+'</option>'
307 print '</select>'
308
epoger@google.comc71174d2011-08-08 17:19:23 +0000309def output_xhtml(lines, oldest_revision, newest_revision,
310 regressions, requested_width, requested_height):
bungeman@google.com85669f92011-06-17 13:58:14 +0000311 """Outputs an svg/xhtml view of the data."""
312 print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"',
313 print '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
314 print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">'
315 print '<head>'
316 print '<title>Bench graph</title>'
317 print '</head>'
318 print '<body>'
319
320 output_svg(lines, regressions, requested_width, requested_height)
321
322 #output the manipulation controls
323 print """
324<script type="text/javascript">//<![CDATA[
325 function getElementsByClass(node, searchClass, tag) {
326 var classElements = new Array();
327 var elements = node.getElementsByTagName(tag);
328 var pattern = new RegExp("^|\\s"+searchClass+"\\s|$");
329 for (var i = 0, elementsFound = 0; i < elements.length; ++i) {
330 if (pattern.test(elements[i].className)) {
331 classElements[elementsFound] = elements[i];
332 ++elementsFound;
333 }
334 }
335 return classElements;
336 }
337 function getAllLines() {
338 var selectElem = document.getElementById('benchSelect');
339 var linesObj = {};
340 for (var i = 0; i < selectElem.options.length; ++i) {
341 var lines = JSON.parse(selectElem.options[i].value);
342 for (var j = 0; j < lines.length; ++j) {
343 linesObj[lines[j]] = true;
344 }
345 }
346 return linesObj;
347 }
348 function getOptions(selectElem) {
349 var linesSelectedObj = {};
350 for (var i = 0; i < selectElem.options.length; ++i) {
351 if (!selectElem.options[i].selected) continue;
352
353 var linesSelected = JSON.parse(selectElem.options[i].value);
354 for (var j = 0; j < linesSelected.length; ++j) {
355 linesSelectedObj[linesSelected[j]] = true;
356 }
357 }
358 return linesSelectedObj;
359 }
360 function objectEmpty(obj) {
361 for (var p in obj) {
362 return false;
363 }
364 return true;
365 }
366 function markSelectedLines(selectElem, allLines) {
367 var linesSelected = getOptions(selectElem);
368 if (!objectEmpty(linesSelected)) {
369 for (var line in allLines) {
370 allLines[line] &= (linesSelected[line] == true);
371 }
372 }
373 }
374 function updateSvg() {
375 var allLines = getAllLines();
376
377 var selects = getElementsByClass(document, 'lines', 'select');
378 for (var i = 0; i < selects.length; ++i) {
379 markSelectedLines(selects[i], allLines);
380 }
381
382 for (var line in allLines) {
383 var svgLine = document.getElementById(line);
384 var display = (allLines[line] ? 'inline' : 'none');
385 svgLine.setAttributeNS(null,'display', display);
386 }
387 }
388
389 function mark(markerId) {
390 for (var line in getAllLines()) {
391 var svgLineGroup = document.getElementById(line);
392 var display = svgLineGroup.getAttributeNS(null,'display');
393 if (display == null || display == "" || display != "none") {
394 var svgLine = document.getElementById(line+'_line');
395 if (markerId == null) {
396 svgLine.removeAttributeNS(null,'marker-mid');
397 } else {
398 svgLine.setAttributeNS(null,'marker-mid', markerId);
399 }
400 }
401 }
402 }
403//]]></script>"""
epoger@google.comc71174d2011-08-08 17:19:23 +0000404
405 print '<table border="0" width="%s">' % requested_width
406 print """
407<form>
408<tr valign="bottom" align="center">
409<td width="1">Bench&nbsp;Type</td>
410<td width="1">Bitmap Config</td>
411<td width="1">Timer&nbsp;Type (Cpu/Gpu/wall)</td>
412<td width="1"><!--buttons--></td>
413<td width="10%"><!--spacing--></td>"""
414
415 print '<td>Skia Bench Performance for r%s to r%s</td>' % (
416 bench_util.CreateRevisionLink(oldest_revision),
417 bench_util.CreateRevisionLink(newest_revision))
418 print '</tr><tr valign="top" align="center">'
419 print '<td width="1">'
bungeman@google.com85669f92011-06-17 13:58:14 +0000420 create_select(lambda l: l.bench, lines, 'benchSelect')
epoger@google.comc71174d2011-08-08 17:19:23 +0000421 print '</td><td width="1">'
bungeman@google.com85669f92011-06-17 13:58:14 +0000422 create_select(lambda l: l.config, lines)
epoger@google.comc71174d2011-08-08 17:19:23 +0000423 print '</td><td width="1">'
bungeman@google.com85669f92011-06-17 13:58:14 +0000424 create_select(lambda l: l.time_type, lines)
epoger@google.comc71174d2011-08-08 17:19:23 +0000425
bungeman@google.com85669f92011-06-17 13:58:14 +0000426 all_settings = {}
427 variant_settings = set()
428 for label in lines.keys():
429 for key, value in label.settings.items():
430 if key not in all_settings:
431 all_settings[key] = value
432 elif all_settings[key] != value:
433 variant_settings.add(key)
epoger@google.comc71174d2011-08-08 17:19:23 +0000434
bungeman@google.com85669f92011-06-17 13:58:14 +0000435 for k in variant_settings:
436 create_select(lambda l: l.settings[k], lines)
epoger@google.comc71174d2011-08-08 17:19:23 +0000437
438 print '</td><td width="1"><button type="button"',
bungeman@google.com85669f92011-06-17 13:58:14 +0000439 print 'onclick=%s' % qa("mark('url(#circleMark)'); return false;"),
epoger@google.comc71174d2011-08-08 17:19:23 +0000440 print '>Mark Points</button>'
441 print '<button type="button" onclick="mark(null);">Clear Points</button>'
442
443 print """
444</td>
445<td width="10%"></td>
446<td align="left">
447<p>Brighter red indicates tests that have gotten worse; brighter green
448indicates tests that have gotten better.</p>
449<p>To highlight individual tests, hold down CONTROL and mouse over
450graph lines.</p>
451<p>To highlight revision numbers, hold down SHIFT and mouse over
452the graph area.</p>
453<p>To only show certain tests on the graph, select any combination of
454tests in the selectors at left. (To show all, select all.)</p>
455<p>Use buttons at left to mark/clear points on the lines for selected
456benchmarks.</p>
457</td>
458</tr>
459</form>
460</table>
461</body>
462</html>"""
bungeman@google.com85669f92011-06-17 13:58:14 +0000463
464def compute_size(requested_width, requested_height, rev_width, time_height):
465 """Converts potentially empty requested size into a concrete size.
466
467 (Number?, Number?) -> (Number, Number)"""
468 pic_width = 0
469 pic_height = 0
470 if (requested_width is not None and requested_height is not None):
471 pic_height = requested_height
472 pic_width = requested_width
473
474 elif (requested_width is not None):
475 pic_width = requested_width
476 pic_height = pic_width * (float(time_height) / rev_width)
477
478 elif (requested_height is not None):
479 pic_height = requested_height
480 pic_width = pic_height * (float(rev_width) / time_height)
481
482 else:
483 pic_height = 800
484 pic_width = max(rev_width*3
485 , pic_height * (float(rev_width) / time_height))
486
487 return (pic_width, pic_height)
488
489def output_svg(lines, regressions, requested_width, requested_height):
490 """Outputs an svg view of the data."""
491
492 (global_min_x, _), (global_max_x, global_max_y) = bounds(lines)
493 max_up_slope, min_down_slope = bounds_slope(regressions)
494
495 #output
496 global_min_y = 0
497 x = global_min_x
498 y = global_min_y
499 w = global_max_x - global_min_x
500 h = global_max_y - global_min_y
501 font_size = 16
502 line_width = 2
503
504 pic_width, pic_height = compute_size(requested_width, requested_height
505 , w, h)
506
507 def cw(w1):
508 """Converts a revision difference to display width."""
509 return (pic_width / float(w)) * w1
510 def cx(x):
511 """Converts a revision to a horizontal display position."""
512 return cw(x - global_min_x)
513
514 def ch(h1):
515 """Converts a time difference to a display height."""
516 return -(pic_height / float(h)) * h1
517 def cy(y):
518 """Converts a time to a vertical display position."""
519 return pic_height + ch(y - global_min_y)
520
521 print '<svg',
522 print 'width=%s' % qa(str(pic_width)+'px')
523 print 'height=%s' % qa(str(pic_height)+'px')
524 print 'viewBox="0 0 %s %s"' % (str(pic_width), str(pic_height))
525 print 'onclick=%s' % qa(
526 "var event = arguments[0] || window.event;"
527 " if (event.shiftKey) { highlightRevision(null); }"
528 " if (event.ctrlKey) { highlight(null); }"
529 " return false;")
530 print 'xmlns="http://www.w3.org/2000/svg"'
531 print 'xmlns:xlink="http://www.w3.org/1999/xlink">'
532
533 print """
534<defs>
535 <marker id="circleMark"
536 viewBox="0 0 2 2" refX="1" refY="1"
537 markerUnits="strokeWidth"
538 markerWidth="2" markerHeight="2"
539 orient="0">
540 <circle cx="1" cy="1" r="1"/>
541 </marker>
542</defs>"""
543
544 #output the revisions
545 print """
546<script type="text/javascript">//<![CDATA[
547 var previousRevision;
548 var previousRevisionFill;
549 var previousRevisionStroke
550 function highlightRevision(id) {
551 if (previousRevision == id) return;
epoger@google.comc71174d2011-08-08 17:19:23 +0000552
553 document.getElementById('revision').firstChild.nodeValue = 'r' + id;
554 document.getElementById('rev_link').setAttribute('xlink:href',
555 'http://code.google.com/p/skia/source/detail?r=' + id);
bungeman@google.com85669f92011-06-17 13:58:14 +0000556
557 var preRevision = document.getElementById(previousRevision);
558 if (preRevision) {
559 preRevision.setAttributeNS(null,'fill', previousRevisionFill);
560 preRevision.setAttributeNS(null,'stroke', previousRevisionStroke);
561 }
562
563 var revision = document.getElementById(id);
564 previousRevision = id;
565 if (revision) {
566 previousRevisionFill = revision.getAttributeNS(null,'fill');
567 revision.setAttributeNS(null,'fill','rgb(100%, 95%, 95%)');
568
569 previousRevisionStroke = revision.getAttributeNS(null,'stroke');
570 revision.setAttributeNS(null,'stroke','rgb(100%, 90%, 90%)');
571 }
572 }
573//]]></script>"""
574
575 def print_rect(x, y, w, h, revision):
576 """Outputs a revision rectangle in display space,
577 taking arguments in revision space."""
578 disp_y = cy(y)
579 disp_h = ch(h)
580 if disp_h < 0:
581 disp_y += disp_h
582 disp_h = -disp_h
583
584 print '<rect id=%s x=%s y=%s' % (qa(revision), qa(cx(x)), qa(disp_y),),
585 print 'width=%s height=%s' % (qa(cw(w)), qa(disp_h),),
586 print 'fill="white"',
epoger@google.comc71174d2011-08-08 17:19:23 +0000587 print 'stroke="rgb(98%%,98%%,88%%)" stroke-width=%s' % qa(line_width),
bungeman@google.com85669f92011-06-17 13:58:14 +0000588 print 'onmouseover=%s' % qa(
589 "var event = arguments[0] || window.event;"
590 " if (event.shiftKey) {"
591 " highlightRevision('"+str(revision)+"');"
592 " return false;"
593 " }"),
594 print ' />'
595
596 xes = set()
597 for line in lines.itervalues():
598 for point in line:
599 xes.add(point[0])
600 revisions = list(xes)
601 revisions.sort()
602
603 left = x
604 current_revision = revisions[0]
605 for next_revision in revisions[1:]:
606 width = (((next_revision - current_revision) / 2.0)
607 + (current_revision - left))
608 print_rect(left, y, width, h, current_revision)
609 left += width
610 current_revision = next_revision
611 print_rect(left, y, x+w - left, h, current_revision)
epoger@google.comc71174d2011-08-08 17:19:23 +0000612
bungeman@google.com85669f92011-06-17 13:58:14 +0000613 #output the lines
614 print """
615<script type="text/javascript">//<![CDATA[
616 var previous;
617 var previousColor;
618 var previousOpacity;
619 function highlight(id) {
620 if (previous == id) return;
epoger@google.comc71174d2011-08-08 17:19:23 +0000621
bungeman@google.com85669f92011-06-17 13:58:14 +0000622 document.getElementById('label').firstChild.nodeValue = id;
epoger@google.comc71174d2011-08-08 17:19:23 +0000623
bungeman@google.com85669f92011-06-17 13:58:14 +0000624 var preGroup = document.getElementById(previous);
625 if (preGroup) {
626 var preLine = document.getElementById(previous+'_line');
627 preLine.setAttributeNS(null,'stroke', previousColor);
628 preLine.setAttributeNS(null,'opacity', previousOpacity);
epoger@google.comc71174d2011-08-08 17:19:23 +0000629
bungeman@google.com85669f92011-06-17 13:58:14 +0000630 var preSlope = document.getElementById(previous+'_linear');
631 if (preSlope) {
632 preSlope.setAttributeNS(null,'visibility', 'hidden');
633 }
634 }
epoger@google.comc71174d2011-08-08 17:19:23 +0000635
bungeman@google.com85669f92011-06-17 13:58:14 +0000636 var group = document.getElementById(id);
637 previous = id;
638 if (group) {
639 group.parentNode.appendChild(group);
640
641 var line = document.getElementById(id+'_line');
642 previousColor = line.getAttributeNS(null,'stroke');
643 previousOpacity = line.getAttributeNS(null,'opacity');
644 line.setAttributeNS(null,'stroke', 'blue');
645 line.setAttributeNS(null,'opacity', '1');
646
647 var slope = document.getElementById(id+'_linear');
648 if (slope) {
649 slope.setAttributeNS(null,'visibility', 'visible');
650 }
651 }
652 }
653//]]></script>"""
654 for label, line in lines.items():
655 print '<g id=%s>' % qa(label)
656 r = 128
657 g = 128
658 b = 128
659 a = .10
660 if label in regressions:
661 regression = regressions[label]
662 min_slope = regression.find_min_slope()
663 if min_slope < 0:
664 d = max(0, (min_slope / min_down_slope))
665 g += int(d*128)
666 a += d*0.9
667 elif min_slope > 0:
668 d = max(0, (min_slope / max_up_slope))
669 r += int(d*128)
670 a += d*0.9
671
672 slope = regression.slope
673 intercept = regression.intercept
674 min_x = regression.min_x
675 max_x = regression.max_x
676 print '<polyline id=%s' % qa(str(label)+'_linear'),
677 print 'fill="none" stroke="yellow"',
678 print 'stroke-width=%s' % qa(abs(ch(regression.serror*2))),
679 print 'opacity="0.5" pointer-events="none" visibility="hidden"',
680 print 'points="',
681 print '%s,%s' % (str(cx(min_x)), str(cy(slope*min_x + intercept))),
682 print '%s,%s' % (str(cx(max_x)), str(cy(slope*max_x + intercept))),
683 print '"/>'
684
685 print '<polyline id=%s' % qa(str(label)+'_line'),
686 print 'onmouseover=%s' % qa(
687 "var event = arguments[0] || window.event;"
688 " if (event.ctrlKey) {"
689 " highlight('"+str(label).replace("'", "\\'")+"');"
690 " return false;"
691 " }"),
692 print 'fill="none" stroke="rgb(%s,%s,%s)"' % (str(r), str(g), str(b)),
693 print 'stroke-width=%s' % qa(line_width),
694 print 'opacity=%s' % qa(a),
695 print 'points="',
696 for point in line:
697 print '%s,%s' % (str(cx(point[0])), str(cy(point[1]))),
698 print '"/>'
epoger@google.comc71174d2011-08-08 17:19:23 +0000699
bungeman@google.com85669f92011-06-17 13:58:14 +0000700 print '</g>'
epoger@google.comc71174d2011-08-08 17:19:23 +0000701
bungeman@google.com85669f92011-06-17 13:58:14 +0000702 #output the labels
703 print '<text id="label" x="0" y=%s' % qa(font_size),
704 print 'font-size=%s> </text>' % qa(font_size)
epoger@google.comc71174d2011-08-08 17:19:23 +0000705
706 print '<a id="rev_link" xlink:href="" target="_top">'
707 print '<text id="revision" x="0" y=%s style="' % qa(font_size*2)
708 print 'font-size: %s; ' % qe(font_size)
709 print 'stroke: #0000dd; text-decoration: underline; '
710 print '"> </text></a>'
711
bungeman@google.com85669f92011-06-17 13:58:14 +0000712 print '</svg>'
epoger@google.comc71174d2011-08-08 17:19:23 +0000713
bungeman@google.com85669f92011-06-17 13:58:14 +0000714if __name__ == "__main__":
715 main()