Html程序  |  74行  |  1.62 KB

<!DOCTYPE HTML>
<html>
<!--
Copyright (c) 2011 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.
-->
<head i18n-values="dir:textdirection;">
<title>Simple Embedded Timeline Viewer</title>
<script src="../src/base.js"></script>
<style>
  .view {
    overflow: hidden;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
  }

</style>
</head>
<body>
  <div class="view">
  </div>

  <script>
  base.require('timeline_view');
  base.require('test_utils');
  </script>
  <script>
  'use strict';

  var timelineViewEl;

  function loadTraces(filenames, callback) {
    var traces = [];
    for (var i = 0; i < filenames.length; i++) {
      traces.push(undefined);
    }
    var numTracesPending = filenames.length;

    filenames.forEach(function(filename, i) {
      test_utils.getAsync(filename, function(trace) {
        traces[i] = trace;
        numTracesPending--;
        if (numTracesPending == 0)
          callback(traces);
      });
    });
  }

  function createViewFromTraces(traces) {
    var m = new tracing.TimelineModel();
    m.importTraces(traces, true);

    timelineViewEl = document.querySelector('.view');
    base.ui.decorate(timelineViewEl, tracing.TimelineView);
    timelineViewEl.model = m;
    timelineViewEl.tabIndex = 1;
    timelineViewEl.timeline.focusElement = timelineViewEl;
  }

  function onLoad() {
    var filenames = ['../test_data/simple_trace.json'];
    loadTraces(filenames,
               createViewFromTraces);
  }

  document.addEventListener('DOMContentLoaded', onLoad);
  </script>
</body>
</html>