summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/catapult/tracing/tracing/value/ui/diagnostic_span.html
blob: cb9785e1969c9d34ab1c947f5165fa492f139713 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<!--
Copyright 2016 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/ui/base/deep_utils.html">
<link rel="import" href="/tracing/value/diagnostics/diagnostic.html">
<link rel="import" href="/tracing/value/ui/breakdown_span.html">
<link rel="import" href="/tracing/value/ui/collected_related_event_set_span.html">
<link rel="import" href="/tracing/value/ui/date_range_span.html">
<link rel="import" href="/tracing/value/ui/generic_set_span.html">
<link rel="import" href="/tracing/value/ui/related_event_set_span.html">
<link rel="import" href="/tracing/value/ui/scalar_diagnostic_span.html">
<link rel="import" href="/tracing/value/ui/unmergeable_diagnostic_set_span.html">

<script>
'use strict';
tr.exportTo('tr.v.ui', function() {
  /**
   * Find the name of a polymer element registered to display |diagnostic|
   * or one of its base classes.
   *
   * @param {!tr.v.d.Diagnostic} diagnostic
   * @return {string}
   */
  function findElementNameForDiagnostic(diagnostic) {
    let typeInfo = undefined;
    let curProto = diagnostic.constructor.prototype;
    while (curProto) {
      typeInfo = tr.v.d.Diagnostic.findTypeInfo(curProto.constructor);
      if (typeInfo && typeInfo.metadata.elementName) break;
      typeInfo = undefined;
      curProto = curProto.__proto__;
    }

    if (typeInfo === undefined) {
      throw new Error(
          diagnostic.constructor.name +
          ' or a base class must have a registered elementName');
    }

    return typeInfo.metadata.elementName;
  }

  /**
   * Create a visualization for |diagnostic|.
   *
   * @param {!tr.v.d.Diagnostic} diagnostic
   * @param {string} name
   * @param {!tr.v.Histogram} histogram
   * @return {Element}
   */
  function createDiagnosticSpan(diagnostic, name, histogram) {
    const tagName = findElementNameForDiagnostic(diagnostic);
    const span = document.createElement(tagName);
    if (span instanceof HTMLUnknownElement) {
      throw new Error('Element not registered: ' + tagName);
    }
    if (span.build === undefined) throw new Error(tagName);
    span.build(diagnostic, name, histogram);
    return span;
  }

  return {
    createDiagnosticSpan,
  };
});
</script>