HMPlot

hmplot/types

Option types for settings a component registers: a default, a settings-pane control and a conversion.

<script>
  // A pattern's settings, shown in the settings pane (see hmplot/compound).
  import { composition } from "hmplot/compound";
  import { IntegerType, SelectType } from "hmplot/types";
  let { name = undefined } = $props();
  const options = composition.getOptionsContext().splitUnique(name, "group", "Strip");
  composition.setOptionsContext(options);
  options.ensure("stripBins", new IntegerType({ defaultValue: 20, min: 1, max: 100 }));
  options.ensure("stripScale", new SelectType({ defaultValue: "count", options: ["count", "density"] }));
</script>

Exports

FieldTypeclass
The base type. params: defaultValue, label (default from the name), transform (value conversion) and ui (the pane's control spec, or false for none).
ScalarTypeclass
A number: params min, max and step; a slider (0 to 1 by 0.01 unless given).
IntegerTypeclass
A ScalarType rounded to an integer; step 1.
CountTypeclass
An IntegerType from 0 to 100,000.
ValueTypeclass
A ScalarType from 0 to 1.
OpacityTypeclass
A ScalarType from 0 to 1, default 1.
WidthTypeclass
A ScalarType from 0 to 20 by 0.1, default 1.
BooleanTypeclass
true or false, default false; a checkbox.
SelectTypeclass
One of params.options; a select.
ColormapTypeclass
A colormap name (default Viridis).
ShapeTypeclass
A point shape name (default circle), the registered shapes included.
Shape3DTypeclass
"sphere" (default) or "cube".
TransformTypeclass
A scale transform: linear (default), log, sqrt or symlog.
VectorTypeclass
A vector of params.dimensions numbers.
Vector2Typeclass
A VectorType of 2.
Vector3Typeclass
A VectorType of 3.
Vector4Typeclass
A VectorType of 4.
PositionTypeclass
A 3D position, default [0, 0, 0].
SizeTypeclass
A size from 1 to 100, default 1.
RangeTypeclass
A [min, max] pair, default [-1, 1]; an interval slider.
BoundsTypeclass
A RangeType for an extent.
ColorTypeclass
A CSS color, default white; a color picker.
FillTypeclass
A fill color, default steelblue.
TypeRegistryobject
The types by name: boolean, bounds, color, colormap, count, fill, integer, opacity, position, range, scalar, shape, shape3d, size, transform, value, vector2, vector3, vector4 and width.
createType(type, params)FieldType
A type from its registry name or class with params; a FieldType passes through. An unknown name is an error.

Usage

A component’s settings (what its settings pane edits, and what Python’s update() and theme defaults reach) are registered on an options node: options.ensure(name, type) names a setting and gives it a type, whose defaultValue is its value until something sets it, whose ui is the pane’s control (a slider, checkbox, select, color picker or text field) and whose transform converts what the pane sends. A pattern written in Svelte registers its settings this way, through getOptionsContext() and setOptionsContext() from hmplot/compound’s composition; composition exports IntegerType, SelectType and FieldType too.

The constructor’s params are defaultValue, label (default: from the setting’s name), ui (an object merged into the control’s spec, or false for no control) and transform; the numeric types also take min, max and step, and SelectType takes options. The types’ other members (the GPU nodes a setting feeds, its uniform type) are internal to the marks and may change.