Difference between revisions of "Introduction"
Line 59: | Line 59: | ||
As already mentioned, ''originX'' and ''originY'' determine the origins position in screen coordinates relative to the upper left corner of the drawing box. In the above example the origin is in the center of the board with screen coordinates <tt>(250, 250)</tt> but has user coordinates - as origins should have - <tt>(0, 0)</tt>. This is the only coordinate you give in screen coordinates - all the other data (e.g. coordinates when constructing a point, parameters when plotting a curve) should be given in user coordinate system. The options ''unitX'' and ''unitY'' determine the amount of pixels representing one unit in user coordinates. For the beginning these two numbers should be equal otherwise you'd get different zoom factors in x and y direction resulting in circles appearing as ellipses. | As already mentioned, ''originX'' and ''originY'' determine the origins position in screen coordinates relative to the upper left corner of the drawing box. In the above example the origin is in the center of the board with screen coordinates <tt>(250, 250)</tt> but has user coordinates - as origins should have - <tt>(0, 0)</tt>. This is the only coordinate you give in screen coordinates - all the other data (e.g. coordinates when constructing a point, parameters when plotting a curve) should be given in user coordinate system. The options ''unitX'' and ''unitY'' determine the amount of pixels representing one unit in user coordinates. For the beginning these two numbers should be equal otherwise you'd get different zoom factors in x and y direction resulting in circles appearing as ellipses. | ||
− | Instead of supplying values for originX, originY, unitX, unitY, you can define the user coordinate region shown on the drawing panel directly. The option for that is called boundingbox and is used like that: | + | Instead of supplying values for originX, originY, unitX, unitY, you can define the user coordinate region shown on the drawing panel directly. The option for that is called <tt>boundingbox</tt> and is used like that: |
<source lang="javascript"> | <source lang="javascript"> | ||
var board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-5, 10, 5, -2], axis:true}); | var board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-5, 10, 5, -2], axis:true}); | ||
Line 67: | Line 67: | ||
<jsxgraph height="500" width="500" box="jxgbox2"> | <jsxgraph height="500" width="500" box="jxgbox2"> | ||
− | var board = JXG.JSXGraph.initBoard('jxgbox2', { | + | var board = JXG.JSXGraph.initBoard('jxgbox2', {boundingbox: [-5, 10, 5, -2], axis:true}); |
</jsxgraph> | </jsxgraph> | ||
+ | |||
+ | The syntax of this option is pretty easy to understand: It takes an array with 4 numbers defining the most left, top, right, bottom point available on screen in user coordinates. | ||
==Various options to affect the initialisation of the board== | ==Various options to affect the initialisation of the board== |
Revision as of 07:01, 24 June 2009
JSXGraph is a browser based library for interactive geometry, function plotting, graphs, and data visualization. It is completely written in JavaScript and everybody with a little experience with JavaScript shouldn't have problems using JSXGraph. Thanks to the dynamics of JavaScript JSXGraph is also very easy to extend and thanks to AJAX many other softwarepackages can be integrated.
If you have any question about JSXGraph or this documentation feel free to contact us.
Contents
Embed JSXGraph in a webpage
To use JSXGraph on your webpage you first have to load either Prototype or JQuery via HTML script tag. Both libraries come with your copy of JSXGraph or can be downloaded here:
- prototype.js from http://www.prototypejs.org or local copy
- jquery.min.js from http://www.jquery.com or local copy
You can choose between those two whatever you want, JSXGraph will run with both equally good.
And of course you need JSXGraph itself:
- jsxgraphcore.js from http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js
- jsxgraph.css from http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css
You can either download these files and use the local copy or you can use the online version.
Usage of a local copy
If you want to include a local copy of JSXGraph in your HTML file then you have to write the following lines into the document head:
<head>
<link rel="stylesheet" type="text/css" href="jsxgraph.css" />
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="jsxgraphcore.js"></script>
</head>
If you prefer to run JSXGraph with jQuery, replace prototype.js with jQuery.
Usage of the online copy
If you want to include the online of JSXGraph in your HTML file then you have to write the following lines into the document head:
<head>
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jquery.min.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
</head>
Same as above, if you'd prefer to run prototype, replace jquery.min.js with prototype.js.
Include a drawing panel into the HTML
General creation of a JSXGraph board
If you want to use JSXGraph in most cases you want to draw something on a web page (although some algorithms that don't depend on visual elements are implemented they're by now not so numerous...). Before anything can be drawn, you'll have to create a board JSXGraph can draw on. To create a board we need a HTML element - usually a div-element is taken - with an ID attribute. Using this ID, we declare this element to be a drawing panel of JSXGraph:
<body>
[...]
<div id="box" class="jxgbox" style="width:200px; height:200px;"></div>
<script type="text/javascript">
var board = JXG.JSXGraph.initBoard('jxgbox', {originX: 100, originY: 100, unitX: 50, unitY: 50});
</script>
[...]
This creates an empty drawing panel sized 200x200 pixels with the origin in the center of the box.
As already mentioned, originX and originY determine the origins position in screen coordinates relative to the upper left corner of the drawing box. In the above example the origin is in the center of the board with screen coordinates (250, 250) but has user coordinates - as origins should have - (0, 0). This is the only coordinate you give in screen coordinates - all the other data (e.g. coordinates when constructing a point, parameters when plotting a curve) should be given in user coordinate system. The options unitX and unitY determine the amount of pixels representing one unit in user coordinates. For the beginning these two numbers should be equal otherwise you'd get different zoom factors in x and y direction resulting in circles appearing as ellipses.
Instead of supplying values for originX, originY, unitX, unitY, you can define the user coordinate region shown on the drawing panel directly. The option for that is called boundingbox and is used like that:
var board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-5, 10, 5, -2], axis:true});
The axis option just draws a standard x- and y-axis on the board and is used to visualize the bounding box:
The syntax of this option is pretty easy to understand: It takes an array with 4 numbers defining the most left, top, right, bottom point available on screen in user coordinates.
Various options to affect the initialisation of the board
Here are the other options explained together with the already mentioned in a small table:
Option | Type | Default value | Explanation |
---|---|---|---|
originX | positive integer | 150 | The horizontal position of the origin relative to the upper left corner of the drawing area. |
originY | positive integer | 150 | The vertical position of the origin relative to the upper left corner of the drawing area. |
unitX | positive integer | 50 | Amount of pixels determining one unit in user coordinates in horizontal direction. |
unitY | positive integer | 50 | Amount of pixels determining one unit in user coordinates in vertical direction. |
axis | bool | false | If true, default axes are drawn on the board. To draw axes with special options set this to false and create them manually. See also Ticks. |
grid | bool | false | If true, a grid is drawn on the board. |
zoomfactor | positive float | 1.0 | Sets zoom factor on the board. |
zoomX | positive float | 1.0 | Sets zoom factor in horizontal direction. The final zoom factor in this direction is this value multiplied with zoomfactor. |
zoomY | positive float | 1.0 | Sets zoom factor in vertical direction. The final zoom factor in this direction is this value multiplied with zoomfactor. |