// dygraph
// Codacy declarations
/* global smoothPlotter */
/* global Dygraph */
NETDATA.dygraph = {
smooth: false
};
NETDATA.dygraphToolboxPanAndZoom = function (state, after, before) {
if (after < state.netdata_first) {
after = state.netdata_first;
}
if (before > state.netdata_last) {
before = state.netdata_last;
}
state.setMode('zoom');
NETDATA.globalSelectionSync.stop();
NETDATA.globalSelectionSync.delay();
state.tmp.dygraph_user_action = true;
state.tmp.dygraph_force_zoom = true;
// state.log('toolboxPanAndZoom');
state.updateChartPanOrZoom(after, before);
NETDATA.globalPanAndZoom.setMaster(state, after, before);
};
NETDATA.dygraphSetSelection = function (state, t) {
if (typeof state.tmp.dygraph_instance !== 'undefined') {
let r = state.calculateRowForTime(t);
if (r !== -1) {
state.tmp.dygraph_instance.setSelection(r);
return true;
} else {
state.tmp.dygraph_instance.clearSelection();
state.legendShowUndefined();
}
}
return false;
};
NETDATA.dygraphClearSelection = function (state) {
if (typeof state.tmp.dygraph_instance !== 'undefined') {
state.tmp.dygraph_instance.clearSelection();
}
return true;
};
NETDATA.dygraphSmoothInitialize = function (callback) {
$.ajax({
url: NETDATA.dygraph_smooth_js,
cache: true,
dataType: "script",
xhrFields: {withCredentials: true} // required for the cookie
})
.done(function () {
NETDATA.dygraph.smooth = true;
smoothPlotter.smoothing = 0.3;
})
.fail(function () {
NETDATA.dygraph.smooth = false;
})
.always(function () {
if (typeof callback === "function") {
return callback();
}
});
};
NETDATA.dygraphInitialize = function (callback) {
if (typeof netdataNoDygraphs === 'undefined' || !netdataNoDygraphs) {
$.ajax({
url: NETDATA.dygraph_js,
cache: true,
dataType: "script",
xhrFields: {withCredentials: true} // required for the cookie
})
.done(function () {
NETDATA.registerChartLibrary('dygraph', NETDATA.dygraph_js);
})
.fail(function () {
NETDATA.chartLibraries.dygraph.enabled = false;
NETDATA.error(100, NETDATA.dygraph_js);
})
.always(function () {
if (NETDATA.chartLibraries.dygraph.enabled && NETDATA.options.current.smooth_plot) {
NETDATA.dygraphSmoothInitialize(callback);
} else if (typeof callback === "function") {
return callback();
}
});
} else {
NETDATA.chartLibraries.dygraph.enabled = false;
if (typeof callback === "function") {