Renamed src directory to public

This commit is contained in:
Torkel Ödegaard
2015-03-29 12:57:28 +02:00
parent adb5d6da84
commit fde11be279
384 changed files with 5297 additions and 15 deletions

View File

@@ -0,0 +1,35 @@
define(['jquery'],
function ($) {
'use strict';
/**
* jQuery extensions
*/
var $win = $(window);
$.fn.place_tt = (function () {
var defaults = {
offset: 5,
};
return function (x, y, opts) {
opts = $.extend(true, {}, defaults, opts);
return this.each(function () {
var $tooltip = $(this), width, height;
$tooltip.addClass('grafana-tooltip');
$("#tooltip").remove();
$tooltip.appendTo(document.body);
width = $tooltip.outerWidth(true);
height = $tooltip.outerHeight(true);
$tooltip.css('left', x + opts.offset + width > $win.width() ? x - opts.offset - width : x + opts.offset);
$tooltip.css('top', y + opts.offset + height > $win.height() ? y - opts.offset - height : y + opts.offset);
});
};
})();
return $;
});

View File

@@ -0,0 +1,587 @@
define([
'jquery',
'lodash',
'moment'
],
function($, _, moment) {
'use strict';
var kbn = {};
kbn.valueFormats = {};
kbn.round_interval = function(interval) {
switch (true) {
// 0.5s
case (interval <= 500):
return 100; // 0.1s
// 5s
case (interval <= 5000):
return 1000; // 1s
// 7.5s
case (interval <= 7500):
return 5000; // 5s
// 15s
case (interval <= 15000):
return 10000; // 10s
// 45s
case (interval <= 45000):
return 30000; // 30s
// 3m
case (interval <= 180000):
return 60000; // 1m
// 9m
case (interval <= 450000):
return 300000; // 5m
// 20m
case (interval <= 1200000):
return 600000; // 10m
// 45m
case (interval <= 2700000):
return 1800000; // 30m
// 2h
case (interval <= 7200000):
return 3600000; // 1h
// 6h
case (interval <= 21600000):
return 10800000; // 3h
// 24h
case (interval <= 86400000):
return 43200000; // 12h
// 48h
case (interval <= 172800000):
return 86400000; // 24h
// 1w
case (interval <= 604800000):
return 86400000; // 24h
// 3w
case (interval <= 1814400000):
return 604800000; // 1w
// 2y
case (interval < 3628800000):
return 2592000000; // 30d
default:
return 31536000000; // 1y
}
};
kbn.secondsToHms = function(seconds) {
var numyears = Math.floor(seconds / 31536000);
if(numyears){
return numyears + 'y';
}
var numdays = Math.floor((seconds % 31536000) / 86400);
if(numdays){
return numdays + 'd';
}
var numhours = Math.floor(((seconds % 31536000) % 86400) / 3600);
if(numhours){
return numhours + 'h';
}
var numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
if(numminutes){
return numminutes + 'm';
}
var numseconds = (((seconds % 31536000) % 86400) % 3600) % 60;
if(numseconds){
return numseconds + 's';
}
return 'less then a second'; //'just now' //or other string you like;
};
kbn.to_percent = function(number,outof) {
return Math.floor((number/outof)*10000)/100 + "%";
};
kbn.addslashes = function(str) {
str = str.replace(/\\/g, '\\\\');
str = str.replace(/\'/g, '\\\'');
str = str.replace(/\"/g, '\\"');
str = str.replace(/\0/g, '\\0');
return str;
};
kbn.interval_regex = /(\d+(?:\.\d+)?)([Mwdhmsy])/;
// histogram & trends
kbn.intervals_in_seconds = {
y: 31536000,
M: 2592000,
w: 604800,
d: 86400,
h: 3600,
m: 60,
s: 1
};
kbn.calculateInterval = function(range, resolution, userInterval) {
var lowLimitMs = 1; // 1 millisecond default low limit
var intervalMs, lowLimitInterval;
if (userInterval) {
if (userInterval[0] === '>') {
lowLimitInterval = userInterval.slice(1);
lowLimitMs = kbn.interval_to_ms(lowLimitInterval);
}
else {
return userInterval;
}
}
intervalMs = kbn.round_interval((range.to.valueOf() - range.from.valueOf()) / resolution);
if (lowLimitMs > intervalMs) {
intervalMs = lowLimitMs;
}
return kbn.secondsToHms(intervalMs / 1000);
};
kbn.describe_interval = function (string) {
var matches = string.match(kbn.interval_regex);
if (!matches || !_.has(kbn.intervals_in_seconds, matches[2])) {
throw new Error('Invalid interval string, expexcting a number followed by one of "Mwdhmsy"');
} else {
return {
sec: kbn.intervals_in_seconds[matches[2]],
type: matches[2],
count: parseInt(matches[1], 10)
};
}
};
kbn.interval_to_ms = function(string) {
var info = kbn.describe_interval(string);
return info.sec * 1000 * info.count;
};
kbn.interval_to_seconds = function (string) {
var info = kbn.describe_interval(string);
return info.sec * info.count;
};
/* This is a simplified version of elasticsearch's date parser */
kbn.parseDate = function(text) {
if(_.isDate(text)) {
return text;
}
var time;
var mathString = "";
var index;
var parseString;
if (text.substring(0,3) === "now") {
time = new Date();
mathString = text.substring(3);
}
else if (text.substring(0,5) === 'today') {
time = new Date();
time.setHours(0,0,0,0);
mathString = text.substring(5);
}
else {
index = text.indexOf("||");
parseString;
if (index === -1) {
parseString = text;
mathString = ""; // nothing else
} else {
parseString = text.substring(0, index);
mathString = text.substring(index + 2);
}
// We're going to just require ISO8601 timestamps, k?
time = new Date(parseString);
}
if (!mathString.length) {
return time;
}
//return [time,parseString,mathString];
return kbn.parseDateMath(mathString, time);
};
kbn._timespanRegex = /^\d+[h,m,M,w,s,H,d]$/;
kbn.isValidTimeSpan = function(str) {
return kbn._timespanRegex.test(str);
};
kbn.parseDateMath = function(mathString, time, roundUp) {
var dateTime = moment(time);
for (var i = 0; i < mathString.length;) {
var c = mathString.charAt(i++),
type,
num,
unit;
if (c === '/') {
type = 0;
} else if (c === '+') {
type = 1;
} else if (c === '-') {
type = 2;
} else {
return false;
}
if (isNaN(mathString.charAt(i))) {
num = 1;
} else {
var numFrom = i;
while (!isNaN(mathString.charAt(i))) {
i++;
}
num = parseInt(mathString.substring(numFrom, i),10);
}
if (type === 0) {
// rounding is only allowed on whole numbers
if (num !== 1) {
return false;
}
}
unit = mathString.charAt(i++);
switch (unit) {
case 'y':
if (type === 0) {
roundUp ? dateTime.endOf('year') : dateTime.startOf('year');
} else if (type === 1) {
dateTime.add(num, 'years');
} else if (type === 2) {
dateTime.subtract(num, 'years');
}
break;
case 'M':
if (type === 0) {
roundUp ? dateTime.endOf('month') : dateTime.startOf('month');
} else if (type === 1) {
dateTime.add(num, 'months');
} else if (type === 2) {
dateTime.subtract(num, 'months');
}
break;
case 'w':
if (type === 0) {
roundUp ? dateTime.endOf('week') : dateTime.startOf('week');
} else if (type === 1) {
dateTime.add(num, 'weeks');
} else if (type === 2) {
dateTime.subtract(num, 'weeks');
}
break;
case 'd':
if (type === 0) {
roundUp ? dateTime.endOf('day') : dateTime.startOf('day');
} else if (type === 1) {
dateTime.add(num, 'days');
} else if (type === 2) {
dateTime.subtract(num, 'days');
}
break;
case 'h':
case 'H':
if (type === 0) {
roundUp ? dateTime.endOf('hour') : dateTime.startOf('hour');
} else if (type === 1) {
dateTime.add(num, 'hours');
} else if (type === 2) {
dateTime.subtract(num,'hours');
}
break;
case 'm':
if (type === 0) {
roundUp ? dateTime.endOf('minute') : dateTime.startOf('minute');
} else if (type === 1) {
dateTime.add(num, 'minutes');
} else if (type === 2) {
dateTime.subtract(num, 'minutes');
}
break;
case 's':
if (type === 0) {
roundUp ? dateTime.endOf('second') : dateTime.startOf('second');
} else if (type === 1) {
dateTime.add(num, 'seconds');
} else if (type === 2) {
dateTime.subtract(num, 'seconds');
}
break;
default:
return false;
}
}
return dateTime.toDate();
};
kbn.query_color_dot = function (color, diameter) {
return '<div class="icon-circle" style="' + [
'display:inline-block',
'color:' + color,
'font-size:' + diameter + 'px',
].join(';') + '"></div>';
};
kbn.valueFormats.percent = function(size, decimals) {
return kbn.toFixed(size, decimals) + '%';
};
kbn.formatFuncCreator = function(factor, extArray) {
return function(size, decimals, scaledDecimals) {
if (size === null) {
return "";
}
var steps = 0;
var limit = extArray.length;
while (Math.abs(size) >= factor) {
steps++;
size /= factor;
if (steps >= limit) { return "NA"; }
}
if (steps > 0 && scaledDecimals !== null) {
decimals = scaledDecimals + (3 * steps);
}
return kbn.toFixed(size, decimals) + extArray[steps];
};
};
kbn.toFixed = function(value, decimals) {
if (value === null) {
return "";
}
var factor = decimals ? Math.pow(10, Math.max(0, decimals)) : 1;
var formatted = String(Math.round(value * factor) / factor);
// if exponent return directly
if (formatted.indexOf('e') !== -1 || value === 0) {
return formatted;
}
// If tickDecimals was specified, ensure that we have exactly that
// much precision; otherwise default to the value's own precision.
if (decimals != null) {
var decimalPos = formatted.indexOf(".");
var precision = decimalPos === -1 ? 0 : formatted.length - decimalPos - 1;
if (precision < decimals) {
return (precision ? formatted : formatted + ".") + (String(factor)).substr(1, decimals - precision);
}
}
return formatted;
};
kbn.valueFormats.bits = kbn.formatFuncCreator(1024, [' b', ' Kib', ' Mib', ' Gib', ' Tib', ' Pib', ' Eib', ' Zib', ' Yib']);
kbn.valueFormats.bytes = kbn.formatFuncCreator(1024, [' B', ' KiB', ' MiB', ' GiB', ' TiB', ' PiB', ' EiB', ' ZiB', ' YiB']);
kbn.valueFormats.kbytes = kbn.formatFuncCreator(1024, [' KiB', ' MiB', ' GiB', ' TiB', ' PiB', ' EiB', ' ZiB', ' YiB']);
kbn.valueFormats.mbytes = kbn.formatFuncCreator(1024, [' MiB', ' GiB', ' TiB', ' PiB', ' EiB', ' ZiB', ' YiB']);
kbn.valueFormats.bps = kbn.formatFuncCreator(1000, [' bps', ' Kbps', ' Mbps', ' Gbps', ' Tbps', ' Pbps', ' Ebps', ' Zbps', ' Ybps']);
kbn.valueFormats.Bps = kbn.formatFuncCreator(1000, [' Bps', ' KBps', ' MBps', ' GBps', ' TBps', ' PBps', ' EBps', ' ZBps', ' YBps']);
kbn.valueFormats.short = kbn.formatFuncCreator(1000, ['', ' K', ' Mil', ' Bil', ' Tri', ' Qaudr', ' Quint', ' Sext', ' Sept']);
kbn.valueFormats.joule = kbn.formatFuncCreator(1000, [' J', ' kJ', ' MJ', ' GJ', ' TJ', ' PJ', ' EJ', ' ZJ', ' YJ']);
kbn.valueFormats.watt = kbn.formatFuncCreator(1000, [' W', ' kW', ' MW', ' GW', ' TW', ' PW', ' EW', ' ZW', ' YW']);
kbn.valueFormats.kwatt = kbn.formatFuncCreator(1000, [' kW', ' MW', ' GW', ' TW', ' PW', ' EW', ' ZW', ' YW']);
kbn.valueFormats.watth = kbn.formatFuncCreator(1000, [' Wh', ' kWh', ' MWh', ' GWh', ' TWh', ' PWh', ' EWh', ' ZWh', ' YWh']);
kbn.valueFormats.kwatth = kbn.formatFuncCreator(1000, [' kWh', ' MWh', ' GWh', ' TWh', ' PWh', ' EWh', ' ZWh', ' YWh']);
kbn.valueFormats.ev = kbn.formatFuncCreator(1000, [' eV', ' keV', ' MeV', 'GeV', 'TeV', 'PeV', 'EeV', 'ZeV', 'YeV']);
kbn.valueFormats.none = kbn.toFixed;
kbn.valueFormats.celsius = function(value, decimals) { return kbn.toFixed(value, decimals) + ' °C'; };
kbn.valueFormats.farenheit = function(value, decimals) { return kbn.toFixed(value, decimals) + ' °F'; };
kbn.valueFormats.humidity = function(value, decimals) { return kbn.toFixed(value, decimals) + ' %H'; };
kbn.valueFormats.ppm = function(value, decimals) { return kbn.toFixed(value, decimals) + ' ppm'; };
kbn.valueFormats.velocityms = function(value, decimals) { return kbn.toFixed(value, decimals) + ' m/s'; };
kbn.valueFormats.velocitykmh = function(value, decimals) { return kbn.toFixed(value, decimals) + ' km/h'; };
kbn.valueFormats.velocitymph = function(value, decimals) { return kbn.toFixed(value, decimals) + ' mph'; };
kbn.valueFormats.velocityknot = function(value, decimals) { return kbn.toFixed(value, decimals) + ' kn'; };
kbn.toFixedScaled = function(value, decimals, scaledDecimals, additionalDecimals, ext) {
if (scaledDecimals === null) {
return kbn.toFixed(value, decimals) + ext;
} else {
return kbn.toFixed(value, scaledDecimals + additionalDecimals) + ext;
}
};
kbn.valueFormats.ms = function(size, decimals, scaledDecimals) {
if (size === null) { return ""; }
if (Math.abs(size) < 1000) {
return kbn.toFixed(size, decimals) + " ms";
}
// Less than 1 min
else if (Math.abs(size) < 60000) {
return kbn.toFixedScaled(size / 1000, decimals, scaledDecimals, 3, " s");
}
// Less than 1 hour, devide in minutes
else if (Math.abs(size) < 3600000) {
return kbn.toFixedScaled(size / 60000, decimals, scaledDecimals, 5, " min");
}
// Less than one day, devide in hours
else if (Math.abs(size) < 86400000) {
return kbn.toFixedScaled(size / 3600000, decimals, scaledDecimals, 7, " hour");
}
// Less than one year, devide in days
else if (Math.abs(size) < 31536000000) {
return kbn.toFixedScaled(size / 86400000, decimals, scaledDecimals, 8, " day");
}
return kbn.toFixedScaled(size / 31536000000, decimals, scaledDecimals, 10, " year");
};
kbn.valueFormats.s = function(size, decimals, scaledDecimals) {
if (size === null) { return ""; }
if (Math.abs(size) < 600) {
return kbn.toFixed(size, decimals) + " s";
}
// Less than 1 hour, devide in minutes
else if (Math.abs(size) < 3600) {
return kbn.toFixedScaled(size / 60, decimals, scaledDecimals, 1, " min");
}
// Less than one day, devide in hours
else if (Math.abs(size) < 86400) {
return kbn.toFixedScaled(size / 3600, decimals, scaledDecimals, 4, " hour");
}
// Less than one week, devide in days
else if (Math.abs(size) < 604800) {
return kbn.toFixedScaled(size / 86400, decimals, scaledDecimals, 5, " day");
}
// Less than one year, devide in week
else if (Math.abs(size) < 31536000) {
return kbn.toFixedScaled(size / 604800, decimals, scaledDecimals, 6, " week");
}
return kbn.toFixedScaled(size / 3.15569e7, decimals, scaledDecimals, 7, " year");
};
kbn.valueFormats['µs'] = function(size, decimals, scaledDecimals) {
if (size === null) { return ""; }
if (Math.abs(size) < 1000) {
return kbn.toFixed(size, decimals) + " µs";
}
else if (Math.abs(size) < 1000000) {
return kbn.toFixedScaled(size / 1000, decimals, scaledDecimals, 3, " ms");
}
else {
return kbn.toFixedScaled(size / 1000000, decimals, scaledDecimals, 6, " s");
}
};
kbn.valueFormats.ns = function(size, decimals, scaledDecimals) {
if (size === null) { return ""; }
if (Math.abs(size) < 1000) {
return kbn.toFixed(size, decimals) + " ns";
}
else if (Math.abs(size) < 1000000) {
return kbn.toFixedScaled(size / 1000, decimals, scaledDecimals, 3, " µs");
}
else if (Math.abs(size) < 1000000000) {
return kbn.toFixedScaled(size / 1000000, decimals, scaledDecimals, 6, " ms");
}
else if (Math.abs(size) < 60000000000){
return kbn.toFixedScaled(size / 1000000000, decimals, scaledDecimals, 9, " s");
}
else {
return kbn.toFixedScaled(size / 60000000000, decimals, scaledDecimals, 12, " min");
}
};
kbn.slugifyForUrl = function(str) {
return str
.toLowerCase()
.replace(/[^\w ]+/g,'')
.replace(/ +/g,'-');
};
kbn.exportSeriesListToCsv = function(seriesList) {
var text = 'Series;Time;Value\n';
_.each(seriesList, function(series) {
_.each(series.datapoints, function(dp) {
text += series.alias + ';' + new Date(dp[1]).toISOString() + ';' + dp[0] + '\n';
});
});
var blob = new Blob([text], { type: "text/csv;charset=utf-8" });
window.saveAs(blob, 'grafana_data_export.csv');
};
kbn.stringToJsRegex = function(str) {
if (str[0] !== '/') {
return new RegExp(str);
}
var match = str.match(new RegExp('^/(.*?)/(g?i?m?y?)$'));
return new RegExp(match[1], match[2]);
};
kbn.getUnitFormats = function() {
return [
{
text: 'none',
submenu: [
{text: 'none' , value: 'none'},
{text: 'short', value: 'short'},
{text: 'percent', value: 'percent'},
{text: 'ppm', value: 'ppm'},
]
},
{
text: 'duration',
submenu: [
{text: 'nanoseconds (ns)' , value: 'ns'},
{text: 'microseconds (µs)', value: 'µs'},
{text: 'milliseconds (ms)', value: 'ms'},
{text: 'seconds (s)', value: 's'},
]
},
{
text: 'data',
submenu: [
{text: 'bits', value: 'bits'},
{text: 'bytes', value: 'bytes'},
{text: 'kilobytes', value: 'kbytes'},
{text: 'megabytes', value: 'mbytes'},
]
},
{
text: 'data rate',
submenu: [
{text: 'bits/sec', value: 'bps'},
{text: 'bytes/sec', value: 'Bps'},
]
},
{
text: 'energy',
submenu: [
{text: 'watt (W)', value: 'watt'},
{text: 'kilowatt (kW)', value: 'kwatt'},
{text: 'watt-hour (Wh)', value: 'watth'},
{text: 'kilowatt-hour (kWh)', value: 'kwatth'},
{text: 'joule (J)', value: 'joule'},
{text: 'electron volt (eV)', value: 'ev'},
]
},
{
text: 'weather',
submenu: [
{text: 'Celcius (°C)', value: 'celsius' },
{text: 'Farenheit (°F)', value: 'farenheit'},
{text: 'Humidity (%H)', value: 'humidity' },
]
},
{
text: 'velocity',
submenu: [
{text: 'm/s', value: 'velocityms' },
{text: 'km/h', value: 'velocitykmh' },
{text: 'mph', value: 'velocitymph' },
{text: 'knot (kn)', value: 'velocityknot' },
]
},
];
};
return kbn;
});

View File

@@ -0,0 +1,32 @@
define([
'lodash-src'
],
function () {
'use strict';
var _ = window._;
/*
Mixins :)
*/
_.mixin({
move: function (array, fromIndex, toIndex) {
array.splice(toIndex, 0, array.splice(fromIndex, 1)[0]);
return array;
},
// If variable is value, then return alt. If variable is anything else, return value;
toggle: function (variable, value, alt) {
return variable === value ? alt : value;
},
toggleInOut: function(array,value) {
if(_.contains(array,value)) {
array = _.without(array,value);
} else {
array.push(value);
}
return array;
}
});
return _;
});

View File

@@ -0,0 +1,46 @@
define([
],
function () {
"use strict";
function PanelMeta(options) {
this.description = options.description;
this.fullscreen = options.fullscreen;
this.editIcon = options.editIcon;
this.panelName = options.panelName;
this.menu = [];
this.editorTabs = [];
this.extendedMenu = [];
if (options.fullscreen) {
this.addMenuItem('view', 'icon-eye-open', 'toggleFullscreen(false); dismiss();');
}
this.addMenuItem('edit', 'icon-cog', 'editPanel(); dismiss();');
this.addMenuItem('duplicate', 'icon-copy', 'duplicatePanel()');
this.addMenuItem('share', 'icon-share', 'sharePanel(); dismiss();');
this.addEditorTab('General', 'app/partials/panelgeneral.html');
if (options.metricsEditor) {
this.addEditorTab('Metrics', 'app/partials/metrics.html');
}
this.addExtendedMenuItem('Panel JSON', '', 'editPanelJson(); dismiss();');
}
PanelMeta.prototype.addMenuItem = function(text, icon, click) {
this.menu.push({text: text, icon: icon, click: click});
};
PanelMeta.prototype.addExtendedMenuItem = function(text, icon, click) {
this.extendedMenu.push({text: text, icon: icon, click: click});
};
PanelMeta.prototype.addEditorTab = function(title, src) {
this.editorTabs.push({title: title, src: src});
};
return PanelMeta;
});

View File

@@ -0,0 +1,2 @@
define([
], function () {});

View File

@@ -0,0 +1,105 @@
require.config({
urlArgs: 'bust=' + (new Date().getTime()),
baseUrl: 'public/app',
paths: {
config: 'components/config',
settings: 'components/settings',
kbn: 'components/kbn',
store: 'components/store',
css: '../vendor/require/css',
text: '../vendor/require/text',
moment: '../vendor/moment',
filesaver: '../vendor/filesaver',
ZeroClipboard: '../vendor/ZeroClipboard',
angular: '../vendor/angular/angular',
'angular-route': '../vendor/angular/angular-route',
'angular-sanitize': '../vendor/angular/angular-sanitize',
'angular-dragdrop': '../vendor/angular/angular-dragdrop',
'angular-strap': '../vendor/angular/angular-strap',
timepicker: '../vendor/angular/timepicker',
datepicker: '../vendor/angular/datepicker',
bindonce: '../vendor/angular/bindonce',
crypto: '../vendor/crypto.min',
spectrum: '../vendor/spectrum',
lodash: 'components/lodash.extended',
'lodash-src': '../vendor/lodash',
bootstrap: '../vendor/bootstrap/bootstrap',
jquery: '../vendor/jquery/jquery-2.1.1.min',
'extend-jquery': 'components/extend-jquery',
'jquery.flot': '../vendor/jquery/jquery.flot',
'jquery.flot.pie': '../vendor/jquery/jquery.flot.pie',
'jquery.flot.events': '../vendor/jquery/jquery.flot.events',
'jquery.flot.selection': '../vendor/jquery/jquery.flot.selection',
'jquery.flot.stack': '../vendor/jquery/jquery.flot.stack',
'jquery.flot.stackpercent':'../vendor/jquery/jquery.flot.stackpercent',
'jquery.flot.time': '../vendor/jquery/jquery.flot.time',
'jquery.flot.crosshair': '../vendor/jquery/jquery.flot.crosshair',
'jquery.flot.fillbelow': '../vendor/jquery/jquery.flot.fillbelow',
modernizr: '../vendor/modernizr-2.6.1',
'bootstrap-tagsinput': '../vendor/tagsinput/bootstrap-tagsinput',
},
shim: {
spectrum: {
deps: ['jquery']
},
crypto: {
exports: 'Crypto'
},
ZeroClipboard: {
exports: 'ZeroClipboard'
},
angular: {
deps: ['jquery','config'],
exports: 'angular'
},
bootstrap: {
deps: ['jquery']
},
modernizr: {
exports: 'Modernizr'
},
jquery: {
exports: 'jQuery'
},
// simple dependency declaration
//
'jquery.flot': ['jquery'],
'jquery.flot.pie': ['jquery', 'jquery.flot'],
'jquery.flot.events': ['jquery', 'jquery.flot'],
'jquery.flot.selection':['jquery', 'jquery.flot'],
'jquery.flot.stack': ['jquery', 'jquery.flot'],
'jquery.flot.stackpercent':['jquery', 'jquery.flot'],
'jquery.flot.time': ['jquery', 'jquery.flot'],
'jquery.flot.crosshair':['jquery', 'jquery.flot'],
'jquery.flot.fillbelow':['jquery', 'jquery.flot'],
'angular-dragdrop': ['jquery', 'angular'],
'angular-mocks': ['angular'],
'angular-sanitize': ['angular'],
'angular-route': ['angular'],
'angular-strap': ['angular', 'bootstrap','timepicker', 'datepicker'],
'bindonce': ['angular'],
timepicker: ['jquery', 'bootstrap'],
datepicker: ['jquery', 'bootstrap'],
'bootstrap-tagsinput': ['jquery'],
},
waitSeconds: 60,
});

View File

@@ -0,0 +1,57 @@
define([
'lodash',
],
function (_) {
"use strict";
return function Settings (options) {
/**
* To add a setting, you MUST define a default. Also,
* THESE ARE ONLY DEFAULTS.
* They are overridden by config.js in the root directory
* @type {Object}
*/
var defaults = {
datasources : {},
window_title_prefix : 'Grafana - ',
panels : {
'graph': { path: 'panels/graph', name: 'Graph' },
'singlestat': { path: 'panels/singlestat', name: 'Single stat' },
'text': { path: 'panels/text', name: 'Text' },
'dashlist': { path: 'panels/dashlist', name: 'Dashboard list' },
},
new_panel_title: 'no title (click here)',
plugins: {},
default_route: '/dashboard/file/default.json',
playlist_timespan: "1m",
unsaved_changes_warning: true,
search: { max_results: 100 },
appSubUrl: ""
};
var settings = _.extend({}, defaults, options);
// var parseBasicAuth = function(datasource) {
// var passwordEnd = datasource.url.indexOf('@');
// if (passwordEnd > 0) {
// var userStart = datasource.url.indexOf('//') + 2;
// var userAndPassword = datasource.url.substring(userStart, passwordEnd);
// var bytes = crypto.charenc.Binary.stringToBytes(userAndPassword);
// datasource.basicAuth = crypto.util.bytesToBase64(bytes);
//
// var urlHead = datasource.url.substring(0, userStart);
// datasource.url = urlHead + datasource.url.substring(passwordEnd + 1);
// }
//
// return datasource;
// };
//
// _.each(settings.datasources, function(datasource, key) {
// datasource.name = key;
// if (datasource.url) { parseBasicAuth(datasource); }
// if (datasource.type === 'influxdb') { parseMultipleHosts(datasource); }
// });
return settings;
};
});

View File

@@ -0,0 +1,26 @@
define([], function() {
'use strict';
return {
get: function(key) {
return window.localStorage[key];
},
set: function(key, value) {
window.localStorage[key] = value;
},
getBool: function(key, def) {
if (def !== void 0 && !this.exists(key)) {
return def;
}
return window.localStorage[key] === 'true' ? true : false;
},
exists: function(key) {
return window.localStorage[key] !== void 0;
},
delete: function(key) {
window.localStorage.removeItem(key);
}
};
});

View File

@@ -0,0 +1,137 @@
define([
'lodash',
'kbn'
],
function (_, kbn) {
'use strict';
function TimeSeries(opts) {
this.datapoints = opts.datapoints;
this.label = opts.alias;
this.id = opts.alias;
this.alias = opts.alias;
this.color = opts.color;
this.valueFormater = kbn.valueFormats.none;
this.stats = {};
}
function matchSeriesOverride(aliasOrRegex, seriesAlias) {
if (!aliasOrRegex) { return false; }
if (aliasOrRegex[0] === '/') {
var regex = kbn.stringToJsRegex(aliasOrRegex);
return seriesAlias.match(regex) != null;
}
return aliasOrRegex === seriesAlias;
}
function translateFillOption(fill) {
return fill === 0 ? 0.001 : fill/10;
}
TimeSeries.prototype.applySeriesOverrides = function(overrides) {
this.lines = {};
this.points = {};
this.bars = {};
this.yaxis = 1;
this.zindex = 0;
delete this.stack;
for (var i = 0; i < overrides.length; i++) {
var override = overrides[i];
if (!matchSeriesOverride(override.alias, this.alias)) {
continue;
}
if (override.lines !== void 0) { this.lines.show = override.lines; }
if (override.points !== void 0) { this.points.show = override.points; }
if (override.bars !== void 0) { this.bars.show = override.bars; }
if (override.fill !== void 0) { this.lines.fill = translateFillOption(override.fill); }
if (override.stack !== void 0) { this.stack = override.stack; }
if (override.linewidth !== void 0) { this.lines.lineWidth = override.linewidth; }
if (override.pointradius !== void 0) { this.points.radius = override.pointradius; }
if (override.steppedLine !== void 0) { this.lines.steps = override.steppedLine; }
if (override.zindex !== void 0) { this.zindex = override.zindex; }
if (override.fillBelowTo !== void 0) { this.fillBelowTo = override.fillBelowTo; }
if (override.yaxis !== void 0) {
this.yaxis = override.yaxis;
}
}
};
TimeSeries.prototype.getFlotPairs = function (fillStyle) {
var result = [];
this.stats.total = 0;
this.stats.max = -Number.MAX_VALUE;
this.stats.min = Number.MAX_VALUE;
this.stats.avg = null;
this.stats.current = null;
this.allIsNull = true;
var ignoreNulls = fillStyle === 'connected';
var nullAsZero = fillStyle === 'null as zero';
var currentTime;
var currentValue;
for (var i = 0; i < this.datapoints.length; i++) {
currentValue = this.datapoints[i][0];
currentTime = this.datapoints[i][1];
if (currentValue === null) {
if (ignoreNulls) { continue; }
if (nullAsZero) {
currentValue = 0;
}
}
if (currentValue !== null) {
if (_.isNumber(currentValue)) {
this.stats.total += currentValue;
this.allIsNull = false;
}
if (currentValue > this.stats.max) {
this.stats.max = currentValue;
}
if (currentValue < this.stats.min) {
this.stats.min = currentValue;
}
}
result.push([currentTime, currentValue]);
}
if (this.datapoints.length >= 2) {
this.stats.timeStep = this.datapoints[1][1] - this.datapoints[0][1];
}
if (this.stats.max === -Number.MAX_VALUE) { this.stats.max = null; }
if (this.stats.min === Number.MAX_VALUE) { this.stats.min = null; }
if (result.length) {
this.stats.avg = (this.stats.total / result.length);
this.stats.current = result[result.length-1][1];
if (this.stats.current === null && result.length > 1) {
this.stats.current = result[result.length-2][1];
}
}
return result;
};
TimeSeries.prototype.updateLegendValues = function(formater, decimals, scaledDecimals) {
this.valueFormater = formater;
this.decimals = decimals;
this.scaledDecimals = scaledDecimals;
};
TimeSeries.prototype.formatValue = function(value) {
return this.valueFormater(value, this.decimals, this.scaledDecimals);
};
return TimeSeries;
});