I want to make a slider with several movable index points (thumbs). I can't find an example where someone has tried this before.
I have started with this module which works on its own.
ClearAll[multiSlider];
multiSlider::usage =
"multiSlider[points,{x1, x2}] Create a slider with as many thumbs \
as points. Range {x1, x2}";
SetAttributes[multiSlider, HoldFirst];
Options[multiSlider] = {ImageSize -> 5 72, AspectRatio -> 1/10};
multiSlider[xx_, {x1_, x2_}, opts : OptionsPattern[]] :=
DynamicModule[{},
Column[{
LocatorPane[
Dynamic[xx, {xx = #;
xx[[All, 2]] = ConstantArray[0, Length[xx]]} &],
Graphics[{Line[{{x1, 0}, {x2, 0}}]},
FilterRules[{opts, Options[multiSlider]}, Options[ListPlot]]
], Appearance -> Table[
Graphics[{White, Disk[],
Black, Text[i, {0, 0}],
Line[{{0, 0.7}, {0, 1}}]},
ImageSize -> 20],
{i, Length[xx]}]
]
}]
]
This works on its own.
pos = Transpose[{Range[6], ConstantArray[0, 6]}];
multiSlider[pos, {0.5, 7}]
I am suspicious about using SetAttributes[multiSlider, HoldFirst] but my multiSlider did not work without it.
I then tried to use it in a DynamicModule. First I created a function that I could interact with.
ClearAll[f];
f[x_, xx_] := Sum[1/Sqrt[(xx[[n]]^2 - x^2)^2 + 0.1], {n, Length@xx}];
SetOptions[Plot, PlotHighlighting -> None];
With[{x1 = 3, x2 = 5},
xx = Table[x1 + n (x2 - x1)/7, {n, 6}];
Plot[f[x, xx], {x, x1, x2}, PlotRange -> All,
Epilog -> {Pink, InfiniteLine[{#, 0}, {0, 1}] & /@ xx},
AspectRatio -> 1/4, Frame -> True]]
Now for the DynamicModule that should have interaction between my multiSlider and my function.
DynamicModule[{xx, x1 = 3, x2 = 5, is = 8 72},
xx = Transpose[{Table[x1 + n (x2 - x1)/7., {n, 6}],
ConstantArray[0, 6]}];
Column[{
Dynamic@Plot[f[x, xx[[All, 1]]], {x, x1, x2}, PlotRange -> All,
Epilog -> {Pink, InfiniteLine[#, {0, 1}] & /@ xx},
AspectRatio -> 1/4, Frame -> True, ImageSize -> is],
multiSlider[xx, {x1, x2}, ImageSize -> is]
}]
]
This does work. There are two changes I need to make.
I have been trying to work with the points being put into the slider being just a list. I can't get this to work. Here is the module where the input is just a list.
ClearAll[multiSlider]; multiSlider::usage = "multiSlider[points,{x1, x2}] Create a slider with as many thumbs \ as points. Range {x1, x2}"; SetAttributes[multiSlider, HoldFirst]; Options[multiSlider] = {ImageSize -> 5 72, AspectRatio -> 1/10}; multiSlider[xx_, {x1_, x2_}, opts : OptionsPattern[]] := DynamicModule[{ss}, ss = Transpose[{xx, ConstantArray[0, Length[xx]]}]; Column[{ LocatorPane[ Dynamic[ss, {ss = #; ss[[All, 2]] = ConstantArray[0, Length[ss]]} &], Graphics[{Line[{{x1, 0}, {x2, 0}}]}, FilterRules[{opts, Options[multiSlider]}, Options[ListPlot]] ], Appearance -> Table[ Graphics[{White, Disk[], Black, Text[i, {0, 0}], Line[{{0, 0.7}, {0, 1}}]}, ImageSize -> 20], {i, Length[ss]}] ] }] ] pos = Range[6]; multiSlider[pos, {0.5, 7}]
The slider seems to work but when added to the module this does not work.
DynamicModule[{xx, x1 = 3, x2 = 5, is = 8 72},
xx = Table[x1 + n (x2 - x1)/7., {n, 6}];
Column[{
Dynamic@Plot[f[x, xx], {x, x1, x2}, PlotRange -> All,
Epilog -> {Pink, InfiniteLine[{#, 0}, {0, 1}] & /@ xx},
AspectRatio -> 1/4, Frame -> True, ImageSize -> is],
multiSlider[xx, {x1, x2}, ImageSize -> is]
}]
]
- I can't add a
Dynamicaround the input to my slider. This is needed so that other actions may be triggered.
Thanks for any help.






Dynamic[..]holding the first argument:multiSlider[Dynamic[xx_], {x1_, x2_}, opts : OptionsPattern[]]...-- have you tried that? $\endgroup$Dynamic. However, I can't get it to work. Is there something deeper about aDynamicor am I along the correct lines. $\endgroup$