Skip to content

JavaScript API reference

The JavaScript library, geneviewer 0.3.11: newChart(), the chart spec, the chart's methods and events. The spec's options are generated from the JSON Schema in the repository; names may still change until 1.0.

The R and Python packages have their own references: R reference, Python reference.

newChart()

geneviewer.newChart(target, spec, options?) → Chart
ArgumentTypeDescription
targetstring or ElementA CSS selector or the element to draw in. The chart takes its size.
specobjectWhat to draw: see the chart spec.
options.onobjectEvent handlers by name, added before the first draw, so they also get its events.
options.saveAsfunctionCalled as saveAs(blob, filename) instead of the browser's download.
options.injectStylesbooleanDefault true: the library adds its stylesheet to the page once. Turn off where a Content-Security-Policy blocks it, and load geneviewer.css.
options.serverbooleanFor the R and Python packages: events go to a server that may draw the chart again.

Other functions

NameDescription
geneviewer.compile(spec)The render model a spec gives: clusters split, per-cluster settings applied, theme resolved. For tests and debugging; its shape is internal and may change in any version.
geneviewer.themesThe built-in themes and their settings, by name. The names are those of theme; the settings use the renderer's names and are not part of spec v1.
geneviewer.palettesThe built-in colour palettes: arrays of colours, by the names theme.palette takes.
geneviewer.versionThe library's version.

The chart spec

A chart is one plain object, which can be written as JSON. Its keys mirror the R package's functions: GC_labels() becomes labels, and arguments become camelCase options.

KeyTypeDefaultDescription
version11The spec version. Optional: a spec without one is version 1.
datatableThe genes: an array of rows, or columns (an object of equal-length arrays), as R and Python send them.
fieldsobjectThe columns of data that hold each gene's position, cluster, group and strand.
widthnumber or string"100%"Width of the chart: pixels, or a CSS length such as "100%".
heightnumber or string"400px"Height of the chart: pixels, or a CSS length such as "400px".
stylestyle objectCSS styles of the chart's element, e.g. { backgroundColor: "white" }.

fields

OptionTypeDefaultDescription
startcolumn name"start"Column with the start position of each gene.
endcolumn name"end"Column with the end position of each gene.
clustercolumn nameColumn that splits the genes into clusters. Default: one cluster.
groupcolumn nameColumn that groups the genes, which sets their colours and the legend.
strandcolumn nameColumn with the strand of each gene: 1, "forward", "sense" or "+" for forward; -1, 0, "reverse", "antisense", "complement" or "-" for reverse. Default: a column named strand if the data has one; otherwise a gene with start less than end is forward and any other gene is reverse.

Per-cluster settings

Most components can be an array of entries. Entries apply in order; an entry with clusters applies only to those clusters, by name or by 1-based position:

labels: [
  { label: "name" },                      // every cluster
  { clusters: ["dbophA"], show: false },  // then hide the labels of dbophA
]

Components

align

Aligns the clusters on one gene: each cluster's scale is set so the gene is at the same place in every cluster. One object.

OptionTypeDefaultDescription
idColumncolumn nameColumn that identifies the gene to align on.
idstring or numberThe value of idColumn of the gene to align on; one gene per cluster.
align"left" | "center" | "right""left"The side of the gene the clusters align on.

annotation

Annotations drawn in the clusters: text, lines, arrows, symbols and more. One entry, or an array of entries applied in order.

OptionTypeDefaultDescription
type"text" | "textMarker" | "line" | "arrow" | "symbol" | "rectangle" | "promoter" | "terminator" | "arc""text"The kind of annotation.
clustersclustersThe clusters this entry applies to, by name or 1-based position. Default: all clusters.
xnumber or array of numberPosition along the scale (text, symbol, promoter, terminator); an array draws one per position; an array draws one per value.
ynumber or array of numberVertical position, from 1 to 100 (text, symbol, promoter, terminator); an array draws one per value.
textstring or number or array of string or numberThe text (text, textMarker, arc); an array draws one per value.
x1number or array of numberStart position along the scale (line, arrow, textMarker, arc); an array draws one per value.
x2number or array of numberEnd position along the scale (line, arrow, textMarker, arc); an array draws one per value.
y1number or array of numberStart height, from 1 to 100 (line, arrow, textMarker, arc); an array draws one per value.
y2number or array of numberEnd height, from 1 to 100 (line, arrow, textMarker, arc); an array draws one per value.
positionanytextMarker: the position along the scale; rectangle: corners [[x1, y1], [x2, y2]], or an array of them.
labelXnumber or array of numberHorizontal offset of the text, in pixels (textMarker, arc); an array draws one per value.
labelYnumber or array of numberVertical offset of the text, in pixels (textMarker, arc); an array draws one per value.
showArrowbooleanWhether the textMarker has an arrowhead.
arrowSizenumber or array of numberSize of the arrowhead, in pixels (arrow, textMarker); an array draws one per value.
symbolstring or array of stringSymbol: circle, cross, diamond, square, star, triangle or wye.
sizenumber or array of numberSize of the symbol, in square pixels; an array draws one per value.
rotationnumber or array of numberRotation, in degrees (symbol, rectangle, promoter, terminator); an array draws one per value.
direction"forward" | "reverse"Direction of a promoter or terminator.
scalenumber or array of numberSize factor of a promoter or terminator; an array draws one per value.
midYnumber or array of numberHeight of the arc's middle, from 1 to 100; an array draws one per value.
strokestring or array of stringLine colour of an arc.
strokeWidthnumber or array of numberLine width of an arc, in pixels; an array draws one per value.
stylestyle objectStyle of the annotation (text, line, symbol, rectangle, promoter, terminator).
textStylestyle objectStyle of the text (textMarker, arc).
arrowStylestyle objectStyle of the arrowhead (arrow, textMarker).
lineStylestyle objectStyle of the line (arrow, textMarker, arc).

