FAQ - Frequently asked questions: Difference between revisions
A WASSERMANN (talk | contribs) No edit summary |
A WASSERMANN (talk | contribs) No edit summary |
||
(9 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
* | ====* What is the event model of JSXGraph?==== | ||
The | 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. |
Latest revision as of 14:29, 29 October 2009
* 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.