nicoespeon / gitgraph.js

[ARCHIVED] A JavaScript library to draw pretty git graphs in the browser
https://www.nicoespeon.com/gitgraph.js
MIT License
3.02k stars 362 forks source link

How to properly draw a gitgraph and regard the order? #400

Closed MMcKester closed 2 months ago

MMcKester commented 3 years ago

This is a support question, please excuse me, if this is not the right channel. I have a custom but plain JSON hierarchy of commits in the following format:

commits: [
    {hash: "076be...", message: "Hello World", parent: "1234..."),
    {hash: "...", message: "Hello World", parent: "076be..."),
],
refs: ["1234...", "076be..."]

I tried now a variety of possibilities but can't find a way to properly draw the right graph. 1) I tried to collect all commits to sort with commit time, but that might lose the connection to which branch the commit belongs. 2) I tried to iterate all over all branches, and from then backwards through the parents and skip every commit that is already drawn in the graph.

In either case, I get weird representations of the graph. Am I missing something fundamental here? What is the best and easiest way to render the graph dynamically? Could anyone help out?

P.S. Is there a way to get access to an already "drawn" commit object and to call branch(...) on this? Currently all graph functions return this, so I always append a new commit to the end. If I instead can locate a commit and branch off from there, that would help a lot