mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-26 19:22:23 +00:00
updates
This commit is contained in:
@@ -14,6 +14,7 @@ import autoScaling from "./AutoScaling";
|
||||
import { non_blocking, saveImage } from "../utils/utils";
|
||||
import ResizeHandler from "./ResizeHandler";
|
||||
import ChangeColor from "./ChangeColor";
|
||||
import clsx from "clsx";
|
||||
|
||||
const Plot = createPlotlyComponent(Plotly);
|
||||
|
||||
@@ -54,6 +55,7 @@ export default function Chart({
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [plotDiv, setPlotDiv] = useState(null);
|
||||
const [volumeBars, setVolumeBars] = useState({ old_nticks: {} });
|
||||
const [maximizePlot, setMaximizePlot] = useState(false);
|
||||
|
||||
const [plotData, setPlotData] = useState(json);
|
||||
const [annotations, setAnnotations] = useState([]);
|
||||
@@ -338,7 +340,11 @@ export default function Chart({
|
||||
}
|
||||
|
||||
window.addEventListener("resize", async function () {
|
||||
let update = await ResizeHandler({ plotData, volumeBars });
|
||||
let update = await ResizeHandler({
|
||||
plotData,
|
||||
volumeBars,
|
||||
setMaximizePlot,
|
||||
});
|
||||
let layout_update = update.layout_update;
|
||||
let newPlotData = update.plotData;
|
||||
let volume_update = update.volume_update;
|
||||
@@ -445,7 +451,12 @@ export default function Chart({
|
||||
</p>
|
||||
)} */}
|
||||
</div>
|
||||
<div className="w-full h-[calc(100%-50px)] sm:pb-12">
|
||||
<div
|
||||
className={clsx("w-full sm:pb-12", {
|
||||
"h-[calc(100%-10px)]": maximizePlot,
|
||||
"h-[calc(100%-50px)]": !maximizePlot,
|
||||
})}
|
||||
>
|
||||
<Plot
|
||||
onInitialized={() => {
|
||||
if (!plotDiv) {
|
||||
|
||||
@@ -109,7 +109,6 @@ export function PlotConfig({
|
||||
name: "Download CSV (Ctrl+Shift+S)",
|
||||
icon: ICONS.downloadCsv,
|
||||
click: async function (gd: any) {
|
||||
setModal({ name: "downloadCsv" });
|
||||
await downloadCSV(gd);
|
||||
},
|
||||
},
|
||||
|
||||
@@ -4,10 +4,12 @@ import { hideModebar } from "./PlotlyConfig";
|
||||
|
||||
export default async function ResizeHandler({
|
||||
plotData,
|
||||
Volume,
|
||||
volumeBars,
|
||||
setMaximizePlot
|
||||
}: {
|
||||
plotData: Figure;
|
||||
Volume: any;
|
||||
volumeBars: any;
|
||||
setMaximizePlot: (value: boolean) => void;
|
||||
}) {
|
||||
// We hide the modebar and set the number of ticks to 5
|
||||
const XAXIS = Object.keys(plotData.layout)
|
||||
@@ -19,12 +21,12 @@ export default async function ResizeHandler({
|
||||
);
|
||||
|
||||
let layout_update: any = {};
|
||||
let volume: any = Volume || { old_nticks: {} };
|
||||
let volume: any = volumeBars || { old_nticks: {} };
|
||||
|
||||
const width = window.innerWidth;
|
||||
const height = window.innerHeight;
|
||||
let tick_size =
|
||||
height > 420 && width < 920 ? 9 : height > 420 && width < 500 ? 10 : 8;
|
||||
height > 420 && width < 920 ? 8 : height > 420 && width < 500 ? 9 : 7;
|
||||
|
||||
if (width < 750) {
|
||||
// We hide the modebar and set the number of ticks to 5
|
||||
@@ -33,7 +35,7 @@ export default async function ResizeHandler({
|
||||
if (trace.type == "bar") {
|
||||
trace.opacity = 1;
|
||||
trace.marker.line.width = 0.09;
|
||||
if (Volume.yaxis == undefined) {
|
||||
if (volumeBars.yaxis == undefined) {
|
||||
volume.yaxis = "yaxis" + trace.yaxis.replace("y", "");
|
||||
layout_update[volume.yaxis + ".tickfont.size"] = tick_size;
|
||||
volume.tickfont = plotData.layout[volume.yaxis].tickfont || {};
|
||||
@@ -48,12 +50,15 @@ export default async function ResizeHandler({
|
||||
volume.old_nticks[x] = plotData.layout[x].nticks || 10;
|
||||
}
|
||||
});
|
||||
setMaximizePlot(true);
|
||||
|
||||
await hideModebar();
|
||||
} else if (window.MODEBAR.style.cssText.includes("display: none")) {
|
||||
// We show the modebar
|
||||
await hideModebar(false);
|
||||
setMaximizePlot(false);
|
||||
|
||||
if (Volume.old_nticks != undefined) {
|
||||
if (volumeBars.old_nticks != undefined) {
|
||||
XAXIS.forEach((x) => {
|
||||
if (volume.old_nticks[x] != undefined) {
|
||||
layout_update[x + ".nticks"] = volume.old_nticks[x];
|
||||
@@ -62,7 +67,7 @@ export default async function ResizeHandler({
|
||||
});
|
||||
}
|
||||
|
||||
if (Volume.yaxis != undefined) {
|
||||
if (volumeBars.yaxis != undefined) {
|
||||
TRACES.forEach((trace) => {
|
||||
if (trace.type == "bar") {
|
||||
trace.opacity = 0.5;
|
||||
|
||||
@@ -144,7 +144,7 @@ export async function downloadCSV(gd: Figure) {
|
||||
if (columns.length == 0) {
|
||||
columns.push(xaxis);
|
||||
}
|
||||
columns.push(trace.name);
|
||||
columns.push(trace.name != undefined ? trace.name : yaxis);
|
||||
trace.x.forEach(function (x, i) {
|
||||
if (rows[i] == undefined) {
|
||||
rows[i] = [x];
|
||||
@@ -327,6 +327,7 @@ export async function downloadImage(
|
||||
const filename = `${window.title}.png`;
|
||||
|
||||
try {
|
||||
loading(true);
|
||||
let fileHandle = await getNewFileHandle({
|
||||
filename: filename,
|
||||
is_image: true,
|
||||
@@ -336,7 +337,6 @@ export async function downloadImage(
|
||||
// @ts-ignore
|
||||
extension = fileHandle.name.split(".").pop();
|
||||
}
|
||||
loading(true);
|
||||
await loadingOverlay(`Saving ${extension.toUpperCase()}`);
|
||||
|
||||
if (["svg", "pdf"].includes(extension)) {
|
||||
@@ -351,12 +351,13 @@ export async function downloadImage(
|
||||
saveToFile(blob, filename, fileHandle).then(async function () {
|
||||
await loadingOverlay("", true);
|
||||
hidemodebar(false);
|
||||
loading(false);
|
||||
});
|
||||
});
|
||||
}, 2)();
|
||||
loading(false);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
hidemodebar(false);
|
||||
loading(false);
|
||||
}
|
||||
}
|
||||
|
||||
188
openbb_terminal/core/plots/plotly.html
vendored
188
openbb_terminal/core/plots/plotly.html
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user