<!DOCTYPE html> | |
<!-- | |
Copyright (c) 2015 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="/base/base.html"> | |
<link rel="import" href="/base/event_target.html"> | |
<script> | |
'use strict'; | |
/** | |
* @fileoverview Time currentDisplayUnit | |
*/ | |
tr.exportTo('tr.b.units', function() { | |
var ms = { | |
suffix: 'ms', | |
format: function(ts) { | |
var tsRounded = Math.round(ts * 1000.0) / 1000.0; | |
var n = new Number(tsRounded); | |
return n.toLocaleString(undefined, { minimumFractionDigits: 3 }) + ' ms'; | |
} | |
}; | |
var ns = { | |
suffix: 'ns', | |
format: function(ts) { | |
var tsRounded = Math.round(ts * 1000000.0); | |
var n = new Number(tsRounded); | |
return n.toLocaleString(undefined, { maximumFractionDigits: 0 }) + ' ns'; | |
} | |
}; | |
var Time = { | |
supportedUnits: { | |
ms: ms, | |
ns: ns | |
}, | |
reset: function() { | |
this.currentDisplayUnit = ms; | |
}, | |
currentDisplayUnit_: ms, | |
get currentDisplayUnit() { | |
return this.currentDisplayUnit_; | |
}, | |
set currentDisplayUnit(value) { | |
if (this.currentDisplayUnit_ == value) | |
return; | |
this.currentDisplayUnit_ = value; | |
this.dispatchEvent(new Event('display-unit-changed')); | |
} | |
}; | |
tr.b.EventTarget.decorate(Time); | |
return { | |
Time: Time | |
}; | |
}); | |
</script> |