Last active
March 27, 2017 22:25
-
-
Save ieatfood/387ee6ef6a0a6876c4530b3cdaeb0041 to your computer and use it in GitHub Desktop.
Grafana Tooltip Sort Bookmarklet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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