-
Notifications
You must be signed in to change notification settings - Fork 29
Plot
Home ▸ Plot
A Plot is a complete LocusZoom instance. It is the value returned from LocusZoom.populate()
.
Once a plot has been created (e.g. the value returned from LocusZoom.populate()
there are various supported methods for interacting with the plot:
-
addPanel(layout)
Add a new panel with the panel layout (object) provided. Will automatically update the dimensions of the plot to accommodate the new panel. -
removePanel(id)
Remove a panel by ID (string). Will automatically update the dimensions of the plot to account for the panel's removal. -
setDimensions([width, height])
Set the total dimensions for the plot. If passed with no arguments will calculate optimal size based on layout directives and the available area on the page. If passed discrete width (number) and height (number) will attempt to resize the plot to them, but may be limited by minimum dimensions defined on the plot or panels. -
applyState(state)
Accepts a state (object) to be applied to the plot's layout. Properties of the state argument are merged with the existing state on the plot. This triggers requests to get new data for the updated state values across all panels and emits adata_requested
event. -
refresh()
Shortcut to apply an empty state object withapplyState
. In other words this triggers a call to request all data for the plot using all existing state values, essentially re-requesting and re-rendering all existing data.
There are several events that a LocusZoom plot can "emit" when appropriate and LocusZoom supports registering "hooks" for these events which are essentially custom functions intended to fire at certain times.
The following plot-level events are currently supported:
-
layout_changed
- context: plot
Any aspect of the plot's layout (including dimensions or state) has changed. -
data_requested
- context: plot
A request for new data from any data source anywhere in the plot has been made. -
data_rendered
- context: plot
Data from a request has been received and rendered. -
element_clicked
- context: element A data element in any of the plots panels has been clicked.
To register a hook for any of these events use the plot's on()
method like so:
var plot = LocusZoom.populate(selector, data_sources, layout);
plot.on("data_requested", function(){
console.log("data requested for LocusZoom plot" + this.id);
});
plot.on("data_rendered", function(){
console.log("data rendered for LocusZoom plot" + this.id);
});
In the above example we log to the console a message containing the plot's ID whenever data is requested and subsequently rendered.
There can be arbitrarily many functions registered to the same event. They will be executed in then order they were registered. The this
context bound to each event hook function is dependent on the type of event, as denoted above. For example, when data_requested
is emitted the context for this
in the event hook will be the plot itself, but when element_clicked
is emitted the context for this
in the event hook will be the element that was clicked.
A plot's layout is a serializable object that describes every customizable feature of a LocusZoom plot with nested values. It should only ever contain scalar values, arrays, and objects - no functions!
Example:
var layout = {
width: 500,
height: 500,
panels: {
positions: {
origin: { x: 0, y: 0 },
width: 500,
height: 250,
data_layers: {
positions:
type: "scatter",
...
}
}
},
...
}
};
-
width
- Number
Discrete width, in pixels, of the LocusZoom plot. Must be non-zero. Subject to being limited bymin_width
. -
height
- Number
Discrete height, in pixels, of the LocusZoom plot. Must be non-zero. Subject to being limited bymin_height
. -
aspect_ratio
- Number
Aspect ratio for the LocusZoom plot expressed as the evaluation of the plot's width divided by it's height (e.g. an aspect ratio of 8:5 would be1.6
). Must be non-zero. -
min_width
- Number
Minimum discrete width, in pixels, allowable for the LocusZoom plot. May automatically increase to the greatestpanels.{$panel_id}.min_width
for each$panel_id
. -
min_height
- Number
Minimum discrete height, in pixels, allowable for the LocusZoom plot. May automatically increase based onpanels.{$panel_id}.min_height
andpanels.{$panel_id}.proportional_height
for each$panel_id
. -
panel_boundaries
- Boolean
Whether or not to show draggable boundary elements between panels when the mouse is over the plot that allow for a user to adjust the heights of panels on an individual basis. Defaults totrue
. -
resizable
- String: "manual", "responsive", or null/false
Whether and how a LocusZoom plot can be automatically resized.-
"manual"
- Provide a resize handle in the lower right corner of the plot that can be dragged by the user to resize the plot arbitrarily -
"responsive"
- Attempt to expand the plot to fill 100% of the available width of the containing element at all times. Attach a namespacedwindow.resize
event listener to automatically resize the plot as resizing the browser window changes the available width in the containing element. Note: apply the classlz-container-responsive
to the containing element for best results. -
false
/null
- Do not allow resizing of the plot.
-
-
controls
- Object
The controls element provides plot-wide information and UI elements in an HTML element that appears below the plot itself. The following parameters for the controls element are supported:-
controls.show
- String: "always", "onmouseover", or null/false
When to show the controls element. Set toalways
to display the controls element at all times, set toonmouseover
to only show the controls element when the mouse is over the plot, and set tonull
orfalse
to prevent the controls element from being rendered. -
controls.hide_delay
- Number
Number of milliseconds to set for a timeout to hide the controls element when the mouse exits the plot. Only applies whencontrols.show
is set toonmouseover
. Defaults to300
.
-
-
state
- Object
The state contains information describing the current parameters used to query/filter data and current selections and/or customizations by the end user. For more information see State.
-
panels
- Object
An object describing all Panels in the plot. For more information see Panels.