import d3 from 'd3'; import _ from 'lodash'; import $ from 'jquery'; import { ExtraSeriesFormatValue } from './extra_series_format'; const TOOLTIP_PADDING_X = -50; const TOOLTIP_PADDING_Y = 5; export class StatusHeatmapTooltipExtraSeries { scope: any; dashboard: any; panelCtrl: any; panel: any; heatmapPanel: any; mouseOverBucket: any; originalFillColor: any; tooltip: any; constructor(elem: any, scope: any) { this.scope = scope; this.dashboard = scope.ctrl.dashboard; this.panelCtrl = scope.ctrl; this.panel = scope.ctrl.panel; this.heatmapPanel = elem; this.mouseOverBucket = false; this.originalFillColor = null; elem.on("mouseover", this.onMouseOver.bind(this)); elem.on("click", this.onMouseClick.bind(this)); } public onMouseOver(e: Event) { if (!this.panel.usingUrl || !this.scope.ctrl.data || _.isEmpty(this.scope.ctrl.data)) { return; } } public onMouseClick(e: Event) { if (!this.panel.usingUrl) { return; } this.destroy(); this.add(); } public add() { this.tooltip = d3.select("body") .append("div") .attr("class", "statusmap-tooltip-extraseries graph-tooltip grafana-tooltip"); } public destroy() { if (this.tooltip) { this.tooltip.remove(); } this.tooltip = null; } public show(pos: any) { if (!this.panel.usingUrl || !this.tooltip) { return; } // shared tooltip mode if (pos.panelRelY) { return; } let cardId: any = d3.select(pos.target).attr('cardId'); if (!cardId) { this.destroy(); return; } let card: any = this.panelCtrl.cardsData.cards[cardId]; if (!card) { this.destroy(); return; } if (card.value == null) { this.destroy(); return; } let x: any = card.x; let y: any = card.y; let value: any = card.value; let values: any = card.values; let tooltipTimeFormat: string = 'YYYY-MM-DD HH:mm:ss'; let time: Date = this.dashboard.formatDate(+x, tooltipTimeFormat); let tooltipHtml: string = `
${v.tooltip}
`), "")}${v.label ? v.label : (v.base_url != "" ? _.truncate(v.base_url) : "Empty URL" )}