ArrField
viz.macros.ArrField
class ArrField(path: List[String], headAccessor: Option[Any], elementAccessorFactory: Option[Int => Any], tupleAccessors: Map[String, Any]) extends Selectable
Accessor for array fields in a Vega/Vega-Lite spec.
Provides type-safe modification of array-valued JSON fields. Unlike other field types, the += operator on arrays appends elements rather than deep merging.
For heterogeneous arrays (where elements have different structures), tuple-style accessors are available: _0, _1, _2, etc. Each accessor has the precise type of that specific element.
Value parameters
- elementAccessorFactory
-
Optional factory function to create accessors for array elements at any index
- headAccessor
-
Optional accessor for the first element of the array (if available)
- path
-
The JSON path to this field as a list of field names
- tupleAccessors
-
Map of tuple-style accessors (_0, _1, etc.) for precise per-element types
Attributes
- Example
-
// Replace the entire array spec.build(_.data.values := json"[{\"a\": 1}, {\"a\": 2}]") // Append a single element spec.build(_.data.values += json"{\"a\": 3}") // Append multiple elements spec.build(_.signals += Vector(json"{\"name\": \"sig1\"}", json"{\"name\": \"sig2\"}")) // Access first element's nested field spec.build(_.data.head.values := json"[{\"a\": 1}]") // Access element at index 2 with tuple-style accessor (precise type) spec.build(_.layer._2.data.sequence.start := 5) // Access element at index 2 with apply (uses first element's type) spec.build(_.data(2).values := json"[{\"a\": 1}]") - Graph
-
- Supertypes
-
trait Selectableclass Objecttrait Matchableclass Any
Members list
In this article