js_data += "["
metric_data_map[metric_id].each() do |metric_data|
m_date = Time.parse(metric_data[:date])
- js_data += "{\"x\":d("
+ js_data += "{x:d("
js_data += m_date.year.to_s
js_data += ","
# Need to decrease by 1 the month as the JS Date object start months at 0 (= January)
js_data += m_date.min.to_s
js_data += ","
js_data += m_date.sec.to_s
- js_data += "),\"y\":"
+ js_data += "),y:"
js_data += sprintf( "%0.02f", metric_data[:value])
js_data += "},"
if index == 0
# we fill the js_snapshots array (no need to do this more than once)
- js_snapshots += "{\"sid\":"
+ js_snapshots += "{sid:"
js_snapshots += metric_data[:sid]
- js_snapshots += ",\"d\":\""
+ js_snapshots += ",d:\""
js_snapshots += l m_date, :format => :long
js_snapshots += "\"},"
end
end
- js_data += "],"
+ js_data = js_data.chomp(',') + "],"
end
end
- js_data += "]"
- js_snapshots += "]"
- js_metrics += "]"
+ js_data = js_data.chomp(',') + "]"
+ js_snapshots = js_snapshots.chomp(',') + "]"
+ js_metrics = js_metrics.chomp(',') + "]"
# Prepare also event structure if required
unless widget_properties["hideEvents"]
js_events = "["
events.keys().sort.each() do |e_date|
e_details = events[e_date]
- js_events += "{\"sid\":"
+ js_events += "{sid:"
js_events += e_details[0].snapshot_id.to_s
- js_events += ",\"d\":d("
+ js_events += ",d:d("
js_events += e_date.year.to_s
js_events += ","
# Need to decrease by 1 the month as the JS Date object start months at 0 (= January)
js_events += e_date.min.to_s
js_events += ","
js_events += e_date.sec.to_s
- js_events += "),\"l\":["
+ js_events += "),l:["
e_details.each() do |e|
- js_events += "{\"n\":\""
+ js_events += "{n:\""
js_events += e.name
js_events += "\"},"
end
- js_events += "]},"
+ js_events = js_events.chomp(',') + "]},"
end
- js_events += "]"
+ js_events = js_events.chomp(',') + "]"
end
# And prepare translations for labels
var snapshots = this.wSnapshots;
var translations = this.wTranslations;
var events = this.wEvents;
- var widgetDiv = document.getElementById(this.wDivId);
+ var widgetDiv = document.getElementById(this.wDivId);
var footerFont = "10.5px Arial,Helvetica,sans-serif";
- var show_y_axis = (data.length==1)
+ var show_y_axis = (trendData.size()==1)
/* Sizing and scales. */
var headerHeight = 4 + Math.max(this.wMetrics.size(), events ? 2 : 1) * 18;
var h = (this.wHeight == null ? 80 : this.wHeight) + headerHeight;
var yMaxHeight = h-headerHeight;
- var x = pv.Scale.linear(pv.blend(pv.map(data, function(d) {return d;})), function(d) {return d.x}).range(0, w);
- var y = new Array(data.length);
- for(var i = 0; i < data.length; i++){
- y[i]=pv.Scale.linear(data[i], function(d) {return d.y;}).range(20, yMaxHeight);
+ var x = pv.Scale.linear(pv.blend(pv.map(trendData, function(d) {return d;})), function(d) {return d.x}).range(0, w);
+ var y = new Array(trendData.size());
+ for(var i = 0; i < trendData.size(); i++){
+ y[i]=pv.Scale.linear(trendData[i], function(d) {return d.y;}).range(20, yMaxHeight);
}
var interpolate = "linear"; /* cardinal or linear */
var idx = this.wData[0].size() - 1;
})
.event("mousemove", function() {
var mx = x.invert(vis.mouse().x);
- idx = pv.search(data[0].map(function(d) {return d.x;}), mx);
+ idx = pv.search(trendData[0].map(function(d) {return d.x;}), mx);
idx = idx < 0 ? (-idx - 2) : idx;
idx = idx < 0 ? 0 : idx;
return vis;