1

I would like to use GitGraph.js to generate some nice looking graphs for documentation of workflows. Therefor I need these graphs as png files.

My first attempt was to create a static html page, load the gitgraph.js, create the graph, load it browser and take a screenshot to save the result as png.

<html>
<head><script src="https://cdn.jsdelivr.net/npm/@gitgraph/js"></script></head>
<body>
  <div id="graph-container"></div>
  <script>
    const graphContainer = document.getElementById("graph-container");
    const gitgraph = GitgraphJS.createGitgraph(graphContainer);
    const master = gitgraph.branch("master");
    master.commit("Initial commit");
    master.commit("Second commit");
  </script>
</body>
</html>

Just to get the graph:

nice looking git graph

As these steps are painful work for more than one picture, I would like to do it automatically. In my dreams I have a file for each picture containing only the javascript code, e.g. graph_A.js:

const gitgraph = GitgraphJS.createGitgraph(graphContainer);
const master = gitgraph.branch("master");
master.commit("Initial commit");
master.commit("Second commit");

Next step is to call a batch script, press a button or execute a command in my favorite IDE (in this case Visual Studio Code) and after a few seconds I have a graph_A.png with the result as shown above.

As I'm new to javascript can you give me some hints how to solve my problem? Any advice what kind of toolchain I can use?

Thank you very much in advance from a low level embedded C programmer ;-)

Bastian
  • 438
  • 4
  • 11

1 Answers1

1

That was requested in nicoespeon/gitgraph.js issue 183 (2018) and again with issue 375 (2020).

But this is outside the scope of the nicoespeon/gitgraph.js library, so you will have to include a third party screenshot utility like html2canvas used here.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250