Robert Derber
Robert Derber

Reputation: 65

JSXGraph create codependent board elements

I would like to create a point and a line that are codependent, so that changing the position of one changes the other and vice versa. Is this possible?

Upvotes: 1

Views: 96

Answers (1)

Alfred Wassermann
Alfred Wassermann

Reputation: 2323

My suggestion is to create event handlers for both elements. Here is an example for two codependent points:

const board = JXG.JSXGraph.initBoard('jxgbox', {
                            boundingbox: [-5, 5, 5, -5],
              axis: true
          });
var A = board.create('point', [-3, 2]);     
var B = board.create('point', [ 3, 2]);     

A.on('drag', function() {
        B.moveTo([B.X(), A.Y()]);
});

B.on('drag', function() {
        A.moveTo([A.X(), B.Y()]);
});

It can be see in action at https://jsfiddle.net/vcL7aepo/204/ .

Upvotes: 2

Related Questions