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 Groupchannel(String, required): visual channelattribute(String, required): data attributeparams(Object): has the following propertiesaggregator(String, optional): aggregator, defaults to"sum"scale(Scale, optional): the scale to use for the encodingscaleType(String, optional): type of scaleshareScale(Encoding, optional): share the scale of another encodingflipScale(Boolean, optional): whether the scale is flipped, defaults tofalseincludeZero(Boolean, optional): whether the scale domain includes 0, defaults tofalserangeExtent(Number, optional): range extentmapping(Object, optional): user-defined mapping between field values and visual propertiesscheme(String, optional): color scheme; only the schemes in d3-scale-chromatic are supported, specified by their d3 name (e.g.,"schemeTableau10","interpolateYlOrRd"). Use ascheme*name for categorical data and aninterpolate*name for continuous data. The available schemes are:- Categorical:
schemeCategory10,schemeAccent,schemeDark2,schemePaired,schemePastel1,schemePastel2,schemeSet1,schemeSet2,schemeSet3,schemeTableau10 - Diverging:
BrBG,PRGn,PiYG,PuOr,RdBu,RdGy,RdYlBu,RdYlGn,Spectral(asinterpolate*orscheme*, e.g.,interpolateRdBu) - Sequential (single hue):
Blues,Greens,Greys,Oranges,Purples,Reds(asinterpolate*orscheme*, e.g.,interpolateBlues) - Sequential (multi-hue):
BuGn,BuPu,GnBu,OrRd,PuBuGn,PuBu,PuRd,RdPu,YlGnBu,YlGn,YlOrBr,YlOrRd(asinterpolate*orscheme*);Cividis,Viridis,Inferno,Magma,Plasma,Warm,Cool,CubehelixDefault,Turbo(asinterpolate*only, e.g.,interpolateViridis) - Cyclical:
Rainbow,Sinebow(asinterpolate*only, e.g.,interpolateRainbow)
- Categorical:
startAngle(Number, optional): start angle in degrees when encoding with the"angle"channel, defaults to90angleDirection(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.
attribute(String): data attributechannel(String): visual channelscene(Scene): the scene to search- Return type: Encoding or
null
msc.getChannelEncodingByElement(elem, channel)
Returns the encoding for the given channel on a specific element.
elem: Mark or Groupchannel(String): visual channel- Return type: Encoding or
null
msc.getEncodingsByChannel(channel, scene)
Returns all the encodings in the scene that use the given channel.
channel(String): visual channelscene(Scene): the scene to search- Return type: Array of Encodings
msc.getEncodingsByElement(elem, includeVertexSegment)
Returns all encodings associated with the element.
elem: Mark or GroupincludeVertexSegment(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.