1
$\begingroup$

I have a graphic where each Arrow, Rectangle, and Text is a Button. If any of these elements are clicked on it will turn blue and the number of selected Rectangles and Arrows will be counted.

When an Arrow is clicked on more Text will appear below that Arrow. This Text can also be clicked on.

I have been able to get all of this to work except for one important detail: when an Arrow/stream (A, B, C, or D) is clicked on and Subscript[a,i], Subscript[b,i], Subscript[c,i], or Subscript[d,i] (where i ranges from 1 to 3) is shown, I want to be able to click on one of these new selections individually...

For example: I click on stream A and Subscript[a,1], Subscript[a,2], and Subscript[a,3] show up. I want to be able to click on Subscript[a,1] but not Subscript[a,2] or Subscript[a,3] (or some other combination) so the one I click turns blue.

Currently if I click one, all three turn blue.

enter image description here

Here is the code I've been using:

Manipulate[
 Module[{comp, equipment, streams},
  comp[label_, pos_] := 
   Text[Style[Subscript[label, #], 15], pos, {0, #*2}] & /@ 
    Range@species;

  equipment = {
    {"unit 1", Rectangle[{2, 0}, {4, 2}], Text["unit 1", {3, 1}]},
    {"unit 2", Rectangle[{6, 0}, {8, 2}], Text["unit 2", {7, 1}]}
    };

  streams = {
    {"A", Arrow[{{-1, 1}, {2, 1}}], Text["A", {0, 1}, {0, -1}], 
     comp["a", {0, 1}]},
    {"B", Arrow[{{4, 1}, {6, 1}}], Text["B", {5, 1}, {0, -1}], 
     comp["b", {5, 1}]},
    {"C", Arrow[{{8, 1}, {10, 1}}], Text["C", {9, 1}, {0, -1}], 
     comp["c", {9, 1}]},
    {"D", Arrow[{{7, 0}, {7, -1}, {1, -1}, {1, 1}}], 
     Text["D", {4, -1}, {0, -1}], comp["d", {4, -1}]}
    };

  Graphics[{
    {FaceForm[Transparent],
     If[FreeQ[e, #[[1]]],
        Button[{EdgeForm[Thick], #[[2]], Style[#[[3]], 16]}, 
         AppendTo[e, #[[1]]]],
        Button[{EdgeForm[{Thick, Blue}], #[[2]], 
          Style[#[[3]], 16, Bold, Blue]}, e = DeleteCases[e, #[[1]]]]
        ] & /@ equipment
     },
    {Thick,
     If[FreeQ[s, #],
        Button[{#[[2]], Style[#[[3]], 16]}, AppendTo[s, #]],
        Button[{Blue, #[[2]], Style[#[[3]], 16, Bold]}, 
         s = DeleteCases[s, #]]
        ] & /@ streams
     },

    Map[If[FreeQ[c, #],
       Button[#[[4]], AppendTo[c, #]],
       Button[Style[#[[4]], Bold, Blue], c = DeleteCases[c, #]]
       ] &, s]

    }, ImageSize -> 500]
  ],
 Control[{{species, 3, "number of species"}, {2, 3, 4}, Setter}],
 Control[{{e, {}}, ControlType -> None}],
 Control[{{s, {}}, ControlType -> None}],
 Control[{{c, {}}, ControlType -> None}]
 ]

I have tried to separate each Subscript[j,i] button without success.

$\endgroup$

1 Answer 1

2
$\begingroup$

There really is no question in your post. I'll assume you are asking what is going wrong but not expecting to get free code to fix it.

A call to comp returns a list of subscripted lowercase letters which you insert into one of rows of streams. When one of the labels is clicked on, the whole list of subscripted lowercase letters associated with that label is made into one button. You will have to map Button over the list of subscripted lowercase letters to get such letters to act independently.

BTW, the control specifications in your Manipulate can be simplified to

{{species, 3, "number of species"}, {2, 3, 4}, Setter}, 
{{e, {}}, None},
{{s, {}}, None},
{{c, {}}, None}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.