从美人鱼导出为图像(甘特图)

Exporting as image from mermaid (Gantt)

我在尝试将甘特图导出为 png 或任何其他图像格式时遇到问题。 RStudio 中的查看器向我展示了甘特图的呈现。它还为我提供了另存为图像的选项,但我发现放大时图像非常像素化。

这是我试过的方法,但是文件在 运行 之后变成空的:

    library(DiagrammeR)
    m1<-mermaid("
      gantt
      dateFormat MM/DD/YY
      title Example Gantt

      section Example Section
      Process1 :done, task_1, 01/01/01, 01/05/01
      Process2 :done, task_2, 02/01/02, 02/05/02
      Process3 :done, task_3, 03/01/03, 03/05/03
    ")
    m1$x$config = list(ganttConfig = list(
      axisFormatter = list(list(
        "%y" 
        ,htmlwidgets::JS(
          'function(d){ return d.getDay() }' 
        )
      ))
    ))
    png("Example.png")
    m1
    dev.off()

这是在 运行 从 R 控制台执行 m1 对象时创建的代码。我在 SO 查看 window 中没有看到图像,但很抱歉,因为我不是该设施的特别知识渊博的用户。您可以在浏览器中查看它,这是 RSudio 提供的,它可以放大到浏览器限制,然后屏幕截图将不会被像素化:

<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.3.8/d3.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script src="lib/htmlwidgets-0.5/htmlwidgets.js"></script>
<script src="lib/d3-3.3.8/d3.min.js"></script>
<script src="lib/dagre-0.4.0/dagre-d3.min.js"></script>
<link href="lib/mermaid-0.3.0/dist/mermaid.css" rel="stylesheet" />
<script src="lib/mermaid-0.3.0/dist/mermaid.slim.min.js"></script>
<link href="lib/DiagrammeR-styles-0.2/styles.css" rel="stylesheet" />
<script src="lib/chromatography-0.1/chromatography.js"></script>
<script src="lib/DiagrammeR-binding-0.8.1/DiagrammeR.js"></script>

</head>
<body style="background-color:white;">
<div id="htmlwidget_container">
  <div id="htmlwidget-2084" style="width:960px;height:500px;" class="DiagrammeR"></div>
</div>
<script type="application/json" data-for="htmlwidget-2084">{"x":{"diagram":"\n      gantt\n      dateFormat MM/DD/YY\n      title Example Gantt\n\n      section Example Section\n      Process1 :done, task_1, 01/01/01, 01/05/01\n      Process2 :done, task_2, 02/01/02, 02/05/02\n      Process3 :done, task_3, 03/01/03, 03/05/03\n    ","config":{"ganttConfig":{"axisFormatter":[["%y","function(d){ return d.getDay() }"]]}}},"evals":["config.ganttConfig.axisFormatter.0.1"]}</script>
<script type="application/htmlwidget-sizing" data-for="htmlwidget-2084">{"viewer":{"width":450,"height":350,"padding":15,"fill":true},"browser":{"width":960,"height":500,"padding":40,"fill":false}}</script>
</body>
</html>