-
Notifications
You must be signed in to change notification settings - Fork 44
Genoverse.Track.View functions
The following are functions that exist in the Genoverse.Track.View
object. Any of these can have before/after hooks added to them unless otherwise specified, or be overwritten by supplying them as properties in configuration.
The following is a list of order of operations, where one of the functions documented below is called by another:
Sets initial properties of the instance. Does not have before/after hooks.
Creates a
featurePositions
RTree for the current chromosome and givenscale
.If
labels = "separate"
, alabelPositions
RTree is also created.
Argument Type Description scale Float The scale (browser pixel width / browser region size) to create settings for
For each feature, adds a
feature.position[scale]
property, containing the height of the feature and its scaled start and width. This property is used to determine where on the image the feature will be drawn.Returns the features.
Argument Type Description features Array The features to be drawn scale Float The scale for the image being drawn
Calls
view.positionFeature
for each feature given.Returns the features.
Argument Type Description features Array The features to be positioned params Object A set of properties required to create the image
Modifies the feature's
position
property to contain the values needed to draw it on the image. Also inserts the feature into thefeaturePositions
RTree, which is used to determine when features are being clicked on by the user, and for bumping.
Argument Type Description feature Object The feature to be positioned params Object A set of properties required to create the image
If
bump
is set, features are moved vertically within the track so that the do not overlap horizontally. This is referred to as "bumping".The
featurePositions
RTree is searched for the givenbounds
to discover if it contains another feature in the position. If there is, the givenbounds
' y coordinate is updated such that it doesn't overlap with the found feature any more.This process is done in a loop until searching the RTree for
bounds
no longer finds any features, at which point the givenfeature
's y coordinate is updated to the value ofbounds.y
.The nature of this process means that it can be quite slow for feature-dense regions. A
depth
cut-off can be specified to limit the maximum number of iterations, but any features which would need to exceed that limit will not be displayed on the image (they will have avisible
property set tofalse
).
Argument Type Description bounds Object The region used to search the RTree, in the form { "x": 1, "y": 1, "width": 1, "height": 1 }
feature Object The feature to be bumped scale Float The scale for the image being drawn tree RTree The RTree to be searched. Will be either featurePositions
orlabelPositions
, depending on what is being bumped.
Calls
view.drawFeature
for each feature withoutvisible
property set tofalse
. Features are cloned before being passed toview.drawFeature
to stop the stored versions from being mutated (view.setFeatureColor
,view.setLabelColor
, andview.truncateForDrawing
can all mutate their input feature).
Argument Type Description features Array The features to be drawn featureContext Canvas 2D rendering context The rendering context for the canvas on which the features will be drawn labelContext Canvas 2D rendering context The rendering context for the canvas on which the features' labels will be drawn. Different from featureContext
iflabels = "separate"
.scale Float The scale for the image being drawn
Can be used like
view.draw
to draw a background image for a track.By default does nothing - must be implemented.
Argument Type Description features Array The features which were drawn on the foreground image context Canvas 2D rendering context The rendering context for the canvas on which the background will be drawn params Object A set of properties required to create the image
Uses the Canvas 2D rendering context to draw a feature on the
featureContext
canvas.Calls
view.drawLabel
if the feature has a label andlabels
are being displayed.Calls
view.drawSubFeatures
iffeature.subFeatures
is present.Calls
view.decorateFeatures
iffeature.decorations
is present.
Argument Type Description feature Object The feature to be drawn featureContext Canvas 2D rendering context The rendering context for the canvas on which the feature will be drawn labelContext Canvas 2D rendering context The rendering context for the canvas on which the feature's label will be drawn. Different from featureContext
iflabels = "separate"
.scale Float The scale for the image being drawn
Uses the Canvas 2D rendering context to draw a feature's label on the
labelContext
canvas
Argument Type Description feature Object The feature whose label will be drawn labelContext Canvas 2D rendering context The rendering context for the canvas on which the label will be drawn scale Float The scale for the image being drawn
Uses the Canvas 2D rendering context to draw a feature's
subFeatures
on thefeatureContext
canvas.
Argument Type Description feature Object The feature whose sub-features will be drawn featureContext Canvas 2D rendering context The rendering context for the canvas on which the sub-features will be drawn labelContext Canvas 2D rendering context The rendering context for the canvas on which the sub-features' labels will be drawn. Different from featureContext
iflabels = "separate"
.scale Float The scale for the image being drawn
Sets
feature.color
toview.color
. Called byview.drawFeature
for features which don't have acolor
property.
Argument Type Description feature Object The feature whose color
will be set
Sets
feature.labelColor
toview.fontColor
,feature.color
, orview.color
. Called byview.drawLabel
for features which don't have alabelColor
property.
Argument Type Description feature Object The feature whose labelColor
will be set
If a feature extends beyond the edge of the canvas, makes it start and end at 1px outside the canvas to reduce unnecessary drawing operations.
Uses 1px outside rather than on the edges of the canvas in order to stop feature borders being erroneously included in an image (a border will be drawn at the start/end of a feature, meaning that a feature which ends at the end of a canvas will have a vertical border inside the canvas).
Argument Type Description feature Object The feature to truncate
Called by
view.drawFeature
iffeature.decorations
is present. By default,view.drawFeature
draws features as rectangles. This function can be used to add other shapes if necessary, positioning them based onfeature.position[scale]
.By default does nothing - must be implemented.
Argument Type Description feature Object The feature to decorate featureContext Canvas 2D rendering context The rendering context for the canvas on which the feature was drawn scale Float The scale for the image being drawn