shift-plot API reference
Generated from the module's JSDoc and JSON-Schema data contract — npm run docs:api fails on undocumented surface.
Overview
Every safety.viz renderer is one factory call. shiftPlot(element, settings) empties the container, renders the shared control shell, and returns a chart instance; pass data to setData (or init) and the module validates it against its data contract, structures it, and draws. Settings are merged onto the module's defaults, so callers supply only overrides — column mappings follow ADaM naming out of the box. The same lifecycle (init, setData, setSettings, render, selectInPixelRect, brushValues, clearSelection, resize, destroy) is shared by every module and consumed unchanged by the gsm.safety R bindings. See Architecture for how the pieces fit together.
Factory
shiftPlot([element], [settings])
Create a safety shift plot inside a container element. The control shell renders immediately; pass long-format result records to setData (or init) on the returned instance to validate the data and draw the scatter.
| Param | Type | Default | Description |
|---|---|---|---|
element (optional) | string | HTMLElement | 'body' | Container node, or a CSS selector for it. |
settings (optional) | ShiftPlotSettings | {} | Setting overrides, merged onto DEFAULT_SETTINGS and normalized. |
Returns: SafetyShiftPlot — The live shift-plot instance.
Methods
init(data)
Load data and render: an alias for setData that keeps the pilot's two-step create-then-init call shape working (SSP-DATA-003).
| Param | Type | Default | Description |
|---|---|---|---|
data | Array.<Object> | — | Long-format result records matching the shift-plot data contract. |
Returns: SafetyShiftPlot — The instance, for chaining.
setData(data)
Replace the bound data and re-render. The data is validated against the settings mapping (throwing, and rendering the message into the target element, when required columns are missing), rows with missing or non-numeric results are removed with a console warning, and the controls are rebuilt from the new data's measures and visits.
| Param | Type | Default | Description |
|---|---|---|---|
data | Array.<Object> | — | Long-format result records matching the shift-plot data contract. |
Returns: SafetyShiftPlot — The instance, for chaining.
setSettings(settings)
Merge setting overrides onto the current settings, re-normalize them (same rules as the factory), rebuild the controls, and re-render.
| Param | Type | Default | Description |
|---|---|---|---|
settings | ShiftPlotSettings | — | Setting overrides to merge. |
Returns: SafetyShiftPlot — The instance, for chaining.
render()
Redraw everything from the current data, settings, and control state: destroys the live chart, clears the listing and any brush selection, then draws the scatter, the identity line, and the participant-count notes. Called automatically by the controls and the data/settings setters; call it directly only after mutating state by hand.
Returns: void —
selectInPixelRect(rect)
Select every point whose pixel position falls inside a rectangle, opening the listing (or clearing when the rectangle catches nothing).
| Param | Type | Default | Description |
|---|---|---|---|
rect | Object | — | Pixel rectangle. |
Returns: void —
brushValues(x0, x1, y0, y1)
Select points inside a data-space rectangle. The programmatic entry point the R widget bindings and tests use in place of a mouse drag.
| Param | Type | Default | Description |
|---|---|---|---|
x0 | number | — | One baseline-axis bound of the rectangle. |
x1 | number | — | The other baseline-axis bound. |
y0 | number | — | One comparison-axis bound of the rectangle. |
y1 | number | — | The other comparison-axis bound. |
Returns: void —
clearSelection()
Clear the brush selection: restore uniform point colors, hide the gray box and the listing, and dispatch an empty participantsSelected event (SSP-REG-011).
Returns: void —
resize()
Resize the live chart to its container. For host layouts that change the container size without a window resize — e.g. the R htmlwidget bindings.
Returns: void —
destroy()
Tear the shift plot down: destroy the Chart.js instance and empty the target element. The instance cannot be reused afterwards — create a new one via the factory instead.
Returns: void —
Settings
| Setting | Type | Default | Description |
|---|---|---|---|
measure_col | string | 'TEST' | Column holding the measure name; required in the data. Each distinct measure (with its unit) becomes an option in the Measure control. |
value_col | string | 'STRESN' | Column holding the numeric result; required in the data. Rows with missing or non-numeric values are removed with a console warning. |
visit_col | string | 'VISIT' | Column holding the visit label; required in the data. Its distinct values populate the baseline and comparison visit controls. |
visit_order_col | string | null | 'VISITNUM' | Numeric column that orders the visits; when its column is absent from the data the visits sort alphanumerically (SSP-REG-013/014). |
id_col | string | 'USUBJID' | Participant identifier column; drives the participant counts shown above the chart and the default listing's first column. |
unit_col | string | 'STRESU' | Unit column, appended to the measure name in labels when present. |
baseline_visits | Array.<string> | null | null | Visit label(s) plotted on the x-axis; when null the first visit is selected on first render (SSP-CFG-004). |
comparison_visits | Array.<string> | null | null | Visit label(s) plotted on the y-axis; when null every visit after the baseline is selected on first render (SSP-CFG-005). |
baseline_stat | string | 'mean' | Statistic collapsing a participant's several baseline-visit results to one value; one of STATS. |
comparison_stat | string | 'mean' | Statistic collapsing a participant's several comparison-visit results to one value; one of STATS. |
filters | Array.<(string|Object)> | [] | Filter controls: column names or { value_col, label } specs. Filters whose column is absent from the data are dropped with a console warning. |
details | Array.<(string|Object)> | null | null | Columns for the linked participant listing; when null, defaults to participant ID, baseline, comparison, change, and percent change (SSP-REQ-005). |
start_value | string | null | null | Measure selected on first render; falls back to the first measure (with a console warning) when absent from the data. |
width | string | '100%' | Widget width, carried over for the R widget bindings; the current shell always spans its container. |
height | number | 460 | Chart-area height in pixels, carried over for the R widget bindings; the current shell fixes the chart area at 460px. |
page_size | number | 10 | Rows per page in the linked participant listing. |
Data contract
safety.viz shift-plot data contract
Long-format results data: one record per participant per visit per measure (SSP-DATA-001). Column names are supplied by the settings mapping; the shift plot pairs each participant's baseline-visit value against their comparison-visit value for the selected measure, removes missing/non-numeric results with a reported count (SSP-REG-020), and degrades gracefully when optional columns are absent (SSP-DATA-003).
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
data | array | yes | — | d3.csv()-style records; every row carries the measure, visit, and result columns named in settings. |
settings | object | yes | — | Column mappings and rendering options; merged onto the module's DEFAULT_SETTINGS, so only overrides need to be supplied. |
settings.measure_col | string | yes | TEST | Column holding the measure name; required in data. |
settings.value_col | string | yes | STRESN | Column holding the numeric result; required in data. |
settings.visit_col | string | yes | VISIT | Column holding the visit label; required in data. Its distinct values populate the baseline and comparison visit controls. |
settings.visit_order_col | string | no | VISITNUM | Optional numeric column that orders the visits; when absent the visits sort alphanumerically (SSP-REG-013/014). |
settings.id_col | string | no | USUBJID | Optional participant identifier column; drives the participant counts and the default listing's first column. |
settings.unit_col | string | no | STRESU | Optional unit column, appended to measure labels. |
settings.baseline_visits | array | no | — | Optional baseline visit(s) selected on first render; defaults to the first visit (SSP-CFG-004). |
settings.comparison_visits | array | no | — | Optional comparison visit(s) selected on first render; defaults to every visit after the baseline (SSP-CFG-005). |
settings.baseline_stat | string | no | mean | Summary statistic applied when a participant has several results across the baseline visit(s). |
settings.comparison_stat | string | no | mean | Summary statistic applied when a participant has several results across the comparison visit(s). |
settings.filters | array | no | — | Optional filter columns rendered as controls (SSP-CFG-006). |
settings.details | array | no | — | Optional listing columns; defaults to participant ID, baseline, comparison, change, and percent change (SSP-REQ-005). |