Filter Scored Lables¶
The "filterScoredLabels" transform fits prioritized elements such as labels
into the available space, dynamically adjusting as the scale domain changes
(such as during zooming). It is particularly suited for gene annotation tracks,
where genes have an associated importance or score, such as their popularity or
relevance, and only the most significant labels should be displayed when space
is limited. This transform is typically used in conjunction with the
measureText transform to calculate the width of each label.
For an usage example, check the Annotation Tracks notebook or the example below.
Parameters¶
asMidpoint- Type: string
Outputs the average of pos and pos2 as the midpoint of the element. This is useful for elements that have a width, such as transcripts. The midpoint is clamped to the visible region of the element.
channel- Type: string
Default:
"x" lane- Type: string (field name)
An optional field representing element's lane, e.g., if transcripts are shown using a piled up layout. Each line is processed separately.
padding- Type: number
Padding (in pixels) around the element.
Default:
0 posRequired- Type: string (field name)
The field representing element's start position on the domain.
pos2- Type: string (field name)
The field representing element's end position on the domain. If not specified, the
posfield is used. scoreRequired- Type: string (field name)
The field representing the score used for prioritization.
widthRequired- Type: string (field name)
The field representing element's width in pixels.
Example¶
Zoom in to see how the labels are filtered based on their score and the available space.
{
"data": { "sequence": { "start": 0, "stop": 100000, "step": 1, "as": "_z" } },
"transform": [
{ "type": "formula", "expr": "floor(random() * 10000000)", "as": "x" },
{ "type": "formula", "expr": "floor(random() * 100000)", "as": "score" },
{ "type": "formula", "expr": "'' + datum.score", "as": "label" },
{
"type": "measureText",
"fontSize": 16,
"field": "label",
"as": "textWidth"
},
{
"type": "filterScoredLabels",
"score": "score",
"width": "textWidth",
"pos": "x",
"padding": 5
}
],
"mark": {
"type": "text",
"size": 16
},
"encoding": {
"x": { "field": "x", "type": "index", "scale": { "domain": [0, 1000000] } },
"text": { "field": "label" }
}
}