Ticks: Difference between revisions
No edit summary |
A WASSERMANN (talk | contribs) No edit summary |
||
(11 intermediate revisions by 2 users not shown) | |||
Line 6: | Line 6: | ||
==Equidistant ticks== | ==Equidistant ticks== | ||
To construct equidistant ticks you just have to call <tt> | To construct equidistant ticks you just have to call <tt>create</tt> with type '''ticks''' and parents array with a line or axis in the first and a positive number describing the distance between two ticks in the second element: | ||
<source lang="javascript"> | <source lang="javascript"> | ||
brd1. | brd1.create('ticks',[axis, 5]); | ||
</source> | </source> | ||
Line 14: | Line 14: | ||
<jsxgraph height="200" width="700" box="box1"> | <jsxgraph height="200" width="700" box="box1"> | ||
var brd1 = JXG.JSXGraph.initBoard('box1', {boundingbox: [-8.75, 2.5, 8.75, -2.5]}); | var brd1 = JXG.JSXGraph.initBoard('box1', {boundingbox: [-8.75, 2.5, 8.75, -2.5]}); | ||
var ax1 = brd1. | var ax1 = brd1.create('line', [[0,0],[1,0]]); | ||
brd1. | brd1.create('ticks',[ax1, 5], {minorTicks:4, majorHeight:20, minorHeight:4}); | ||
</jsxgraph> | </jsxgraph> | ||
<source lang="javascript"> | <source lang="javascript"> | ||
var brd1 = JXG.JSXGraph.initBoard('box1', {boundingbox: [-8.75, 2.5, 8.75, -2.5]}); | var brd1 = JXG.JSXGraph.initBoard('box1', {boundingbox: [-8.75, 2.5, 8.75, -2.5]}); | ||
var ax1 = brd1. | var ax1 = brd1.create('line', [[0,0],[1,0]]); | ||
brd1. | brd1.create('ticks',[ax1, 5], {minorTicks:4, majorHeight:20, minorHeight:4}); | ||
</source> | </source> | ||
You may notice that here are some ticks that have bigger height than other ticks. Those are called ''major ticks'', the smaller ones are called ''minor ticks''. | You may notice that here are some ticks that have bigger height than other ticks. Those are called ''major ticks'', the smaller ones are called ''minor ticks''. | ||
Line 26: | Line 26: | ||
<jsxgraph height="200" width="700" box="box2"> | <jsxgraph height="200" width="700" box="box2"> | ||
var brd2 = JXG.JSXGraph.initBoard('box2', {boundingbox: [-8.75, 2.5, 8.75, -2.5]}); | var brd2 = JXG.JSXGraph.initBoard('box2', {boundingbox: [-8.75, 2.5, 8.75, -2.5]}); | ||
var ax2 = brd2. | var ax2 = brd2.create('axis', [[0,0],[1,0]]); | ||
</jsxgraph> | </jsxgraph> | ||
<source lang="javascript"> | <source lang="javascript"> | ||
var brd2 = JXG.JSXGraph.initBoard('box2', {boundingbox: [-8.75, 2.5, 8.75, -2.5]}); | var brd2 = JXG.JSXGraph.initBoard('box2', {boundingbox: [-8.75, 2.5, 8.75, -2.5]}); | ||
var ax2 = brd2. | var ax2 = brd2.create('axis', [[0,0],[1,0]]); | ||
</source> | </source> | ||
Line 60: | Line 60: | ||
Special ticks can't be constructed together with an axis and therefore have to be created directly. The only difference between creating equidistant and creating special ticks is the second element of the parents array. For special ticks you have to give an array of positions on the axis, where special ticks are to be drawn. You always need an array for this, even if there's only one special tick to draw: | Special ticks can't be constructed together with an axis and therefore have to be created directly. The only difference between creating equidistant and creating special ticks is the second element of the parents array. For special ticks you have to give an array of positions on the axis, where special ticks are to be drawn. You always need an array for this, even if there's only one special tick to draw: | ||
<jsxgraph height="200" width="700" box="box3"> | <jsxgraph height="200" width="700" box="box3"> | ||
var brd3 = JXG.JSXGraph.initBoard('box3', {boundingbox: [-8.75, 2.5, 8.75, -2.5]}); | var brd3 = JXG.JSXGraph.initBoard('box3', {boundingbox: [-8.75, 2.5, 8.75, -2.5]}); | ||
var ax3 = brd3. | var ax3 = brd3.create('axis', [[0,0],[1,0]]); | ||
brd3. | brd3.create('ticks', [ax3, [3.5]], {strokeColor: '#00ff00', majorHeight:15, drawLabels: true}); | ||
</jsxgraph> | </jsxgraph> | ||
<source lang="javascript"> | <source lang="javascript"> | ||
var brd3 = JXG.JSXGraph.initBoard('box3', {boundingbox: [-8.75, 2.5, 8.75, -2.5]}); | var brd3 = JXG.JSXGraph.initBoard('box3', {boundingbox: [-8.75, 2.5, 8.75, -2.5]}); | ||
var ax3 = brd3. | var ax3 = brd3.create('axis', [[0,0],[1,0]]); | ||
brd3. | brd3.create('ticks', [ax3, [3.5]], {strokeColor: '#00ff00', majorHeight:15, drawLabels: true}); | ||
</source> | </source> | ||
Or more than one special tick: | Or more than one special tick: | ||
<jsxgraph height="200" width="700" box="box4"> | <jsxgraph height="200" width="700" box="box4"> | ||
var brd4 = JXG.JSXGraph.initBoard('box4', {boundingbox: [-8.75, 2.5, 8.75, -2.5]}); | var brd4 = JXG.JSXGraph.initBoard('box4', {boundingbox: [-8.75, 2.5, 8.75, -2.5]}); | ||
var ax4 = brd4. | var ax4 = brd4.create('axis', [[0,0],[1,0]]); | ||
brd4. | brd4.create('ticks', [ax4, [-4.33333, -1.5, 3.5, 4.321]], {strokeColor: '#00ff00', majorHeight: 15, drawLabels: true}); | ||
</jsxgraph> | </jsxgraph> | ||
<source lang="javascript"> | <source lang="javascript"> | ||
var brd4 = JXG.JSXGraph.initBoard('box4', {boundingbox: [-8.75, 2.5, 8.75, -2.5]}); | var brd4 = JXG.JSXGraph.initBoard('box4', {boundingbox: [-8.75, 2.5, 8.75, -2.5]}); | ||
var ax4 = brd4. | var ax4 = brd4.create('axis', [[0,0],[1,0]]); | ||
brd4. | brd4.create('ticks', [ax4, [-4.33333, -1.5, 3.5, 4.321]], {strokeColor: '#00ff00', majorHeight: 15, drawLabels: true}); | ||
</source> | </source> | ||
The possible attributes here are mostly the same as above when creating equidistant ticks: | The possible attributes here are mostly the same as above when creating equidistant ticks: | ||
Line 84: | Line 84: | ||
! Attribute !! Type !! Effect | ! Attribute !! Type !! Effect | ||
|- | |- | ||
| | | majorHeight || positive integer || This is the height (in pixel) for all special ticks. | ||
|- | |- | ||
| drawLabels || bool || If ''true'', labels showing the ticks position on the axis are drawn beneath every majorTick. | | drawLabels || bool || If ''true'', labels showing the ticks position on the axis are drawn beneath every majorTick. | ||
Line 96: | Line 96: | ||
You can remove all ticks attached to a line or an axis by calling the <tt>removeAllTicks()</tt> method of the line you want to have 'tickless' or you can remove specific ticks by calling <tt>removeTicks</tt> method of the given line instance with the a reference to the ticks instance as a parameter: | You can remove all ticks attached to a line or an axis by calling the <tt>removeAllTicks()</tt> method of the line you want to have 'tickless' or you can remove specific ticks by calling <tt>removeTicks</tt> method of the given line instance with the a reference to the ticks instance as a parameter: | ||
<source lang="javascript"> | <source lang="javascript"> | ||
var xaxis = board. | var xaxis = board.create('line', [point1, point2]); | ||
var ticks = board. | var ticks = board.create('ticks', [xaxis, [1.0, 2.0, 5.0]]); | ||
xaxis.removeTicks(ticks); | xaxis.removeTicks(ticks); | ||
</source> | </source> | ||
To access ticks automatically constructed on creation of an axis, use the axis property called '''defaultTicks''': | To access ticks automatically constructed on creation of an axis, use the axis property called '''defaultTicks''': | ||
<source lang="javascript"> | <source lang="javascript"> | ||
var xaxis = board. | var xaxis = board.create('axis', [point1, point2]); | ||
xaxis.removeTicks(xaxis.defaultTicks); | xaxis.removeTicks(xaxis.defaultTicks); | ||
</source> | </source> | ||
[[Category:Examples]] | [[Category:Examples]] | ||
[[Category:Text]] |
Latest revision as of 14:08, 10 January 2023
Ticks are little indicators on an axis to mark special positions on that axis. In JSXGraph they come in mainly three flavors: Equidistant, functional and special ticks. Equidistant ticks are those with the same distance between each marker, the distance between two functional ticks is determined by a function taking the number i of the tick ([math]\displaystyle{ i \in \mathbb{Z} }[/math]) and returning the distance between the (i-1)-th and the i-th tick. Equidistant and functional ticks are created all over the axis against what special ticks are only created once.
Create Ticks
Note: You can create ticks on any GeometryElement based on the Line-object such as Line and Axis. So every appearance of axis in the examples on this page can be replaced by line and vice versa.
Equidistant ticks
To construct equidistant ticks you just have to call create with type ticks and parents array with a line or axis in the first and a positive number describing the distance between two ticks in the second element:
brd1.create('ticks',[axis, 5]);
For example:
var brd1 = JXG.JSXGraph.initBoard('box1', {boundingbox: [-8.75, 2.5, 8.75, -2.5]});
var ax1 = brd1.create('line', [[0,0],[1,0]]);
brd1.create('ticks',[ax1, 5], {minorTicks:4, majorHeight:20, minorHeight:4});
You may notice that here are some ticks that have bigger height than other ticks. Those are called major ticks, the smaller ones are called minor ticks. Ticks like shown below are automatically constructed when creating an axis:
var brd2 = JXG.JSXGraph.initBoard('box2', {boundingbox: [-8.75, 2.5, 8.75, -2.5]});
var ax2 = brd2.create('axis', [[0,0],[1,0]]);
If you wish to use other than the default options for the ticks when creating an axis, you can do so. The attributes names are the same when creating ticks directly:
Attribute | Type | Effect |
---|---|---|
insertTicks | bool | Inserts ticks whenever the distance between two ticks is too big. |
majorHeight | positive integer | This is the height (in pixel) for major ticks. |
minorHeight | positive integer | This is the height (in pixel) for minor ticks. |
minorTicks | positive integer | minorTicks is the amount of minor ticks between two major ticks. |
drawZero | bool | If true, a tick at zero (the first point of the two defining the line) is drawn. |
drawLabels | bool | If true, labels showing the ticks position on the axis are drawn beneath every majorTick. |
strokeColor | HTML colorstring | Changes stroke color of the ticks |
strokeWidth | positive integer | Drawing width for ticks. |
There's just one special attribute for creating equidistant ticks together with their axis: ticksDistance determines the distance between two major ticks.
Note: These options are for axis creation only and are ignored when constructing lines!
Special ticks
Special ticks can't be constructed together with an axis and therefore have to be created directly. The only difference between creating equidistant and creating special ticks is the second element of the parents array. For special ticks you have to give an array of positions on the axis, where special ticks are to be drawn. You always need an array for this, even if there's only one special tick to draw:
var brd3 = JXG.JSXGraph.initBoard('box3', {boundingbox: [-8.75, 2.5, 8.75, -2.5]});
var ax3 = brd3.create('axis', [[0,0],[1,0]]);
brd3.create('ticks', [ax3, [3.5]], {strokeColor: '#00ff00', majorHeight:15, drawLabels: true});
Or more than one special tick:
var brd4 = JXG.JSXGraph.initBoard('box4', {boundingbox: [-8.75, 2.5, 8.75, -2.5]});
var ax4 = brd4.create('axis', [[0,0],[1,0]]);
brd4.create('ticks', [ax4, [-4.33333, -1.5, 3.5, 4.321]], {strokeColor: '#00ff00', majorHeight: 15, drawLabels: true});
The possible attributes here are mostly the same as above when creating equidistant ticks:
Attribute | Type | Effect |
---|---|---|
majorHeight | positive integer | This is the height (in pixel) for all special ticks. |
drawLabels | bool | If true, labels showing the ticks position on the axis are drawn beneath every majorTick. |
strokeColor | HTML colorstring | Changes stroke color of the ticks |
strokeWidth | positive integer | Drawing width for ticks. |
Remove ticks
You can remove all ticks attached to a line or an axis by calling the removeAllTicks() method of the line you want to have 'tickless' or you can remove specific ticks by calling removeTicks method of the given line instance with the a reference to the ticks instance as a parameter:
var xaxis = board.create('line', [point1, point2]);
var ticks = board.create('ticks', [xaxis, [1.0, 2.0, 5.0]]);
xaxis.removeTicks(ticks);
To access ticks automatically constructed on creation of an axis, use the axis property called defaultTicks:
var xaxis = board.create('axis', [point1, point2]);
xaxis.removeTicks(xaxis.defaultTicks);