histogram 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. histogram(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, 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

histogram([element], [settings])

Create a safety histogram 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 chart.

ParamTypeDefaultDescription
element (optional)string | HTMLElement'body'Container node, or a CSS selector for it.
settings (optional)HistogramSettings{}Setting overrides, merged onto DEFAULT_SETTINGS and normalized.

Returns: SafetyHistogram — The live histogram 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 (SH-API-001).

ParamTypeDefaultDescription
dataArray.<Object>Long-format result records matching the histogram data contract.

Returns: SafetyHistogram — 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 filter values.

ParamTypeDefaultDescription
dataArray.<Object>Long-format result records matching the histogram data contract.

Returns: SafetyHistogram — 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
settingsHistogramSettingsSetting overrides to merge.

Returns: SafetyHistogram — The instance, for chaining.

render()

Redraw everything from the current data, settings, and control state: destroys the live charts, clears the listing and any bar selection, then draws the main chart, the grouped small multiples, 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

resize()

Resize every live chart (the main chart and any small multiples) 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 histogram down: destroy every 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.
id_colstring'USUBJID'Participant identifier column; drives the participant counts shown above the chart and the default listing columns.
unit_colstring'STRESU'Unit column, appended to the measure name in labels when present.
normal_col_lowstring'STNRLO'Lower-limit-of-normal column; with normal_col_high, feeds the normal-range overlay. The control hides for measures without normal-range data (SH-FUNC-004C).
normal_col_highstring'STNRHI'Upper-limit-of-normal column; see normal_col_low.
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.
groupsArray.<(string|Object)>[]Group-by options for the small-multiple charts; a "None" option is always offered first.
detailsArray.<(string|Object)> | nullnullColumns for the linked participant listing; when null, defaults to participant ID, the filter columns, result, normal limits, and unit.
start_valuestring | nullnullMeasure selected on first render. When null (the default) the histogram opens on the all-measures overview — one small-multiple histogram per measure, click one to drill in. A measure absent from the data falls back to the overview with a console warning.
bin_algorithmstring"Scott's normal reference rule"Binning algorithm applied on first render; one of the ALGORITHMS options. Setting an explicit bin quantity or width in the UI switches it to "Custom".
normal_rangebooleantrueOffer the Show Normal Range control (visible only for measures with normal-range data).
display_normal_rangebooleanfalseDraw the normal-range overlay on first render. The pilot's camelCase alias displayNormalRange is still honored.
annotate_bin_boundariesbooleanfalseLabel the x-axis with bin boundaries instead of linear ticks on first render.
test_normalitybooleanfalseAnnotate the main chart with an approximate Jarque-Bera normality screen.
group_bystring'sh_none'Column the small multiples are grouped by on first render; 'sh_none' disables grouping. Unknown columns are added to the group options as-is.
compare_distributionsbooleanfalseWhen grouped, annotate each panel with an approximate one-way ANOVA screen comparing the groups.
widthstring'100%'Widget width, carried over from the pilot API for the R widget bindings; the current shell always spans its container.
heightnumber460Chart-area height in pixels, carried over from the pilot API 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 histogram data contract

Long-format results data: one record per measurement (SH-DATA-001). Column names are supplied by the settings mapping; the histogram removes missing/non-numeric results with a reported count (SH-DATA-002) and degrades gracefully when optional columns are absent (SH-DATA-003).

FieldTypeRequiredDefaultDescription
dataarrayyesd3.csv()-style records; every row carries the measure 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.id_colstringnoUSUBJIDOptional participant identifier column.
settings.unit_colstringnoSTRESUOptional unit column, appended to measure labels.
settings.normal_col_lowstringnoSTNRLOOptional lower limit of normal; normal-range UI hides for measures without normal data (SH-FUNC-004C).
settings.normal_col_highstringnoSTNRHIOptional upper limit of normal.
settings.filtersarraynoOptional filter columns rendered as controls.
settings.groupsarraynoOptional group-by columns for small-multiple charts.
settings.detailsarraynoOptional listing columns; defaults derive from the other mappings.