Other options are passed to the renderer as they are.

cluster

Layout of the genes in a cluster: strands on separate rows, overlapping genes on separate tracks, and the cluster's style. An array of entries applies them in order; an entry with clusters only to those clusters. One entry, or an array of entries applied in order.

OptionTypeDefaultDescription
separateStrandsbooleanWhether forward and reverse genes go on separate rows.
strandSpacingnumberSpace between the forward and reverse rows, with separateStrands.
preventGeneOverlapboolean or "nested"Overlapping genes go on separate tracks: true for all overlapping genes, "nested" only for genes that lie inside another gene. The track of each gene is in its geneTrack field.
overlapMinnumber or stringHow much two genes must overlap to go on separate tracks: base pairs, or a share of the shorter gene such as "10%". Default: any overlap.
overlapSpacingnumberSpace between tracks, with preventGeneOverlap.
clustersclustersThe clusters this entry applies to, by name or 1-based position. Default: all clusters.
stylestyle objectCSS styles of the cluster's element.
marginmarginsMargins of the cluster, in pixels.
widthnumber or stringWidth of the cluster.
heightnumber or stringHeight of the cluster.

Other options are passed to the renderer as they are.

clusterFooter

Footer below each cluster: a title and subtitle. An array of entries applies them in order; an entry with clusters only to those clusters. One entry, or an array of entries applied in order.

OptionTypeDefaultDescription
titlestring or number or array of string or numberTitle of each footer; an array is recycled over the clusters.
subtitlestring or number or array of string or numberSubtitle of each footer.
showboolean or array of booleantrueWhether to show the footer.
clustersclustersThe clusters this entry applies to, by name or 1-based position. Default: all clusters.
subtitleFontstyle objectFont options of the subtitle.
titleFontstyle objectFont options of the title.
align"left" | "center" | "right" or array of "left" | "center" | "right"Alignment of the title and subtitle; x moves them from there. Default: the theme's, otherwise "left".
spacingnumber or array of numberPixels between the title and subtitle. Default: the theme's, otherwise 12.
xnumberHorizontal offset of the footer, in pixels.
ynumberVertical offset of the footer, in pixels.

Other options are passed to the renderer as they are.

clusterLabel

Label in the left or right margin of each cluster. An array of entries applies them in order; an entry with clusters only to those clusters. One entry, or an array of entries applied in order.

OptionTypeDefaultDescription
titlestring or number or array of string or numberText of the label; an array is recycled over the clusters.
showbooleantrueWhether to show the label.
widthnumber or stringWidth of the label, which sets the cluster's margin on that side. Default: a margin set with grid, otherwise the theme's, otherwise "100px".
clustersclustersThe clusters this entry applies to, by name or 1-based position. Default: all clusters.
position"left" | "right"Side of the label. Default: the theme's, otherwise "left".
align"left" | "center" | "right" or array of "left" | "center" | "right"Alignment of the label's lines in its margin; x moves it from there. Default: the theme's, otherwise "center".
wrapLabelbooleanWhether long labels wrap over several lines. Default: the theme's, otherwise true.
wrapOptionsobjectOptions for wrapping the label.
subtitlestring or number or array of string or numberA second line below the title, e.g. the species.
subtitleFontstyle objectFont options of the subtitle. Default: 11px, not bold.
spacingnumber or array of numberPixels between the middle of the title's last line and the subtitle. Default: the theme's, otherwise 1.2 times the mean font size of the two.
xnumberHorizontal offset of the label, in pixels.
ynumberVertical offset of the label, in pixels.
fontSizenumber or stringFont size, e.g. "12px".
fontStylestringFont style, e.g. "italic".
fontWeightnumber or stringFont weight, e.g. "bold".
fontFamilystringFont family.
cursorstringMouse cursor over it.

