samwilson / diagrams-extension

A MediaWiki extension that displays GraphViz, Mscgen, PlantUML, and Mermaid diagrams in wiki pages.
https://www.mediawiki.org/wiki/Extension:Diagrams
GNU General Public License v2.0
8 stars 11 forks source link

Erratic behaviour of diagrams with URL #76

Closed alberto0723 closed 7 months ago

alberto0723 commented 1 year ago

The diagrams with URL in the nodes are properly created and stored in the diagrams directory with the active URLs. However, there is some weird behavior and sometimes the URLs are not recognized from the wiki page (although they are in the png or svg file). I associate this behavior to: 1) The existence of more than one diagram in the same wiki page 2) Modifying the page, but not the diagram (making some change in the diagram and recreating the file enables the URLs in the wiki again)

samwilson commented 1 year ago

Sounds like something wrong with the imagemap functionality.

Can you share an example of the wikitext for a diagram that this is happening with?

alberto0723 commented 1 year ago

Something simple like this already generates the problem. It is not related to the complexity of the graph.

<graphviz border='frame' format='svg'>
digraph MyDiagram {
  MyNode [label="Label", URL="#Section"];
}
</graphviz>

=Section=
This is some text that I change without modifying the graph.
alberto0723 commented 1 year ago

Not sure if this is the same problem, but looks related.

<graphviz border='frame' format='svg'>
digraph OneDiagram {
  MyNode [label="Label", URL="#Section"];
}
</graphviz>

<graphviz border='frame' format='svg'>
digraph AnotherDiagram {
  OtherNode [label="OtherLabel", URL="#Section"];}
</graphviz>

=Section=
The URL of the first graph never works.
samwilson commented 1 year ago

It looks like the imagemap data is not being cached at all.

tomzu commented 1 year ago

To me it rather looks that the imagemap will only work as long the page remains in the Parser Cache. See also my description the the Talk page of the extension under https://www.mediawiki.org/wiki/Topic:Xjluxsew16svfii6

samwilson commented 1 year ago

Yeah, that's right. I'm sorry I've been slow to work on this! I think the image map data should either be saved as a file as well, or saved to the wan cache (prob the latter, although I guess for large diagrams there could be a size issue).

tomzu commented 12 months ago

I implemented a solution for this, which stores the image map in a separate file in the LocalRepo also used for the diagram images.

My solution definitely needs an improvement: I was unable to find out how to correctly read contents of a file in the LocalRepo, so I statically added the file system path. I guess this is definitely the wrong way to do it, though it seems to work for my installation.

Anyway, I have no idea how to correctly create a pull request.

samwilson commented 12 months ago

If you want to just copy and past your work into a gist that'd be fine.

And you're right, the file path does need to be done via the FileRepo, otherwise it won't work for wikis using other repos (such as the AWS extension).

I've done a little bit of looking at this, and might have a fix for it.

samwilson commented 12 months ago

I think this is resolved now. Can you test with the latest, before I tag a release?

tomzu commented 12 months ago

Looks good to me, thanks a lot! (The bug I seemed to have found was my mistake, it really works well!)

samwilson commented 11 months ago

@tomzu great! I wonder if the bug you found was for an existing image where the first time round it failed to store the imagemap data, but then when you modified the graphviz code it rendered a new image and new data and so worked correctly?

I think a small improvement can be made to make it work in the former situation.

samwilson commented 7 months ago

I think all is good here now.

alberto0723 commented 7 months ago

Thanks a lot for the nice work!!!