setAttribute for strokeOpacity

24 views
Skip to first unread message

Wigand Rathmann

unread,
Feb 6, 2025, 1:41:02 PMFeb 6
to JSXGraph
Hello,
If I try to change the strokeOpacity of a line, it does not work usging line.setAttribute('strokeOpacity:0.1') 
but using 
line.visProp.strokeopacity=0.1;

The fiddle at setAttribute Examples demonstrates the behavior. 
To change the attribute strokeWidth by setAttribute works fine.

Regards,
Wigand

ampwi...@gmail.com

unread,
Feb 6, 2025, 2:21:21 PMFeb 6
to JSXGraph
Hey Wigand! So I saw a couple things,  but you can look at this one here:
Which is based upon yours. The few changes:

  • When setting up the line you can just equate the strokeOpacity to the slider value. No listeners needed!
  • But if you wanted to add a listener you can. 
  • The function of changeOpac that runs the setAttribute.. the parameter you pass is an object, like {strokeColor: JXG.palette.blue} so it needs to have the curly braces around the parameter parts. I would avoid creating it using text, just update the value you want to changed
Hope that helps!

-Colin

Alfred Wassermann

unread,
Feb 6, 2025, 4:14:48 PMFeb 6
to JSXGraph
Oops, this is a missing feature! 
A quick workaround in Wigand's example would be to set
   linetest.setAttribute({strokeOpacity: slider.Value()});
instead of
    let txt = 'strokeopacity: ' + slider.Value().toFixed(1);
    linetest.setAttribute(txt);

The latter approach fails, because at the time being JSXGraph does not cast
the received value of strokeOpacity - which is a string - to floating point. That is,
in an expression like 
    el.setAttribute('key:value');
the type of value is always a string. 
In contrast, in
    el.setAttribute({key:value});
value keeps its type.

We have to check if this can be repaired without side effects.

Best wishes,
Alfred



Wigand Rathmann

unread,
Feb 6, 2025, 5:00:59 PMFeb 6
to JSXGraph
Hello,
Thanks for the help! I used this to update a legend, where I need to change the opacity.
May be, this is a bit sophisticated, and it is possible to pass list of opacities to the legend object.

A legend containing the levels of a function.

Best,
Wigand

Alfred Wassermann

unread,
Feb 7, 2025, 1:45:52 AMFeb 7
to JSXGraph
Dear Wigand,
your contour line example is very tasteful!
One small problem remains to be solved: if the sliders are changed, new legend elements are created above the old ones.

Best wishes,
Alfred



Wigand Rathmann

unread,
Feb 7, 2025, 4:22:31 AMFeb 7
to JSXGraph
Dear Alfred,

Right! I simply forgot to save the fix. Now that works too.

Best wishes,
Wigand
Reply all
Reply to author
Forward
0 new messages