Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Grafana Tooltip Sort Bookmarklet
/**
* Minified with http://ted.mielczarek.org/code/mozilla/bookmarklet.html
*/
javascript:(function(){function observe(){var observer=new MutationObserver(sortTooltip);observer.observe(document.body,{childList:true});}function sortTooltip(){var tooltip=$('#tooltip');if(!tooltip.length){return;}var items=$('#tooltip > .graph-tooltip-list-item');items.sort((a,b)=>strToNum($('.graph-tooltip-value',a).text())>strToNum($('.graph-tooltip-value',b).text())?-1:1);items.detach().appendTo(tooltip);}function strToNum(str){var num=parseFloat(str);if(isNaN(num)){return-1;}if(str.indexOf('K')>-1){return num*1000;}if(str.indexOf('Mil')>-1){return num*1000000;}if(str.indexOf('min')>-1){return num*60000;}if(str.indexOf('ms')>-1){return num*1;}if(str.indexOf('s')>-1){return num*1000;}return parseFloat(str);}observe();})();
/**
* Unminified:
*/
function observe () {
var observer = new MutationObserver (sortTooltip);
observer.observe(document.body, {childList: true});
}
function sortTooltip () {
var tooltip = $('#tooltip');
if (!tooltip.length) { return; }
var items = $('#tooltip > .graph-tooltip-list-item');
items.sort((a,b) =>
strToNum($('.graph-tooltip-value', a).text()) >
strToNum($('.graph-tooltip-value', b).text()) ?
-1 : 1
);
items.detach().appendTo(tooltip);
}
function strToNum (str) {
var num = parseFloat(str);
if (isNaN(num)) {
return -1;
}
// volume
if (str.indexOf('K') > -1) {
return num * 1000;
}
if (str.indexOf('Mil') > -1) {
return num * 1000000;
}
// time
if (str.indexOf('min') > -1) {
return num * 60000;
}
if (str.indexOf('ms') > -1) {
return num * 1;
}
if (str.indexOf('s') > -1) {
return num * 1000;
}
return parseFloat(str);
}
observe();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.