function resizeChart(a, b = null) { var _xaxis = {}; var min = a.hasOwnProperty('config') && a.config.opts.hasOwnProperty('xaxis') && a.config.opts.xaxis.hasOwnProperty('min') ? a.config.opts.xaxis.min : a.opts.xaxis.min; var max = a.hasOwnProperty('config') && a.config.opts.hasOwnProperty('xaxis') && a.config.opts.xaxis.hasOwnProperty('max') ? a.config.opts.xaxis.max : a.opts.xaxis.max; if (b != null) { if (b.xaxis.min < new Date(a.opts.series[0].data[0].x).getTime() && b.xaxis.max > new Date(a.opts.series[0].data[a.opts.series[0].data.length - 1].x).getTime()) _xaxis = fitChart(a); else if (b.xaxis.min < new Date(a.opts.series[0].data[0].x).getTime()) _xaxis.min = fitMin(a); else if (b.xaxis.max > new Date(a.opts.series[0].data[a.opts.series[0].data.length - 1].x).getTime()) _xaxis.max = fitMax(a); } var extremeVals = getMinMax(a, min, max) var axes = []; var config = a.hasOwnProperty("config") ? a.config.opts.yaxis : a.opts.yaxis; for (var y = 0; y < config.length; y++) { config[y].min = extremeVals[y].min; config[y].max = extremeVals[y].max; config[y].opposite = extremeVals[y].opposite; } a.updateOptions({ yaxis: config, xaxis: _xaxis }); } function getMinMax(chart, min, max, index = -1) { if (chart.opts.yaxis.length == 1) { var extremes = getChartExtremes(chart, min, max, index); var _min = extremes.min; var _max = extremes.max; var diff = _max - _min; if (diff < 1) { var multiplier = 0.3; _min -= diff * multiplier; _max += diff * multiplier; _min = Math.round(_min * 10) / 10; _max = Math.round(_max * 10) / 10; } else if (diff > 50000) { var multiplier = 0.1; _min -= diff * multiplier; _max += diff * multiplier; _min = Math.round(_min / 10000) * 10000; _max = Math.round(_max / 10000) * 10000; } else { var multiplier = 0.1; _min -= diff * multiplier; _max += diff * multiplier; _min = Math.floor(_min); _max = Math.ceil(_max); } return [{ min: _min, max: _max }]; } else { var extremeObjs = []; for (var i = 0; i < chart.opts.yaxis.length; i++) { var extremes = getSeriesExtremes(chart, min, max, i); var _min = extremes.min; var _max = extremes.max; var diff = _max - _min; if (diff < 1) { var multiplier = 0.3; _min -= diff * multiplier; _max += diff * multiplier; _min = Math.round(_min * 10) / 10; _max = Math.round(_max * 10) / 10; } else if (diff > 50000) { var multiplier = 0.1; _min -= diff * multiplier; _max += diff * multiplier; _min = Math.round(_min / 10000) * 10000; _max = Math.round(_max / 10000) * 10000; } else { var multiplier = 0.1; _min -= diff * multiplier; _max += diff * multiplier; _min = Math.floor(_min); _max = Math.ceil(_max); } extremeObjs.push({ min: _min, max: _max, opposite: i > 0 }); } return extremeObjs; } } function htmlToElement(html) { if (html == null) { return null; } var template = document.createElement('template'); html = html.trim(); // Never return a text node of whitespace as the result template.innerHTML = html; if (template.content.firstChild.nodeName == "#text") { return htmlToElement(template.content.firstChild.nodeValue); } return template.content.firstChild; } function getSeriesExtremes(chart, n = '', x = '', index) { var series = []; var min = n != '' ? n : chart.opts.xaxis.min; var max = x != '' ? x : chart.opts.xaxis.max; var start = min; var end = max; if (chart.xtype == 'datetime') { start = findNearestIndex(chart.opts.xaxis.categories, getDateString(min)); end = findNearestIndex(chart.opts.xaxis.categories, getDateString(max)); if (new Date(getDateString(max)) > new Date(chart.opts.xaxis.categories[chart.opts.xaxis.categories.length - 1])) end = chart.opts.xaxis.categories.length - 1; } for (var i = start; i <= end; i++) { if (chart.opts.series[index].data[i] === undefined) continue; series.push(chart.opts.series[index].data[i]); } return { min: Math.min(...series), max: Math.max(...series) }; } function getChartExtremes(a, n = '', x = '') { var series = [];// var min = n != '' ? n : a.opts.xaxis.min; var max = x != '' ? x : a.opts.xaxis.max; var start = min; var end = max;// if (a.xtype == 'datetime') { start = findNearestIndex(a.opts.series, getDateString(min)); end = findNearestIndex(a.opts.series, getDateString(max)); if (new Date(getDateString(max)) > new Date(a.opts.series[0].data[a.opts.series[0].data.length - 1].x)) end = a.opts.series[0].data.length - 1; } for (var k = 0; k < a.opts.series.length; k++) { for (var i = start; i <= end; i++) { if (a.opts.series[k].data[i] === undefined) continue; series.push(a.opts.series[k].data[i].y); } } return { min: Math.min(...series), max: Math.max(...series) }; } function getDateString(timestamp) { var date = new Date(timestamp); var dateStr = formatLeadingZero(date.getMonth() + 1) + "/" dateStr += formatLeadingZero(date.getDate()) + "/" dateStr += formatYear(date.getFullYear()); return dateStr; } function formatYear(year) { return year.toString().substring(2,4); } function formatLeadingZero(num) { return num < 10 ? "0" + num.toString() : num.toString(); } function findNearestIndex(series, value) { var dt = new Date(value).getTime(); if (dt < new Date(series[0].data[0].x).getTime()) return 0; for (var i = 0; i < series[0].data.length; i++) { if (i == series[0].data.length - 1) { return i; } else { var bottom = new Date(series[0].data[i].x).getTime() var upper = new Date(series[0].data[i + 1].x).getTime(); if (bottom <= dt && dt < upper) return i + 1; } } } function fitMax(chart) { var _max = chart.opts.xaxis.max; if (chart.xtype == 'datetime') _max = new Date(_max).getTime(); return _max; } function fitMin(chart) { var _min = chart.opts.xaxis.min; if (chart.xtype == 'datetime') _min = new Date(_min).getTime(); return _min; } function fitChart(chart) { var _min = new Date(chart.opts.series[0].data[0].x).getTime(); var _max = new Date(chart.opts.series[0].data[chart.opts.series[0].data.length - 1].x).getTime(); return { min: _min, max: _max }; } function makeComboBox(e, customAction = "", customClassPrefix = "") { var t, s, n, l, i, c, a; for (t = document.getElementsByClassName(makeClassName(e, customClassPrefix)), s = 0; s < t.length; s++) { for (l = t[s].getElementsByTagName('select')[0], (i = document.createElement('DIV')).setAttribute('class', makeClassName('select-selected', customClassPrefix)), i.innerHTML = l.options[l.selectedIndex].innerHTML, t[s].appendChild(i), (c = document.createElement('DIV')).setAttribute('class', makeClassName('select-items', customClassPrefix) + ' ' + makeClassName('select-hide', customClassPrefix)), c.setAttribute("onclick", "simChange(event, getElById('" + l.id + "'));"), n = 1; n < l.length; n++)(a = document.createElement('DIV')).innerHTML = l.options[n].innerHTML, a.setAttribute("data-value", l.options[n].value), a.setAttribute("onclick", customAction == "" ? "handleOptionClick(this,'" + customClassPrefix + "');" : customAction), c.appendChild(a), a.setAttribute("class", l.options[n].selected ? makeClassName("same-as-selected", customClassPrefix) : ""); t[s].appendChild(c), i.setAttribute("id", crypto.randomUUID().replaceAll("-","")), i.setAttribute("onclick", "handleComboBoxChange(event, this,'" + customClassPrefix + "');"); } makeComboBoxListeners(); } function showComboBoxSelection(useDiv, dataValue) { var items = useDiv.getElementsByClassName("infosentience-select-items")[0].childNodes; for (var i = 0; i < items.length; i++) { if (items[i].dataset.value == dataValue) { var img = document.createElement("img"); img.src = "https://alltheintel.com/assets/img/cme/check.svg"; img.classList.add("infosentience-cme-check"); items[i].appendChild(img); } } } function makeClassName(standardName, customPrefix) { if (customPrefix == "") return standardName; return customPrefix + "-" + standardName } function simChange(event, el) { event.stopPropagation(); el.onchange(); } function handleOptionClick(el, customClassPrefix = '') { var y, i, k, s, h, sl, yl; s = el.parentNode.parentNode.getElementsByTagName("select")[0]; sl = s.length; h = el.parentNode.previousSibling; for (i = 0; i < sl; i++) { if (s.options[i].innerHTML == el.innerHTML) { s.selectedIndex = i; h.innerHTML = el.innerHTML; y = el.parentNode.getElementsByClassName(makeClassName("same-as-selected", customClassPrefix)); yl = y.length; for (k = 0; k < yl; k++) { y[k].classList.remove(makeClassName("same-as-selected", customClassPrefix)); } el.setAttribute("class", makeClassName("same-as-selected", customClassPrefix)); break; } } h.click(); } function handleComboBoxChange(event, el, customClassPrefix = '') { if (typeof event !== 'undefined') event.stopPropagation(); closeAllSelect(el); el.nextSibling.classList.toggle(makeClassName('select-hide', customClassPrefix)); el.classList.toggle(makeClassName('select-arrow-active', customClassPrefix)); } function formatYaxis(e) { return (e > 50) ? Math.round(e) : Math.round(e * 100) / 100; } function toggleProgressStatus(el, expand = true) { el.parentElement.style.maxHeight = expand ? "250px" : "40px"; el.onclick = function () {toggleProgressStatus(el,!expand)} } function recordSeries(chart) { var arr = []; for (var i = 0; i < chart.opts.series.length; i++) { arr.push(chart.opts.series[i]); } return arr; } function formatTitle(str) { return str.replace(/'/, "'"); } function createToggleSwitch(id) { var JSVar = new Switch(getElById(id), { size: 'small' }); } var panelOptions = {}; var target = ''; var statusId = ''; var labeledSliders = {}; function getBBox(useEl) { if (useEl) { return useEl.getBBox(); } else { //debugger; } } function getElById(useId, baseEl = undefined) { var startEl = baseEl ? baseEl : document; var retEl = startEl.getElementById(useId); if (retEl) { return retEl; } else { //debugger; } } function usesEllipsis(el) { if (el === null || typeof el === "undefined") return false; return el.offsetWidth < el.scrollWidth; } function getVisualWidth(id) { var el = getElById(id); if (el === null || typeof el === "undefined") return -1; return el.offsetWidth; } function getScrollWidth(id) { var el = getElById(id); if (el === null || typeof el === "undefined") return -1 return el.scrollWidth; } function getCoordsForEl(id) { var el = getElById(id); if (el === null || typeof el === "undefined") return "0,0"; var rect = el.getBoundingClientRect(); return rect.left + "," + rect.top; } function mmm(useDate) { var retStr = useDate.toLocaleString('en-US', { month: 'short' }); return retStr; } function CreatePDFfromHTML(useId, title="") { var HTML_Width = $("#"+useId).width(); var HTML_Height = $("#" + useId).height(); var top_left_margin = 15; var PDF_Width = HTML_Width + (top_left_margin * 2); var PDF_Height = (HTML_Height) + (top_left_margin * 2); var canvas_image_width = HTML_Width; var canvas_image_height = HTML_Height; var totalPDFPages = Math.ceil(HTML_Height / PDF_Height) - 1; html2canvas($("#" + useId)[0], { scale: 2 }).then(function (canvas) { var imgData = canvas.toDataURL("image/jpeg", 1.0); var orientation = PDF_Width > PDF_Height ? 'l' : 'p'; var pdf = new jsPDF(orientation, 'pt', [PDF_Width, PDF_Height]); pdf.addImage(imgData, 'JPG', top_left_margin, top_left_margin, canvas_image_width, canvas_image_height); for (var i = 1; i <= totalPDFPages; i++) { pdf.addPage(PDF_Width, PDF_Height); pdf.addImage(imgData, 'JPG', top_left_margin, -(PDF_Height * i) + (top_left_margin * 4), canvas_image_width, canvas_image_height); } var pdfURI = pdf.output("datauristring"); //pdf.save((title == "" ? "element_" : title) + Date.now().toString() + ".pdf"); requestClick("../Click/SingleClick", useId, 0, "POST", true, false, false, true, "", "", pdfURI); //$("#" + useId).hide(); }); } function hideEl(el) { el.style.display = "none"; } function getWHStr(useId) { var el = document.getElementById(useId); if (el == null) return ""; return el.clientWidth + ":" + el.clientHeight; } var reportDiv, inputSetName, currLabel, currOptPanelId, currPanelOptId, expanderDivId, expanderButtonId, reportProgressId = ''; // Global variables that keep track of targets for certain events. var n; var statusInterval; // Global variable that holds either an interval function or the value false. var statusIntervalTime = 2000; // Interval in milliseconds for requesting status updates on running reports function expand(el) { //el.style.maxWidth = '25vw'; } function collapse(el) { //el.style.maxWidth = '0vw'; } function addReportTab(obj) { var c = JSON.parse(obj); setInnerHTML(b.children[0], c.button, true); setInnerHTML(b, c.div, true); } // Called when a tab button is clicked on a tab controller element. function openTab(el) { // i used in for loops // tabcontent used as array for divs that should be displayed/hidden // tablinks used as array for tab button selection/styling var i, tabcontent, tablinks; // Grab all content divs in the tab controller tabcontent = getElById(el.getAttribute("div-id")).parentElement.children; // Loop through the content divs and set the display to none for (i = 1; i < tabcontent.length; i++) { tabcontent[i].style.display = 'none'; } // Grab all tab buttons in the tab controller tablinks = el.parentElement.children; // Loop through the buttons and apply the deselect function to them. for (i = 0; i < tablinks.length; i++) { deselectTab(tablinks[i]); } // Show the selected content div and select the clicked button getElById(el.getAttribute("div-id")).style.display = 'block'; selectTab(el); } function replace(el, url) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { el.innerHTML = this.responseText; } }; xhttp.open("GET", url, true); xhttp.send(); } // Check to see if a graph request has the necessary attributes to make a successful request function validGraphRequest(el) { return el.hasAttribute('row-key') && el.hasAttribute('table-key') && el.hasAttribute('column-key'); } function appear(id) { getElById(id).style.display = 'block'; } function disappear(id) { getElById(id).style.display = 'none'; } function collapseAll(id) { var nodes = getElById(id).childNodes; for (var i = 0; i < nodes.length; i++) { nodes[i].style.width = '0vw'; nodes[i].style.display = 'none'; nodes[i].style.maxWidth = '0vw'; } } // Expand the epander div to hold the input div that has been selected. The input div is now visible. function expandOptionPanel(expanderId, inputId) { getElById(expanderId).style.width = '50vw'; getElById(inputId).style.display = 'inline-block'; getElById(inputId).style.width = '25vw'; getElById(inputId).style.maxWidth = '25vw'; } function collapseOptionPanel(e, t = '', n = '', l = '') { /*setSpanLabels(); if ('' != t) { getElById(t).innerHTML = n; getElById(l).style.maxWidth = '0vw'; getElById(l).style.display = 'none'; }*/ } function getValues(name) { var list = document.getElementsByName(name); if (list.length < 2) return getValuesByName(name); return getCountByName(name); } function getValuesByName(e) { for (var a = document.getElementsByName(e), t = '', l = '', n = 0; n < a.length; n++) 'radio' == a[n].type || 'checkbox' == a[n].type ? a[n].checked && (t += l + a[n].value, l = ', ') : 'range' == a[n].type ? (t += l + labeledSliders[a[n].id][a[n].value - 1], l = ', ') : validInput(a[n]) && (t += l + a[n].value, l = ', '); return t; } function setSpanLabels() { // Loop through all clickable spans in the expander div for (var prop in panelOptions) { var elmnt = panelOptions[prop]; elmnt.curr = false; // If the span element was not selected with the most recent click if (!elmnt.state) { // Set its content to 'None' elmnt.el.innerHTML = "None"; } } } function resetSpanLabels() { // Loop through all clickable spans in the expander div and set their contents to 'None' for (var prop in panelOptions) { panelOptions[prop].el.innerHTML = "None"; } } function getCountByName(e) { // Loop through each element with the name e and return the count of the number of inputs that have a value for (var t = document.getElementsByName(e), n = 0, u = 0; u < t.length; u++) validInput(t[u]) && n++; return n } // Checks to see if input e has a valid user input function validInput(e) { // Return false if the input value is null or if the input is disabled if (e.value == 'null' || e.disabled) return false; // If the input is a range input, then return its value if the value is not 1 (used with sliders) if (e.type == 'range') return e.value != 1; // If the input is a checkbox or a radio button, return its checked value; else return whether the input's value length is greater than 0 return 'checkbox' == e.type || 'radio' == e.type ? e.checked : e.value.length > 0 } function getItemAtIndex(a, i) { // Return the item at index i in array a return a[i]; } function sortTable(e, n, reverse = !1) { var a, t, s, o, T, i, m; // Change the clicked element's onclick event to call this sort function but with the opposite order that was just called (ascending vs descending) e.onclick = function () { sortTable(e, n, !reverse) }; // a represents the table to which the clicked element belongs. This for loop // sorts the table by the specified column for (a = e.parentElement.parentElement.parentElement, s = !0; s;) { for (s = !1, t = a.rows, o = 1; o < t.length - 1; o++) { m = !1, T = t[o].getElementsByTagName('TD')[n], i = t[o + 1].getElementsByTagName('TD')[n]; var Z = T.dataset.sort; var W = i.dataset.sort; if (Z.includes(':') && W.includes(':')) { // If Z and W are datetimes Z = Z.replace(/T/g, ' '); W = W.replace(/T/g, ' '); }; var N = Number.isNaN(parseFloat(Z)) ? Z.toLowerCase() : parseFloat(Z), L = Number.isNaN(parseFloat(W)) ? W.toLowerCase() : parseFloat(W); if (Z.includes(':') || (!Number.isInteger(parseInt(Z)) && !Number.isInteger(parseInt(W)) && new Date(Z) != "Invalid Date" && new Date(W) != "Invalid Date")) { // If Z and W produce valid dates and Z and W are not integers N = new Date(Z); L = new Date(W); } if (reverse ? N > L : L > N) { // Use the reverse argument to determine sort direction m = !0; break } } // Change the row's position in the table m && (t[o].parentNode.insertBefore(t[o + 1], t[o]), s = !0) } } // Global variable used to store values for a report request var reportBuilderOptions = {}; // On collapse or closing of an input div, collect the values of those inputs and store them in the reportBuilderOptions object function collectSettings(name, r) { var t = r.replace(/ /g, ''), i = document.getElementsByName(name); if (0 != i.length) { if (1 == i.length) { if (i[0].tagName == "SELECT" && i[0].value == "Select") return; return 'checkbox' == i[0].type ? void (reportBuilderOptions[t] = i[0].checked) : void (reportBuilderOptions[t] = i[0].value); } for (var o = !0, l = 1; l < i.length; l++) o = i[l].type == i[l - 1].type && o; if (o && 'radio' == i[0].type) for (var n = 0; n < i.length; n++) if (i[n].checked) return void (reportBuilderOptions[t] = i[n].value); for (var p = [], u = 0; u < i.length; u++) 'radio' == i[u].type || 'checkbox' == i[u].type ? i[u].checked && p.push(i[u].value) : 'InterestValues' == t ? (void 0 === reportBuilderOptions[t] && (reportBuilderOptions[t] = {}), reportBuilderOptions[t][i[u].previousElementSibling.innerHTML.replace(/ /g, '')] = i[u].value) : p.push(i[u].value); p.length > 0 && (reportBuilderOptions[t] = p) } } // Standard ajax call with optional parameters for a send message and a callback function that handles the response text function ajaxCall(url, msg = '', callback = '', method = 'POST') { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { if (typeof callback === 'function') callback(xhttp.responseText); } }; xhttp.open(method, url, true); xhttp.setRequestHeader('Content-type', 'application/json;charset=UTF-8'); xhttp.send(msg); } function printMsg(e) { console.log(e); } // Functionally, this function is the same as directly setting the innerHTML property // of an element, except that any javascript in script tags will be executed var setInnerHTML = function (elm, html, append = false) { if (append) elm.innerHTML += html; else elm.innerHTML = html; var b = Array.from(elm.querySelectorAll("script")); Array.from(elm.querySelectorAll("script")).forEach(oldScript => { const newScript = document.createElement("script"); Array.from(oldScript.attributes) .forEach(attr => newScript.setAttribute(attr.name, attr.value)); newScript.appendChild(document.createTextNode(oldScript.innerHTML)); oldScript.parentNode.replaceChild(newScript, oldScript); }); } // Sets the main columns to the html in a report response function setReport(html) { setInnerHTML(target, html); reportBtn.enabled = true; } /*function allowDrop(t) { t.preventDefault(); } function drag(t) { t.dataTransfer.setData('text', t.target.id); } function drop(t) { t.preventDefault(); var a = t.dataTransfer.getData('text') } document.addEventListener('dragend', function (e) { }, !1); var tableObj = {};*/ function makeTableInfoObj(el) { return { TableKey: el.getAttribute("table-key"), Row: el.getAttribute("row-key"), Column: el.getAttribute("column-key") } } // Global variables used to keep track of dragged elements var prevTarget, prevText; // Listener that is executed whenever a dragged element is dropped, whether that is on a droppable element or not /*$(document).on('dragend', '.draggable', function (e) { // Hide the droppable divs that appear on dragstart hideChartOverlays(); // Set the dragged element's text to its original text prevTarget.innerText = prevText; }), // Listener that is executed whenever a draggable element begins a drag $(document).on('dragstart', '.draggable', function (a) { a.originalEvent.dataTransfer.setData('data', $(this).attr('data-text')); // Display the droppable divs that overlay the charts showChartOverlays(); // Set the previous target to the currently dragged element prevTarget = $(this)[0]; // Set the previous target text to the currently dragged element's text prevText = prevTarget.innerText; // Set the currently dragged element's text to the underlying data of its column if ($(this)[0].hasAttribute('underlying-data')) $(this)[0].innerText = $(this)[0].getAttribute('underlying-data-label'); }), // Listener that executed when a dragged element is dropped into a droppable element $(document).on('drop', '.droppable', function (a) { // If the dragged element does not have a data-id attribute, return if (!(prevTarget.hasAttribute('data-id'))) return; // If the request is going to be a graph request, check to see that the request is valid if ($(this)[0].getAttribute('request-type') == 'graph' && validGraphRequest()) return; $(this).removeClass('hover'); prevTarget.innerText = prevText; if (prevTarget.type != 'span') { clearColor($(this)[0].getAttribute('data-color')) } else clearPColor(); prevTarget.style.backgroundColor = $(this)[0].getAttribute('data-color'); if (!prevTarget.hasAttribute('color')) { var att = document.createAttribute('color'); att.value = $(this)[0].getAttribute('data-color'); prevTarget.setAttributeNode(att); } else { prevTarget.setAttribute('color', $(this)[0].getAttribute('data-color')); }; $(this)[0].children[0].innerHTML = "Replace"; requestObj = { RequestType: 'GetData', Values: getTableInfo(prevTarget), GraphInformation: getGraphRequestInfo($(this)[0]) }; graphKeys[parseInt($(this)[0].getAttribute('chart-number'))] = getTableInfo(prevTarget); getNewData($(this)[0]); }), $(document).on('mouseenter', '.chartReportButton', function () { darken($(this)[0]); }), $(document).on('mouseleave', '.chartReportButton', function () { lighten($(this)[0]); });*/ function getGraphRequestInfo(el) { return { Num: el.getAttribute('chart-number'), Side: el.getAttribute('side-data'), Replace: el.getAttribute('replace') } } function getSubReport(chartNum) { var obj = { RequestType: "GetSubreport", Values: graphKeys[chartNum] } ajaxCall("../Click/GetSubReport", JSON.stringify(obj), setSubreport); } function setSubreport(html) { target.innerHTML = ""; setTimeout(function () { setReport(html); }, 500); } // Get table-info attributes from the target element function getTableInfo(target) { if (!target.hasAttribute('data-id')) return ""; return { ID: prevTarget.hasAttribute('data-id') ? prevTarget.getAttribute('data-id') : '', TableInfo: !prevTarget.hasAttribute('table-key') ? "" : { TableKey: prevTarget.hasAttribute('table-key') ? prevTarget.getAttribute('table-key') : '', Row: prevTarget.hasAttribute('row-key') ? prevTarget.getAttribute('row-key') : '', Column: prevTarget.hasAttribute('column-key') ? prevTarget.getAttribute('column-key') : '' } }; } var currColor; // Function to darken an element's background color function darken(el) { currColor = el.style.backgroundColor; var tc = tinycolor(currColor); el.style.backgroundColor = tc.darken().toRgbString(); } // Function to lighten an element's background color function lighten(el) { el.style.backgroundColor = currColor; } function changeColor(o) { for (var l = chartColors.vals[chartColors.last].color, r = !0, a = 0; a < chartColors.vals.length; a++) if (!chartColors.vals[a].used) { r = !1, chartColors.vals[a].used = !0, l = chartColors.vals[a].color, chartColors.last = a == chartColors.vals.length - 1 ? 0 : a + 1; break } r && (chartColors.last = chartColors.last == chartColors.vals.length - 1 ? 0 : chartColors.last + 1), o.style.backgroundColor = l } // Clear the page of background color function clearColor(color) { var b = document.getElementsByTagName('span'); for (var i = 0; i < b.length; i++) b[i].getAttribute('color') == color && (b[i].style.backgroundColor = ''); for (var e = document.getElementsByTagName('table'), l = 0; l < e.length; l++) for (var a, t = 0; a = e[l].rows[t]; t++) for (var n, c = 0; n = a.cells[c]; c++) n.getAttribute('color') == color && (n.style.backgroundColor = '') } function adjustSelectedTab(o) { var t = Math.floor(parseInt(o.getAttribute('button-count')) * (o.value / 100)); window[o.getAttribute('buttons-array')][t].click(), o.value = t * (100 / parseInt(o.getAttribute('button-count'))) + (100 / parseInt(o.getAttribute('button-count')) / 2) } // Ajax call for getting the status of a report request function getStatus(createDiv = false) { ajaxCall('../Click/GetStatus', JSON.stringify({ RequestType: 'GetReportStatus', CreateDiv: createDiv.toString() }), setStatus); } // Start the status interval that requests the status of a report function startStatusInterval() { getStatus(true); setTimeout(function () { statusInterval = setInterval(getStatus, statusIntervalTime) }, statusIntervalTime); } // Clear the status interval so no more requests are sent function stopStatusInterval() { clearInterval(statusInterval); statusInterval = false; return true; } function setStatus(msg) { var obj = JSON.parse(msg); if (obj.completed) stopStatusInterval() && conditionallyEnableReportButton(); setInnerHTML(getElById(statusId), obj.html); if (obj.completed) { var runningDiv = getElById(statusId).parentElement.parentElement; var completedDiv = getElById(statusCompletedId); completedDiv.innerHTML = runningDiv.innerHTML; runningDiv.innerHTML = ""; } } // Ajax call that requests a new graph based on the dropped element function getNewData(dropper) { var color = dropper.getAttribute('data-color'); var chartHolder = dropper.parentElement; var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { var obj = JSON.parse(xhttp.responseText); if (obj.Message == "invalid-key") return; setInnerHTML(chartHolder, obj.Value); chartHolder.getElementsByTagName('button')[0].style.backgroundColor = color; var panels = chartHolder.getElementsByClassName('droppable'); for (var p = 0; p < panels.length; p++) { panels[p].setAttribute('data-color', color); } } }; xhttp.open('POST', '../Click/GetData', true); xhttp.setRequestHeader('Content-type', 'application/json;charset=UTF-8'); xhttp.send(JSON.stringify(requestObj)); } function formatChartJson(jsonStr) { return JSON.parse(jsonStr); } function closeAllSelect(e) { var t, s, n, l = []; for (t = document.getElementsByClassName('select-items'), s = document.getElementsByClassName('select-selected'), n = 0; n < s.length; n++) e == s[n] ? l.push(n) : s[n].classList.remove('select-arrow-active'); for (n = 0; n < t.length; n++) l.indexOf(n) && t[n].classList.add('select-hide'); } function validateReportRequest() { return false; } function clearInput(el) { if (el.type == 'checkbox' || el.type == 'radio') { el.checked = false; } else if (el.type == 'text' || el.type == 'number' || el.type == 'date') { el.value = ''; } else if (el.type == 'range') { el.value = (parseFloat(el.max) + parseFloat(el.min)) / 2; } else { el.value = ''; } el.onchange(); } function clearByName(name) { var inputs = document.getElementsByName(name); for (var i = 0; i < inputs.length; i++) { clearInput(inputs[i]); } } var reportBtn = document.getElementsByClassName('reportButton')[0]; function conditionallyEnableReportButton() { var enabled = isValidReportRequest(reportBuilderOptions) reportBtn.disabled = !enabled; if (enabled) { reportBtn.classList.remove('disabled'); } else { reportBtn.classList.add('disabled'); } } function isValidReportRequest(opt) { return isValidProp(opt, 'ReportType') && isValidProp(opt, 'Subjects') && isValidProp(opt, 'TimeSpan') } function isValidProp(opt, prop) { return opt.hasOwnProperty(prop) && (opt[prop] != '' || (Array.isArray(opt[prop]) && opt[prop].length > 0)); } function clearBuilderOption(optLabel) { var lbl = optLabel.replace(/ /g, '') if (reportBuilderOptions.hasOwnProperty(lbl)) { if (Array.isArray(reportBuilderOptions[lbl])) { reportBuilderOptions[lbl] = []; } else { reportBuilderOptions[lbl] = ''; } } conditionallyEnableReportButton(); } document.addEventListener('click', closeAllSelect); function removeSeries(chart, seriesName, opts) { //console.log(chart, seriesName, opts); chart.updateSeries([{ name: seriesName.toString(), data: [] }]); } function clearInputsByClass(_class) { var els = document.getElementsByClassName(_class); for (var i = 0; i < els.length; i++) { els[i].value = ""; } } function resizeInputBasedOnId(id) { var castId = String(id); resizeInput(getElById(castId)); } //set a timeout so that text is updated first (e.g. on backspace) and then resized function resizeInput(el) { setTimeout(function () { onInput(el); }, 1); //setTimeout(function () { el.size = el.value.length >= 11 ? el.value.length : 11 }, 100); //this won't actually work quite right because not all characters have the same width } function onInput(el) { if (el != null) { var spanElm = el.nextElementSibling; if (spanElm != null) { spanElm.textContent = el.value; // the hidden span takes the value of the input; var w = spanElm.offsetWidth + 11; //>= 11 ? spanElm.offsetWidth + 10 : 11; el.style.width = w + 'px'; // apply width of the span to the input } } } function encodeHTML(str) { var retStr = str.replace(/[\u00A0-\u9999<>\&]/gim, function (i) { return '&#' + i.charCodeAt(0) + ';'; }); return retStr; } var draggedElId = ""; function handleOnDragStart(evnt) { setToolTipVisibility(false); evnt.dataTransfer.effectAllowed = 'move'; evnt.dataTransfer.setData("Text", evnt.target.getAttribute("id")); draggedElId = evnt.target.id; var drops = document.getElementsByClassName("infosentience-drop-div"); for (var i = 0; i < drops.length; i++) { if (evnt.currentTarget.previousElementSibling != null && evnt.currentTarget.previousElementSibling.id == drops[i].id) { continue; } if (evnt.currentTarget.nextElementSibling != null && evnt.currentTarget.nextElementSibling.id == drops[i].id) { continue; } if (ancestorOrAncestorSibling(draggedElId, drops[i])) { continue; } drops[i].style.backgroundColor = "rgba(0,0,0,0.1)"; drops[i].style.display = "block"; } } function ancestorOrAncestorSibling(elId, dropDiv) { var dragEl = getElById(elId); var parentEl = dragEl.parentNode; if (parentEl != null) parentEl = dragEl.parentNode; while (parentEl != null && parentEl != document.body) { for (var i = 0; i < parentEl.childNodes.length; i++) { if (parentEl.childNodes[i].id == dropDiv.id) return true; } parentEl = parentEl.parentNode; } return false; } function handleOnDragDrop(evnt, el) { evnt.preventDefault(); try { requestClick("../Click/OnDrop", el.id, 0, "POST", true, true, false, true, draggedElId); } catch { var carouselInd = document.getElementById(evnt.dataTransfer.getData("Text")).getAttribute("data-carousel-index"); $("#" + getCarouselId(evnt.currentTarget.id)).carousel(parseInt(carouselInd)); getCarouselHeader(evnt.currentTarget.id).innerHTML = getCarouselItem(evnt.currentTarget.id, carouselInd).getAttribute("header-text"); getCarouselSubHeader(evnt.currentTarget.id).innerHTML = getCarouselItem(evnt.currentTarget.id, carouselInd).getAttribute("sub-header-text"); highlightStory(document.getElementById(evnt.dataTransfer.getData("Text"))); selectNewCarouselSelectorItem(evnt.dataTransfer.getData("Text")); addParamToUrl("chart", getCarouselItem(evnt.currentTarget.id, carouselInd).getAttribute("header-text")); } return true; } function changeTitleFromCarouselButtonPress(el, dir) { var carousel = document.getElementById(getCarouselId(el.id)); var active = carousel.getElementsByClassName("active")[0]; var items = carousel.getElementsByClassName("carousel-item"); var index = Array.prototype.indexOf.call(active.parentElement.childNodes, active); if (index < 1) { if (dir == 0) { index = items.length - 1; } else { index += 1; } } else if (index == items.length - 1) { if (dir == 1) { index = 0; } else { index -= 1; } } else { index += dir==0?-1:1; } getCarouselHeader(el.id).innerHTML = getCarouselItem(el.id, index).getAttribute("header-text"); getCarouselSubHeader(el.id).innerHTML = getCarouselItem(el.id, index).getAttribute("sub-header-text"); highlightStoryByIndex(index); selectNewCarouselSelectorItemByIndex(index); } function changeChartSelectionByActive(active) { var index = Array.prototype.indexOf.call(active.parentElement.childNodes, active); getCarouselHeader(active.id).innerHTML = active.getAttribute("header-text"); getCarouselSubHeader(active.id).innerHTML = active.getAttribute("sub-header-text"); var listContainer = document.getElementsByClassName("infosentience-cme-carousel-list")[0]; var lbl = listContainer.getElementsByClassName("infosentience-text-label")[index]; selectNewDropdownItem(lbl); } function highlightNarSpan(elId) { var carousel = document.getElementById(getCarouselId(elId)); var active = carousel.getElementsByClassName("active")[0]; var index = Array.prototype.indexOf.call(active.parentElement.children, active); highlightStoryByIndex(index); } function getIdOfClassType(useId, useClass) { var el = document.getElementById(useId); while (el != null) { if (el.classList.contains(useClass)) return el.id; el = el.parentElement; } return ""; } function downloadURI(uri, name) { var link = document.createElement("a"); link.download = name; link.href = uri; link.click(); } function getCarouselHeader(useId) { var carousel = getCarouselId(useId); var mainHdr = document.getElementById(carousel).getElementsByClassName("infosentience-carousel-main-header")[0]; if (mainHdr != null) { return mainHdr;} var hdr = document.getElementById(carousel).getElementsByClassName("large-header-text")[0]; if (hdr == null) hdr = document.getElementById(carousel).getElementsByClassName("infosentience-large-header-text")[0]; if (hdr == null) hdr = document.getElementById(carousel).getElementsByClassName("standard-text")[0]; if (hdr == null) hdr = document.getElementById(carousel).getElementsByClassName("infosentience-standard-text")[0]; return hdr; } function getCarouselSubHeader(useId) { var carousel = getCarouselId(useId); var mainHdr = document.getElementById(carousel).getElementsByClassName("infosentience-carousel-sub-header")[0]; if (mainHdr != null) { return mainHdr;} var hdr = document.getElementById(carousel).getElementsByClassName("large-header-text")[1]; if (hdr == null) hdr = document.getElementById(carousel).getElementsByClassName("infosentience-large-header-text")[1]; if (hdr == null) hdr = document.getElementById(carousel).getElementsByClassName("standard-text")[1]; if (hdr == null) hdr = document.getElementById(carousel).getElementsByClassName("infosentience-standard-text")[1]; return hdr; } function getCarouselId(useId) { return getIdOfClassType(useId, "carousel"); } function getCarouselItem(useId, useIndex) { var carousel_el = document.getElementById(getCarouselId(useId)); var item_list = carousel_el.getElementsByClassName("carousel-item"); return item_list[useIndex]; //return document.getElementById(getIdOfClassType(useId, "carousel-item")); } function handleOnDragEnter(evnt) { return true; } function allowDrop(evnt) { evnt.preventDefault(); } function handleOnDragLeave(evnt) { return true; } function handleOnDragEnd(evnt) { var drops = document.getElementsByClassName("infosentience-drop-div"); for (var i = 0; i < drops.length; i++) { drops[i].style.backgroundColor = "rgba(0,0,0,0)"; drops[i].style.display = "none"; } } function copyMyText(el) { var range = document.createRange(); range.selectNode(el); window.getSelection().removeAllRanges(); // clear current selection var selectedstuff = window.getSelection() selectedstuff.addRange(range); // to select text copyToClipboard(selectedstuff.toString()); window.getSelection().removeAllRanges();// to deselect } function copyToClipboard(str) { navigator.clipboard.writeText(str.trim()); } function handleTextAreaChange(ev, el) { if (ev.code == "Enter") { el.rows++; return; } var rows = el.value.split("\n") if (ev.code == "Backspace" && rows.length >= 2 && rows[rows.length - 1] == "") { el.rows--; return; } if (ev.code == "ControlLeft" || ev.code == "ControlRight") { setTimeout(function () {setTextAreaRows(el, el.value.split("\n").length);}, 10); } setTextAreaRows(el, el.value.split("\n").length); } function setTextAreaRows(el, rows) { el.rows = rows <= parseInt(el.getAttribute("maxrows")) ? rows : parseInt(el.getAttribute("maxrows")); } function handleHTMLEditorChange(textEl, displayEl) { var newHtml = textEl.value; getElById(displayEl).innerHTML = newHtml; } var currScreenGrab; function createCanvasOfCurrentPage() { html2canvas(document.body).then(function (canvas) { currScreenGrab = canvas; }) } function stopAllAudio(removeFromDOM = true) { var els = Array.prototype.slice.call(document.getElementsByTagName("audio")); while (els.length > 0) { els[0].pause(); els[0].currentTime = 0; if (removeFromDOM) els[0].parentElement.removeChild(els[0]); els.shift(); } } function pauseAllAudio(removeFromDOM = true) { var els = Array.prototype.slice.call(document.getElementsByTagName("audio")); while (els.length > 0) { els[0].pause(); if (removeFromDOM) els[0].parentElement.removeChild(els[0]); els.shift(); } } function resumeAllAudio() { var els = Array.prototype.slice.call(document.getElementsByTagName("audio")); while (els.length > 0) { els[0].play(); els.shift(); } } //For ApexCharts horizontal bar chart //Indices are inclusive function getMaxWidth(useEl, startIndex, endIndex) { var maxWidth = 0; for (var i = startIndex; i <= endIndex; i++) { if (getBBox(useEl.children[i]).width > maxWidth) { maxWidth = getBBox(useEl.children[i]).width; } } return maxWidth; } function getBarsHeight(useEl, startIndex, endIndex) { return getBBox(useEl.children[endIndex]).y - getBBox(useEl.children[startIndex]).y + getBBox(useEl.children[endIndex]).height; } function pasteIntoEntryBoxes(btn) { navigator.clipboard.readText() .then(text => { var textList = text.split("\r\n"); var box = btn.parentElement; var entryList = box.getElementsByTagName("input"); var subtractVal = 0 for (var i = 0; i < entryList.length; i++) { if (entryList[i].type == ("text")) { entryList[i].value = textList[i - subtractVal]; entryList[i].onchange(); } else { subtractVal++; } } //console.log(textList); }); } function getClipboardText() { navigator.clipboard.readText() .then(text => { return text; }); } function getClipboardPromise() { return navigator.clipboard.readText(); } function passwordsMatch(pe1, pe2) { return (pe1.value == pe2.value) && pe1.value.length > 7; } function selectNewDropdownItem(useItem) { //var par = document.getElementsByClassName("carousel")[0]; var par = useItem.parentNode.parentNode; var lbls = par.getElementsByClassName("infosentience-text-label"); var svgs = par.getElementsByClassName("infosentience-svg"); for (i = 0;i 0) { tooltips[i].style.top = topVal + "px"; } } } function getTopVal(elem) { var box = elem.getBoundingClientRect(); var body = document.body; var docEl = document.documentElement; var scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop; var clientTop = docEl.clientTop || body.clientTop || 0; var top = box.top + scrollTop - clientTop; if (getDashboardDiv() == null) {top += 420}; return Math.round(top); } function getUser() { return "none"; } function submitFeedback(textId, pageType) { var url = makeFeedbackUrl(textId, pageType); var http = new XMLHttpRequest(); http.open("GET", url, true); http.send(); getElById(textId).value = ""; getElById(textId).style.display = "none"; } function makeFeedbackUrl(textId, pageType) { return "https://cmeapi.infosentience.com/CME/LogFeedback?userId=" + getUser() + "&feedbackText=" + getFeedbackText(textId) + "&product=" + getCommodityCode() + "&date=" + getTradeDate() + "&pageType=" + pageType; } function getFeedbackText(textId) { var textEl = document.getElementById(textId); var feedbackText = textEl.value; return encodeURIComponent(feedbackText); } function getTradeDate() { var dashDiv = document.getElementById("dashboard-div"); if (dashDiv != undefined) { var meta = dashDiv.getElementsByTagName("meta")[0]; return meta.dataset["tradeDate"]; } else { var metas = document.getElementsByTagName("meta"); for (var i = 0; i < metas.length; i++) { if (metas[i].hasAttribute("data-trade-date")) return metas[i].dataset["tradeDate"]; } } return ""; } addCloseDropDownListeners();