tclh123 / commits-graph

Git commits graph widget using HTML5/Canvas.
http://oct.tclh123.com/commits-graph/
226 stars 30 forks source link

Document input format #4

Closed marnen closed 6 years ago

marnen commented 8 years ago

I recently had occasion to try to make this into a Chrome extension (so I wouldn't have been able to use the Python script). Unfortunately, the input format is unclear and seems to be undocumented, so I wasn't able to figure it out. This tool draws beautiful graphs, but it's hard to work with if the input format is undocumented.

trexshw commented 7 years ago

Hi Marnen,

It's been a while for this question and I'm not sure if you have figured this out eventually. I reached this project when I was looking for a simple tool to visualise my Git project. I'll try to answer your question in case someone else come to this as well.

What's the input format?

The graph data is composed of an array of nodes. As documented in the _commitsgraphy.py, each node is formatted as follows: [ sha, //commit hash [offest, branch], // Dot - x-axis offset position and branch it belongs to [ [from, to, branch], // Route 1 - The x-axis position from and to, and its corresponding branch [from, to, branch], // Route 2 [from, to, branch], ] // Route array (branches) ]

How does the graph drawn?

Take a vertical graph as example. Let's call the rightest position as x-axis position 0. It loops through the node array and draws from the top, one level by one level. For each iteration,

  1. Draw a dot based on the x-axis offset position and color it based on the assigned branch color. For example, [1,2] will be drawn at position 1 and branch 2 color.
  2. Loop through the route array. For each route, draw a line from its x position to the x position of its y+1 position.

In fact, to draw the branches properly, each node will need to draw other branches even though it does not belong to them. (Otherwise, you won't see the long line for a branch)

Let's use my git project's as example. The data is: [ commit1, [0,0], [[0,0,0]], commit2, [0,0], [[0,0,0], [0,1,1]], commit3, [1,1], [[0,0,0], [1,1,1], [1,2,2]], commit4, [0,0], [[0,0,0], [1,1,1], [2,2,2]], ... ]

//Node 1 Start

//Node 2 Start

//Node 3 Start

screen shot 2016-11-20 at 9 37 44 pm
tclh123 commented 6 years ago

https://github.com/tclh123/commits-graph/pull/5