Other options are passed to the renderer as they are.

clusterTitle

Title and subtitle above each cluster. An array of entries applies them in order; an entry with clusters only to those clusters. One entry, or an array of entries applied in order.

OptionTypeDefaultDescription
titlestring or number or array of string or numberTitle of each cluster; an array is recycled over the clusters.
subtitlestring or number or array of string or numberSubtitle of each cluster; an array is recycled over the clusters.
subtitleFontstyle objectFont options of the subtitle.
titleFontstyle objectFont options of the title.
showbooleantrueWhether to show the title.
heightnumber or stringHeight of the title, e.g. "40px".
clustersclustersThe clusters this entry applies to, by name or 1-based position. Default: all clusters.
align"left" | "center" | "right" or array of "left" | "center" | "right"Alignment of the title and subtitle; x moves them from there. Default: the theme's, otherwise "center".
spacingnumber or array of numberPixels between the title and subtitle. Default: the theme's, otherwise 20.
xnumberHorizontal offset of the title, in pixels.
ynumberVertical offset of the title, in pixels.

Other options are passed to the renderer as they are.

color

Colours of the gene groups, for the genes and the legend. One object.

OptionTypeDefaultDescription
colorSchemestringName of a colour scheme: a D3 scheme such as "schemeTableau10", or a geneviewer palette such as "okabeIto".
customColorscoloursColours of the groups: an array recycled over the groups, or an object of colours by group. Groups left out keep the colours of colorScheme, the theme's palette or the defaults.

coordinates

Start and end positions written at the genes. An array of entries applies them in order; an entry with clusters only to those clusters. One entry, or an array of entries applied in order.

OptionTypeDefaultDescription
showboolean or array of booleantrueWhether to show the coordinates.
tickValuesToparray of numberPositions written above the cluster, in place of the genes' own.
tickValuesBottomarray of numberPositions written below the cluster, in place of the genes' own.
ticksFormatstringD3 number format of the positions. Default: ",.0f".
tickStylestyle objectStyles of the ticks.
textStylestyle objectStyles of the text.
clustersclustersThe clusters this entry applies to, by name or 1-based position. Default: all clusters.
groupStylestyles by groupStyles by group, for the coordinates of every gene of that group: show = false leaves them out, tick styles their ticks, the rest their text.
styleBycolumn nameColumn whose values groupStyle matches. Default: fields.group.
rotatenumber-45Rotation of the coordinates, in degrees.
yPositionTopnumber53Vertical position of the coordinates above the genes, from 1 (bottom) to 100 (top) of the cluster.
yPositionBottomnumber48Vertical position of the coordinates below the genes, from 1 (bottom) to 100 (top) of the cluster.
overlapThresholdnumber20Distance in pixels below which coordinates of neighbouring genes go on the other side.

Other options are passed to the renderer as they are.

elementStyle

Overrides for single elements: a gene, label or coordinate, a title or subtitle, a legend label or marker, a scale bar or axis. Each entry is one element; later entries for the same element add to earlier ones. One entry, or an array of entries applied in order.

OptionTypeDefaultDescription
component"genes" | "labels" | "coordinates" | "clusterTitle" | "clusterFooter" | "clusterLabel" | "legend" | "title" | "scaleBar" | "scale""genes"The component of the element.
rowIDnumberFor genes, labels and coordinates: the gene's rowID, as reported in select and dblclick events.
clusterclusterFor cluster titles, footers, labels, scale bars and axes: the cluster's name or 1-based position.
part"title" | "subtitle" | "label" | "marker"For titles, footers and cluster labels: "title" or "subtitle"; for the legend: "label" or "marker".
end"start" | "end"For coordinates: the start or end coordinate. Default: both.
groupstringFor the legend: the group's original value, as reported in events.

Other options are passed to the renderer as they are.

events

Which interactions the chart reports, and whether parts are clickable. One object.

OptionTypeDefaultDescription
clickbooleantrueWhether clicks are reported, in a spec with an events key; a spec without one reports nothing.
highlightbooleanfalseWhether the part under the mouse is outlined, to show what a click selects.
renderedbooleanfalseWhether each finished draw is reported as a rendered event.
renderIdstring or numberIdentifies this draw in the rendered event. A new value also restarts the zoom at its range. Default: a new unique id for each draw.
dblclickbooleanfalseWhether double-clicks are reported, for editing.
selectbooleanfalseWhether elements can be selected.
legendClickbooleantrueWhether clicks on the legend are reported.
dragbooleanfalseWhether labels, titles, scale bars, axes and legend items can be dragged. Moves can be undone and redone.
zoombooleanfalseWhether the zoom window is reported, on the first draw and after every change.

