This commit is contained in:
teh_coderer
2023-05-03 10:39:13 -04:00
parent 5f5a75248d
commit 1e18dd0b9b
5 changed files with 123 additions and 107 deletions

View File

@@ -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) {

View File

@@ -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);
},
},

View File

@@ -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;

View File

@@ -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);
}
}

File diff suppressed because one or more lines are too long