Skip to content

Genoverse.Track.View functions

Simon Brent edited this page Mar 25, 2022 · 3 revisions

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:

view.setDefaults()

Sets initial properties of the instance. Does not have before/after hooks.

view.setScaleSettings(scale)

Creates a featurePositions RTree for the current chromosome and given scale.

If labels = "separate", a labelPositions RTree is also created.

Argument Type Description
scale Float The scale (browser pixel width / browser region size) to create settings for

view.scaleFeatures(features, scale)

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

view.positionFeatures(features, params)

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

view.positionFeature(feature, params)

Modifies the feature's position property to contain the values needed to draw it on the image. Also inserts the feature into the featurePositions 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

view.bumpFeature(bounds, feature, scale, tree)

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 given bounds to discover if it contains another feature in the position. If there is, the given bounds' 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 given feature's y coordinate is updated to the value of bounds.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 a visible property set to false).

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 or labelPositions, depending on what is being bumped.

view.draw(features, featureContext, labelContext, scale)

Calls view.drawFeature for each feature without visible property set to false. Features are cloned before being passed to view.drawFeature to stop the stored versions from being mutated (view.setFeatureColor, view.setLabelColor, and view.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 if labels = "separate".
scale Float The scale for the image being drawn

view.drawBackground(features, context, params)

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

view.drawFeature(feature, featureContext, labelContext, scale)

Uses the Canvas 2D rendering context to draw a feature on the featureContext canvas.

Calls view.drawLabel if the feature has a label and labels are being displayed.

Calls view.drawSubFeatures if feature.subFeatures is present.

Calls view.decorateFeatures if feature.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 if labels = "separate".
scale Float The scale for the image being drawn

view.drawLabel(feature, labelContext, scale)

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

view.drawSubFeatures(feature, featureContext, labelContext, scale)

Uses the Canvas 2D rendering context to draw a feature's subFeatures on the featureContext 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 if labels = "separate".
scale Float The scale for the image being drawn

view.setFeatureColor(feature)

Sets feature.color to view.color. Called by view.drawFeature for features which don't have a color property.

Argument Type Description
feature Object The feature whose color will be set

view.setLabelColor(feature)

Sets feature.labelColor to view.fontColor, feature.color, or view.color. Called by view.drawLabel for features which don't have a labelColor property.

Argument Type Description
feature Object The feature whose labelColor will be set

view.truncateForDrawing(feature)

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

view.decorateFeature(feature, featureContext, scale)

Called by view.drawFeature if feature.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 on feature.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