genes

The gene markers. An array of entries applies them in order; an entry with clusters only to those clusters. One entry, or an array of entries applied in order.

OptionTypeDefaultDescription
groupcolumn nameColumn that groups the genes for their colours. Default: fields.group.
marker"arrow" | "boxarrow" | "box" | "cbox" | "rbox"Shape of the markers.
markerSize"small" | "medium" | "large"Size of the markers.
showbooleantrueWhether to show the genes.
colorSchemestringColour scheme of the groups. Default: the colours of the color component.
customColorscoloursColours of the groups: an array recycled over the groups, or an object by group.
clustersclustersThe clusters this entry applies to, by name or 1-based position. Default: all clusters.
itemStyleitem stylesStyles of single genes, by their 0-based index in the cluster.
groupStylestyles by groupStyles by group, for every gene of that group. A gene's itemStyle takes precedence.
styleBycolumn nameColumn whose values groupStyle matches, or "geneTrack" for the track of each gene. Default: group.
cornerRadiusnumberRadius in pixels of the markers' corners. Default: sharp, and 5 for "rbox".
xnumberHorizontal offset of the genes, in pixels.
ynumber50Vertical position of the genes, from 1 (bottom) to 100 (top) of the cluster.
strokecolourOutline colour of the genes.
strokeWidthnumber1Outline width of the genes, in pixels.
cursorstring"default"Mouse cursor over a gene.
arrowheadWidthnumberWidth of the arrowhead, in pixels. Default: from markerSize.
arrowheadHeightnumberHeight of the arrowhead, in pixels. Default: from markerSize.
markerHeightnumberHeight of the gene body, in pixels. Default: from markerSize.

Other options are passed to the renderer as they are.

grid

Size and margins of each cluster, and the direction clusters are laid out in. An array of entries applies them in order; an entry with clusters only to those clusters. One entry, or an array of entries applied in order.

OptionTypeDefaultDescription
marginmarginsMargins of the cluster in pixels.
widthnumber or stringWidth of the cluster; a number is a percentage.
heightnumber or stringHeight of the cluster.
direction"column" | "row""column"Clusters below each other ("column") or side by side ("row").
clustersclustersThe clusters this entry applies to, by name or 1-based position. Default: all clusters.

labels

Labels of the genes. An array of entries applies them in order; an entry with clusters only to those clusters. One entry, or an array of entries applied in order.

OptionTypeDefaultDescription
labelcolumn nameColumn with the label of each gene. Default: fields.group.
showbooleantrueWhether to show the labels.
clustersclustersThe clusters this entry applies to, by name or 1-based position. Default: all clusters.
itemStyleitem stylesStyles of single labels, by their 0-based index in the cluster.
groupStylestyles by groupStyles by group, for the labels of every gene of that group.
styleBycolumn nameColumn whose values groupStyle matches, e.g. the label column, or "geneTrack". Default: fields.group.
xnumberHorizontal offset of the labels, in pixels.
ynumber55Vertical position of the labels, from 1 (bottom) to 100 (top) of the cluster.
dxnumber or stringHorizontal shift of each label, e.g. "0.5em".
dynumber or stringVertical shift of each label, e.g. "-1em".
rotatenumber0Rotation of the labels, in degrees.
startnumberPosition where the labels start; labels of genes before it are not drawn.
endnumberPosition where the labels end; labels of genes after it are not drawn.
adjustLabelsboolean or "hide" | "spread"trueOverlapping labels: true moves them apart, "hide" hides them, "spread" spreads them out with leader lines, false leaves them.
spreadPosition"bottom" | "top""bottom"With adjustLabels "spread": the side of the genes the labels go to.
leaderLinefalse or style objectStyle of the lines to spread labels (stroke, strokeWidth, length in pixels); false draws none.
textAnchor"start" | "middle" | "end""middle"Text alignment of each label at its gene.
labelAdjustmentstyle objectHow overlapping labels are moved: rotation, offsetX, offsetY, dx, dy.
fontSizenumber or stringFont size, e.g. "12px".
fontStylestringFont style, e.g. "italic".
fontWeightnumber or stringFont weight, e.g. "bold".
fontFamilystringFont family.
cursorstringMouse cursor over it.

Other options are passed to the renderer as they are.

legend

The legend of the gene groups. One object.

