Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to use custom graphviz implementation #2009

Merged
merged 2 commits into from
Dec 16, 2024

Conversation

PavelTurk
Copy link

Fixes #2008

@PavelTurk
Copy link
Author

I've checked with JPMS service. In module-info I added:

provides net.sourceforge.plantuml.dot.Graphviz with com.foo.TempGraphviz;

and my service provider was called.

@arnaudroques
Copy link
Contributor

That's a nice move. I'm curious to see where this takes us :-)

However, I suggest that we work on a dedicated branch for this https://github.com/plantuml/plantuml/tree/custom_graphviz

Could you please update your pull request accordingly?

@PavelTurk PavelTurk changed the base branch from master to custom_graphviz December 16, 2024 13:53
@PavelTurk
Copy link
Author

Could you please update your pull request accordingly?

Done.

@arnaudroques arnaudroques merged commit 8776a4a into plantuml:custom_graphviz Dec 16, 2024
10 checks passed
@arnaudroques
Copy link
Contributor

com.foo.TempGraphviz;

Are you considering committing this (or other classes) to the codebase?

@PavelTurk
Copy link
Author

Are you considering committing this (or other classes) to the codebase?

No, we will create our own project that uses graphviz-java, but it will be under ASL. The reason is that we don’t want to be tied to PlantUML and prefer to make releases whenever we need.

But that’s exactly the beauty of the solution I’m proposing. From now on, everyone will be able to use PlantUML with the specific version of Graphviz that suits them. Isn’t that wonderful and doesn’t it provide incredible flexibility to PlantUML?

For example, we are working on a program that draws graphs. Everyone who downloads the program should have the ability to use this feature. Of course, telling everyone to install a specific Graphviz version isn’t a great approach. We tried Smetana, but it has some unpleasant bugs. Today, I tested ELK and PlantUML/Vizjs. Vizjs threw a bunch of errors. ELK worked, but the results are still not as good as with Graphviz. That’s why we decided to use graphviz-java.

@arnaudroques
Copy link
Contributor

No, we will create our own project that uses graphviz-java, but it will be under ASL.

Understood, no problem. Tell us when you will have an URL for this project!

The reason is that we don’t want to be tied to PlantUML and prefer to make releases whenever we need.

That makes perfect sense.

But that’s exactly the beauty of the solution I’m proposing. From now on, everyone will be able to use PlantUML with the specific version of Graphviz that suits them. Isn’t that wonderful and doesn’t it provide incredible flexibility to PlantUML?

Absolutely! We’re ready to merge your pull request into the main branch. However, I do have a concern. The interface net.sourceforge.plantuml.dot.Graphviz is not particularly well-designed at the moment. It is subject to changes in the future, which could potentially break your integration.

On a related note, we’ve been considering refactoring parts of our code to make it cleaner. Specifically, we might take advantage of java.util.ServiceLoader to improve some of our existing implementations.

For example, we are working on a program that draws graphs. Everyone who downloads the program should have the ability to use this feature. Of course, telling everyone to install a specific Graphviz version isn’t a great approach. We tried Smetana, but it has some unpleasant bugs. Today, I tested ELK and PlantUML/Vizjs. Vizjs threw a bunch of errors. ELK worked, but the results are still not as good as with Graphviz. That’s why we decided to use graphviz-java.

Thanks for sharing! Since we’re on the topic of Graphviz implementations, you might want to explore https://github.com/jamisonjiang/graph-support
It’s a minimalist Graphviz re-implementation in pure Java with almost no external dependencies. This might be worth considering for your use case.

@PavelTurk
Copy link
Author

Understood, no problem. Tell us when you will have an URL for this project!

Ok. But I will do it firstly as simple as possible, trying to spend minimum time.The main thing is that it does what we need

Absolutely! We’re ready to merge your pull request into the main branch. However, I do have a concern. The interface net.sourceforge.plantuml.dot.Graphviz is not particularly well-designed at the moment. It is subject to changes in the future, which could potentially break your integration.

Yes, I've also noticed that there are some things to discuss, for example, graphviz244onWindows(), as I understand.
However, If you later modify this interface it is not problem and in Service world it can happen.This is the responsibility of the person who assembles the binary distribution.

Now, I am thinking - maybe it is better to load not Graphviz, but GraphvizFactory. I think it will provide more flexibility. I mean:

Iterator<GraphvizFactory> iterator = ServiceLoader.load(GraphvizFactory.class).iterator();
if (iterator.hasNext()) {
    Graphviz graphviz = iterator.next().create();
    Log.info("Using service provider " + graphviz.getClass().getName());
    return graphviz;
}

What do you think? I can make PR.

On a related note, we’ve been considering refactoring parts of our code to make it cleaner. Specifically, we might take advantage of java.util.ServiceLoader to improve some of our existing implementations.

I absolute don't know PlantUML from developer side (I am only PlantUML user), but in our projects we use JPMS and JPMS services. We separate API from IMPL on module level and it works fine. For example, see our small library - ansi4j

Thanks for sharing! Since we’re on the topic of Graphviz implementations, you might want to explore https://github.com/jamisonjiang/graph-support It’s a minimalist Graphviz re-implementation in pure Java with almost no external dependencies. This might be worth considering for your use case.

Thank you for your wonderful project. I like Smetana and I am sure that with time it will be as good as graphviz.

Thank you for your suggestion about graph-support. I know this project and even opened several issues. It is very good that new java libraries related to graph generation are emerging

@arnaudroques
Copy link
Contributor

Now, I am thinking - maybe it is better to load not Graphviz, but GraphvizFactory. I think it will provide more flexibility. I mean:

Iterator<GraphvizFactory> iterator = ServiceLoader.load(GraphvizFactory.class).iterator();
if (iterator.hasNext()) {
    Graphviz graphviz = iterator.next().create();
    Log.info("Using service provider " + graphviz.getClass().getName());
    return graphviz;
}

What do you think? I can make PR.

Yes, this does seem like a more flexible and improved solution.
Please feel free to create a new PR or update the current one. We look forward to reviewing your contribution!

graphviz244onWindows()

This is quite outdated at this point and should probably be removed entirely.
We’ll handle the removal, but we’d prefer to wait for your PR first to streamline the process.

arnaudroques added a commit that referenced this pull request Dec 17, 2024
…2013)

* Add possibility to use custom graphviz implementation (#2009)

* Add possibility to create Graphviz instance using service factory (#2012)

---------
Authored-by: PavelTurk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add possibility to use custom graphviz implementation
2 participants