Files
OpenBB/openbb_terminal/core/plots/plotly.html
teh_coderer 9026a41ff2 Feature / Logging (#4923)
* init

* updates

* Update loggers.py

* Update loggers.py

* sdk handling

* feature flag

* fix MOCKING_USER_PATH for windows

* Update loggers.py

* Update plotly.html

* updates

* Update parent_classes.py

* Update plotly.html

* add posthog to deps

* Update loggers.py
2023-04-28 12:43:57 +00:00

345 lines
13 KiB
HTML
Vendored

<html>
<head>
<meta charset="utf-8" />
<meta name="color-scheme" content="dark" />
<link rel="stylesheet" href="/{{MAIN_PATH}}/web/css/style.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.js" type="text/javascript"></script>
<script src="/{{PLOTLYJS_PATH}}" type="text/javascript"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/dom-to-image/2.6.0/dom-to-image.min.js"
integrity="sha512-01CJ9/g7e8cUmY0DFTMcUw/ikS799FHiOA0eyHsUWfOetgbx/t6oV4otQ5zXKQyIrQGTHSmRVPIgrgLcZi/WMA=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<script>
if (window.plotly_figure?.posthog?.collect_logs) {
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
posthog.init("phc_vhssDAMod5qIplznQ75Kdgz4aB1qPFmeVmfEOZ4hkRw", {
api_host: "https://app.posthog.com",
autocapture: {
css_selector_allowlist: [".ph-capture"],
},
capture_pageview: false,
loaded: function (posthog) {
const log_id = window.plotly_figure?.log_id || "";
if (log_id != "" && log_id != "REPLACE_ME") {
posthog.identify(log_id);
}
posthog.onFeatureFlags(function () {
if (
!posthog.isFeatureEnabled("record-pywry", { send_event: false })
) {
posthog.stopSessionRecording();
}
if (
!posthog.isFeatureEnabled("collect-logs-pywry", {
send_event: false,
})
) {
posthog.opt_out_capturing();
} else if (posthog.has_opted_out_capturing()) {
posthog.opt_in_capturing();
}
});
},
});
}
</script>
</head>
<body>
<!-- Plotly -->
<div id="openbb_container">
<div
id="openbb_header"
class="_header flex items-center justify-between gap-4 py-2 px-4 text-center"
style="z-index: 99999999999; width: 100%; top: 0; max-height: 60px"
>
<div class="w-1/3">
<svg
xmlns="http://www.w3.org/2000/svg"
width="64"
height="40"
fill="none"
viewBox="0 0 64 40"
>
<path
fill="#fff"
d="M61.283 3.965H33.608v27.757h25.699V19.826H37.561v-3.965H63.26V3.965h-1.977zM39.538 23.792h15.815v3.965H37.561v-3.965h1.977zM59.306 9.913v1.983H37.561V7.931h21.745v1.982zM33.606 0h-3.954v3.965H33.606V0zM25.7 3.966H0V15.86h25.7v3.965H3.953v11.896h25.7V3.966h-3.955zm0 21.808v1.983H7.907v-3.965h17.791v1.982zm0-15.86v1.982H3.953V7.931h21.745v1.982zM37.039 35.693v2.952l-.246-.246-.245-.245-.245-.247-.245-.246-.246-.246-.245-.245-.245-.247-.247-.246-.245-.246-.245-.246-.245-.246-.246-.246h-.49v3.936h.49v-3.198l.246.246.245.246.245.246.245.246.246.246.246.246.245.247.246.245.245.246.245.247.245.246.246.245.245.246h.245v-3.936h-.49zM44.938 37.17h-.491v-1.477h-2.944v3.937h3.93v-2.46h-.495zm-2.944-.246v-.739h1.962v.984h-1.962v-.245zm2.944.984v1.23h-2.944V37.66h2.944v.247zM52.835 37.17h-.49v-1.477h-2.946v3.937h3.925v-2.46h-.489zm-2.944-.246v-.739h1.963v.984h-1.965l.002-.245zm2.944.984v1.23H49.89V37.66h2.946v.247zM29.174 35.693H25.739v3.936H29.663v-.491H26.229v-.984h2.943v-.493H26.229v-1.476h3.434v-.492h-.489zM13.37 35.693H9.934v3.937h3.925v-3.937h-.49zm0 .738v2.709h-2.945v-2.955h2.943l.001.246zM21.276 35.693h-3.435v3.937h.491v-1.476h3.434v-2.461h-.49zm0 .738v1.23h-2.944v-1.476h2.944v.246z"
></path>
</svg>
</div>
<strong
class="w-1/3 font-bold"
id="title"
style="font-size: 16px"
></strong>
<p class="w-1/3 text-right" id="date"></p>
</div>
<div id="openbb_chart" class="plotly-graph-div"></div>
</div>
<div
id="openbb_footer"
class="_footer flex items-center justify-between gap-4 py-2 px-4 text-center"
style="
z-index: 99999999999;
width: 100%;
bottom: 0;
max-height: 60px;
min-height: 60px;
font-size: 0px;
"
>
......................
</div>
<div id="loading" class="saving">
<div id="loading_text" class="loading_text"></div>
<div id="loader" class="loader"></div>
</div>
<!-- Popups Overlay -->
<div id="popup_overlay" class="popup_overlay">
<div id="popup_content" class="popup_content">
<!-- CSV Popup -->
<div id="popup_csv" class="popup_content">
<div>
<label for="csv_file">CSV file</label>
<input type="file" id="csv_file" accept=".csv" />
</div>
<div style="margin-top: 15px">
<label for="csv_trace_type"><b>Display data type:</b></label>
<select id="csv_trace_type" value="scatter">
<option value="bar">Bar</option>
<option value="candlestick">Candlestick</option>
<option value="scatter">Scatter (Line)</option>
</select>
</div>
<div style="margin-top: 12px">
<label for="csv_name"><b>Trace Name:</b></label>
<textarea
id="csv_name"
style="
padding: 5px 2px 2px 5px !important;
width: 100%;
max-width: 100%;
max-height: 200px;
margin-top: 8px;
"
rows="2"
cols="20"
value=""
placeholder="Enter a name to give this trace"
></textarea>
</div>
<div style="margin-top: 15px" id="csv_columns"><!-- Empty --></div>
<div style="margin-top: 15px" id="csv_colors"><!-- Empty --></div>
<div
style="margin-top: 10px; display: none"
id="csv_plot_yaxis_options"
>
<div id="csv_percent_change_div" style="display: none">
<input
type="checkbox"
id="csv_percent_change"
name="csv_plot_yaxis_check"
onclick="onlyOne(this)"
/>
<label for="csv_percent_change"
>Plot as percent change from first value</label
>
</div>
<br />
<input
type="checkbox"
id="csv_same_yaxis"
name="csv_plot_yaxis_check"
onclick="onlyOne(this)"
/>
<label for="csv_same_yaxis">Share Y-axis</label>
</div>
<div style="margin-top: 2px; display: none" id="csv_bar_orientation">
<input type="checkbox" id="csv_bar_horizontal" />
<label for="csv_bar_horizontal">Plot horizontally</label>
</div>
<br />
<div style="float: right; margin-top: 20px">
<button
class="_btn-tertiary ph-capture"
id="csv_cancel"
onclick="closePopup()"
>
Cancel
</button>
<button
class="_btn ph-capture"
id="csv_submit"
onclick="on_submit('csv')"
>
Submit
</button>
</div>
</div>
<!-- Text Popup -->
<div class="popup_content" id="popup_text"></div>
<!-- Title Popup -->
<div class="popup_content" id="popup_title"></div>
<!-- Download Popup -->
<div class="popup_content" id="popup_download">
<p>File saved to:</p>
<p id="download_path"></p>
<div style="float: right; margin-top: 20px">
<button class="_btn" id="openfile_button">Open File</button>
<button class="_btn" id="openfolder_button">Open Folder</button>
<button
class="_btn-tertiary"
id="close_button"
onclick="closePopup()"
>
Close
</button>
</div>
</div>
</div>
</div>
<!-- Change Color Popup -->
<div id="changecolor">
<div id="changecolor_header">
<input
type="color"
id="picked_color"
value="#00ACFF"
onchange="update_color()"
/>
</div>
</div>
<!-- Plotly Chart -->
<script type="text/javascript">
window.PlotlyConfig = { MathJaxConfig: "local" };
var interval = setInterval(function () {
// Waits for OpenBBMain and plotly_figure to be defined before
// calling OpenBBMain to avoid errors
globals.cmd_src = "";
if (typeof OpenBBMain != "undefined" && window.plotly_figure) {
clearInterval(interval);
const date = new Date();
const formattedDate = new Intl.DateTimeFormat("en-GB", {
dateStyle: "full",
timeStyle: "long",
})
.format(date)
.replace(/:\d\d /, " ");
let filename = "";
let extension = "";
if (window.export_image != undefined) {
filename = window.export_image.split("/").pop();
extension = filename.split(".").pop().replace("jpg", "jpeg");
}
if (window.plotly_figure.layout.annotations != undefined) {
window.plotly_figure.layout.annotations.forEach(function (
annotation
) {
if (
annotation.text != undefined &&
!["svg", "pdf"].includes(extension)
) {
if (annotation.text[0] == "/") {
globals.cmd_src = annotation.text;
globals.cmd_idx =
window.plotly_figure.layout.annotations.indexOf(annotation);
annotation.text = "";
let margin = window.plotly_figure.layout.margin;
globals.old_margin = { ...margin };
if (margin.t != undefined && margin.t > 40) {
margin.t = 40;
}
margin.l = 70;
if (globals.cmd_src == "/stocks/candle") {
margin.r -= 40;
}
}
}
});
}
if (
globals.cmd_src != "" &&
window.plotly_figure?.posthog?.collect_logs
) {
posthog.capture("chart", {
INFO: {
command: globals.cmd_src,
title: window.plotly_figure.layout.title.text,
date: formattedDate,
python_version: window.plotly_figure.python_version,
pywry_version: window.plotly_figure.pywry_version,
terminal_version: window.plotly_figure.terminal_version,
},
});
}
document
.querySelector('meta[name="color-scheme"]')
.setAttribute(
"content",
window.plotly_figure.layout.template.layout.mapbox.style
);
let title =
window.plotly_figure?.layout?.title?.text ?? "Interactive Chart";
globals.title = title;
if (title.length > 50) {
document.getElementById("title").style.fontSize = "12px";
}
let style = "font-size: 12px; font-weight: 400; color: gray;";
document.getElementById("date").innerHTML =
formattedDate +
`<br /><span style="${style}">${globals.cmd_src}</span>`;
document.getElementById("title").innerHTML = title;
CHART_DIV = document.getElementById("openbb_chart");
CSV_DIV = document.getElementById("popup_csv");
TEXT_DIV = document.getElementById("popup_text");
TITLE_DIV = document.getElementById("popup_title");
DOWNLOAD_DIV = document.getElementById("popup_download");
OpenBBMain(
window.plotly_figure,
CHART_DIV,
CSV_DIV,
TEXT_DIV,
TITLE_DIV,
DOWNLOAD_DIV
);
}
}, 20);
</script>
</body>
</html>