blob: 2e80f96c69f372fa1368da5dafa540fe8d6197b1 [file] [log] [blame]
<!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/generic_diagnostic_span.html">
<link rel="import" href="/tracing/value/ui/iteration_info_span.html">
<link rel="import" href="/tracing/value/ui/related_event_set_span.html">
<link rel="import" href="/tracing/value/ui/related_value_map_span.html">
<link rel="import" href="/tracing/value/ui/related_value_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) {
var typeInfo = undefined;
var 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');
}
var tagName = typeInfo.metadata.elementName;
if (tr.ui.b.isUnknownElementName(tagName))
throw new Error('Element not registered: ' + tagName);
return tagName;
}
/**
* Create a visualization for |diagnostic|.
*
* @param {!tr.v.d.Diagnostic} diagnostic
* @return {Element}
*/
function createDiagnosticSpan(diagnostic) {
var tagName = findElementNameForDiagnostic(diagnostic);
var span = document.createElement(tagName);
span.diagnostic = diagnostic;
return span;
}
return {
createDiagnosticSpan: createDiagnosticSpan
};
});
</script>