2014-09-10 10:45:34 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
|
|
|
(function(Icinga, $) {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
Icinga.Behaviors = Icinga.Behaviors || {};
|
|
|
|
|
|
|
|
var Sparkline = function (icinga) {
|
2014-09-12 09:09:21 +02:00
|
|
|
Icinga.EventListener.call(this, icinga);
|
|
|
|
this.on('rendered', this.onRendered, this);
|
2014-09-10 10:45:34 +02:00
|
|
|
};
|
2014-09-12 09:09:21 +02:00
|
|
|
Sparkline.prototype = new Icinga.EventListener();
|
|
|
|
|
|
|
|
Sparkline.prototype.onRendered = function(evt) {
|
|
|
|
var el = evt.target;
|
2014-09-10 10:45:34 +02:00
|
|
|
|
|
|
|
$('span.sparkline', el).each(function(i, element) {
|
|
|
|
// read custom options
|
|
|
|
var $spark = $(element);
|
|
|
|
var labels = $spark.attr('labels').split('|');
|
|
|
|
var formatted = $spark.attr('formatted').split('|');
|
2014-09-10 15:53:30 +02:00
|
|
|
var tooltipChartTitle = $spark.attr('sparkTooltipChartTitle') || '';
|
2014-09-10 10:45:34 +02:00
|
|
|
var format = $spark.attr('tooltipformat');
|
|
|
|
var hideEmpty = $spark.attr('hideEmptyLabel') === 'true';
|
|
|
|
$spark.sparkline(
|
|
|
|
'html',
|
|
|
|
{
|
|
|
|
enableTagOptions: true,
|
|
|
|
tooltipFormatter: function (sparkline, options, fields) {
|
|
|
|
var out = format;
|
|
|
|
if (hideEmpty && fields.offset === 3) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
var replace = {
|
|
|
|
title: tooltipChartTitle,
|
|
|
|
label: labels[fields.offset] ? labels[fields.offset] : fields.offset,
|
|
|
|
formatted: formatted[fields.offset] ? formatted[fields.offset] : '',
|
|
|
|
value: fields.value,
|
|
|
|
percent: Math.round(fields.percent * 100) / 100
|
|
|
|
};
|
|
|
|
$.each(replace, function(key, value) {
|
|
|
|
out = out.replace('{{' + key + '}}', value);
|
|
|
|
});
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Icinga.Behaviors.Sparkline = Sparkline;
|
|
|
|
|
|
|
|
}) (Icinga, jQuery);
|