Commit 637b9164 authored by Eirik Alvær's avatar Eirik Alvær

Makes metadata tooltip disappear when clicking elsewhere

parent dcace8ef
......@@ -5,7 +5,12 @@ var Chart = (function (Highcharts, $, _) {
defaultOptions = {
'chart': {
'polar' : true,
'type' : 'line'
'type' : 'line',
events: {
click: function (event) {
Messagebus.sendMessage('chart-click', event);
}
}
},
'exporting': {
'enabled': false
......
/*global console, jQuery, Messagebus, Exception */
/*global console, jQuery, Messagebus, Exception, document */
var Metadatatooltips = (function ($) {
"use strict";
var tooltipdiv, measures, i,
var tooltipDiv, measures, i, isFirstClick,
getMetadataTooltips = function (label) {
for (i = 0; i < measures.length; i += 1) {
if (measures[i].label.replace(/ /g, '') === label.replace(/ /g, '')) {
......@@ -11,24 +11,29 @@ var Metadatatooltips = (function ($) {
return "";
},
triggerTooltips = function (event) {
$(tooltipdiv).html('<div class="col-sm-8 metadata-tooltip"><div>' + getMetadataTooltips($(event.currentTarget).text()) + '</div></div>');
$(tooltipdiv).show().offset({left: event.pageX - 5, top: event.pageY - 5});
$(tooltipDiv).html('<div class="col-sm-8 metadata-tooltip"><div>' + getMetadataTooltips($(event.currentTarget).text()) + '</div></div>');
$(tooltipDiv).show().offset({left: event.pageX - 5, top: event.pageY - 5});
},
hideToolTip = function () {
$(tooltipDiv).hide('slow');
},
setTooltipDiv = function (div) {
tooltipdiv = div;
tooltipDiv = div;
Messagebus.add(function (event) {
if (event.name === 'chart-label-click') {
triggerTooltips(event.data);
}
});
Messagebus.add(function (event) {
if (event.name === 'data-updated') {
isFirstClick = true;
} else if (event.name === 'chart-click') {
if (isFirstClick) {
isFirstClick = false;
} else {
hideToolTip();
}
} else if (event.name === 'data-updated') {
measures = event.data.measures;
}
});
$(div).mouseleave(function () {
$(this).hide("slow");
});
$(document).click(hideToolTip);
};
return {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment