mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
Hotfix/ Candle --log (#5039)
* init... might break stuff * fix * clean up * check if array for color keys
This commit is contained in:
327
frontend-components/plotly/src/App.tsx
vendored
327
frontend-components/plotly/src/App.tsx
vendored
@@ -19,185 +19,186 @@ declare global {
|
||||
}
|
||||
|
||||
function App() {
|
||||
const [data, setData] = useState(
|
||||
process.env.NODE_ENV === "production" ? null : candlestickMockup
|
||||
);
|
||||
const [options, setOptions] = useState({});
|
||||
const [data, setData] = useState(
|
||||
process.env.NODE_ENV === "production" ? null : candlestickMockup,
|
||||
);
|
||||
const [options, setOptions] = useState({});
|
||||
|
||||
useEffect(() => {
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
const interval = setInterval(() => {
|
||||
if (window.json_data) {
|
||||
const data = window.json_data;
|
||||
console.log(data);
|
||||
setData(data);
|
||||
clearInterval(interval);
|
||||
}
|
||||
}, 100);
|
||||
return () => clearInterval(interval);
|
||||
}
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
const interval = setInterval(() => {
|
||||
if (window.json_data) {
|
||||
const data = window.json_data;
|
||||
console.log(data);
|
||||
setData(data);
|
||||
clearInterval(interval);
|
||||
}
|
||||
}, 100);
|
||||
return () => clearInterval(interval);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const transformData = (data: any) => {
|
||||
if (!data) return null;
|
||||
let globals = {
|
||||
added_traces: [],
|
||||
csv_yaxis_id: null,
|
||||
cmd_src_idx: null,
|
||||
cmd_idx: null,
|
||||
cmd_src: "",
|
||||
old_margin: null,
|
||||
title: "",
|
||||
};
|
||||
let filename = data.layout?.title?.text
|
||||
.replace(/ -/g, "")
|
||||
.replace(/-/g, "")
|
||||
.replace(/<b>|<\/b>/g, "")
|
||||
.replace(/ /g, "_");
|
||||
let date = new Date().toISOString().slice(0, 10).replace(/-/g, "");
|
||||
let time = new Date().toISOString().slice(11, 19).replace(/:/g, "");
|
||||
window.title = `openbb_${filename}_${date}_${time}`;
|
||||
const transformData = (data: any) => {
|
||||
if (!data) return null;
|
||||
const globals = {
|
||||
added_traces: [],
|
||||
csv_yaxis_id: null,
|
||||
cmd_src_idx: null,
|
||||
cmd_idx: null,
|
||||
cmd_src: "",
|
||||
old_margin: null,
|
||||
title: "",
|
||||
};
|
||||
const filename = data.layout?.title?.text
|
||||
.replace(/ -/g, "")
|
||||
.replace(/-/g, "")
|
||||
.replace(/<b>|<\/b>/g, "")
|
||||
.replace(/ /g, "_");
|
||||
const date = new Date().toISOString().slice(0, 10).replace(/-/g, "");
|
||||
const time = new Date().toISOString().slice(11, 19).replace(/:/g, "");
|
||||
window.title = `openbb_${filename}_${date}_${time}`;
|
||||
|
||||
if (data.layout.annotations != undefined) {
|
||||
data.layout.annotations.forEach(function (annotation) {
|
||||
if (annotation.text != undefined)
|
||||
if (annotation.text[0] == "/") {
|
||||
globals.cmd_src = annotation.text;
|
||||
globals.cmd_idx = data.layout.annotations.indexOf(annotation);
|
||||
annotation.text = "";
|
||||
if (data.layout.annotations !== undefined) {
|
||||
data.layout.annotations.forEach(function (annotation) {
|
||||
if (annotation.text !== undefined)
|
||||
if (annotation.text[0] === "/") {
|
||||
globals.cmd_src = annotation.text;
|
||||
globals.cmd_idx = data.layout.annotations.indexOf(annotation);
|
||||
annotation.text = "";
|
||||
|
||||
let margin = data.layout.margin;
|
||||
globals.old_margin = { ...margin };
|
||||
if (margin.t != undefined && margin.t > 40) margin.t = 40;
|
||||
const margin = data.layout.margin;
|
||||
globals.old_margin = { ...margin };
|
||||
if (margin.t !== undefined && margin.t > 40) margin.t = 40;
|
||||
|
||||
if (data.cmd == "/stocks/candle") margin.r -= 50;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (data.cmd === "/stocks/candle") margin.r -= 50;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// We add spaces to all trace names, due to Fira Code font width issues
|
||||
// to make sure that the legend is not cut off
|
||||
data.data.forEach(function (trace) {
|
||||
if (trace.name != undefined) {
|
||||
const name_length = trace.name.length;
|
||||
trace.name = trace.name + " ";
|
||||
trace.hoverlabel = {
|
||||
namelength: name_length,
|
||||
};
|
||||
}
|
||||
});
|
||||
// We add spaces to all trace names, due to Fira Code font width issues
|
||||
// to make sure that the legend is not cut off
|
||||
data.data.forEach(function (trace) {
|
||||
if (trace.name !== undefined) {
|
||||
const name_length = trace.name.length;
|
||||
trace.name = `${trace.name} `;
|
||||
trace.hoverlabel = {
|
||||
namelength: name_length,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
let title = data.layout?.title?.text || "Interactive Chart";
|
||||
globals.title = title;
|
||||
return {
|
||||
data: data,
|
||||
date: new Date(),
|
||||
globals: globals,
|
||||
cmd: data.command_location,
|
||||
posthog: data.posthog,
|
||||
python_version: data.python_version,
|
||||
pywry_version: data.pywry_version,
|
||||
terminal_version: data.terminal_version,
|
||||
theme: data.theme,
|
||||
title,
|
||||
};
|
||||
};
|
||||
const title = data.layout?.title?.text || "Interactive Chart";
|
||||
globals.title = title;
|
||||
return {
|
||||
data: data,
|
||||
date: new Date(),
|
||||
globals: globals,
|
||||
cmd: data.command_location,
|
||||
posthog: data.posthog,
|
||||
python_version: data.python_version,
|
||||
pywry_version: data.pywry_version,
|
||||
terminal_version: data.terminal_version,
|
||||
theme: data.theme,
|
||||
title,
|
||||
};
|
||||
};
|
||||
|
||||
const transformedData = transformData(data);
|
||||
const transformedData = transformData(data);
|
||||
|
||||
if (transformedData) {
|
||||
if (transformedData.posthog.collect_logs && !options) {
|
||||
const opts = {
|
||||
api_host: "https://app.posthog.com",
|
||||
autocapture: {
|
||||
css_selector_allowlist: [".ph-capture"],
|
||||
},
|
||||
capture_pageview: false,
|
||||
loaded: function (posthog: any) {
|
||||
const log_id = transformedData?.log_id || "";
|
||||
if (transformedData) {
|
||||
if (transformedData.posthog.collect_logs && !options) {
|
||||
const opts = {
|
||||
api_host: "https://app.posthog.com",
|
||||
autocapture: {
|
||||
css_selector_allowlist: [".ph-capture"],
|
||||
},
|
||||
capture_pageview: false,
|
||||
loaded: function (posthog: any) {
|
||||
const log_id = transformedData?.log_id || "";
|
||||
|
||||
if (log_id != "" && log_id != "REPLACE_ME") posthog.identify(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();
|
||||
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();
|
||||
});
|
||||
},
|
||||
};
|
||||
setOptions(opts);
|
||||
}
|
||||
if (
|
||||
!posthog.isFeatureEnabled("collect-logs-pywry", {
|
||||
send_event: false,
|
||||
})
|
||||
)
|
||||
posthog.opt_out_capturing();
|
||||
else if (posthog.has_opted_out_capturing())
|
||||
posthog.opt_in_capturing();
|
||||
});
|
||||
},
|
||||
};
|
||||
setOptions(opts);
|
||||
}
|
||||
|
||||
const info = {
|
||||
INFO: {
|
||||
command: transformedData.cmd,
|
||||
title: transformedData.title,
|
||||
date: transformedData.date,
|
||||
python_version: transformedData.python_version,
|
||||
pywry_version: transformedData.pywry_version,
|
||||
terminal_version: transformedData.terminal_version,
|
||||
},
|
||||
};
|
||||
const info = {
|
||||
INFO: {
|
||||
command: transformedData.cmd,
|
||||
title: transformedData.title,
|
||||
date: transformedData.date,
|
||||
python_version: transformedData.python_version,
|
||||
pywry_version: transformedData.pywry_version,
|
||||
terminal_version: transformedData.terminal_version,
|
||||
},
|
||||
};
|
||||
|
||||
const chartDiv = (
|
||||
<Chart
|
||||
json={transformedData.data}
|
||||
date={transformedData.date}
|
||||
cmd={transformedData.cmd}
|
||||
title={transformedData.title}
|
||||
globals={transformedData.globals}
|
||||
theme={transformedData.theme}
|
||||
info={info}
|
||||
/>
|
||||
);
|
||||
const chartDiv = (
|
||||
<Chart
|
||||
json={transformedData.data}
|
||||
date={transformedData.date}
|
||||
cmd={transformedData.cmd}
|
||||
title={transformedData.title}
|
||||
globals={transformedData.globals}
|
||||
theme={transformedData.theme}
|
||||
info={info}
|
||||
/>
|
||||
);
|
||||
|
||||
if (transformedData.posthog.collect_logs && options) {
|
||||
return (
|
||||
<PostHogProvider
|
||||
apiKey="phc_vhssDAMod5qIplznQ75Kdgz4aB1qPFmeVmfEOZ4hkRw"
|
||||
options={options}
|
||||
>
|
||||
{chartDiv}
|
||||
</PostHogProvider>
|
||||
);
|
||||
}
|
||||
if (transformedData.posthog.collect_logs && options) {
|
||||
return (
|
||||
<PostHogProvider
|
||||
apiKey="phc_vhssDAMod5qIplznQ75Kdgz4aB1qPFmeVmfEOZ4hkRw"
|
||||
options={options}
|
||||
>
|
||||
{chartDiv}
|
||||
</PostHogProvider>
|
||||
);
|
||||
}
|
||||
|
||||
return chartDiv;
|
||||
} else
|
||||
return (
|
||||
<div className="absolute inset-0 flex items-center justify-center z-[100]">
|
||||
<svg
|
||||
className="animate-spin h-20 w-20 text-white"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<circle
|
||||
className="opacity-25"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
stroke="currentColor"
|
||||
strokeWidth="4"
|
||||
></circle>
|
||||
<path
|
||||
className="opacity-75"
|
||||
fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8v8z"
|
||||
></path>
|
||||
</svg>
|
||||
</div>
|
||||
);
|
||||
return chartDiv;
|
||||
} else
|
||||
return (
|
||||
<div className="absolute inset-0 flex items-center justify-center z-[100]">
|
||||
<svg
|
||||
className="animate-spin h-20 w-20 text-white"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<circle
|
||||
className="opacity-25"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
stroke="currentColor"
|
||||
strokeWidth="4"
|
||||
/>
|
||||
<path
|
||||
className="opacity-75"
|
||||
fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8v8z"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
|
||||
1101
frontend-components/plotly/src/components/Chart.tsx
vendored
1101
frontend-components/plotly/src/components/Chart.tsx
vendored
File diff suppressed because it is too large
Load Diff
24967
frontend-components/plotly/src/data/mockup.ts
vendored
24967
frontend-components/plotly/src/data/mockup.ts
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user