Skip to content

Commit

Permalink
Implement colourful tags
Browse files Browse the repository at this point in the history
  • Loading branch information
hexylena committed Dec 4, 2018
1 parent aaa8d1a commit eeffb26
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion client/galaxy/scripts/mvc/history/history-item-li.js
@@ -1,5 +1,14 @@
function _templateNametag(tag) {
return `<span class="badge badge-primary badge-tags">${_.escape(tag.slice(5))}</span>`;
return `<span style="background-color: ${generateTagColor(tag.slice(5))}" class="badge badge-primary badge-tags">${_.escape(tag.slice(5))}</span>`;
}

function generateTagColor(tagValue) {
var hash = hashFnv32a(tagValue);
var r = ((hash & 0xf) % 10),
g = (((hash & 0xf0) >> 4) % 10),
b = (((hash & 0xf00) >> 8) % 10);

return `#${r}${g}${b}`;
}

function nametagTemplate(historyItem) {
Expand All @@ -14,3 +23,23 @@ function nametagTemplate(historyItem) {
export default {
nametagTemplate: nametagTemplate
};

/**
* Calculate a 32 bit FNV-1a hash
* Found here: https://gist.github.com/vaiorabbit/5657561
* Ref.: http://isthe.com/chongo/tech/comp/fnv/
*
* @param {string} str the input value
* @returns {integer}
*/
function hashFnv32a(str) {
/*jshint bitwise:false */
var i, l,
hval = 0x811c9dc5;

for (i = 0, l = str.length; i < l; i++) {
hval ^= str.charCodeAt(i);
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
}
return hval >>> 0;
}

0 comments on commit eeffb26

Please sign in to comment.