如何从 dash 应用程序将全尺寸 cytoscape 图导出到图像?

问题描述 投票:0回答:1

我正在使用 python 的 Dash 库构建一个视觉故事绘图应用程序,其中使用 cytoscape 图来可视化场景(作为节点)以及它们之间的连接(作为边缘)。结果是一个具有各种编辑功能的交互式流程图。

我想为用户提供一个选项,将图形导出到图像文件(例如 png),然后他可以根据需要下载和使用该文件。

到目前为止,我设法创建了一个捕获屏幕上图表部分的过程,但这还不够,因为图表往往会变得比屏幕尺寸更大。用户可以缩小以将整个图表包含在屏幕中,但这会使图表的详细信息太小而没有帮助。

我的问题是:有没有办法将完整尺寸的完整图表导出为图像格式,而不仅仅是屏幕上的内容?我的意思是整个“画布”。

我已经尝试了此处描述的解决方案(https://www.linkedin.com/pulse/test-automation-how-capture-full-page-screenshots-selenium-nir-tal)来捕获完整的屏幕截图使用 selenium 的网页,但它对我也不起作用,因为图表的“画布”比网页和屏幕都大。

这是我现在用于捕获屏幕大小图像的代码:

@self.app.callback(
        Output("network", "generateImage"),
        Input('dashboard-export-project-button', 'n_clicks'),
        prevent_initial_call=True
        )
    def get_image(export_clicks):

        # Get the timezone
        local_tz = pytz.timezone('My Country')

        # Get the current time in UTC
        current_time_utc = datetime.utcnow()

        # Convert the UTC time to the Local timezone
        current_time = current_time_utc.replace(tzinfo=pytz.utc).astimezone(local_tz)

        time_stamp = current_time_local.strftime("%d/%m/%Y - %H:%M")

        # File type to output of 'svg, 'png', 'jpg', or 'jpeg' (alias of 'jpg')
        ftype = "png"

        # 'store': Stores the image data in 'imageData' !only jpg/png are supported
        # 'download'`: Downloads the image as a file with all data handling
        # 'both'`: Stores image data and downloads image as file.
        action = 'store'

        if ctx.triggered:
            if ctx.triggered_id == "dashboard-export-project-button":
                action = "download"

        return {
            'type': ftype,
            'action': action,
            'filename': f'{self.project.title} - {time_stamp}',
        }
python plotly-dash dash-cytoscape
1个回答
0
投票

在检查了一些选项后,发现如果您添加一个选项来设置每个屏幕截图的图形的高度和/或宽度,我上面发布的代码可以完美地完成工作。该代码捕获宽度-高度参数范围内的所有内容,无论图像是否完全显示在屏幕上。

© www.soinside.com 2019 - 2024. All rights reserved.