OptionTypeDefaultDescription
groupcolumn nameColumn whose values the legend lists. Default: fields.group.
showbooleantrueWhether to show the legend.
backgroundColorcolourBackground colour; style.backgroundColor takes precedence. Default: the theme's, otherwise transparent.
orderarray of stringOrder of the groups in the legend.
position"top" | "bottom"Above or below the clusters. Default: the theme's, otherwise "bottom".
align"left" | "center" | "right"Alignment of the legend items; each row on its own. Default: the theme's, otherwise "left".
stylestyle objectCSS styles of the legend's element.
markerStylestyle objectOptions of the legend items (markers), such as cursor.
textStylestyle objectOptions of the legend text, such as fontSize.
cornerRadiusnumberRadius in pixels of the markers' corners. Default: square.
groupStylestyles by groupStyles by group for the text of that group's entry; styles under marker go to its marker.
xnumberHorizontal offset of the legend, in pixels.
ynumberVertical offset of the legend, in pixels.
widthnumber or stringWidth of the legend. Default: the chart's width.
orientation"horizontal" | "vertical""horizontal"Entries side by side or below each other.
adjustHeightbooleantrueWhether the legend's height follows its entries.

Other options are passed to the renderer as they are.

Links between genes of different clusters, drawn from a table of pairs. An array of entries applies them in order; an entry with clusters only to those clusters. One entry, or an array of entries applied in order.

OptionTypeDefaultDescription
datatableThe links: one row per pair, made by R or Python (get_links) or by hand.
groupcolumn nameThe column the genes were matched on (R and Python: get_links). Its values pick the genes labelled with the measure; without it, links.data was given and labelPosition "gene" draws no labels.
value1string or number or array of string or numberValues of group matched in the first cluster of each pair; only their genes are labelled with the measure.
value2string or number or array of string or numberValues of group matched in the second cluster of each pair; only their genes are labelled with the measure.
clustersclustersThe clusters this entry applies to, by name or 1-based position. Default: all clusters.
curvebooleanWhether links are curved. Default: the theme's, otherwise true.
measure"identity" | "similarity" | "none""identity"The measure that sets the links' colour.
showbooleantrueWhether to show the links.
labelbooleantrueWhether to write the measure on the links.
labelPosition"gene" | "link""gene"Where the measure goes: with the gene's label ("gene") or in the middle of the link ("link").
normalColorcolourColour of links. Default: the theme's, otherwise "#969696".
invertedColorcolourColour of inverted links. Default: the theme's, otherwise "#d62728".
lowColorcolourColour links fade to at a low measure. Default: the theme's, otherwise white.
vminnumberMeasure of the lightest colour, and the low end of the colour bar. Default: the theme's, otherwise 0.
vmaxnumberMeasure of the full colour, and the high end of the colour bar. Default: the theme's, otherwise 100.
useGroupColorsbooleanfalseWhether links take the colour of their group.
colorBarbooleanWhether to show the colour bar. Default: the theme's, otherwise true.
colorBarOptionsobjectOptions of the colour bar: position, orientation, labels, x, y, width, height, title and its styles.
linkWidthnumberWidth of the links: 1 is the full width of the genes, 0 none.
linkStylestyle objectCSS styles of the links.
labelStylestyle objectCSS styles of the measure labels.
ynumber50Vertical position of the links, from 1 (bottom) to 100 (top) of the cluster.
labelAdjustmentstyle objectHow overlapping measures on the links are moved: rotation, offsetX, offsetY, dx, dy.

Other options are passed to the renderer as they are.

pattern

Pattern fills of the genes, exons and legend markers by group, e.g. for black and white figures. One object.

OptionTypeDefaultDescription
patternsarray of string or objectPattern names: an array recycled over the groups, or an object by group (groups left out get none). Default: a pattern for each group in a fixed order.
colorcolours"black"Colour of the pattern: one colour, an array recycled over the groups, or an object by group.
backgroundcolours or null"white"Colour behind the pattern, in the same forms as color; null keeps the gene colours.
sizenumber6Width and height of one pattern tile in pixels.
strokeWidthnumber1Width of the pattern lines in pixels.

scale

The position scale of each cluster: its range, axis and scale breaks. An array of entries applies them in order; an entry with clusters only to those clusters. One entry, or an array of entries applied in order.

