diff --git a/frontend-components/plotly/src/components/Chart.tsx b/frontend-components/plotly/src/components/Chart.tsx index 9a2525d75fd..f52acff397c 100644 --- a/frontend-components/plotly/src/components/Chart.tsx +++ b/frontend-components/plotly/src/components/Chart.tsx @@ -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({

)} */} -
+
{ if (!plotDiv) { diff --git a/frontend-components/plotly/src/components/PlotlyConfig.tsx b/frontend-components/plotly/src/components/PlotlyConfig.tsx index a42c13f62f8..60a04fcaeae 100644 --- a/frontend-components/plotly/src/components/PlotlyConfig.tsx +++ b/frontend-components/plotly/src/components/PlotlyConfig.tsx @@ -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); }, }, diff --git a/frontend-components/plotly/src/components/ResizeHandler.tsx b/frontend-components/plotly/src/components/ResizeHandler.tsx index 9262f6cf764..e2997905c1c 100644 --- a/frontend-components/plotly/src/components/ResizeHandler.tsx +++ b/frontend-components/plotly/src/components/ResizeHandler.tsx @@ -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; diff --git a/frontend-components/plotly/src/utils/utils.ts b/frontend-components/plotly/src/utils/utils.ts index ec2967ad880..56f195e8f87 100644 --- a/frontend-components/plotly/src/utils/utils.ts +++ b/frontend-components/plotly/src/utils/utils.ts @@ -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); } } diff --git a/openbb_terminal/core/plots/plotly.html b/openbb_terminal/core/plots/plotly.html index c54b1452874..3aec2d5a963 100644 --- a/openbb_terminal/core/plots/plotly.html +++ b/openbb_terminal/core/plots/plotly.html @@ -33,60 +33,60 @@ }