gitgraph.js icon indicating copy to clipboard operation
gitgraph.js copied to clipboard

Add event handlers on whole commit line (vertical mode)

Open IsaacHub opened this issue 5 years ago • 14 comments

I want to build exactly as in this image, how can I achieve this?

Screenshot from 2019-04-10 18-42-52

Each and every row must hold an id and those must be clickable, and upon clicking it I need to console log the id of the row which was clicked.

Right now I have this:

gitgraph

IsaacHub avatar Apr 11 '19 08:04 IsaacHub

Hi @IsaacHub 👋

Interesting use case, thanks for providing the detailed screenshot.

First of all, I think you're still using the gitgraph.js package. This one has been deprecated and I'd suggest you to move to @gitgraph/js (or @gitgraph/react), if possible. There are breaking changes though, here's a guide that could help: https://github.com/nicoespeon/gitgraph.js/blob/master/packages/gitgraph-js/MIGRATE_FROM_GITGRAPH.JS.md

If you're stuck with v1, there's a onClick() option you could pass to each commit. But I'm not sure it would do exactly as you need.


Now, speaking about @gitgraph/js (or react) package, we provide different events handlers. For example, you can provide a onMessageClick() option that will execute when you click on the commit message part. Here's the list of the existing use-cases we support: https://github.com/nicoespeon/gitgraph.js/blob/master/packages/stories/src/gitgraph-js/3-events.stories.tsx

However, there's no event handler on the "line" as your screenshot suggest. Actually, there is no such lines in the current rendering. For the moment, this would be the best englobing target we would have:

image

As you can see, it doesn't regroup the line as you'd expect. Plus, there's no event handler on such group for the moment.

Would onMessageClick() be good enough for your use-case though?


I think it's an interesting use case though. I feel it wouldn't be too hard to add a line object in vertical mode that would allow to interact with the whole commit.

Especially to achieve the "hover" effect that looks quite neat to highlight a commit.

But it might be redundant with the existing handlers (onMessageClick() and onClick() especially). I would like to think about it twice before adding more handlers around.

What do you think @fabien0102?

nicoespeon avatar Apr 12 '19 01:04 nicoespeon

Yes! finally I have achieved it! I had to modify the svg-elements.ts and gitgraph.ts files inside gitgraph-js folder, of course I copied it from node_modules and put it in assets folder (angular project) and imported those files from here instead of node_modules.

The green highlight is the one I clicked and corresponding details will be shown on the right, and blue highlight is what I'm hovering, and all commits are generated from JSON, The drawback is whenever a new version of this library is released then I need to do these changes again, or don't update at all.

gitgraph_challenge

As you can see I have given id and class to identify the elements because all elements are <g> elements, and by putting id and class, it became easy to style. I achieved highlighting by creating <rect> element and attached to dom using .prepend() in the component file.

IsaacHub avatar Aug 06 '19 13:08 IsaacHub

Wow, great job @IsaacHub, the result looks really nice 👏

Thanks for sharing. The idea of using id and classes to identify the DOM element is a good idea indeed.

If you feel like it, don't hesitate to fork the source code and open a PR with your changes. Modulo some eventual improvements, it would be the best way for you to get this directly baked in the node_modules library, so you'd be able to update again 😉

nicoespeon avatar Aug 07 '19 11:08 nicoespeon

@IsaacHub would you share what you've done there? Looks fantastic and I'm trying to achieve the same thing on my app. Thanks!!

Danita avatar Mar 06 '20 19:03 Danita

@IsaacHub I'm also interested in that! Can you shed some light on that? Or @Danita can you share something also? Thanks!

xukez2 avatar Jun 04 '20 22:06 xukez2

I ended doing all drawing and interaction on my part and just using the library to draw the lines only.

Danita avatar Jun 04 '20 23:06 Danita

@IsaacHub Would love to see how you pulled this off. Mind sharing? I'm working on a project that has similar row selecting need and your contribution would be much appreciated.

levi217 avatar Jun 09 '20 15:06 levi217

@IsaacHub Bump. Would love to see this be a part of the gitgraph repo too. To make it easier on your part, I think we'd even be interested in just some snippets of code used to get here, even if some assembly is required.

levi217 avatar Jun 10 '20 12:06 levi217

Hate to be a bother @IsaacHub but it would be super cool if you could add some more color to this.

levi217 avatar Jun 11 '20 13:06 levi217

My implementation is just a Bootstrap list-group with sufficient left padding to make room, superimposed on the gitgraph generated graph, which is absolutely positioned inside a common container.

graph code

Danita avatar Jun 11 '20 13:06 Danita

Very nice @Danita Thanks for sharing. It looks like the next best thing. Although I bet you're having to sync the row height between the two. That makes me a little nervous especially with variable height line wrapping content in the list view but I suppose it could work.

levi217 avatar Jun 12 '20 13:06 levi217

@levi217 Yes, this limits you to having fixed height rows; but is the best I could get.

Danita avatar Jun 12 '20 14:06 Danita

I think an option to get this to work on @gitgraph/js is to wrap each commit rendered inside a <rect> that would take the whole space and could be styled: https://github.com/nicoespeon/gitgraph.js/blob/46a98c9f145224d0c41afb472b5580bc4644aaa1/packages/gitgraph-js/src/gitgraph.ts#L295

We might even be able to add specific classes depending if the commit is selected. That will allow people to override style using CSS.

nicoespeon avatar Jun 14 '20 13:06 nicoespeon

Hi :), any progress made?

inventivejon avatar Nov 04 '21 11:11 inventivejon