OptionTypeDefaultDescription
clustersclustersThe clusters this entry applies to, by name or 1-based position. Default: all clusters.
startnumber or array of numberStart of the scale. Default: the first gene's start, less padding.
endnumber or array of numberEnd of the scale. Default: the last gene's end, plus padding.
paddingnumber or stringRoom on either side: a number, or a share such as "2%". Default: the theme's, otherwise 2.
hiddenbooleanfalseWhether the axis is hidden.
breaksarray of breakStretches of the scale left out, with break marks on the line, in the data's positions.
tickValuesarray of numberPositions of the ticks. Default: chosen by D3.
reversebooleanfalseWhether the scale runs from right to left.
axisPosition"top" | "bottom"Axis above or below the genes. Default: the theme's, otherwise "bottom".
axisType"position" | "range""position"Whether ticks show positions, or the range from the scale's start.
ynumberVertical position of the axis, from 1 to 100.
autoBreaksbooleanfalseWhether to add scale breaks at large gaps between genes.
autoBreakThresholdnumber20Gaps larger than this percentage of the cluster become scale breaks, with autoBreaks.
breakPaddingnumber or string1Room left on either side of a break: a percentage of the region shown, or base pairs as a string such as "500bp".
ticksCountnumberNumber of ticks. Default: the theme's, otherwise 10.
ticksFormatstringD3 number format of the ticks. Default: ",.0f" for positions, ".2s" for ranges.
tickStylestyle objectStyles of the ticks.
textStylestyle objectStyles of the tick text.
lineStylestyle objectStyles of the axis line.

Other options are passed to the renderer as they are.

scaleBar

A scale bar in each cluster. An array of entries applies them in order; an entry with clusters only to those clusters. One entry, or an array of entries applied in order.

OptionTypeDefaultDescription
showbooleantrueWhether to show the scale bar.
clustersclustersThe clusters this entry applies to, by name or 1-based position. Default: all clusters.
lineStylestyle objectStyles of the bar's line.
tickStylestyle objectStyles of the bar's ticks.
labelStylestyle objectStyles of the bar's label.
titlestring"1 kb"Text of the scale bar.
unitnumber1000Length of the scale bar, in base pairs.
xnumberHorizontal offset of the scale bar, in pixels.
ynumberVertical offset of the scale bar, in pixels.
textPaddingnumber0Space between the text and the bar, in pixels.

Other options are passed to the renderer as they are.

sequence

The line the genes sit on, with marks at scale breaks. An array of entries applies them in order; an entry with clusters only to those clusters. One entry, or an array of entries applied in order.

OptionTypeDefaultDescription
showbooleantrueWhether to show the line.
clustersclustersThe clusters this entry applies to, by name or 1-based position. Default: all clusters.
ynumberVertical position of the line. Default: the theme's, otherwise 50.
lineStylestyle objectStyles of the line.
markerStylestyle objectStyles of the break marks, plus markerHeight, tiltAmount and gap.
startnumberPosition where the line starts. Default: the scale's start.
endnumberPosition where the line ends. Default: the scale's end.

Other options are passed to the renderer as they are.

theme

The default look of every part of the chart. A built-in theme's name, or an object that starts from one and changes it. Options set in the other components take precedence. A built-in theme's name, or an object.

OptionTypeDefaultDescription
basetheme nameThe built-in theme to start from; R's list of theme settings is the theme object itself. Default: the current theme.
textScalenumberText size as a factor of the default font sizes.
fontFamilystringFont family of all text.
textColorcolourColour of all text.
lineColorcolourColour of the lines: sequence, axis, coordinates, scale bar and leader lines.
backgroundcolourBackground colour of the chart, also the fill of UTRs.
palettestring or array of colourGene colours: a colour scheme's name or an array of colours, in the order of the groups.
patternobject or falsePatterns, with the properties of the pattern component; false removes the theme's patterns.

Other options are passed to the renderer as they are.

title

The chart's title and subtitle. One object.

OptionTypeDefaultDescription
titlestringThe title.
subtitlestringThe subtitle.
stylestyle objectCSS styles of the title's element.
subtitleFontstyle objectFont options of the subtitle.
titleFontstyle objectFont options of the title.
showbooleantrueWhether to show the title.
heightnumber or stringHeight of the title. Default: the theme's, otherwise 50 pixels with a subtitle and 40 without.
align"left" | "center" | "right"Alignment of the title and subtitle. Default: the theme's, otherwise "center".
spacingnumberPixels between the title and subtitle. Default: the theme's, otherwise 20.
xnumberHorizontal offset of the title, in pixels.
ynumberVertical offset of the title, in pixels.

Other options are passed to the renderer as they are.

toolbar

The chart's own buttons: undo, redo, reset, reset zoom and save. One object.

