OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Serves JSON for a graph. | 5 """Serves JSON for a graph. |
6 | 6 |
7 This serves the JSON in the format consumed by Flot: | 7 This serves the JSON in the format consumed by Flot: |
8 https://github.com/flot/flot/blob/master/API.md | 8 https://github.com/flot/flot/blob/master/API.md |
9 """ | 9 """ |
10 | 10 |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 revision_map: A dict which maps revision numbers to data point info. | 388 revision_map: A dict which maps revision numbers to data point info. |
389 tests: A list of TestMetadata entities. | 389 tests: A list of TestMetadata entities. |
390 | 390 |
391 Returns: | 391 Returns: |
392 JSON serialization of a dict with line data, annotations, error range data, | 392 JSON serialization of a dict with line data, annotations, error range data, |
393 (This data may not be passed exactly as-is to the Flot plot function, but | 393 (This data may not be passed exactly as-is to the Flot plot function, but |
394 it will all be used when plotting.) | 394 it will all be used when plotting.) |
395 """ | 395 """ |
396 # Each entry in the following dict is one Flot series object. The actual | 396 # Each entry in the following dict is one Flot series object. The actual |
397 # x-y values will be put into the 'data' properties for each object. | 397 # x-y values will be put into the 'data' properties for each object. |
398 cols = {i: _FlotSeries(i) for i in range(len(tests))} | 398 cols = {i: _FlotSeries(i, test) for i, test in enumerate(tests)} |
399 | 399 |
400 flot_annotations = {} | 400 flot_annotations = {} |
401 flot_annotations['series'] = _GetSeriesAnnotations(tests) | 401 flot_annotations['series'] = _GetSeriesAnnotations(tests) |
402 | 402 |
403 # For each TestMetadata (which corresponds to a trace line), the shaded error | 403 # For each TestMetadata (which corresponds to a trace line), the shaded error |
404 # region is specified by two series objects. For a demo, see: | 404 # region is specified by two series objects. For a demo, see: |
405 # http://www.flotcharts.org/flot/examples/percentiles/index.html | 405 # http://www.flotcharts.org/flot/examples/percentiles/index.html |
406 error_bars = {x: [ | 406 error_bars = {x: [ |
407 { | 407 { |
408 'id': 'bottom_%d' % x, | 408 'id': 'bottom_%d' % x, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 | 464 |
465 return json.dumps( | 465 return json.dumps( |
466 { | 466 { |
467 'data': cols, | 467 'data': cols, |
468 'annotations': flot_annotations, | 468 'annotations': flot_annotations, |
469 'error_bars': error_bars, | 469 'error_bars': error_bars, |
470 }, | 470 }, |
471 allow_nan=False) | 471 allow_nan=False) |
472 | 472 |
473 | 473 |
474 def _FlotSeries(index): | 474 def _FlotSeries(index, test): |
475 return { | 475 return { |
476 'data': [], | 476 'data': [], |
477 'color': index, | 477 'color': index, |
478 'id': 'line_%d' % index | 478 'id': 'line_%d' % index, |
| 479 'testpath': test.test_path, |
479 } | 480 } |
OLD | NEW |