diff options
author | teh_coderer <me@tehcoderer.com> | 2023-05-16 16:05:48 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-16 21:05:48 +0000 |
commit | 0f3497a3c170770ca37d1d1e155a78e6a2c4bdce (patch) | |
tree | 9f9bbc68ac0283f478aa8e06c4e79c44d4789864 | |
parent | fd0ad2187369dca6ed81827f82ae42173486488b (diff) |
remove plotly charts legacy web modules (#5034)
-rw-r--r-- | openbb_terminal/core/plots/assets/icon.png | bin | 727 -> 0 bytes | |||
-rw-r--r-- | openbb_terminal/core/plots/old_table.html | 41 | ||||
-rw-r--r-- | openbb_terminal/core/plots/web/bar_menus.js | 460 | ||||
-rw-r--r-- | openbb_terminal/core/plots/web/css/fonts/FiraCode-Regular.ttf | bin | 289624 -> 0 bytes | |||
-rw-r--r-- | openbb_terminal/core/plots/web/css/fonts/FiraCode-VF.ttf | bin | 286320 -> 0 bytes | |||
-rw-r--r-- | openbb_terminal/core/plots/web/css/style.css | 1351 | ||||
-rw-r--r-- | openbb_terminal/core/plots/web/css/table.css | 7 | ||||
-rw-r--r-- | openbb_terminal/core/plots/web/helpers.js | 1080 | ||||
-rw-r--r-- | openbb_terminal/core/plots/web/main.js | 646 | ||||
-rw-r--r-- | openbb_terminal/core/plots/web/main_table.js | 119 | ||||
-rw-r--r-- | openbb_terminal/core/plots/web/popups.js | 738 |
11 files changed, 0 insertions, 4442 deletions
diff --git a/openbb_terminal/core/plots/assets/icon.png b/openbb_terminal/core/plots/assets/icon.png Binary files differdeleted file mode 100644 index 1d77bc133cc..00000000000 --- a/openbb_terminal/core/plots/assets/icon.png +++ /dev/null diff --git a/openbb_terminal/core/plots/old_table.html b/openbb_terminal/core/plots/old_table.html deleted file mode 100644 index 4aefb6e015e..00000000000 --- a/openbb_terminal/core/plots/old_table.html +++ /dev/null @@ -1,41 +0,0 @@ -<html> - <head> - <meta charset="utf-8" /> - <meta name="color-scheme" content="dark" /> - <link rel="stylesheet" href="/{{MAIN_PATH}}/web/css/table.css" /> - - <script src="/{{MAIN_PATH}}/web/helpers.js" type="text/javascript"></script> - <script - src="/{{MAIN_PATH}}/web/bar_menus.js" - type="text/javascript" - ></script> - <script src="/{{MAIN_PATH}}/web/popups.js" type="text/javascript"></script> - <script - src="/{{MAIN_PATH}}/web/main_table.js" - type="text/javascript" - ></script> - - <link - href="https://unpkg.com/tabulator-tables@5.4.3/dist/css/tabulator_midnight.min.css" - rel="stylesheet" - /> - <script - type="text/javascript" - src="https://unpkg.com/tabulator-tables@5.4.3/dist/js/tabulator.min.js" - ></script> - </head> - - <body> - <div id="example-table"></div> - <script type="text/javascript"> - var interval = setInterval(function () { - // Waits for OpenBBMain and plotly_figure to be defined before - // calling OpenBBMain to avoid errors - if (typeof TableProcessor != "undefined" && window.plotly_figure) { - clearInterval(interval); - TableProcessor(window.plotly_figure); - } - }, 20); - </script> - </body> -</html> diff --git a/openbb_terminal/core/plots/web/bar_menus.js b/openbb_terminal/core/plots/web/bar_menus.js deleted file mode 100644 index 455e96326f8..00000000000 --- a/openbb_terminal/core/plots/web/bar_menus.js +++ /dev/null @@ -1,460 +0,0 @@ -// Custom Menu functions for Plotly charts - -async function autoScaling(eventdata, graphs) { - try { - if (eventdata["xaxis.range[0]"] != undefined) { - const x_min = eventdata["xaxis.range[0]"]; - const x_max = eventdata["xaxis.range[1]"]; - let to_update = {}; - let y_min, y_max; - - const YaxisData = graphs.data.filter((trace) => trace.yaxis != undefined); - const yaxis_unique = [ - ...new Set( - YaxisData.map( - (trace) => - trace.yaxis || trace.y != undefined || trace.type == "candlestick" - ) - ), - ]; - - const get_all_yaxis_traces = (yaxis) => { - return graphs.data.filter( - (trace) => - trace.yaxis == yaxis && (trace.y || trace.type == "candlestick") - ); - }; - - yaxis_unique.forEach((unique) => { - if (typeof unique != "string") { - return; - } - let yaxis = "yaxis" + unique.replace("y", ""); - let y_candle = []; - let y_values = []; - let log_scale = graphs.layout[yaxis].type == "log"; - - get_all_yaxis_traces(unique).forEach((trace2) => { - let x = trace2.x; - log_scale = graphs.layout[yaxis].type == "log"; - - let y = trace2.y != undefined ? trace2.y : []; - let y_low = trace2.type == "candlestick" ? trace2.low : []; - let y_high = trace2.type == "candlestick" ? trace2.high : []; - - if (log_scale) { - y = y.map(Math.log10); - if (trace2.type == "candlestick") { - y_low = trace2.low.map(Math.log10); - y_high = trace2.high.map(Math.log10); - } - } - - let yx_values = x.map((x, i) => { - let out = null; - if (x >= x_min && x <= x_max) { - if (trace2.y != undefined) { - console.log(trace2.name, trace2.type, trace2.yaxis); - out = y[i]; - } - if (trace2.type == "candlestick") { - y_candle.push(y_low[i]); - y_candle.push(y_high[i]); - } - } - return out; - }); - - y_values = y_values.concat(yx_values); - }); - - y_values = y_values.filter((y2) => y2 != undefined && y2 != null); - y_min = Math.min(...y_values); - y_max = Math.max(...y_values); - - if (y_candle.length > 0) { - y_candle = y_candle.filter((y2) => y2 != undefined && y2 != null); - y_min = Math.min(...y_candle); - y_max = Math.max(...y_candle); - } - - let org_y_max = y_max; - let is_volume = - graphs.layout[yaxis].fixedrange != undefined && - graphs.layout[yaxis].fixedrange == true; - - if (y_min != undefined && y_max != undefined) { - let y_range = y_max - y_min; - let y_mult = 0.15; - if (y_candle.length > 0) { - y_mult = 0.3; - } - - y_min -= y_range * y_mult; - y_max += y_range * y_mult; - - if (is_volume) { - if (graphs.layout[yaxis].tickvals != undefined) { - const range_x = 7; - let volume_ticks = org_y_max; - let round_digits = -3; - let first_val = Math.round(volume_ticks * 0.2, round_digits); - let x_zipped = [2, 5, 6, 7, 8, 9, 10]; - let y_zipped = [1, 4, 5, 6, 7, 8, 9]; - - for (let i = 0; i < x_zipped.length; i++) { - if (String(volume_ticks).length > x_zipped[i]) { - round_digits = -y_zipped[i]; - first_val = Math.round(volume_ticks * 0.2, round_digits); - } - } - let tickvals = [ - Math.floor(first_val), - Math.floor(first_val * 2), - Math.floor(first_val * 3), - Math.floor(first_val * 4), - ]; - let volume_range = [0, Math.floor(volume_ticks * range_x)]; - - to_update[yaxis + ".tickvals"] = tickvals; - to_update[yaxis + ".range"] = volume_range; - to_update[yaxis + ".tickformat"] = ".2s"; - return; - } - y_min = 0; - y_max = graphs.layout[yaxis].range[1]; - } - to_update[yaxis + ".range"] = [y_min, y_max]; - } - }); - Plotly.update(graphs, {}, to_update); - } - } catch (e) { - console.log(`Error in AutoScaling: ${e}`); - } -} - -function changeColor() { - if (!globals.color_picker) { - let color_picker = document.getElementById("changecolor"); - globals.color_picker = color_picker; - - color_picker.style.display = "block"; - color_picker.style.width = null; - dragElement(color_picker); - - function dragElement(elmnt) { - let pos1 = 0, - pos2 = 0, - pos3 = 0, - pos4 = 0; - if (document.getElementById(elmnt.id + "_header")) { - // if present, the header is where you move the DIV from: - document.getElementById(elmnt.id + "_header").onmousedown = - dragMouseDown; - } else { - // otherwise, move the DIV from anywhere inside the DIV: - elmnt.onmousedown = dragMouseDown; - } - - function dragMouseDown(e) { - e = e || window.event; - e.preventDefault(); - // get the mouse cursor position at startup: - pos3 = e.clientX; - pos4 = e.clientY; - document.onmouseup = closeDragElement; - // call a function whenever the cursor moves: - document.onmousemove = elementDrag; - } - - function elementDrag(e) { - e = e || window.event; - e.preventDefault(); - // calculate the new cursor position: - pos1 = pos3 - e.clientX; - pos2 = pos4 - e.clientY; - pos3 = e.clientX; - pos4 = e.clientY; - // set the element's new position: - elmnt.style.top = elmnt.offsetTop - pos2 + "px"; - elmnt.style.left = elmnt.offsetLeft - pos1 + "px"; - } - - function closeDragElement() { - // stop moving when mouse button is released: - document.onmouseup = null; - document.onmousemove = null; - } - } - } else { - globals.color_picker.style.display = "none"; - globals.color_picker = null; - } -} - -function uploadImage() { - const loader = document.getElementById("loader"); - loader.classList.add("show"); - Plotly.toImage(globals.CHART_DIV, { - format: "png", - height: 627, - width: 1200, - }) - .then(function (url) { - let data = { - image: url, - title: globals.title, - description: "Check out this chart from OpenBB", - }; - - fetch("https://uppy-self.vercel.app/api/upload-image", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(data), - }) - .then(function (response) { - return response.json(); - }) - .then(function (data) { - const { url, id } = data; - loader.classList.remove("show"); - openPopup("popup_upload", { url }); - }) - .catch(function (err) { - console.log(err); - loader.classList.remove("show"); - }); - }) - .catch(function (err) { - console.log(err); - loader.classList.remove("show"); - }); -} - -const openbb_watermark = { - yref: "paper", - xref: "paper", - x: 1, - y: 0, - text: "OpenBB Terminal", - font_size: 17, - font_color: "gray", - opacity: 0.5, - xanchor: "right", - yanchor: "bottom", - yshift: -80, - xshift: 40, -}; - -async function setWatermarks(margin, old_index, init = false) { - if (init) { - globals.CHART_DIV.layout.annotations.push(openbb_watermark); - if (globals.cmd_idx && globals.cmd_src) { - globals.CHART_DIV.layout.annotations[globals.cmd_idx].text = - globals.cmd_src; - } - - Plotly.relayout(globals.CHART_DIV, { - "title.text": globals.title, - margin: globals.old_margin, - }); - } - - if (!init) { - if (globals.cmd_idx && globals.cmd_src) { - globals.CHART_DIV.layout.annotations[globals.cmd_idx].text = ""; - } - globals.CHART_DIV.layout.annotations.splice(old_index, 1); - - Plotly.relayout(globals.CHART_DIV, { - "title.text": "", - margin: margin, - }); - } -} - -async function downloadImage(filename, extension, writable = undefined) { - const loader = document.getElementById("loader"); - loader.classList.add("show"); - - let imageDownload = undefined; - - if (extension == "png") { - imageDownload = domtoimage.toPng; - } else if (extension == "jpeg") { - imageDownload = domtoimage.toJpeg; - // } else if (extension == "svg") { - // imageDownload = domtoimage.toSvg; - } else if (["svg", "pdf"].includes(extension)) { - const margin = globals.CHART_DIV.layout.margin; - const old_index = globals.CHART_DIV.layout.annotations.length; - - await setWatermarks(margin, old_index, true); - - if (window.showSaveFilePicker && writable) { - await Plotly.toImage(globals.CHART_DIV, { - format: "svg", - height: globals.CHART_DIV.clientHeight, - width: globals.CHART_DIV.clientWidth, - }).then(async function (dataUrl) { - const blob = await fetch(dataUrl).then((r) => r.blob()); - await writable.write(blob); - await writable.close(); - }); - } else { - Plotly.downloadImage(globals.CHART_DIV, { - format: "svg", - height: globals.CHART_DIV.clientHeight, - width: globals.CHART_DIV.clientWidth, - filename: filename, - }); - } - - await setWatermarks(margin, old_index, false); - - return; - } else { - console.log("Invalid extension"); - return; - } - - imageDownload(document.getElementById("openbb_container")) - .then(async function (dataUrl) { - if (window.showSaveFilePicker && writable) { - const blob = await fetch(dataUrl).then((r) => r.blob()); - await writable.write(blob); - await writable.close(); - } else { - downloadURI(dataUrl, filename + "." + extension); - } - loader.classList.remove("show"); - }) - .catch(function (error) { - console.error("oops, something went wrong!", error); - loader.classList.remove("show"); - hideModebar(); - }); -} - -function downloadURI(uri, name) { - let link = document.createElement("a"); - link.download = name; - link.href = uri; - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); -} - -async function downloadData(gd, filename, writable = undefined) { - let data = gd.data; - let candlestick = false; - let csv = undefined; - - data.forEach(function (trace) { - // check if candlestick - if (trace.type == "candlestick") { - candlestick = true; - return; - } - }); - - let xaxis = - "title" in gd.layout["xaxis"] && - gd.layout["xaxis"]["title"]["text"] != undefined - ? gd.layout["xaxis"]["title"]["text"] - : "x"; - - let yaxis = - "title" in gd.layout["yaxis"] && - gd.layout["yaxis"]["title"]["text"] != undefined - ? gd.layout["yaxis"]["title"]["text"] - : "y"; - - if (candlestick) { - csv = "Date,Open,High,Low,Close\n"; - data.forEach(function (trace) { - if (trace.type == "candlestick") { - let x = trace.x; - let open = trace.open; - let high = trace.high; - let low = trace.low; - let close = trace.close; - - for (let i = 0; i < x.length; i++) { - csv += `${x[i]},${open[i]},${high[i]},${low[i]},${close[i]}\n`; - } - } - }); - } else { - let traces = 0; - data.forEach(function (trace) { - if (trace.type == "scatter") { - traces++; - } - }); - - if (traces == 1) { - csv = `${data[0].name},${xaxis},${yaxis}\n`; - data.forEach(function (trace) { - if (trace.type == "scatter") { - let x = trace.x; - let y = trace.y; - - for (let i = 0; i < x.length; i++) { - csv += `${x[i]},${y[i]}\n`; - } - } - }); - } else if (traces > 1) { - csv = `${xaxis}`; - data.forEach(function (trace) { - if (trace.type == "scatter") { - csv += `,${trace.name}`; - } - }); - csv += "\n"; - - let x = data[0].x; - for (let i = 0; i < x.length; i++) { - csv += `${x[i]}`; - data.forEach(function (trace) { - if (trace.type == "scatter") { - csv += `,${trace.y[i]}`; - } - }); - csv += "\n"; - } - } else { - return; - } - } - - const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" }); - if (navigator.msSaveBlob) { - // IE 10+ - navigator.msSaveBlob(blob, filename); - } else { - // feature detection - // Browsers that support showSaveFilePicker or HTML5 download attribute - if (window.showSaveFilePicker && writable) { - await writable.write(blob); - await writable.close(); - } else { - let link = window.document.createElement("a"); - if (link.download !== undefined) { - // feature detection - // Browsers that support HTML5 download attribute - let url = URL.createObjectURL(blob); - link.setAttribute("href", url); - link.setAttribute("download", filename); - link.style.visibility = "hidden"; - window.document.body.appendChild(link); - link.click(); - window.document.body.removeChild(link); - } - } - } -} diff --git a/openbb_terminal/core/plots/web/css/fonts/FiraCode-Regular.ttf b/openbb_terminal/core/plots/web/css/fonts/FiraCode-Regular.ttf Binary files differdeleted file mode 100644 index bd736851948..00000000000 --- a/openbb_terminal/core/plots/web/css/fonts/FiraCode-Regular.ttf +++ /dev/null diff --git a/openbb_terminal/core/plots/web/css/fonts/FiraCode-VF.ttf b/openbb_terminal/core/plots/web/css/fonts/FiraCode-VF.ttf Binary files differdeleted file mode 100644 index c05ac827c58..00000000000 --- a/openbb_terminal/core/plots/web/css/fonts/FiraCode-VF.ttf +++ /dev/null diff --git a/openbb_terminal/core/plots/web/css/style.css b/openbb_terminal/core/plots/web/css/style.css deleted file mode 100644 index ad5e6454b36..00000000000 --- a/openbb_terminal/core/plots/web/css/style.css +++ /dev/null @@ -1,1351 +0,0 @@ -/* local Fira Code font */ -@font-face { - font-family: "Fira Code"; - src: url("fonts/FiraCode-VF.ttf") format("truetype"); - /* fix Fire Code font width issue that makes Text get cut off in Plotly.js */ - font-weight: 400 700; - font-stretch: 50%; -} - -html { - font-size: 62.5%; - font-family: "Fira Code", monospace, "Arial Black"; -} - -body { - font-family: "Fira Code", monospace, "Arial Black"; - font-size: 12px; - font-size: 1.2rem; - color: #ffffff; - background-color: #000000; - font-stretch: 50%; - overflow: hidden; -} - -.saving { - position: absolute; - z-index: 9999999; - top: 50%; - left: 50%; - transform: translate(-50%, -50%); - height: 100px; - width: 200px; - display: none; - justify-content: center; - align-items: center; - background-color: rgba(0, 0, 0, 0.7); - color: white; - box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.5); - border: 4px solid rgba(250, 250, 250, 0.5); - font-size: 1.5em; - border-radius: 20px; - animation: popup 0.3s ease-in-out; -} - -.saving.show { - display: flex; -} - -.openbb_container { - align-items: center; - width: 100%; - height: 100%; - background-color: #000000; - position: absolute; - top: 0; - left: 0; -} - -.openbb_header { - position: relative; - z-index: 99999999999; - text-align: center; - top: 0; - background-color: transparent; - box-sizing: border-box; -} - -.plotly-graph-div { - width: 100%; - height: 89.6%; - position: relative; - font-size: 12px; - font-size: 1.2rem; - font-family: "Fira Code", monospace, "Arial Black"; - visibility: visible; -} - -#changecolor { - position: absolute; - z-index: 9; - text-align: center; - top: 50%; - left: 50%; - width: 100px; - height: 60px; - background-color: transparent; - padding: 10px; - box-sizing: border-box; - display: none; -} - -#changecolor_header:hover { - margin-top: 0px !important; - margin-bottom: 0px !important; - border: 1px solid gold; - box-shadow: 0 0 5px gold; -} - -#changecolor_header { - padding: 10px; - cursor: move; - z-index: 10; - color: #fff; -} - -#changecolor_header input[type="color"] { - width: 100%; - height: 40px; - border: none; - border-radius: 5px; - margin-bottom: 20px !important; - cursor: pointer; - border: 1px solid #7d7d7d; - padding: 5px; - background-color: #131313; - color: #ffffff; - margin-right: 50px !important; -} - -@keyframes popup { - 0% { - -webkit-transition: all 0.3s ease-in-out; - transform: translate(-50%, -50%) scale(0.2); - } - - 40% { - transform: translate(-50%, -50%) scale(1.1); - } - - 80% { - transform: translate(-50%, -50%) scale(1.05); - } - - 100% { - transform: translate(-50%, -50%) scale(1); - } -} - -.popup_overlay { - position: absolute; - top: 50%; - left: 50%; - transform: translate(-50%, -50%); - width: 420px; - background: #070707; - border: 1px solid #dcdcdc; - box-shadow: 0px 4px 24px rgba(0, 0, 0, 0.06); - border-radius: 4px; - padding: 40px; - box-sizing: border-box; - display: none; - font-family: "Fira Code", monospace, "Arial Black"; - animation: popup 0.3s ease-in-out; - box-shadow: 0 3px 10px rgb(0 0 0 / 0.2); - z-index: 2; -} - -.popup_content { - position: relative; - background-color: transparent; - padding: 0px; - width: 100%; - height: 100%; - z-index: 3; -} - -.popup_warning { - color: #ff0000; - font-size: 12px; - font-size: 1.2rem; - font-family: "Fira Code", monospace, "Arial Black"; - display: none; - font-weight: bold; - margin-top: -15px; - margin-left: 135px; -} - -.csv_column_container { - display: grid; - grid-template-columns: 1fr 1fr; - grid-gap: 10px; - margin-top: 10px; - margin-bottom: 10px; -} - -.plotly-graph-div .modebar--hover .modebar-group { - border: 2px solid #5a5a5a !important; - border-radius: 4px; - padding: 2px 2px 2px !important; -} - -.modebar-group { - display: flex !important; - background-color: transparent !important; -} - -.modebar { - z-index: 5000 !important; - position: fixed !important; - bottom: 10px !important; - top: auto !important; - left: 50% !important; - right: auto !important; - align-items: center; - transform: translate(-50%, 10%) !important; -} - -@media screen and (max-width: 600px) { - .modebar-group { - display: block !important; - background-color: transparent !important; - } - - .modebar { - bottom: 20px !important; - } -} - -.modebar-group { - margin-left: 10px; - margin-right: 10px; - background: #0f0f0f !important; - border: 1px solid #404040; - box-shadow: 0px 4px 24px rgba(0, 0, 0, 0.06); - border-radius: 8px; -} - - -.modebar-group:nth-of-type(1):after { - content: "Panning Tools"; - height: fit-content; - width: fit-content; - position: absolute; - display: none; -} - -.modebar-group:nth-of-type(1):hover:after { - padding: 10px; - display: block; - font-size: 10px; - color: white; - cursor: pointer; - background: #0f0f0f !important; - border: 1px solid #404040; - box-shadow: 0px 4px 24px rgba(0, 0, 0, 0.06); - border-radius: 8px; - top: -40px; - left: 50%; - transform: translateX(-50%); -} - -.modebar-group:nth-of-type(2):after { - content: "Indicator Tools"; - height: fit-content; - width: fit-content; - position: absolute; - display: none; -} - -.modebar-group:nth-of-type(2):hover:after { - padding: 10px; - display: block; - font-size: 10px; - color: white; - cursor: pointer; - background: #0f0f0f !important; - border: 1px solid #404040; - box-shadow: 0px 4px 24px rgba(0, 0, 0, 0.06); - border-radius: 8px; - top: -40px; - left: 50%; - transform: translateX(-50%); -} - -.modebar-group:nth-of-type(3):after { - content: "Chart Tools"; - height: fit-content; - width: fit-content; - position: absolute; - display: none; -} - -.modebar-group:nth-of-type(3):hover:after { - padding: 10px; - display: block; - font-size: 10px; - color: white; - cursor: pointer; - background: #0f0f0f !important; - border: 1px solid #404040; - box-shadow: 0px 4px 24px rgba(0, 0, 0, 0.06); - border-radius: 8px; - top: -40px; - left: 50%; - transform: translateX(-50%); -} - -.modebar-group:nth-of-type(4):after { - content: "Drawing Tools"; - height: fit-content; - width: fit-content; - position: absolute; - display: none; -} - -.modebar-group:nth-of-type(4):hover:after { - padding: 10px; - display: block; - font-size: 10px; - color: white; - cursor: pointer; - background: #0f0f0f !important; - border: 1px solid #404040; - box-shadow: 0px 4px 24px rgba(0, 0, 0, 0.06); - border-radius: 8px; - top: -40px; - left: 50%; - transform: translateX(-50%); -} - -.modebar-group:nth-of-type(5):after { - content: "Export Tools"; - height: fit-content; - width: fit-content; - position: absolute; - display: none; -} - -.modebar-group:nth-of-type(5):hover:after { - padding: 10px; - display: block; - font-size: 10px; - color: white; - cursor: pointer; - background: #0f0f0f !important; - border: 1px solid #404040; - box-shadow: 0px 4px 24px rgba(0, 0, 0, 0.06); - border-radius: 8px; - top: -40px; - left: 50%; - transform: translateX(-50%); -} - -.modebar.vertical { - flex-direction: row !important; - flex-flow: initial !important; - gap: 6px !important; -} - -.js-plotly-plot .plotly .modebar.vertical .modebar-group { - padding-bottom: 0px !important; -} - -.modebar-container { - position: initial !important; -} |