web/js/fnordmetric.timeseries_widget.js in fnordmetric-1.0.1 vs web/js/fnordmetric.timeseries_widget.js in fnordmetric-1.2.0
- old
+ new
@@ -1,10 +1,9 @@
FnordMetric.widgets.timeseriesWidget = function(){
/*
options:
-
height: 430
default_cardinal: true/false
default_style: line/area/stack/flow
series
*/
@@ -18,11 +17,12 @@
function render(_opts){
opts = _opts;
if(opts.default_style == "areaspline"){ opts.default_style = 'area'; }
if(!opts.default_style){ opts.default_style = 'line'; }
- if(!opts.default_cardinal){ opts.default_cardinal = true; }
+ if(!opts.default_cardinal){ opts.default_cardinal = false; }
+ if(opts.xticks){ xticks = opts.xticks; }
draw_layout();
gconfig = {
element: $('.container', opts.elem)[0],
@@ -98,15 +98,15 @@
trgt_resolution -
(opts.timespan / opts.series_resolutions[ind])
);
if((!best_resolution) || (_diff < best_resolution)){
- best_resolution = opts.series_resolutions[ind];
+ best_resolution = opts.series_resolutions[ind];
}
}
-
- resolution = best_resolution;
+
+ resolution = best_resolution;
}
for(ind in gconfig.series){
gconfig.series[ind].data = gconfig.series[ind]["data"+resolution];
}
@@ -116,11 +116,11 @@
.filter('[data-tick="'+resolution+'"]')
.addClass('active');
}
function draw_layout(){
- if(!opts.no_headbar){
+ if(!opts.ext && !opts.no_headbar){
$(opts.elem).append(
$('<div></div>')
.addClass('headbar')
.append($('<h2></h2>').html(opts.title))
.append(
@@ -183,12 +183,12 @@
.css({
height: opts.height,
margin: '0 23px 25px 23px',
})
);
-
- if(opts.async_chart){
+
+ if(!opts.ext && opts.async_chart && !opts.no_datepicker){
$('.headbar', opts.elem).prepend(
$('<div></div>')
.addClass('button ml')
.append($('<span></span>').html('←'))
.click(function(){ moveRange(-1); })
@@ -225,11 +225,11 @@
}
if((opts.autoupdate) && (opts.async_chart)){
var secs = parseInt(opts.autoupdate);
if(secs > 0){
- var autoupdate_interval = window.setInterval(function(){
+ var autoupdate_interval = window.setInterval(function(){
updateChart(false, true);
}, secs*1000);
$('body').bind('fm_dashboard_close', function(){
window.clearInterval(autoupdate_interval);
@@ -244,42 +244,42 @@
gconfig.width = width;
gconfig.height = height;
$(gconfig.element).html("");
- $(".rickshaw_legend", opts.elem).html("");
+ $(".fnordmetric_legend", opts.elem).html("");
if(opts.series_resolutions){
apply_resolution();
}
- graph = new Rickshaw.Graph(gconfig);
+ graph = new FnordMetric.rickshaw.Graph(gconfig);
- legend = new Rickshaw.Graph.Legend({
+ legend = new FnordMetric.rickshaw.Graph.Legend({
graph: graph,
element: $('.legend', opts.elem)[0]
});
- hoverDetail = new Rickshaw.Graph.HoverDetail( {
+ hoverDetail = new FnordMetric.rickshaw.Graph.HoverDetail( {
graph: graph
});
- shelving = new Rickshaw.Graph.Behavior.Series.Toggle({
+ shelving = new FnordMetric.rickshaw.Graph.Behavior.Series.Toggle({
graph: graph,
legend: legend
});
- highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({
+ highlighter = new FnordMetric.rickshaw.Graph.Behavior.Series.Highlight({
graph: graph,
legend: legend
});
- new Rickshaw.Graph.Axis.Time({
+ new FnordMetric.rickshaw.Graph.Axis.Time({
graph: graph,
}).render();
- new Rickshaw.Graph.Axis.Y({
+ new FnordMetric.rickshaw.Graph.Axis.Y({
graph: graph,
}).render();
if(!gconfig.renderer){
gconfig.renderer = "line";
@@ -290,42 +290,42 @@
}
function announce(evt){
if(evt.widget_key == opts.widget_key){
- if((evt.class == "widget_response") && (evt.cmd == "values_at")){
+ if((evt.type == "widget_response") && (evt.cmd == "values_at")){
running_request = false;
- $(opts.elem).css('opacity', 1);
- updateSeriesData(evt.gauges);
+ $(opts.elem).css('opacity', 1);
+ updateSeriesData(evt.gauges);
}
}
}
function requestValuesAsync(){
FnordMetric.publish({
"type": "widget_request",
- "klass": "TimeseriesWidget",
+ "klass": "generic",
"gauges": opts.gauges,
"cmd": "values_at",
"tick": opts.tick,
"since": opts.start_timestamp,
"until": opts.end_timestamp,
"widget_key": opts.widget_key
- })
+ });
}
function updateSeriesData(dgauges){
gconfig.series = [];
for(var ind = 0; ind < dgauges.length; ind++){
-
+
gconfig.series.push({
- name: dgauges[ind].key,
+ name: dgauges[ind].title,
color: opts.series[ind].color,
data: []
});
-
+
for(_time in dgauges[ind].vals){
gconfig.series[ind].data.push(
{ x: parseInt(_time), y: parseInt(dgauges[ind].vals[_time] || 0) }
);
}
@@ -334,11 +334,11 @@
renderChart();
}
function updateChart(first_time, silent){
- if(!silent){ $(opts.elem).css('opacity', 0.5); }
+ if(!silent){ $(opts.elem).css('opacity', 0.7); }
updateRange();
redrawDatepicker();
requestValuesAsync();
}
@@ -349,16 +349,25 @@
FnordMetric.util.dateFormat(opts.end_timestamp)
);
}
function updateRange(force){
+ var _now = parseInt(new Date().getTime() / 1000);
+
+ if (opts.no_update_range)
+ return;
+
+ if (opts.ext) {
+ opts.end_timestamp = _now;
+ opts.start_timestamp = _now - opts.trange;
+ return;
+ }
+
if(!opts.tick){
opts.tick = opts.ticks[0];
}
- var _now = parseInt(new Date().getTime() / 1000);
-
if((opts.autoupdate) &&
((_now - opts.end_timestamp) < ((opts.tick*(opts.autoupdate+1)) + 5))){
force = true;
}
@@ -378,11 +387,19 @@
redrawDatepicker();
requestValuesAsync();
}
+ function set_timerange(s, e){
+ opts.start_timestamp = s;
+ opts.end_timestamp = e;
+ redrawDatepicker();
+ requestValuesAsync();
+ }
+
return {
render: render,
- announce: announce
+ announce: announce,
+ set_timerange: set_timerange
}
};