Skip to content

Commit

Permalink
tidy up types
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Nov 7, 2023
1 parent 1da61eb commit a7acc5a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 52 deletions.
46 changes: 14 additions & 32 deletions app/static/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 25 additions & 20 deletions app/static/src/app/components/mixins/downloadPlot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import {reactive, Ref, ref} from "vue";
import {Config, PlotlyDataLayoutConfig, RootOrData} from "plotly.js-basic-dist-min";
import * as Plotly from "plotly.js-basic-dist-min";
import { reactive, Ref, ref } from "vue";
import {
Config,
PlotlyDataLayoutConfig,
RootOrData,
Icons,
downloadImage as downloadPlotlyImage, DataTitle
} from "plotly.js-basic-dist-min";

export interface DownloadPlotMixin {
showDownloadImageModal: Ref<boolean>,
Expand All @@ -17,10 +22,10 @@ export default (): DownloadPlotMixin => {
const downloadImageProps = reactive({ title: "", xLabel: "", yLabel: "" });
const downloadImageClick = (gd: PlotlyDataLayoutConfig) => {
plotlyContext.value = gd;
const layout = gd.layout! as any;
downloadImageProps.title = layout.title || "";
downloadImageProps.xLabel = layout.xaxis.title?.text || "";
downloadImageProps.yLabel = layout.yaxis.title?.text || "";
const layout = gd.layout!;
downloadImageProps.title = layout.title as string || "";
downloadImageProps.xLabel = (layout.xaxis?.title as Partial<DataTitle | null>)?.text || "";
downloadImageProps.yLabel = (layout.yaxis?.title as Partial<DataTitle | null>)?.text || "";
showDownloadImageModal.value = true;
};
const closeModal = () => {
Expand All @@ -29,29 +34,29 @@ export default (): DownloadPlotMixin => {

const downloadImage = (title: string, xLabel: string, yLabel: string) => {
plotlyContext.value!.layout!.title = title;
(plotlyContext.value!.layout!.xaxis! as any).title = {text: xLabel};
(plotlyContext.value!.layout!.yaxis! as any).title = {text: yLabel};
Plotly.downloadImage(plotlyContext.value as RootOrData, {
plotlyContext.value!.layout!.xaxis!.title = { text: xLabel };
plotlyContext.value!.layout!.yaxis!.title = { text: yLabel };
downloadPlotlyImage(plotlyContext.value as RootOrData, {
filename: "WODIN plot",
format: "png",
width: (plotlyContext.value as any)._fullLayout.width,
height: (plotlyContext.value as any)._fullLayout.height
width: plotlyContext.value!.layout!.width!,
height: plotlyContext.value!.layout!.height!
});
};

const config = {
responsive: true,
modeBarButtons: [[{
name: "Download plot as a png",
icon: (Plotly as any).Icons.camera,
icon: Icons.camera,
click: downloadImageClick
},
"zoom2d",
"pan2d",
"zoomIn2d",
"zoomOut2d",
"autoScale2d",
"resetScale2d"]]
"zoom2d",
"pan2d",
"zoomIn2d",
"zoomOut2d",
"autoScale2d",
"resetScale2d"]]
} as Partial<Config>;

return {
Expand All @@ -62,4 +67,4 @@ export default (): DownloadPlotMixin => {
downloadImage,
config
};
};
};

0 comments on commit a7acc5a

Please sign in to comment.