Class: RangeSelectionModel

RangeSelectionModel

new RangeSelectionModel() → {RangeSelectionModel}

This object models selection of "cells" within an abstract single-dimensional matrix.

Disjoint selections can be built with calls to the following methods:

Two more methods are available:

Internally, the selection is run-length-encoded. It is therefore a "sparse" matrix with undefined bounds. A single data property called selection is an array that contains all the "runs" (ranges) of selected cells albeit in no particular order. This property should not normally need to be accessed directly.

Note: This object should be instantiated with the new keyword.

Returns:

Self (i.e., this object).

Type
RangeSelectionModel

Members

(abstract) selection :Array.Array.number

Unordered list of runs.

A "run" is defined as an Array(2) where:

  • element [0] is the beginning of the run
  • element [1] is the end of the run (inclusive) and is always >= element [0] The order of the runs within is undefined.
Type:
  • Array.Array.number

Methods

clear() → {RangeSelectionModel}

Empties this.selection, effectively removing all runs.

Returns:

Self (i.e., this), for chaining.

Type
RangeSelectionModel

deselect(start, stopopt) → {RangeSelectionModel}

Remove a contiguous run of points from the selection.

Truncate and/or remove run(s) from this.selection. Removing part of existing runs will (correctly) shorten them or break them into two fragments.

The two parameters may be given in either order.

Note that this.selection is updated in place, preserving validity of any external references.

Parameters:
Name Type Attributes Default Description
start number

Start of run. May be greater than stop.

stop number <optional>
stop

End of run (inclusive). May be less than start.

Returns:

Self (i.e., this), for chaining.

Type
RangeSelectionModel

getSelections() → {Array.Array.number}

Return the indexes that are selected.

Return the indexes that are selected.

Returns:
Type
Array.Array.number

isSelected(cell) → {boolean}

Determines if the given cell is selected.

Parameters:
Name Type Description
cell number

The cell to test for inclusion in the selection.

Returns:

true iff given cell is within any of the runs in this.selection.

Type
boolean

select(start, stopopt) → {RangeSelectionModel}

Add a contiguous run of points to the selection.

Insert a new run into this.selection. The new run will be merged with overlapping and adjacent runs.

The two parameters may be given in either order. The start and stop elements in the resulting run will however always be ordered. (However, note that the order of the runs within this.selection is itself always unordered.)

Note that this.selection is updated in place, preserving validity of any external references.

Parameters:
Name Type Attributes Default Description
start number

Start of run. May be greater than stop.

stop number <optional>
stop

End of run (inclusive). May be less than start.

Returns:

Self (i.e., this), for chaining.

Type
RangeSelectionModel