FAQ - Frequently asked questions: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 19: Line 19:
The ''update()'' method of each element computes the new position of the element
The ''update()'' method of each element computes the new position of the element
and its layout (''strokeColor, strokeWidth'').  This update() method can use  
and its layout (''strokeColor, strokeWidth'').  This update() method can use  
the position of other elements, see the [[Lissajous curves]] example. So, for example you can handover functions to a geometric element which determine the X-coordinate and the Y-coordinate during an update() call, respectively. The same is possible for strokeWidth and strokeColor.
the position of other elements, see the [[Lissajous curves]] example. So, for example you can handover functions to a geometric element which determine the X-coordinate and the Y-coordinate during an update() call, respectively. The same is possible for strokeWidth and strokeColor, see [[Highlight curve via slider]].


The [[Hilbert curve]] is somewhat more complicated:
The [[Hilbert curve]] is somewhat more complicated:

Revision as of 13:34, 2 June 2009

  • The documentation suggests using either JQuery.js or prototype.js, but the AJAX example appears to require prototype.js. By, what reasons would one choose JQuery over prototype, or vice versa.

The choice completely depends on you. JSXGraph works with both packages equally good. If you want to use JavaScript features like AJAX choose the package you're most familiar with.

  • What is the event model of JSXGraph?

The event model of JSXGraph is the following: An onmousemove event in the HTML element containing the JSXGraph construction and an onmouseup event of the whole HTML document trigger the method JXG.Board.update().

JXG.Board.update() calls the update() method of each element (points, lines, texts, ...) of the board.

Thus, by dragging a point, onmousemove of the HTML element containing the construction is triggered. This triggers the call of JXG.Board.update(), which calls all update() methods of each element.

The update() method of each element computes the new position of the element and its layout (strokeColor, strokeWidth). This update() method can use the position of other elements, see the Lissajous curves example. So, for example you can handover functions to a geometric element which determine the X-coordinate and the Y-coordinate during an update() call, respectively. The same is possible for strokeWidth and strokeColor, see Highlight curve via slider.

The Hilbert curve is somewhat more complicated: It overwrites the (previously empty) method updateDataArray() of a curve of curveType "plot". In that method the new data points are computed depending on one slider. Then, with

           this.dataX = ...;
           this.dataY = ...;

they are handed to the curve tight before they are plotted.

Other special cases: - In order to speed up things the update() of (all) elements can be prevented by calling board.suspendUpdate(); until the call of board.unsuspendUpdate();

- JSXGraph updates ALL JXG.Boards in an HTML document. So elements of one board can depend from elements in another board. See the sine and cosine example.