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.

ParamTypeDefaultDescription
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).

ParamTypeDefaultDescription
dataArray.<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.

ParamTypeDefaultDescription
dataArray.<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.

ParamTypeDefaultDescription
settingsShiftPlotSettingsSetting 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).

ParamTypeDefaultDescription
rectObjectPixel 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.

ParamTypeDefaultDescription
x0numberOne baseline-axis bound of the rectangle.
x1numberThe other baseline-axis bound.
y0numberOne comparison-axis bound of the rectangle.
y1numberThe 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

SettingTypeDefaultDescription
measure_colstring'TEST'Column holding the measure name; required in the data. Each distinct measure (with its unit) becomes an option in the Measure control.
value_colstring'STRESN'Column holding the numeric result; required in the data. Rows with missing or non-numeric values are removed with a console warning.
visit_colstring'VISIT'Column holding the visit label; required in the data. Its distinct values populate the baseline and comparison visit controls.
visit_order_colstring | 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_colstring'USUBJID'Participant identifier column; drives the participant counts shown above the chart and the default listing's first column.
unit_colstring'STRESU'Unit column, appended to the measure name in labels when present.
baseline_visitsArray.<string> | nullnullVisit label(s) plotted on the x-axis; when null the first visit is selected on first render (SSP-CFG-004).
comparison_visitsArray.<string> | nullnullVisit label(s) plotted on the y-axis; when null every visit after the baseline is selected on first render (SSP-CFG-005).
baseline_statstring'mean'Statistic collapsing a participant's several baseline-visit results to one value; one of STATS.
comparison_statstring'mean'Statistic collapsing a participant's several comparison-visit results to one value; one of STATS.
filtersArray.<(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.
detailsArray.<(string|Object)> | nullnullColumns for the linked participant listing; when null, defaults to participant ID, baseline, comparison, change, and percent change (SSP-REQ-005).
start_valuestring | nullnullMeasure selected on first render; falls back to the first measure (with a console warning) when absent from the data.
widthstring'100%'Widget width, carried over for the R widget bindings; the current shell always spans its container.
heightnumber460Chart-area height in pixels, carried over for the R widget bindings; the current shell fixes the chart area at 460px.
page_sizenumber10Rows 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).

FieldTypeRequiredDefaultDescription
dataarrayyesd3.csv()-style records; every row carries the measure, visit, and result columns named in settings.
settingsobjectyesColumn mappings and rendering options; merged onto the module's DEFAULT_SETTINGS, so only overrides need to be supplied.
settings.measure_colstringyesTESTColumn holding the measure name; required in data.
settings.value_colstringyesSTRESNColumn holding the numeric result; required in data.
settings.visit_colstringyesVISITColumn holding the visit label; required in data. Its distinct values populate the baseline and comparison visit controls.
settings.visit_order_colstringnoVISITNUMOptional numeric column that orders the visits; when absent the visits sort alphanumerically (SSP-REG-013/014).
settings.id_colstringnoUSUBJIDOptional participant identifier column; drives the participant counts and the default listing's first column.
settings.unit_colstringnoSTRESUOptional unit column, appended to measure labels.
settings.baseline_visitsarraynoOptional baseline visit(s) selected on first render; defaults to the first visit (SSP-CFG-004).
settings.comparison_visitsarraynoOptional comparison visit(s) selected on first render; defaults to every visit after the baseline (SSP-CFG-005).
settings.baseline_statstringnomeanSummary statistic applied when a participant has several results across the baseline visit(s).
settings.comparison_statstringnomeanSummary statistic applied when a participant has several results across the comparison visit(s).
settings.filtersarraynoOptional filter columns rendered as controls (SSP-CFG-006).
settings.detailsarraynoOptional listing columns; defaults to participant ID, baseline, comparison, change, and percent change (SSP-REQ-005).