Implement possibility of choosing git graph rendering algorithm
See original GitHub issueIs your feature request related to a problem? Please describe.
I was analysing the problem mentioned in feature request https://github.com/nicoespeon/gitgraph.js/issues/290 and I realised this is bigger change and demands more discussion and proper planning and design so I decided to open a proper feature proposal issue.
Briefly for those unfamiliar with https://github.com/nicoespeon/gitgraph.js/issues/290, every time we branch a new column gets assigned to new branch even if there is available space. For projects with many short-lived branches layout grows really large pretty quickly. I prepared an example that demonstrates it pretty clearly:

Describe the solution you’d like
I came across the article commit graph drawing algorithms by @pvigier the developer of Gitamine who written a master thesis about this subject.
It appears like the process of rendering git graph consists of three steps
- finding appropriate order of commits (
x-coordinate
of each commits) - finding appropriate column (compute
y-coordinates
) - optimise the layout
I propose to isolate those steps and implement separate functions for them so that user can select which algorithm would like to use
const options = {
"sorting": "topological",
"algorithm": "curved",
"optimisation": "all-nodes-and-all-edges"
}
that gives full customisation regarding the output layout, for less advanced users who would want to replicate the behaviour of their favourite software we could prepare pre-defined layout, each consisting of sorting and column order algorithm and eventual optimisation, such as
const options = {
"layout": "SourceTree"
}
would replicate the output as similar to SourceTree as we can reproduce
the disadvantage is, there would be a lot of code to take into account all those algorithms and possibly not enough contributors to implement all of those, so I also suggest and alternative solution
Describe alternatives you’ve considered
We could also adapt some code from Gitamine which is GPL-3.0 licenced, I briefly researched it and it looks like it is possible to include GPL-3.0 code in MIT licence project as stated here.
My alternative proposal is to still abstract out part of the code that assigns order to columns and keep the layout
option proposed earlier as
const options = {
"layout": "gitamine"
}
would use the Gitamine-based algorithm and
const options = {
"layout": "regular"
}
would render everything exactly as it is now, also regular
would be the default value so update would not break backwards compatibility and in the future we could consider using different layout as default if community demands it.
Additional context
I attach some figures from article by @pvigier, they demonstrate quite nicely the possible variety of layouts.
Also, I’d like to mention that I already forked and briefly researched the source and if there would be positive feedback on proposal I’ll be happy to discuss techy details based on my notes and I can take care of the implementation.
I’d like to mention that the adapted algorithm by @pvigier I would commit separately and set him as the author of that commit.
![]() |
![]() |
---|---|
![]() |
![]() |
![]() |
![]() |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:13 (3 by maintainers)
Hi,
If you need my code to be under MIT license, I can change the license. And if you need more information concerning the algorithm, I can help.
Best, Pierre
Hi,
I’m also interested in such a feature, not a configurable graph-rendering algorithm as suggested by @marekyggdrasil , but at least a fix that addresses the one-column-can-have-only-one-branch problem.
Best regards jl