2
$\begingroup$

I'd like to split my TogglerBar into several rows, with it's length given in a list.

I found the Appearance options, but they only allow one fixed horizontal/vertical dimension. Which is why I thought splitting my TogglerBar up in several pieces would be the way to go.

data = {2, 3, 1}
Manipulate[Boole @ MemberQ[x, #] & /@ Range@Total @ data,
{x, {1, 2}, ControlType -> TogglerBar},
{x, {3, 4, 5}, ControlType -> TogglerBar},
{x, {6}, ControlType -> TogglerBar}]

How can I write this, so that it'll still work when I change the length of data? E.g. to data = {1, 1, 2, 2}.

$\endgroup$
1
  • $\begingroup$ Sorry about that! So currently I'm getting 3 TogglerBars with the length 2, 3 respectively 1, as given by the list data. This list is not always going to be the same though. So I'd like to write Manipulate in a way, that I can have any dataI want and get a number of toggler bars given by the number of elements in data, with the number of togglers given by the numbers in data. Please let me know if it's still confusing. $\endgroup$
    – Jason
    Commented Jan 15, 2015 at 13:52

1 Answer 1

2
$\begingroup$

Something like this?:

data = {1, 1, 2, 2};

DynamicModule[{max = Tr @ data, x},
  Manipulate[
    Normal @ SparseArray[Thread[x -> 1], max],
    ##
  ] & @@
    Thread[{x, Internal`PartitionRagged[Range@max, data], 
    ControlType -> TogglerBar}]
]

enter image description here

$\endgroup$
6
  • $\begingroup$ Yes, this is it! Can I ask another question though? I was using the output of manipulate to change the opacity of a number of graphs in my ListPlotin order to toggle their visibility. I'm not that advanced with Mathematica yet and have a hard time implementing your code into what I wanted to achieve. Could you help me get into the right direction? This is what I was going for. I was now trying to break my ToggleBar into several parts. $\endgroup$
    – Jason
    Commented Jan 15, 2015 at 18:19
  • $\begingroup$ I got it to work! Thank you for the help! $\endgroup$
    – Jason
    Commented Jan 16, 2015 at 13:01
  • $\begingroup$ @Jason Good. Sorry I wasn't around sooner to help, but working through it yourself was probably a better learning experience anyway. $\endgroup$
    – Mr.Wizard
    Commented Jan 16, 2015 at 14:04
  • $\begingroup$ Can I ask, I'd love to learn the more advanced language Syntax using @, @@, #&, /@ etc. I found a stackexchange post where their meanings are listed. Do you know if there are any tutorials on this? Or is there a way to practice their usage, or see examples where they are used in a well written way? $\endgroup$
    – Jason
    Commented Jan 16, 2015 at 15:52
  • $\begingroup$ @Jason There is no short-cut to learning the language in my opinion. In that post each of the operators has a [ref] link that will take you to its documentation page. If you prefer a more linear tutorial I recommend Leonid's online book but I warn you that despite the name "introduction" it is quite thorough. Other than these general guidelines anything I can think to point you toward would be more specific, such as my own answer to (46238). $\endgroup$
    – Mr.Wizard
    Commented Jan 16, 2015 at 16:07

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.