Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Nested diagrams (Read 72 times)
Joel D.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 47
Location: Vancouver, Canada
Joined: Feb 6th, 2017
Nested diagrams
Oct 21st, 2026 at 12:00am
Print Post  
Hello. I would like some advice on the best way to go about nesting diagrams.

My app has multiple diagrams, each on their own UserControl and never more than one visible at a time. They tend to have dozens or possibly over a hundred nodes, all of which are TemplatedNodes (some that have fairly complex ControlTemplates), and many links between all of the nodes.

I want to create a new diagram that acts as an overview of the entire system and would therefore have nodes where each node is a view of one of the existing diagrams. There is no need for the child diagrams to accept mouse clicks when being viewed as a node on the overview diagram, however the child diagrams do have their nodes change colour depending on what the connected server is doing, and it would be nice for that to work on the overview diagram.

One way I tried to do this was to create a new Diagram instance, call LoadFromString() with the result from the child diagram's SaveToString(), go through all of the nodes to reattach the viewmodels, embed this new Diagram instance in a DiagramView, and place that in a simple TemplatedNode.  This seems to work, however I was having stability issues where exceptions were occurring in the MindFusion code (which I haven't investigated yet), especially if I tried to move around the nodes on the overview diagram.

Another way I tried was to call CreateImage() on the child diagram, and then use the resulting BitmapSource as the Source of an Image placed in a simple TemplatedNode, and then update the bitmap once per second to be able to catch the colour changing nodes.  Issues I found with this was that after a few minutes of calling CreateImage() once per second, eventually I received an OutOfMemoryException, and before receiving the exception, switching over to the original child diagram's UserControl I would notice that interacting with the original diagram was now incredible sluggish and would cause CPU usage spikes.  The CPU usage spikes could be solved by calling Clone() before CreateImage(), but then the resulting image would lose all of the ControlTemplates and the memory issue still occurred. Also, since CreateImage() must be called from the Dispatcher, complex child diagrams would cause a short UI freeze.

What do you think is the best approach?  Should I go back to creating an actual embedded Diagram and try to solve stability issues?

Thanks!
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3529
Joined: Oct 19th, 2005
Re: Nested diagrams
Reply #1 - Oct 21st, 2026 at 7:12am
Print Post  
Hi,

Showing images sounds like most lightweight option (as in WPF visual tree size), but that would be a trade-off vs CPU load for re-rendering whole diagrams each second. I guess if some colors don't change often, you could keep track if an image has to be re-created, skipping CreateImage calls if no colors changed when next timer ticks.

You should be able to work around missing ControlTemplate after cloning by assigning the copy to a hidden DiagramView in same window where the templates are defined, so it gets connected to the logical tree.

Regaring memory, try showing CreateImage() result inside ShapeNode { Image = ...; Transparent = true } to eliminate possibility of templating system keeping cached images. Also try setting this flag:

Quote:
DevFlags.ResetRenderersAfterImageExport = true;


which helped in mysterious situation with ControlNodes here:

https://mindfusion.dev/Forum/YaBB.pl?num=1763113124/18

Another possibility to show 'live' nested diagrams is to use the more lightweight DiagramPresenter in your TemplatedNodes or ControlNodes, instead of full DiagramView.

Please send us the exception stack trace in either case.

Regards,
Slavcho
Mindfusion
« Last Edit: Oct 21st, 2026 at 8:56am by Slavcho »  
Back to top
 
IP Logged
 
Joel D.
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 47
Location: Vancouver, Canada
Joined: Feb 6th, 2017
Re: Nested diagrams
Reply #2 - Oct 21st, 2026 at 9:07pm
Print Post  
It looks like ResetRenderersAfterImageExport set to true clears up the memory issue and the sluggish interactivity on the child diagram.

I tried out a DiagramPresenter and so far that seems to be working well. (I forgot they existed, so thanks for that reminder!)

My old branch that used a DiagramView and had the stability issues has drifted too far from mainline making merging difficult, but if I ever revive it, I'll try to get you a stack trace.

I will continue with DiagramPresenters for now.  Thanks so much!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint