Create and Manage Encodings

Manage encodings to control how data maps to marks, channels, and layout behavior.

msc.encode(elem, channel, attribute, params)

Encodes a data attribute using a visual channel on an element.

  • elem: Mark or Group
  • channel (String, required): visual channel
  • attribute (String, required): data attribute
  • params (Object): has the following properties
    • aggregator (String, optional): aggregator, defaults to "sum"
    • scale (Scale, optional): the scale to use for the encoding
    • scaleType (String, optional): type of scale
    • shareScale (Encoding, optional): share the scale of another encoding
    • flipScale (Boolean, optional): whether the scale is flipped, defaults to false
    • includeZero (Boolean, optional): whether the scale domain includes 0, defaults to false
    • rangeExtent (Number, optional): range extent
    • mapping (Object, optional): user-defined mapping between field values and visual properties
    • scheme (String, optional): color scheme
    • startAngle (Number, optional): start angle in degrees when encoding with the "angle" channel, defaults to 90
    • angleDirection (String, optional): direction to encode angles, defaults to "clockwise"
  • Return type: Encoding

msc.getChannelEncodingByAttribute(attribute, channel, scene)

Returns the encoding for given attribute and channel within a scene.


msc.getChannelEncodingByElement(elem, channel)

Returns the encoding for the given channel on a specific element.


msc.getEncodingsByChannel(channel, scene)

Returns all the encodings in the scene that use the given channel.


msc.getEncodingsByElement(elem, includeVertexSegment)

Returns all encodings associated with the element.

  • elem: Mark or Group
  • includeVertexSegment (Boolean, optional): whether to also include encodings on the element’s vertices and segments
  • Return type: Array of Encodings

msc.removeEncoding(enc, scene)

Removes an encoding from the scene.

  • enc (Encoding): the encoding to remove
  • scene (Scene, optional): the scene to remove from; defaults to the encoding’s own scene
  • Return type: void