Skip to content

Instantly share code, notes, and snippets.

@excalq
Last active February 26, 2018 17:57
Show Gist options
  • Save excalq/b5930b4d1e12dcec7cefb939329c626b to your computer and use it in GitHub Desktop.
Save excalq/b5930b4d1e12dcec7cefb939329c626b to your computer and use it in GitHub Desktop.
Kibana Heatmap Colors for Relative Dates
// ==UserScript==
// @name Kibana App Data by Category Heatmap Improvments
// @namespace http://navgigatingcancer.com/
// @version 0.2
// @description Sets App Data Heatmap to use date-relative colors, fixes x-axis
// @author Arthur Kepler
// @match https://kibana.navigatingcare.com/*
// @match https://status.navigatingcare.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @grant none
// ==/UserScript==
$(document).ready(function(){
// Run every 10s as Kibana visualizations dynamically load and redraw.
var INTERVAL = 10 * 1000;
setInterval(function(){
'use strict';
// Fix the time-relative heat map timestamp value colors
// Less than 12 hours ago = green. Reddens to 96+ hours.
//
var chartTitle = 'App: Integrated Data by Category';
var chart = $("ul").find(`[data-title='`+chartTitle+`']`);
chart.find('g.square').map(function(cell) {
var colorableEl = $(this).children('rect').first();
var timeEl = $(this).children('text').first();
if (typeof timeEl !== 'undefined') {
console.log('timeEl: '+ timeEl.text());
var time = Date.parse(timeEl.text());
var hoursAgo = (new Date() - new Date(time))/1000/60/60;
if (new Date().getDay() == 1) { // On Monday: many clinics had no data over the weekend
hoursAgo -= 48; // So give a 48 hour graceperiod
}
if (hoursAgo <= 12.0) { $(colorableEl).attr("fill", "#1a9750"); }
if (hoursAgo > 12.0) { $(colorableEl).attr("fill", "#66bd63"); }
if (hoursAgo > 18.0) { $(colorableEl).attr("fill", "#a6d96a"); }
if (hoursAgo > 24.0) { $(colorableEl).attr("fill", "#fee08b"); }
if (hoursAgo > 48.0) { $(colorableEl).attr("fill", "#f46d43"); }
if (hoursAgo > 72.0) { $(colorableEl).attr("fill", "#d62f27"); }
if (hoursAgo > 96.0) { $(colorableEl).attr("fill", "#a50026"); }
}
});
// X-Axis label: Orient horizontally
chart.find('.x-axis-div text').map(function() {
$(this).attr('transform', 'rotate(0, 0, 0),translate(0,10)');
$(this).css('font-size', '10pt');
$(this).css('font-weight', 'bold');
});
console.log('Applied NC Kibana Userscripts.');
}, INTERVAL);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment