Parameters¶
Reactive parameters — param, Parameter, VariableParameter.
Ferrum — a statistical visualization library with a Rust core.
Parameter ¶
Base class for all ferrum reactive parameters.
Both VariableParameter and Selection are subtypes.
isinstance(x, Parameter) is the canonical discriminator used at
reference sites (e.g. scale domain, transform filter, conditional
encoding) to detect that a value is a parameter reference rather than a
literal.
Subclasses must implement to_param_spec_dict(). The base raises
NotImplementedError only as an unreachable guard — every concrete
type (VariableParameter, Selection) provides its own override.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Stable identifier used across the chart spec to link parameters to their reference sites. |
Examples:
>>> import ferrum as fm
>>> p = fm.param("threshold", value=50)
>>> isinstance(p, fm.Parameter)
True
>>> p.ref()
{'param': 'threshold'}
ref ¶
Return the reference marker dict used at parameter reference sites.
Returns:
| Type | Description |
|---|---|
dict
|
|
Examples:
to_param_spec_dict ¶
Serialize to the wire dict emitted into the params spec array.
Subclasses must override this. This base implementation is an
unreachable guard — concrete types (VariableParameter,
Selection) each supply their own implementation.
Returns:
| Type | Description |
|---|---|
dict
|
Entry in the top-level |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always (guard for subclasses that forget to override). |
VariableParameter
dataclass
¶
Bases: Parameter
A named scalar or array parameter with an optional initial value.
Created via fm.param(). Do not construct directly.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Stable parameter identifier. |
value |
Any, default None
|
Static initial value (serialized into the spec as the starting state
for the WASM runtime and the static renderer). |
bind |
str, dict, or None, default None
|
Optional bind target. |
Examples:
>>> import ferrum as fm
>>> p = fm.param("threshold", value=50)
>>> p.to_param_spec_dict()
{'name': 'threshold', 'kind': 'variable', 'value': 50}
>>> fm.param("t", value=0, bind="legend").to_param_spec_dict()
{'name': 't', 'kind': 'variable', 'value': 0, 'bind': 'legend'}
ref ¶
Return the reference marker dict used at parameter reference sites.
Returns:
| Type | Description |
|---|---|
dict
|
|
Examples:
to_param_spec_dict ¶
Serialize to the params-array wire dict.
"bind" is omitted when None to avoid emitting null
clutter in the spec JSON. "value" is always emitted (it is the
static initial value and may legitimately be None).
Returns:
| Type | Description |
|---|---|
dict
|
Wire shape:: |
Examples:
param ¶
Construct a named variable parameter.
A VariableParameter declares a named, mutable scalar or array
parameter that can be referenced at scale domains, filter predicates,
and conditional encoding values. At static render time the initial
value is used; in interactive WASM exports the parameter is driven
by its bind widget or by a linked selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Stable identifier for the parameter. Must be unique within the
chart. Used in |
required |
value
|
Any
|
Static initial value. Serialized as the starting state for both
the static renderer and the WASM runtime. |
None
|
bind
|
str, dict, or None
|
Optional bind target controlling how the parameter is driven at runtime.
|
None
|
Returns:
| Type | Description |
|---|---|
VariableParameter
|
Frozen, immutable parameter descriptor. Pass to
|
Examples:
Static threshold parameter:
>>> import ferrum as fm
>>> thresh = fm.param("threshold", value=50)
>>> thresh.to_param_spec_dict()
{'name': 'threshold', 'kind': 'variable', 'value': 50}
Range-slider binding:
>>> slider = fm.param(
... "k",
... value=3,
... bind={"input": "range", "min": 1, "max": 20, "step": 1},
... )
Legend bind: