Point: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary  | 
				No edit summary  | 
				||
| Line 40: | Line 40: | ||
=== Point styles===  | === Point styles===  | ||
The property type of a point can attain the values 0..12. In this examples we use a for loop to create 13 points.    | The property type of a point can attain the values 0..12. Alternatively you can use these equivalent constants for that:  | ||
{| cellpadding="8" cellspacing="0" border="1"  | |||
! Constant !! Value !! Short description  | |||
|-  | |||
| JXG.POINT_STYLE_X_SMALL     || 0 || Small x  | |||
|-  | |||
| JXG.POINT_STYLE_X            || 1  || Medium x  | |||
|-  | |||
| JXG.POINT_STYLE_X_BIG        || 2  || Big x  | |||
|-  | |||
| JXG.POINT_STYLE_CIRCLE_TINY  || 3  || Tiny circle  | |||
|-  | |||
| JXG.POINT_STYLE_CIRCLE_SMALL || 4  || Small circle  | |||
|-  | |||
| JXG.POINT_STYLE_CIRCLE       || 5  || Medium circle  | |||
|-  | |||
| JXG.POINT_STYLE_CIRCLE_BIG   || 6  || Big circle  | |||
|-  | |||
| JXG.POINT_STYLE_SQUARE_SMALL || 7  || Small square  | |||
|-  | |||
| JXG.POINT_STYLE_SQUARE       || 8  || Medium square  | |||
|-  | |||
| JXG.POINT_STYLE_SQUARE_BIG   || 9  || Big square  | |||
|-  | |||
| JXG.POINT_STYLE_PLUS_SMALL   || 10 || Small +  | |||
|-  | |||
| JXG.POINT_STYLE_PLUS         || 11 || Medium +  | |||
|-  | |||
| JXG.POINT_STYLE_PLUS_BIG     || 12 || Big +  | |||
|}  | |||
In this examples we use a for loop to create 13 points.    | |||
<source lang="javascript">  | <source lang="javascript">  | ||
var b3 = JXG.JSXGraph.initBoard('jxgbox3', {originX: 40, originY: 100, unitX: 40, unitY: 40});  | var b3 = JXG.JSXGraph.initBoard('jxgbox3', {originX: 40, originY: 100, unitX: 40, unitY: 40});  | ||
Revision as of 13:21, 2 June 2009
Construction of a free point
This example shows how to construct a simple, draggable point. It is produced by the following commands:
<div id="jxgbox" class="jxgbox" style="width:500px; height:200px;"></div>
<script type="text/javascript">
 var board = JXG.JSXGraph.initBoard('jxgbox', {originX: 200, originY: 100, unitX: 50, unitY: 50});
 var p = board.createElement('point',[1,1]);
</script>
The JavaScript code has to be placed AFTER the div element which will contain the construction. From now on, we will only show the JavaScript code.
Attributes of a point
User defined name
Several attributes can be given to change the properties of a point, for example a name.
var b2 = JXG.JSXGraph.initBoard('jxgbox2', {originX: 200, originY: 100, unitX: 50, unitY: 50});
var p = b2.createElement('point',[1,1], {name:'X',style:5});
This point will be labeled with "X":
Point styles
The property type of a point can attain the values 0..12. Alternatively you can use these equivalent constants for that:
| Constant | Value | Short description | 
|---|---|---|
| JXG.POINT_STYLE_X_SMALL | 0 | Small x | 
| JXG.POINT_STYLE_X | 1 | Medium x | 
| JXG.POINT_STYLE_X_BIG | 2 | Big x | 
| JXG.POINT_STYLE_CIRCLE_TINY | 3 | Tiny circle | 
| JXG.POINT_STYLE_CIRCLE_SMALL | 4 | Small circle | 
| JXG.POINT_STYLE_CIRCLE | 5 | Medium circle | 
| JXG.POINT_STYLE_CIRCLE_BIG | 6 | Big circle | 
| JXG.POINT_STYLE_SQUARE_SMALL | 7 | Small square | 
| JXG.POINT_STYLE_SQUARE | 8 | Medium square | 
| JXG.POINT_STYLE_SQUARE_BIG | 9 | Big square | 
| JXG.POINT_STYLE_PLUS_SMALL | 10 | Small + | 
| JXG.POINT_STYLE_PLUS | 11 | Medium + | 
| JXG.POINT_STYLE_PLUS_BIG | 12 | Big + | 
In this examples we use a for loop to create 13 points.
var b3 = JXG.JSXGraph.initBoard('jxgbox3', {originX: 40, originY: 100, unitX: 40, unitY: 40});
for (var i=0;i<13;i++) {
  var p = b3.createElement('point',[i,0], {name:'P_{'+i+'}', style:i});
}
Fixed points
A property of an element may also be set after creating it. In the above example we set the property fixed of the last point, P_12, to true. I.e. the point is no longer draggable.
p.setProperty({fixed:true});