Class JXG.Ticks
JXG.GeometryElement
↳ JXG.Ticks
Ticks provides methods for creation and management
of ticks on an axis.
Defined in: ticks.js.
Extends
JXG.GeometryElement.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
JXG.Ticks(line, ticks, attributes)
Creates ticks for an axis.
|
| Field Attributes | Field Name and Description |
|---|---|
|
Determine the position of the tick with value 0.
|
|
|
Draw labels yes/no
|
|
|
Draw the zero tick, that lies at line.point1?
|
|
|
A function that expects two JXG.Coords, the first one representing the coordinates of the
tick that is to be labeled, the second one the coordinates of the center (the tick with position 0).
|
|
|
Whether line boundaries should be counted or not in the lower and upper bounds when
creating ticks.
|
|
|
If the distance between two ticks is too big we could insert new ticks.
|
|
|
User defined labels for special ticks.
|
|
|
Total height of a major tick.
|
|
|
The maximum number of characters a tick label can use.
|
|
|
Total height of a minor tick.
|
|
|
The number of minor ticks between two major ticks.
|
|
|
If a label exceeds JXG.Ticks#maxLabelLength this determines the precision used to shorten the tick label.
|
|
|
Scale the ticks but not the tick labels.
|
|
|
A string that is appended to every tick, used to represent the scale
factor given in JXG.Ticks#scaleSymbol.
|
|
|
Decides in which direction finite ticks are visible.
|
|
|
The default distance between two ticks.
|
- Fields borrowed from class JXG.GeometryElement:
- _pos, addEvent, ancestors, baseElement, childElements, dash, descendants, draft, dump, elementClass, elType, eventHandlers, fillColor, fillOpacity, fixed, frozen, getProperty, hasLabel, highlight, highlighted, highlightFillColor, highlightFillOpacity, highlightStrokeColor, highlightStrokeOpacity, highlightStrokeWidth, id, isDraggable, isReal, lastDragTime, methodMap, mouseover, name, needsRegularUpdate, needsUpdate, notExistingParents, numTraces, quadraticform, removeEvent, rendNode, scalable, setProperty, shadow, snapToGrid, stdform, strokeColor, strokeOpacity, strokeWidth, subs, symbolic, trace, traceAttributes, traces, transformations, type, visible, visProp, withLabel
| Field Attributes | Field Name and Description |
|---|---|
|
The board the ticks line is drawn on.
|
|
|
Equidistant ticks.
|
|
|
Array of fixed ticks.
|
|
|
To ensure the uniqueness of label ids this counter is used.
|
|
|
A list of labels that are currently unused and ready for reassignment.
|
|
|
The line the ticks belong to.
|
|
|
Least distance between two ticks, measured in pixels.
|
|
|
Stores the ticks coordinates
|
|
|
Distance between two major ticks in user coordinates
|
|
|
A function calculating ticks delta depending on the ticks number.
|
- Fields borrowed from class JXG.GeometryElement:
- _pos, addEvent, ancestors, baseElement, childElements, dash, descendants, draft, dump, elementClass, elType, eventHandlers, fillColor, fillOpacity, fixed, frozen, getProperty, hasLabel, highlight, highlighted, highlightFillColor, highlightFillOpacity, highlightStrokeColor, highlightStrokeOpacity, highlightStrokeWidth, id, isDraggable, isReal, lastDragTime, methodMap, mouseover, name, needsRegularUpdate, needsUpdate, notExistingParents, numTraces, quadraticform, removeEvent, rendNode, scalable, setProperty, shadow, snapToGrid, stdform, strokeColor, strokeOpacity, strokeWidth, subs, symbolic, trace, traceAttributes, traces, transformations, type, visible, visProp, withLabel
| Method Attributes | Method Name and Description |
|---|---|
| <private> |
adjustTickDistance(ticksDelta, distScr, coordsZero, deltas)
Auxiliary method used by JXG.Ticks#generateEquidistantTicks to adjust the
distance between two ticks depending on JXG.Ticks#minTicksDistance value
|
| <private> |
(Re-)calculates the ticks coordinates.
|
| <private> |
generateEquidistantTicks(coordsZero, bounds)
Creates ticks coordinates and labels automatically.
|
| <private> |
generateFixedTicks(coordsZero, bounds)
Creates ticks coordinates and labels based on JXG.Ticks#fixedTicks and JXG.Ticks#labels.
|
| <private> |
generateLabel(labelText, tick, tickNumber)
Create a tick label
|
| <private> |
generateLabelText(tick, zero, value)
Creates the label text for a given tick.
|
| <private> |
getDistanceFromZero(zero, point)
Calculates the distance in user coordinates from zero to a given point including its sign
|
| <private> |
getLowerAndUpperBounds(coordsZero)
Calculate the lower and upper bounds for tick rendering
If JXG.Ticks#includeBoundaries is false, the boundaries will exclude point1 and point2
|
| <private> |
Calculates the x and y distance between two major ticks
|
| <private> |
Returns the coordinates of the point zero of the line.
|
|
hasPoint(x, y)
Checks whether (x,y) is near the line.
|
|
| <private> |
processTickPosition(coordsZero, tickPosition, ticksDelta, deltas)
Auxiliary method used by JXG.Ticks#generateEquidistantTicks to create a tick
in the line at the given tickPosition.
|
| <private> |
Removes the HTML divs of the tick labels
before repositioning
|
|
setPositionDirectly(method, coords, oldcoords)
Sets x and y coordinate of the tick.
|
|
| <private> |
Sets the variables used to set the height and slope of each tick.
|
|
update()
Recalculate the tick positions and the labels.
|
|
|
Uses the boards renderer to update the arc.
|
- Methods borrowed from class JXG.GeometryElement:
- _set, addChild, addDescendants, addRotation, addTransform, animate, bounds, clearTrace, cloneToBackground, countChildren, createGradient, createLabel, draggable, generatePolynomial, getAttribute, getAttributes, getLabelAnchor, getName, getParents, getTextAnchor, getType, handleSnapToGrid, hideElement, labelColor, noHighlight, normalize, off, on, prepareUpdate, remove, removeChild, removeDescendants, resolveShortcuts, setArrow, setAttribute, setDash, setLabelText, setName, showElement, snapToPoints, triggerEventHandlers
- Events borrowed from class JXG.GeometryElement:
- attribute, attribute:<attribute><attribute>, down, drag, mousedown, mousedrag, mousemove, mouseout, mouseover, mouseup, move, out, over, touchdown, touchdrag, touchup, up
Class Detail
JXG.Ticks(line, ticks, attributes)
Creates ticks for an axis.
- Parameters:
- {JXG.Line} line
- Reference to the axis the ticks are drawn on.
- {Number|Array} ticks
- Number defining the distance between two major ticks or an array defining static ticks.
- {Object} attributes
- Properties
- See:
- JXG.Line#addTicks
Attribute Detail
{String}
anchor
Determine the position of the tick with value 0. 'left' means point1 of the line, 'right' means point2,
and 'middle' is equivalent to the midpoint of the defining points. This attribute is ignored if the parent
line is of type axis and is parallel to either the x (i.e. y = 0) or the y (i.e. x = 0) axis.
Defined in: options.js.
Defined in: options.js.
- Default Value:
- 'left'
{Boolean}
drawLabels
Draw labels yes/no
Defined in: options.js.
Defined in: options.js.
- Default Value:
- false
{Boolean}
drawZero
Draw the zero tick, that lies at line.point1?
Defined in: options.js.
Defined in: options.js.
- Default Value:
- false
{function}
generateLabelValue
A function that expects two JXG.Coords, the first one representing the coordinates of the
tick that is to be labeled, the second one the coordinates of the center (the tick with position 0).
Defined in: options.js.
Defined in: options.js.
{Boolean}
includeBoundaries
Whether line boundaries should be counted or not in the lower and upper bounds when
creating ticks.
Defined in: options.js.
Defined in: options.js.
- Default Value:
- false
{Boolean}
insertTicks
If the distance between two ticks is too big we could insert new ticks. If insertTicks
is true, we'll do so, otherwise we leave the distance as is.
This option is ignored if equidistant is false. In the example below the distance between
two ticks is given as 1 but because insertTicks is set to true many ticks will
be omitted in the rendering process to keep the display clear.
Defined in: options.js.
Defined in: options.js.
// Create an axis providing two coord pairs.
var p1 = board.create('point', [0, 0]);
var p2 = board.create('point', [50, 25]);
var l1 = board.create('line', [p1, p2]);
var t = board.create('ticks', [l1, 1], {
insertTicks: true,
majorHeight: -1,
label: {
offset: [4, -9]
},
drawLabels: true
});
- Default Value:
- false
{Array}
labels
User defined labels for special ticks. Instead of the i-th tick's position, the i-th string stored in this array
is shown. If the number of strings in this array is less than the number of special ticks, the tick's position is
shown as a fallback.
Defined in: options.js.
Defined in: options.js.
- Default Value:
- []
{Number}
majorHeight
Total height of a major tick. If negative the full height of the board is taken.
Defined in: options.js.
Defined in: options.js.
{Number}
maxLabelLength
The maximum number of characters a tick label can use.
Defined in: options.js.
Defined in: options.js.
- See:
- JXG.Ticks#precision
- Default Value:
- 3
{Number}
minorHeight
Total height of a minor tick. If negative the full height of the board is taken.
Defined in: options.js.
Defined in: options.js.
{Number}
minorTicks
The number of minor ticks between two major ticks.
Defined in: options.js.
Defined in: options.js.
{Number}
precision
If a label exceeds JXG.Ticks#maxLabelLength this determines the precision used to shorten the tick label.
Defined in: options.js.
Defined in: options.js.
- Default Value:
- 3
{Number}
scale
Scale the ticks but not the tick labels.
Defined in: options.js.
Defined in: options.js.
- Default Value:
- 1
{String}
scaleSymbol
A string that is appended to every tick, used to represent the scale
factor given in JXG.Ticks#scaleSymbol.
Defined in: options.js.
Defined in: options.js.
- See:
- JXG.Ticks#scale
- Default Value:
- ''
{Array}
tickEndings
Decides in which direction finite ticks are visible. Possible values are 0=false or 1=true.
In case of [0,1] the tick is only visible to the right of the line. In case of
[1,0] the tick is only visible to the left of the line.
Defined in: options.js.
Defined in: options.js.
{Number}
ticksDistance
The default distance between two ticks. Please be aware that this value does not have
to be used if JXG.Ticks#insertTicks is set to true.
Defined in: options.js.
Defined in: options.js.
- Default Value:
- 1
Field Detail
{JXG.Board}
board
The board the ticks line is drawn on.
{Boolean}
equidistant
Equidistant ticks. Distance is defined by ticksFunction
{Array}
fixedTicks
Array of fixed ticks.
labelCounter
To ensure the uniqueness of label ids this counter is used.
labelsRepo
A list of labels that are currently unused and ready for reassignment.
{JXG.Line}
line
The line the ticks belong to.
{int}
minTicksDistance
Least distance between two ticks, measured in pixels.
ticks
Stores the ticks coordinates
ticksDelta
Distance between two major ticks in user coordinates
{Function}
ticksFunction
A function calculating ticks delta depending on the ticks number.
Method Detail
<private>
adjustTickDistance(ticksDelta, distScr, coordsZero, deltas)
Auxiliary method used by JXG.Ticks#generateEquidistantTicks to adjust the
distance between two ticks depending on JXG.Ticks#minTicksDistance value
- Parameters:
- {Number} ticksDelta
- distance between two major ticks in user coordinates
- {Number} distScr
- distance between two major ticks in screen coordinates
- {JXG.Coords} coordsZero
- coordinates of the point considered zero
- {Object} deltas
- x and y distance between two major ticks
<private>
calculateTicksCoordinates()
(Re-)calculates the ticks coordinates.
<private>
generateEquidistantTicks(coordsZero, bounds)
Creates ticks coordinates and labels automatically.
The frequency of ticks is affected by the values of JXG.Ticks#insertTicks and JXG.Ticks#ticksDistance
- Parameters:
- {JXG.Coords} coordsZero
- coordinates of the point considered zero
- {Object} bounds
- contains the lower and upper boundaries for ticks placement
<private>
generateFixedTicks(coordsZero, bounds)
Creates ticks coordinates and labels based on JXG.Ticks#fixedTicks and JXG.Ticks#labels.
- Parameters:
- {JXG.Coords} coordsZero
- Coordinates of the point considered zero
- {Object} bounds
- contains the lower and upper boundaries for ticks placement
<private>
{JXG.Text}
generateLabel(labelText, tick, tickNumber)
Create a tick label
- Parameters:
- {String} labelText
- {JXG.Coords} tick
- {Number} tickNumber
- Returns:
- {JXG.Text}
<private>
{String}
generateLabelText(tick, zero, value)
Creates the label text for a given tick. A value for the text can be provided as a number or string
- Parameters:
- {JXG.Coords} tick
- The Coords of the tick to create a label for
- {JXG.Coords} zero
- The Coords of line's zero
- {Number|String} value
- A predefined value for this tick
- Returns:
- {String}
<private>
{Number}
getDistanceFromZero(zero, point)
Calculates the distance in user coordinates from zero to a given point including its sign
- Parameters:
- {JXG.Coords} zero
- coordinates of the point considered zero
- {JXG.Coords} point
- coordinates of the point to find out the distance
- Returns:
- {Number} distance between zero and point, including its sign
<private>
{Object}
getLowerAndUpperBounds(coordsZero)
Calculate the lower and upper bounds for tick rendering
If JXG.Ticks#includeBoundaries is false, the boundaries will exclude point1 and point2
- Parameters:
- {JXG.Coords} coordsZero
- Returns:
- {Object} contains the lower and upper bounds
<private>
{Object}
getXandYdeltas()
Calculates the x and y distance between two major ticks
- Returns:
- {Object}
<private>
{JXG.Coords}
getZeroCoordinates()
Returns the coordinates of the point zero of the line.
If the line is an Axis, the coordinates of the projection of the board's zero point is returned
Otherwise, the coordinates of the point that acts as zero are established depending on the value of JXG.Ticks#anchor
- Returns:
- {JXG.Coords} Coords object for the Zero point on the line
{Boolean}
hasPoint(x, y)
Checks whether (x,y) is near the line.
- Parameters:
- {Number} x
- Coordinate in x direction, screen coordinates.
- {Number} y
- Coordinate in y direction, screen coordinates.
- Returns:
- {Boolean} True if (x,y) is near the line, False otherwise.
<private>
processTickPosition(coordsZero, tickPosition, ticksDelta, deltas)
Auxiliary method used by JXG.Ticks#generateEquidistantTicks to create a tick
in the line at the given tickPosition.
- Parameters:
- {JXG.Coords} coordsZero
- coordinates of the point considered zero
- {Number} tickPosition
- current tick position relative to zero
- {Number} ticksDelta
- distance between two major ticks in user coordinates
- {Object} deltas
- x and y distance between two major ticks
<private>
removeTickLabels()
Removes the HTML divs of the tick labels
before repositioning
{JXG.Ticks}
setPositionDirectly(method, coords, oldcoords)
Sets x and y coordinate of the tick.
- Parameters:
- {number} method
- The type of coordinates used here. Possible values are JXG.COORDS_BY_USER and JXG.COORDS_BY_SCREEN.
- {Array} coords
- coordinates in screen/user units
- {Array} oldcoords
- previous coordinates in screen/user units
- Returns:
- {JXG.Ticks} this element
<private>
setTicksSizeVariables()
Sets the variables used to set the height and slope of each tick.
{JXG.Ticks}
update()
Recalculate the tick positions and the labels.
- Returns:
- {JXG.Ticks}
{JXG.Ticks}
updateRenderer()
Uses the boards renderer to update the arc.
- Returns:
- {JXG.Ticks}
JSXGraph Reference
Elements