1<!DOCTYPE html>
2<!--
3Copyright 2015 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7
8<link rel="import" href="/tracing/base/base.html">
9
10<script>
11'use strict';
12
13/**
14 * @fileoverview Time currentDisplayUnit
15 */
16tr.exportTo('tr.v', function() {
17  var msDisplayMode = {
18    scale: 1e-3,
19    suffix: 'ms',
20    // Compares a < b with adjustments to precision errors.
21    roundedLess: function(a, b) {
22      return Math.round(a * 1000) < Math.round(b * 1000);
23    },
24    format: function(ts) {
25      return new Number(ts)
26          .toLocaleString(undefined, { minimumFractionDigits: 3 }) + ' ms';
27    }
28  };
29
30  var nsDisplayMode = {
31    scale: 1e-9,
32    suffix: 'ns',
33    // Compares a < b with adjustments to precision errors.
34    roundedLess: function(a, b) {
35      return Math.round(a * 1000000) < Math.round(b * 1000000);
36    },
37    format: function(ts) {
38      return new Number(ts * 1000000)
39          .toLocaleString(undefined, { maximumFractionDigits: 0 }) + ' ns';
40    }
41  };
42
43  var TimeDisplayModes = {
44    ns: nsDisplayMode,
45    ms: msDisplayMode
46  };
47
48  return {
49    TimeDisplayModes: TimeDisplayModes
50  };
51});
52</script>
53