Source
* actual data point and adds N pixels to all sides. Then looks if mouse is in calculated area. N is calculated by
/*
** Zabbix
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/**
* JQuery class that initializes interactivity for SVG graph.
*
* Supported options:
* - SBox - time range selector;
* - show_problems - show problems in hintbox when mouse is moved over the problem zone;
* - min_period - min period in seconds that must be s-boxed to change the data in dashboard timeselector.
*/
(function ($) {
"use strict";
// Makes SBox selection cancelable pressing Esc.
function sBoxKeyboardInteraction(e) {
if (e.keyCode == 27) {
destroySBox(e, e.data.graph);
}
}
// Disable text selection in document when move mouse pressed cursor.
function disableSelect(e) {
e.preventDefault();
}
// Cancel SBox and unset its variables.
function destroySBox(e, graph) {
var graph = graph || e.data.graph,
data = graph.data('options');
if (data) {
if (!data.isHintBoxFrozen) {
graph.data('widget')._resumeUpdating();
}
$('.svg-graph-selection', graph).attr({'width': 0, 'height': 0});
$('.svg-graph-selection-text', graph).text('');
graph.data('options').boxing = false;
}
dropDocumentListeners(e, graph);
}
/**
* Function removes SBox related $(document) event listeners:
* - if no other widget have active SBox;
* - to avoid another call of destroySBox on 'mouseup' (in case if user has pressed ESC).
*/
function dropDocumentListeners(e, graph) {
let widgets_boxing = 0; // Number of widgets with active SBox.
ZABBIX.Dashboard.getSelectedDashboardPage().getWidgets().forEach((widget) => {
if (widget.getType() === 'svggraph' && widget._svg !== null) {
const options = jQuery(widget._svg).data('options');
if (options !== undefined && options.boxing) {
widgets_boxing++;
}
}
});
if (widgets_boxing == 0 || (e && 'keyCode' in e && e.keyCode == 27)) {
$(document)
.off('selectstart', disableSelect)
.off('keydown', sBoxKeyboardInteraction)
.off('mousemove', moveSBoxMouse)
.off('mouseup', destroySBox)
.off('mouseup', endSBoxDrag);
}
}
// Destroy hintbox, unset its variables and event listeners.
function destroyHintbox(graph) {
var data = graph.data('options'),
hbox = graph.data('hintbox') || null;