blob: 45438fed04dbd9a90f6aaea8d572b7f5da4f18e3 [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2013 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="/model/event.html">
<link rel="import" href="/base/iteration_helpers.html">
<link rel="import" href="/base/units/util.html">
<link rel="import" href="/base/sorted_array_utils.html">
<script>
'use strict';
tr.exportTo('tr.model', function() {
function CounterSample(series, timestamp, value) {
tr.model.Event.call(this);
this.series_ = series;
this.timestamp_ = timestamp;
this.value_ = value;
}
CounterSample.groupByTimestamp = function(samples) {
var samplesByTimestamp = tr.b.group(samples, function(sample) {
return sample.timestamp;
});
var timestamps = tr.b.dictionaryKeys(samplesByTimestamp);
timestamps.sort();
var groups = [];
for (var i = 0; i < timestamps.length; i++) {
var ts = timestamps[i];
var group = samplesByTimestamp[ts];
group.sort(function(x, y) {
return x.series.seriesIndex - y.series.seriesIndex;
});
groups.push(group);
}
return groups;
}
CounterSample.prototype = {
__proto__: tr.model.Event.prototype,
get series() {
return this.series_;
},
get timestamp() {
return this.timestamp_;
},
get value() {
return this.value_;
},
set timestamp(timestamp) {
this.timestamp_ = timestamp;
},
addBoundsToRange: function(range) {
range.addValue(this.timestamp);
},
getSampleIndex: function() {
return tr.b.findLowIndexInSortedArray(
this.series.timestamps,
function(x) { return x; },
this.timestamp_);
},
get userFriendlyName() {
return 'Counter sample from ' + this.series_.title + ' at ' +
tr.b.units.tsString(this.timestamp);
}
};
tr.model.EventRegistry.register(
CounterSample,
{
name: 'counterSample',
pluralName: 'counterSamples',
singleViewElementName: 'tr-c-a-counter-sample-sub-view',
multiViewElementName: 'tr-c-a-counter-sample-sub-view'
});
return {
CounterSample: CounterSample
};
});
</script>