OptionTypeDefaultDescription
show"hover" | "always" | "never"When the toolbar shows. Default: "hover".
position"topright" | "topleft" | "bottomright" | "bottomleft"The corner of the toolbar. Default: "topright".
buttonsarray of "undo" | "redo" | "reset" | "zoom" | "save"The buttons, in their order. Default: all.
sizenumberSize of the icons in pixels. Default: 20.
colorcolourColour of the icons. Default: "#D3D3D3".
hoverColorcolourColour of an icon under the mouse. Default: "#555555".
tooltipBackgroundcolourBackground of the tooltips and the save menu. Default: "#333333".
tooltipColorcolourText colour of the tooltips and the menu. Default: "white".
tooltipBorderstringCSS border of the tooltips and the menu. Default: none.
tooltipRadiusnumber or stringCorner radius of the tooltips and the menu. Default: 3.
tooltipShadowstringCSS box shadow of the tooltips and the menu. Default: none.
fontFamilystringFont of the tooltips and the menu. Default: Arial.
iconsobjectIcons by button, as Font Awesome names, e.g. { save: "camera" }. Buttons left out keep theirs.

tooltip

The tooltip shown over a gene. An array of entries applies them in order; an entry with clusters only to those clusters. One entry, or an array of entries applied in order.

OptionTypeDefaultDescription
formatterstring"<b>Start:</b> {start}<br><b>End:</b> {end}"HTML of the tooltip; {column} is replaced by the gene's value.
showbooleantrueWhether to show the tooltip.
clustersclustersThe clusters this entry applies to, by name or 1-based position. Default: all clusters.
triggersarray of "markers" | "genes" | "labels" | "exons" | "introns" | "utrs"["markers","genes","labels","exons","introns","utrs"]The parts that show the tooltip.
opacitynumber0Opacity of the tooltip when hidden.
positionstring"absolute"CSS position of the tooltip.
pointerEventsstring"none"CSS pointer-events of the tooltip.
backgroundColorcolourBackground colour.
colorcolourText colour.
paddingstringPadding, as CSS.
borderRadiusstringCorner radius, as CSS.
borderstringBorder, as CSS.
boxShadowstringShadow, as CSS.
fontFamilystringFont family.
fontSizestringFont size, as CSS.
lineHeightnumber or stringLine height, as CSS.
zIndexnumberStacking order, as CSS.

Other options are passed to the renderer as they are.

trackMouse

Shows the position under the mouse, e.g. to place annotations. An array of entries applies them in order; an entry with clusters only to those clusters. One entry, or an array of entries applied in order.

OptionTypeDefaultDescription
showbooleantrueWhether to show the position.
clustersclustersThe clusters this entry applies to, by name or 1-based position. Default: all clusters.
cursorstring"crosshair"Mouse cursor over the clusters.
backgroundColorcolourBackground colour.
colorcolourText colour.
paddingstringPadding, as CSS.
borderRadiusstringCorner radius, as CSS.
borderstringBorder, as CSS.
boxShadowstringShadow, as CSS.
fontFamilystringFont family.
fontSizestringFont size, as CSS.
lineHeightnumber or stringLine height, as CSS.
zIndexnumberStacking order, as CSS.

Other options are passed to the renderer as they are.

transcript

Transcripts: exons, introns and UTRs. An array of entries applies them in order; an entry with selection only to those transcripts. One entry, or an array of entries applied in order.

OptionTypeDefaultDescription
transcriptcolumn nameColumn that groups the rows into transcripts.
typecolumn nameColumn with the feature type of each row ("exon", "intron", "UTR").
strandcolumn nameColumn with the strand of each transcript, read as fields.strand.
groupcolumn nameColumn that groups the transcripts for their colours.
selectionstring or number or array of string or numberOnly these transcripts are drawn.
showbooleantrueWhether to show the transcripts.
colorSchemestringColour scheme of the groups. Default: the colours of the color component.
customColorscoloursColours of the groups: an array recycled over the groups, or an object by group.
styleExonsstyle objectStyles of the exons.
styleIntronsstyle objectStyles of the introns.
styleUTRsstyle objectStyles of the UTRs.
itemStyleExonsitem stylesStyles of single exons, by 0-based index.
itemStyleIntronsitem stylesStyles of single introns, by 0-based index.
itemStyleUTRsitem stylesStyles of single UTRs, by 0-based index.
groupStyleExonsstyles by groupStyles by group, for every exon of that group.
groupStyleIntronsstyles by groupStyles by group, for every intron of that group.
groupStyleUTRsstyles by groupStyles by group, for every UTR of that group.
styleBycolumn nameColumn whose values the group styles match. Default: group.
labelOptionsstyle objectOptions of the transcript labels.
xnumberHorizontal offset of the transcripts, in pixels.
ynumber50Vertical position of the transcripts, from 1 (bottom) to 100 (top) of the cluster.

Other options are passed to the renderer as they are.

zoom

A slider below the clusters to zoom in on part of them. One object.

