/* * This code is executed from document ready function * Also note that some variable are set from C++ code */ var x1 = $.url("?x1"); var x2 = $.url("?x2"); var y1 = $.url("?y1"); var y2 = $.url("?y2"); var gantt = $.url("?gantt"); var out = $.url("?out"); var linesfill = $.url("?linesfill") == "y"; var linessteps = $.url("?linessteps") == "y"; var linesshow = $.url("?linesshow") != "n"; var pointsshow = $.url("?pointsshow") != "n"; var autoscale = $.url("?autoscale") == "y"; var legendshow = $.url("?legendshow") != "n"; var cutts = $.url("?cutts") == "y"; var fullscreen = $.url("?fullscreen") == "y"; var realnames = $.url("?realnames") == "y"; var xzoomoff = $.url("?xzoomoff") == "y"; var yzoomoff = $.url("?yzoomoff") == "y"; function inIframe() { try { return window.self !== window.top; } catch (e) { return true; } } function inDashboard() { return fullscreen && inIframe(); } // URL management function makeUrl(url, queryFunc, hashFunc) { var query = $.url("?", url); var hash = $.url("#", url); if (paused) { query.paused = "y"; } if (queryFunc) { queryFunc(query); } if (hashFunc) { hashFunc(hash); } var queryStr = ""; var first = true; for (var k in query) { queryStr += (first? "?": "&") + k + "=" + encodeURIComponent(query[k]); first = false; } var hashStr = ""; first = true; for (k in hash) { hashStr += (first? "#": "&") + k + "=" + encodeURIComponent(hash[k]); first = false; } return queryStr + hashStr; } function dataUrl() { return makeUrl(dataurl, function(query) { query.error = "text"; }); } // Error message popup $("
").css({ position: "absolute", display: "none", border: "1px solid #faa", padding: "2px", "background-color": "#fcc", opacity: 0.80 }).appendTo("body"); if (out == "gantt") { $("#gantt-apply").click(function() { try { let val = $("#textareaGantt").val().replace(/\s/g, ""); JSON.parse(val); window.location.replace(makeUrl($.url(), function(query) { query.gantt = val; })); } catch(e) { $("#errmsg").text("Not valid JSON: " + e) .css({bottom: "5px", left: "25%", width: "50%"}) .fadeIn(200); } }); if (gantt) { // Data fetching and auto-refreshing var fetchCounter = 0; function fetchData() { function onDataReceived(json, textStatus, xhr) { $("#errmsg").hide(); logs = json; chart(config, logs, true); } function onDataError(xhr, error) { console.log(arguments); $("#errmsg").text("Fetch data error: " + error + (xhr.status == 200? xhr.responseText: "")) .css({bottom: "5px", left: "25%", width: "50%"}) .fadeIn(200); } if (dataurl) { $.ajax({ url: dataUrl(), type: "GET", dataType: "json", success: function (json, textStatus, xhr) { onDataReceived(json, textStatus, xhr); }, error: onDataError }); } else { onDataReceived(datajson, "textStatus", "xhr"); } // if (fetchPeriod > 0) { // if (fetchCounter == 0) { // fetchCounter++; // setTimeout(function() { // fetchCounter--; // if (!paused) { // fetchData(); // } // }, $("#errmsg").is(":visible")? errorPeriod: fetchPeriod); // } // } } try { var config = JSON.parse(gantt); $("#textareaGantt").val(JSON.stringify(config, "\n", " ")); let formHeight = 220; var chart = d3.gantt() .height(window.innerHeight - $("#placeholder")[0].getBoundingClientRect().y - window.scrollY - formHeight) .selector("#placeholder"); var logs = null; fetchData(); } catch(e) { $("#textareaGantt").val(gantt); alert("Not valid JSON: " + e); } } } else { // flot // Special options adjustment for fullscreen charts in iframe (solomon dashboards) if (fullscreen) { navigate = false; // Disable navigation to avoid scrolling problems legendshow = false; // Show legend only on hover } // Adjust zooming options var xZoomRange = null; var yZoomRange = null; if (xzoomoff) { xZoomRange = false; } if (yzoomoff) { yZoomRange = false; } var placeholder = $("#placeholder"); var playback = $("#playback"); var data = null; var loaded_data = []; var imported_data = []; var fetchPeriod = refreshPeriod; var errorPeriod = 5000; var playbackPeriod = 500; var abstimestep = 1.0; var paused = $.url("?paused") == "y"; var timestep = abstimestep; var seriesDescription = { _time: "time", _thread: "thread" } function seriesDesc(name) { if (seriesDescription.hasOwnProperty(name)) { return (realnames? "[" + name + "] ": "") + seriesDescription[name]; } else { return name; } } playback.show(); var options = { series: { lines: { show: linesshow, fill: linesfill, steps: linessteps}, points: { show: pointsshow }, shadowSize: 0 }, xaxis: { zoomRange: xZoomRange }, yaxis: { zoomRange: yZoomRange }, grid: { clickable: true, hoverable: true }, zoom: { interactive: navigate }, pan: { interactive: navigate }, legend: { show: legendshow, labelFormatter: function(label, series) { return seriesDesc(label) + '(' + seriesDesc(xn) + ')'; } } }; if (fullscreen) { $("body").attr("class","body-fullscreen"); $("#container").attr("class","container-fullscreen"); $("#toolbar").attr("class","toolbar-fullscreen"); $("#selectors-container").attr("class","toolbar-fullscreen"); options.grid.margin = 0; } if (x1) { options.xaxis.min = x1; } if (x2) { options.xaxis.max = x2; } if (y1) { options.yaxis.min = y1; } if (y2) { options.yaxis.max = y2; } $("").css({ position: "absolute", display: "none", border: "1px solid #fdd", padding: "2px", "background-color": "#fee", opacity: 0.80 }).appendTo("body"); // Helper to hide tooltip var lastShow = new Date(); var hideCounter = 0; function hideTooltip() { if (hideCounter == 0) { hideCounter++; setTimeout(function() { hideCounter--; if (new Date().getTime() - lastShow.getTime() > 1000) { $("#tooltip").fadeOut(200); } else if ($("#tooltip").is(":visible")) { hideTooltip(); } }, 200); } } // Helper to hide legend var legendLastShow = new Date(); var legendHideCounter = 0; function hideLegend() { if (legendHideCounter == 0) { legendHideCounter++; setTimeout(function() { legendHideCounter--; if (new Date().getTime() - legendLastShow.getTime() > 1000) { options.legend.show = false; $.plot(placeholder, data, options); } else { hideLegend(); } }, 200); } } function onPlotClick(event, pos, item) { // Leave fullscreen on click var nonFullscreenUrl = makeUrl($.url(), function(query) { delete query.fullscreen; }); if (inDashboard()) { window.open(nonFullscreenUrl, "_blank"); } else if (fullscreen) { window.location.href = nonFullscreenUrl; } } function onPlotHover(event, pos, item) { var redraw = false; // Show legend on hover if (fullscreen) { legendLastShow = new Date(); if (!options.legend.show) { redraw = true; } options.legend.show = true; hideLegend(); } // Show names on hover var left = placeholder.position().left; var top = placeholder.position().top; var ttmargin = 10; var ttwidth = $("#tooltip").width(); var ttheight = $("#tooltip").height(); if (linessteps) { var pts = data[0].data; var idx = 0; for (var i = 0; i < pts.length - 1; i++) { var x1 = pts[i][0]; var x2 = pts[i+1][0]; if (pos.x >= x1 && (x2 == null || pos.x < x2)) { idx = i; } } var n = pts[idx][2]; var html = (n? "" + seriesDesc(xn) + " | : | " + pts[idx][3] + " |
" + seriesDesc(series.label) + " | : | " + y + " |