Source
if (!this.hasBroadcast(CWidgetsData.DATA_TYPE_TIME_PERIOD) || this.isFieldsReferredDataUpdated('time_period')) {
/*
** 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 Affero General Public License as published by the Free Software Foundation, version 3.
**
** 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
class CWidgetGraph extends CWidget {
onInitialize() {
this._is_graph_mode = false;
}
onStart() {
this.events_handlers = {
rangeUpdate: (e) => {
if (this._is_graph_mode && this.getState() === WIDGET_STATE_ACTIVE) {
const time_period = e.detail;
timeControl.objectUpdate.call(timeControl.objectList[`graph_${this._unique_id}`], time_period);
timeControl.refreshObject(`graph_${this._unique_id}`);
this.feedback({time_period});
this.broadcast({
[CWidgetsData.DATA_TYPE_TIME_PERIOD]: time_period
});
}
}
};
}
onActivate() {
if (this._is_graph_mode) {
this._activateGraph();
}
}
onDeactivate() {
if (this._is_graph_mode) {
this._deactivateGraph();
}
}
onResize() {
if (this._is_graph_mode && this.getState() === WIDGET_STATE_ACTIVE) {
const graph_size = this._getContentsSize();
if (graph_size.width <= 0 || graph_size.height <= 0) {
return;
}
const image = document.getElementById(`graph_${this._unique_id}`);
if (!image.complete) {
image.addEventListener('load', () => this.resize(), {once: true});