OptionTypeDefaultDescription
showbooleantrueWhether to show the slider.
rangearray of number or nullThe window shown first, [start, end] in the units of mode. Default: everything.
mode"relative" | "absolute""relative": every cluster shows the same share of its range; "absolute": the same base pairs. Default: "relative".
minnumberThe narrowest window, in the units of mode. Default: 1% of the slider.
update"live" | "release"Draw while the slider moves, or when it is let go. Default: "live".
heightnumberHeight of the slider in pixels. Default: 24.
overviewbooleanWhether the slider shows the genes of each cluster. Default: true.
colorcolourOne colour for the overview's genes in place of their group colours.
stylestyle objectCSS styles of the slider's track.
windowStylestyle objectCSS styles of the window.
handleStylestyle objectCSS styles of the two handles.

Chart methods

MethodDescription
update(partial)Merge a partial spec into the spec and draw again: objects merge key by key; arrays, other values and tables (data, links.data) replace. update({ theme: "dark" }) changes only the theme.
setSpec(spec)Replace the spec and draw again.
getSpec()A copy of the spec.
on(name, handler)Call handler({ type, detail }) on each event of that name. Returns a function that stops it.
off(name, handler)Stop calling a handler.
zoomTo([start, end])Set the zoom window, in the units of zoom.mode; zoomTo(null) shows everything.
select(items)Select elements, as a click does, and report select and selection when that changes the selection. An item gives a component and any of cluster, part and data; it selects every drawn element that matches all it gives, so { component: "genes", data: { rowID: 3 } } selects gene row 3, and the items of getSelection() select their elements again. select(null) or select([]) clears it. Needs events: { select: true }.
getSelection()The selected elements, as the selection event reports them.
undo(), redo()Undo or redo the last move, as the toolbar does (events: { drag: true }).
download(format, filename)Save the chart as "svg" or "png", as the save menu does: through the saveAs option, or as a browser download. The name defaults to graph.svg or graph.png. A Promise.
toSVG()The chart as SVG text.
toPNG()The chart as a PNG Blob (a Promise).
resize()Draw again at the element's size.
destroy()Remove the chart and its listeners.

Events

Handlers get { type, detail }. Each event is also sent as a DOM event, geneviewer:<name>, on the chart's element; see the interactive example. events in the spec turns them on.

EventWhenDetail
clickAn element was clicked (events.click).The element (below).
dblclickAn element was double-clicked (events.dblclick).The element.
selectThe selected element changed (events.select).The element selected last, or null when the selection is cleared.
selectionThe list of selected elements changed.An array of elements, in the order they were selected.
dragAn element was moved: dropped, nudged with the arrow keys, or moved by undo, redo or reset (events.drag).The element, with position: { moveX, moveY }, its offset in pixels, and action: "drag", "nudge", "undo", "redo" or "reset".
dragmoveAn element is being moved.The element, with position.
movesSeveral elements were moved in one step.{ action, moves }: moves is an array of what drag reports.
zoomThe zoom window changed (events.zoom).mode, start, end, zoomed, range (null when everything shows), clusters ({ cluster, start, end }, the base pairs each shows) and action: "drag", "keyboard", "reset", "set" (zoomTo()) or "render".
renderedThe chart was drawn (events.rendered).id (events.renderId, or one made for each draw), chartId, width and height in pixels.

An element, as click, dblclick, select and selection report it:

FieldDescription
componentThe part of the chart: "genes", "transcript", "labels", "coordinates", "links", "legend", "scale", "scaleBar", "sequence", "title", "clusterTitle", "clusterFooter", "clusterLabel" or "annotations".
clusterThe cluster's name; null for the chart title, the legend and links between clusters.
dataThe gene's row for genes, transcripts and labels, the link's row for links, the group for the legend; otherwise null.
part"title" or "subtitle" of a title, cluster title, footer or label; "label" or "marker" in the legend.
styleHow a selectable element is drawn, with the names of elementStyle options, so an editor can show the current values.

The TypeScript types give each event's detail: ChartEventDetails in geneviewer.d.ts.

Builds

FileFormatD3For
geneviewer.min.jsScript tag, global geneviewer; minified, source mapincludedCDNs and plain HTML pages
geneviewer.mjsES module (import ... from "geneviewer-js")imported from npmBundlers
geneviewer.standalone.mjsES module (geneviewer-js/standalone), minifiedincludedBrowser import, Jupyter
geneviewer.core.jsScript tag, not minifiedthe page's d3The R package
geneviewer.cssStylesheetPages that turn off injectStyles
geneviewer.d.ts, spec.d.tsTypeScript typesEditors and TypeScript

Versions

  • Library: semantic versioning from 1.0. While on 0.x, minor versions may change the API.
  • Spec: the optional version key. A spec without one is version 1, the only version so far. A spec with a newer version than the library knows is drawn as far as possible, with a warning in the console.
  • Not part of spec v1: the output of compile(), and the settings in geneviewer.themes. Theme and palette names are.