0
$\begingroup$

I have read the suggested similar question here:

VertexRenderingFunction (or EdgeRenderingFunction) with movable nodes?

and Mr. Wizard's solution. Please could someone help me to apply his method to my example:

graphexample

My code is below. I would like the vertices of the graph to move with the pictures of the grids, when I click and drag the grids around.

arraydims = {2, 2};
cases = Tuples[{False, True}, arraydims];
elementsum[array_] := Total[Flatten[array]];
directsuccesorQ[case1_, case2_] := If[
   And[
    Total[
      Boole[MapThread[#1 =!= #2 &, {Flatten[case1], 
         Flatten[case2]}]]] == 1,
    elementsum[Boole[Flatten[case1, 1]]] < 
     elementsum[Boole[Flatten[case2, 1]]]
    ],
   True, False];
plotsystem[array_] := 
  MatrixPlot[array, ColorRules -> {False -> White, True -> Black}, 
   Mesh -> True, Frame -> False, FrameTicks -> False, ImageSize -> 20];
adjacencymatrix = 
  Table[Boole[directsuccesorQ[cases[[i]], cases[[j]]]], {i, 1, 
    Length[cases]}, {j, 1, Length[cases]}];
G = AdjacencyGraph[adjacencymatrix];
LayeredGraphPlot[G, 
 VertexRenderingFunction -> (Inset[plotsystem[cases[[#2]]], #] &), 
 ImageSize -> Large]
$\endgroup$
5
  • $\begingroup$ Simply replace GraphPlot with LayeredGraphPlot in the definition of withVRF and it works as written. I am closing this as a duplicate. $\endgroup$ Commented Mar 20, 2015 at 12:40
  • $\begingroup$ Thank you very much for your response, @Mr.Wizard. In fact I tried replacing GraphPlot with LayeredGraphPlot in your other answer, in the definition of withVRF. That worked very well, but the vertex pictures were your circles with numbers inside, whereas I would like them to be the little grids generated by my function "plotsystem" above. I tried but failed to replace your circles with my plotsystem command. Any help you could give me with that would be greatly appreciated. Thank you again for all your input. $\endgroup$ Commented Mar 20, 2015 at 19:27
  • $\begingroup$ You still need to use your vertex rendering function. Evaluate the code in your post, then: fn = Inset[plotsystem[cases[[#2]]], #] &; LayeredGraphPlot[G, ImageSize -> Large] /. Tooltip[Point[n_Integer], label_] :> fn[n, label]. Or define: withVRFlayered[VRF_][args__] := LayeredGraphPlot[args] /. Tooltip[Point[n_Integer], label_] :> VRF[n, label] and then use: withVRFlayered[Inset[plotsystem[cases[[#2]]], #] &][G, ImageSize -> Large] $\endgroup$ Commented Mar 21, 2015 at 2:16
  • $\begingroup$ Thank you so much @Mr.Wizard ! Sorry to seem idle. In fact I tried hard to implement your code with my function, but failed. I really appreciate you helping me out ! $\endgroup$ Commented Mar 21, 2015 at 17:57
  • $\begingroup$ It's okay, and you're welcome. As I have said to many before you I wouldn't be here if I didn't wish to help. $\endgroup$ Commented Mar 22, 2015 at 5:46

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.