Search code examples
javascriptjsxgraph

jsxgraph: How do I update a line's points?


Say I created a line with:

var line = board.create('line', [2, 2], [3, 3], { ... });

The documentation states for Line.point1:

You really should not set this field directly as it may break JSXGraph's udpate system so your construction won't be updated properly.

What is the recommended way in jsxgraph to update these point co-ordinates I passed in to the constructor?

Update: I just tried:

line.point1.moveTo(4, 4);
line.point2.moveTo(5, 5);

But this seems to mess things up, i.e., the line is not draggable after I do that.


Solution

  • According to the documentation moveTo takes an array for the co-ordinates to move to:

    line.point1.moveTo([4, 4]);
    line.point2.moveTo([5, 5]);
    

    It also takes a time as a second parameter in milliseconds for the animation duration. As you're looking for an instant move (and the same thing happens when milliseconds is omitted or 0), you could use setPosition instead.