Commit 65f7c5f0 by Patrick O'Carroll

started migration to ts

parent b41370ca
define([ import $ from 'jquery';
'jquery', import { appEvents } from 'app/core/core';
'app/core/core',
],
function ($, core) {
'use strict';
var appEvents = core.appEvents; //var appEvents = appEvents;
function GraphTooltip(elem, dashboard, scope, getSeriesFn) { export default function GraphTooltip(elem, dashboard, scope, getSeriesFn) {
var self = this; let self = this;
var ctrl = scope.ctrl; let ctrl = scope.ctrl;
var panel = ctrl.panel; let panel = ctrl.panel;
var $tooltip = $('<div class="graph-tooltip">'); let $tooltip = $('<div class="graph-tooltip">');
this.destroy = function() { this.destroy = function() {
$tooltip.remove(); $tooltip.remove();
...@@ -20,17 +16,19 @@ function ($, core) { ...@@ -20,17 +16,19 @@ function ($, core) {
this.findHoverIndexFromDataPoints = function(posX, series, last) { this.findHoverIndexFromDataPoints = function(posX, series, last) {
var ps = series.datapoints.pointsize; var ps = series.datapoints.pointsize;
var initial = last*ps; var initial = last * ps;
var len = series.datapoints.points.length; var len = series.datapoints.points.length;
for (var j = initial; j < len; j += ps) { for (var j = initial; j < len; j += ps) {
// Special case of a non stepped line, highlight the very last point just before a null point // Special case of a non stepped line, highlight the very last point just before a null point
if ((!series.lines.steps && series.datapoints.points[initial] != null && series.datapoints.points[j] == null) if (
(!series.lines.steps && series.datapoints.points[initial] != null && series.datapoints.points[j] == null) ||
//normal case //normal case
|| series.datapoints.points[j] > posX) { series.datapoints.points[j] > posX
return Math.max(j - ps, 0)/ps; ) {
return Math.max(j - ps, 0) / ps;
} }
} }
return j/ps - 1; return j / ps - 1;
}; };
this.findHoverIndexFromData = function(posX, series) { this.findHoverIndexFromData = function(posX, series) {
...@@ -54,7 +52,7 @@ function ($, core) { ...@@ -54,7 +52,7 @@ function ($, core) {
this.renderAndShow = function(absoluteTime, innerHtml, pos, xMode) { this.renderAndShow = function(absoluteTime, innerHtml, pos, xMode) {
if (xMode === 'time') { if (xMode === 'time') {
innerHtml = '<div class="graph-tooltip-time">'+ absoluteTime + '</div>' + innerHtml; innerHtml = '<div class="graph-tooltip-time">' + absoluteTime + '</div>' + innerHtml;
} }
$tooltip.html(innerHtml).place_tt(pos.pageX + 20, pos.pageY); $tooltip.html(innerHtml).place_tt(pos.pageX + 20, pos.pageY);
}; };
...@@ -62,7 +60,7 @@ function ($, core) { ...@@ -62,7 +60,7 @@ function ($, core) {
this.getMultiSeriesPlotHoverInfo = function(seriesList, pos) { this.getMultiSeriesPlotHoverInfo = function(seriesList, pos) {
var value, i, series, hoverIndex, hoverDistance, pointTime, yaxis; var value, i, series, hoverIndex, hoverDistance, pointTime, yaxis;
// 3 sub-arrays, 1st for hidden series, 2nd for left yaxis, 3rd for right yaxis. // 3 sub-arrays, 1st for hidden series, 2nd for left yaxis, 3rd for right yaxis.
var results = [[],[],[]]; var results: any = [[], [], []];
//now we know the current X (j) position for X and Y values //now we know the current X (j) position for X and Y values
var last_value = 0; //needed for stacked values var last_value = 0; //needed for stacked values
...@@ -89,9 +87,11 @@ function ($, core) { ...@@ -89,9 +87,11 @@ function ($, core) {
pointTime = series.data[hoverIndex][0]; pointTime = series.data[hoverIndex][0];
// Take the closest point before the cursor, or if it does not exist, the closest after // Take the closest point before the cursor, or if it does not exist, the closest after
if (! minDistance if (
|| (hoverDistance >=0 && (hoverDistance < minDistance || minDistance < 0)) !minDistance ||
|| (hoverDistance < 0 && hoverDistance > minDistance)) { (hoverDistance >= 0 && (hoverDistance < minDistance || minDistance < 0)) ||
(hoverDistance < 0 && hoverDistance > minDistance)
) {
minDistance = hoverDistance; minDistance = hoverDistance;
minTime = pointTime; minTime = pointTime;
} }
...@@ -130,12 +130,12 @@ function ($, core) { ...@@ -130,12 +130,12 @@ function ($, core) {
label: series.aliasEscaped, label: series.aliasEscaped,
time: pointTime, time: pointTime,
distance: hoverDistance, distance: hoverDistance,
index: i index: i,
}); });
} }
// Contat the 3 sub-arrays // Contat the 3 sub-arrays
results = results[0].concat(results[1],results[2]); results = results[0].concat(results[1], results[2]);
// Time of the point closer to pointer // Time of the point closer to pointer
results.time = minTime; results.time = minTime;
...@@ -143,7 +143,7 @@ function ($, core) { ...@@ -143,7 +143,7 @@ function ($, core) {
return results; return results;
}; };
elem.mouseleave(function () { elem.mouseleave(function() {
if (panel.tooltip.shared) { if (panel.tooltip.shared) {
var plot = elem.data().plot; var plot = elem.data().plot;
if (plot) { if (plot) {
...@@ -154,16 +154,16 @@ function ($, core) { ...@@ -154,16 +154,16 @@ function ($, core) {
appEvents.emit('graph-hover-clear'); appEvents.emit('graph-hover-clear');
}); });
elem.bind("plothover", function (event, pos, item) { elem.bind('plothover', function(event, pos, item) {
self.show(pos, item); self.show(pos, item);
// broadcast to other graph panels that we are hovering! // broadcast to other graph panels that we are hovering!
pos.panelRelY = (pos.pageY - elem.offset().top) / elem.height(); pos.panelRelY = (pos.pageY - elem.offset().top) / elem.height();
appEvents.emit('graph-hover', {pos: pos, panel: panel}); appEvents.emit('graph-hover', { pos: pos, panel: panel });
}); });
elem.bind("plotclick", function (event, pos, item) { elem.bind('plotclick', function(event, pos, item) {
appEvents.emit('graph-click', {pos: pos, panel: panel, item: item}); appEvents.emit('graph-click', { pos: pos, panel: panel, item: item });
}); });
this.clear = function(plot) { this.clear = function(plot) {
...@@ -184,14 +184,15 @@ function ($, core) { ...@@ -184,14 +184,15 @@ function ($, core) {
// if panelRelY is defined another panel wants us to show a tooltip // if panelRelY is defined another panel wants us to show a tooltip
// get pageX from position on x axis and pageY from relative position in original panel // get pageX from position on x axis and pageY from relative position in original panel
if (pos.panelRelY) { if (pos.panelRelY) {
var pointOffset = plot.pointOffset({x: pos.x}); var pointOffset = plot.pointOffset({ x: pos.x });
if (Number.isNaN(pointOffset.left) || pointOffset.left < 0 || pointOffset.left > elem.width()) { if (Number.isNaN(pointOffset.left) || pointOffset.left < 0 || pointOffset.left > elem.width()) {
self.clear(plot); self.clear(plot);
return; return;
} }
pos.pageX = elem.offset().left + pointOffset.left; pos.pageX = elem.offset().left + pointOffset.left;
pos.pageY = elem.offset().top + elem.height() * pos.panelRelY; pos.pageY = elem.offset().top + elem.height() * pos.panelRelY;
var isVisible = pos.pageY >= $(window).scrollTop() && pos.pageY <= $(window).innerHeight() + $(window).scrollTop(); var isVisible =
pos.pageY >= $(window).scrollTop() && pos.pageY <= $(window).innerHeight() + $(window).scrollTop();
if (!isVisible) { if (!isVisible) {
self.clear(plot); self.clear(plot);
return; return;
...@@ -252,24 +253,25 @@ function ($, core) { ...@@ -252,24 +253,25 @@ function ($, core) {
value = series.formatValue(hoverInfo.value); value = series.formatValue(hoverInfo.value);
seriesHtml += '<div class="graph-tooltip-list-item ' + highlightClass + '"><div class="graph-tooltip-series-name">'; seriesHtml +=
seriesHtml += '<i class="fa fa-minus" style="color:' + hoverInfo.color +';"></i> ' + hoverInfo.label + ':</div>'; '<div class="graph-tooltip-list-item ' + highlightClass + '"><div class="graph-tooltip-series-name">';
seriesHtml +=
'<i class="fa fa-minus" style="color:' + hoverInfo.color + ';"></i> ' + hoverInfo.label + ':</div>';
seriesHtml += '<div class="graph-tooltip-value">' + value + '</div></div>'; seriesHtml += '<div class="graph-tooltip-value">' + value + '</div></div>';
plot.highlight(hoverInfo.index, hoverInfo.hoverIndex); plot.highlight(hoverInfo.index, hoverInfo.hoverIndex);
} }
self.renderAndShow(absoluteTime, seriesHtml, pos, xMode); self.renderAndShow(absoluteTime, seriesHtml, pos, xMode);
} } else if (item) {
// single series tooltip // single series tooltip
else if (item) {
series = seriesList[item.seriesIndex]; series = seriesList[item.seriesIndex];
group = '<div class="graph-tooltip-list-item"><div class="graph-tooltip-series-name">'; group = '<div class="graph-tooltip-list-item"><div class="graph-tooltip-series-name">';
group += '<i class="fa fa-minus" style="color:' + item.series.color +';"></i> ' + series.aliasEscaped + ':</div>'; group +=
'<i class="fa fa-minus" style="color:' + item.series.color + ';"></i> ' + series.aliasEscaped + ':</div>';
if (panel.stack && panel.tooltip.value_type === 'individual') { if (panel.stack && panel.tooltip.value_type === 'individual') {
value = item.datapoint[1] - item.datapoint[2]; value = item.datapoint[1] - item.datapoint[2];
} } else {
else {
value = item.datapoint[1]; value = item.datapoint[1];
} }
...@@ -280,13 +282,9 @@ function ($, core) { ...@@ -280,13 +282,9 @@ function ($, core) {
group += '<div class="graph-tooltip-value">' + value + '</div>'; group += '<div class="graph-tooltip-value">' + value + '</div>';
self.renderAndShow(absoluteTime, group, pos, xMode); self.renderAndShow(absoluteTime, group, pos, xMode);
} } else {
// no hit // no hit
else {
$tooltip.detach(); $tooltip.detach();
} }
}; };
} }
return GraphTooltip;
});
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