Commit 65f7c5f0 by Patrick O'Carroll

started migration to ts

parent b41370ca
define([
'jquery',
'app/core/core',
],
function ($, core) {
'use strict';
import $ from 'jquery';
import { appEvents } from 'app/core/core';
var appEvents = core.appEvents;
//var appEvents = appEvents;
function GraphTooltip(elem, dashboard, scope, getSeriesFn) {
var self = this;
var ctrl = scope.ctrl;
var panel = ctrl.panel;
export default function GraphTooltip(elem, dashboard, scope, getSeriesFn) {
let self = this;
let ctrl = scope.ctrl;
let panel = ctrl.panel;
var $tooltip = $('<div class="graph-tooltip">');
let $tooltip = $('<div class="graph-tooltip">');
this.destroy = function() {
$tooltip.remove();
......@@ -20,17 +16,19 @@ function ($, core) {
this.findHoverIndexFromDataPoints = function(posX, series, last) {
var ps = series.datapoints.pointsize;
var initial = last*ps;
var initial = last * ps;
var len = series.datapoints.points.length;
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
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
|| series.datapoints.points[j] > posX) {
return Math.max(j - ps, 0)/ps;
series.datapoints.points[j] > posX
) {
return Math.max(j - ps, 0) / ps;
}
}
return j/ps - 1;
return j / ps - 1;
};
this.findHoverIndexFromData = function(posX, series) {
......@@ -54,7 +52,7 @@ function ($, core) {
this.renderAndShow = function(absoluteTime, innerHtml, pos, xMode) {
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);
};
......@@ -62,7 +60,7 @@ function ($, core) {
this.getMultiSeriesPlotHoverInfo = function(seriesList, pos) {
var value, i, series, hoverIndex, hoverDistance, pointTime, 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
var last_value = 0; //needed for stacked values
......@@ -89,9 +87,11 @@ function ($, core) {
pointTime = series.data[hoverIndex][0];
// Take the closest point before the cursor, or if it does not exist, the closest after
if (! minDistance
|| (hoverDistance >=0 && (hoverDistance < minDistance || minDistance < 0))
|| (hoverDistance < 0 && hoverDistance > minDistance)) {
if (
!minDistance ||
(hoverDistance >= 0 && (hoverDistance < minDistance || minDistance < 0)) ||
(hoverDistance < 0 && hoverDistance > minDistance)
) {
minDistance = hoverDistance;
minTime = pointTime;
}
......@@ -130,12 +130,12 @@ function ($, core) {
label: series.aliasEscaped,
time: pointTime,
distance: hoverDistance,
index: i
index: i,
});
}
// 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
results.time = minTime;
......@@ -143,7 +143,7 @@ function ($, core) {
return results;
};
elem.mouseleave(function () {
elem.mouseleave(function() {
if (panel.tooltip.shared) {
var plot = elem.data().plot;
if (plot) {
......@@ -154,16 +154,16 @@ function ($, core) {
appEvents.emit('graph-hover-clear');
});
elem.bind("plothover", function (event, pos, item) {
elem.bind('plothover', function(event, pos, item) {
self.show(pos, item);
// broadcast to other graph panels that we are hovering!
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) {
appEvents.emit('graph-click', {pos: pos, panel: panel, item: item});
elem.bind('plotclick', function(event, pos, item) {
appEvents.emit('graph-click', { pos: pos, panel: panel, item: item });
});
this.clear = function(plot) {
......@@ -184,14 +184,15 @@ function ($, core) {
// 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
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()) {
self.clear(plot);
return;
}
pos.pageX = elem.offset().left + pointOffset.left;
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) {
self.clear(plot);
return;
......@@ -252,24 +253,25 @@ function ($, core) {
value = series.formatValue(hoverInfo.value);
seriesHtml += '<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-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>';
plot.highlight(hoverInfo.index, hoverInfo.hoverIndex);
}
self.renderAndShow(absoluteTime, seriesHtml, pos, xMode);
}
} else if (item) {
// single series tooltip
else if (item) {
series = seriesList[item.seriesIndex];
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') {
value = item.datapoint[1] - item.datapoint[2];
}
else {
} else {
value = item.datapoint[1];
}
......@@ -280,13 +282,9 @@ function ($, core) {
group += '<div class="graph-tooltip-value">' + value + '</div>';
self.renderAndShow(absoluteTime, group, pos, xMode);
}
} else {
// no hit
else {
$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