var TimelineGraphView = (function() {
'use strict';
- // Default starting scale factor, in terms of milliseconds per pixel.
- var DEFAULT_SCALE = 1000;
-
// Maximum number of labels placed vertically along the sides of the graph.
var MAX_VERTICAL_LABELS = 6;
var TEXT_COLOR = '#000';
var BACKGROUND_COLOR = '#FFF';
+ var MAX_DECIMAL_PRECISION = 2;
/**
* @constructor
*/
this.graph_ = null;
+ // Horizontal scale factor, in terms of milliseconds per pixel.
+ this.scale_ = 1000;
+
// Initialize the scrollbar.
this.updateScrollbarRange_(true);
}
TimelineGraphView.prototype = {
+ setScale: function(scale) {
+ this.scale_ = scale;
+ },
+
// Returns the total length of the graph, in pixels.
getLength_: function() {
var timeRange = this.endTime_ - this.startTime_;
// Math.floor is used to ignore the last partial area, of length less
- // than DEFAULT_SCALE.
- return Math.floor(timeRange / DEFAULT_SCALE);
+ // than this.scale_.
+ return Math.floor(timeRange / this.scale_);
},
/**
* all the way to the right, keeps it all the way to the right. Otherwise,
* leaves the view as-is and doesn't redraw anything.
*/
- updateEndDate: function() {
- this.endTime_ = (new Date()).getTime();
+ updateEndDate: function(opt_date) {
+ this.endTime_ = opt_date || (new Date()).getTime();
this.updateScrollbarRange_(this.graphScrolledToRightEdge_());
},
// the graph to the end of the time range.
if (this.scrollbar_.range_ == 0)
position = this.getLength_() - this.canvas_.width;
- var visibleStartTime = this.startTime_ + position * DEFAULT_SCALE;
+ var visibleStartTime = this.startTime_ + position * this.scale_;
// Make space at the bottom of the graph for the time labels, and then
// draw the labels.
if (this.graph_) {
// Layout graph and have them draw their tick marks.
this.graph_.layout(
- width, height, fontHeight, visibleStartTime, DEFAULT_SCALE);
+ width, height, fontHeight, visibleStartTime, this.scale_);
this.graph_.drawTicks(context);
// Draw the lines of all graphs, and then draw their labels.
// Draw labels and vertical grid lines.
while (true) {
- var x = Math.round((time - startTime) / DEFAULT_SCALE);
+ var x = Math.round((time - startTime) / this.scale_);
if (x >= width)
break;
var text = (new Date(time)).toLocaleTimeString();
*/
layoutLabels_: function(maxValue) {
if (maxValue < 1024) {
- this.layoutLabelsBasic_(maxValue, 0);
+ this.layoutLabelsBasic_(maxValue, MAX_DECIMAL_PRECISION);
return;
}
}
// Calculate labels.
- this.layoutLabelsBasic_(maxValue, 1);
+ this.layoutLabelsBasic_(maxValue, MAX_DECIMAL_PRECISION);
// Append units to labels.
for (var i = 0; i < this.labels_.length; ++i)