Skip to main content

Visual Encodings

Each specification has a vis entry, which contains a list of visual mappings.

Each of these is a mappings from a set of data elements to set of visual marks.

The definition of this mapping has several parts:

  • Which data elements are to be mapped. This may be specified by setting the entries attribute to the name of a a loaded dataset, grouping, or the nodes or links or a network. Alternatively, they may be the entries of a table.
  • How the representation of each element should be positioned. If a table is being used, then the positions will be set automatically. Otherwise, the layout attribute to the name of a layout. Alternatively, the position can be set explicitly for each mark.
  • What visual marks should actually be drawn for each data element. This is specified as a list of mark definitions.
  • optionally, whether rendering should be restricted to data elements that belong to a particular selection

Types of Vis Entry

For Non-tables

AttributeTypeDescription
entriesstringName of the dataset/grouping/network to render.
layout?stringName of the layout ot be used to assign a position to each element.
drawAxes?booleanIf true, will draw axes corresponding to the layout.
border?boolean or BorderSpecIf true, will draw rectangular border around entry. Can be an object, with stroke/strokeWidth/strokeOpacity/strokeDash attributes controlling appearance.
ifInSelection?stringThe name of a selection: if set, the mark will only be drawn for data elements that are included in the selection.
if?stringAn optional expression: if specified, the mark will only be drawn for data elements for which the expression evaluates to true.
markMark[]Mark to be created for each data element.
occlusion?OcclusionSpecIf specified, remove overlaps between marks with an occlusion mechanism.

An OcclusionSpec object is defined by:

AttributeTypeDescription
importance?Field or ExpressionImportance function to use to determine which node is removed first when an overlap is detected. A field can be specified to show in priority the entries with the highest value. A random order is used if not specified
density?numberSpecify a factor on the dimensions of the labels used when computing the occlusion. For higher values, less labels will be shown with larger gaps. Default to 1.
shrinkLabels?booleanIf true, when labels overlap, starts by dividing the fontsize by two before removing them. Default to false.

For Tables

AttributeTypeDescription
tablestringName of the table to render.
rowLabels?anySpecification for row labels.
colLabels?anySpecification for column labels.
rowLines?anyProperties for ruled horizontal lines between each row in the table.
rowMidLines?anyProperties for ruled horizontal lines through the middle of each row in the table.
colLines?anyProperties for ruled vertical lines between each column in the table.
colMidLines?anyProperties for ruled vertical lines through the middle of each column in the table.
colMidLines?anyProperties for ruled vertical lines through the middle of each column in the table.
ifInSelection?stringThe name of a selection: if set, the mark will only be drawn for data elements that are included in the selection.
if?stringAn optional expression: if specified, the mark will only be drawn for data elements for which the expression evaluates to true.
markMark[]Mark to be created for each data element

Conditional rendering

You can control the appearance of elements conditionally (including setting the fill color or opacity so that they are not visible) by using an expression or using a condition.

You can specify that an entry in the vis block should only be rendered for elements in the corresponding list of entries if they belong to a specified selection. This allows you to render labels or highlighting halos for only selected nodes.

{
"entries": "le-mis-network.nodes",
"ifInSelection": "neighbours.nodes",
"layout": "le-mis-layout",
"mark": {
"type": "circle",
"area": 600,
"fill": "lightblue"
}
}

Nesting

Rather than directly defining a list of visual marks, an entry in the vis array can also include definition for other objects (scales, groupings etc.) and a vis block.

This allows the creation of nested visualizations.

Marks

note

NetPanorama uses a similar set of graphical marks and properties to the marks in Vega. However, there are some additions:

The values of specific property of marks encoding a data element may be specified as:

  • a constant value (e.g, "fill": red")
  • a parameter (e.g, "fill": { "parameter": "color" })
  • the value of a specific field of the data element (e.g,"fill": { "field": "color" })
  • the value of a specific field of the data element, after transformation by a scale (e.g, "fill": { "parameter": "age", "scale": "colorScale" })
  • the value of an expression or formula (which can reference the data element as datum) (e.g, "tooltip": { "expression": "datum.name + ' (' + datum.age + ')' " })

Additionally, a condition may specify alternative ways of setting the value depending on a particular expression (or membership of a selection)

Scaling

Netpanorama integrates zooming easily with the global zoom property. By default, for better readability, the size of visual marks is not scaled with the zoom, meaning that a circle will always have the same radius, before of after zooming in. The scaling property inside a mark definition can be set to true to make marks scale proportionally to the active zoom.

Clipping

The clip property can be used on a visual mark definition similarly as in vega. However, it behaves slightly differently and is used to clip marks when a translation is applied through panning and zooming.

Using an expression

You can set the value of a visual property using an expression . This may use a JavaScript ternary operator.

{
"entries": "network.nodes",
"layout": "layout",
"mark": {
"type": "circle",
"area": { "field": "degree", "scale": "radius" },
"fill": {"expression": "datum._type === 'person' ? 'red' : 'white' "}
}
}

Using a condition

When specifying the value of a property, you can provide a condition object. If this evaluates to true, then the value that it provides overrides whatever other value is provided.

The condition can be specified as one of:

  • a test attribute, containing an expression
  • an inSelection attribute, with the name of a selection as a value
  • a selectionIsEmpty attribute, with the name of a selection as a value
  • a selectionIsNotEmpty attribute, with the name of a selection as a value
{
"entries": "le-mis-network.nodes",
"layout": "le-mis-layout",
"mark": {
"type": "circle",
"area": { "field": "degree", "scale": "radius" },

"fill": {
// if a node has a degree > 10, color it blue
"condition": {
"test": "datum.degree > 10",
"value": "blue"
},
// otherwise, apply the color scale to the degree
"field": "degree", "scale": "color"
}
}
}

A series of conditions can be provided as an array of conditions:

      "mark": {
"type": "circle",
"area": { "field": "degree", "scale": "radius" },
"fill": {
"conditions": [
// if the node is selected, highlight it in blue
{
"inSelection": "my_selection.nodes",
"value": "blue"
},
// if the node wasn't selected, but no nodes were, use the color scale
{
"selectionIsEmpty": "my_selection.nodes",
"field": "degree", "scale": "color"
}
],
// otherise, some nodes were selected but this one wasn't, so draw it in grey
"value": "lightgrey"
}
}

Nested Conditions

Conditions can also be specified in a nested way te following:

"mark": {
"type": "circle",
"fill": {
"conditions": [
{
"test": "params.node_selection.nodes.length > 0",
"value": {
"conditions": [{
"inSelection": "node_selection.nodes",
"value": "red"
}],
"value": "blue"
}
},
{
"inSelection": "node_selection2.nodes"
"value": "lightgray"
}
],
"value": ""
},
}

Maps

We also provide a specific map mark that is used to render map tiles, providing context for networks using a geographic layout.

This mark has type map, and a map attribute that contains the name of the map to be rendered.

See the maps section of the documentation for more details.

We provide a specific linkpath mark that is intended to represent links, and is more customizable than a simple line.

As well as line properties such as color, dash pattern, stroke width, and stroke opacity, a marker can be added to one or both ends of the line.

Directionality can be encoded in several different ways:

  • markers at one or both ends of the link
  • a color gradient along the link
  • representing the link as a sequence of glyphs, and applying a color gradient to these
  • representing the edge as a wedge or triangle, rather than a line of uniform thickness
  • using asymmetric curvature

Common attributes of all links types

AttributeTypeDescription
shapestringThe shape of the linkPath mark.
startstringThe name of the field in the link object pointing at the source node.
endstringThe name of the field in the link object pointing at the target node.
startMarker?MarkerSpecDefinition of marker to be drawn at the start of an edge.
endMarker?MarkerSpecDefinition of marker to be drawn at the end of an edge.
tooltip?ValueDefinition of marker to be drawn at the end of an edge.
directionForShape?directionForShapeFor some link types, the shape of the link depends on which node is treated as the source or target. If set, this determines how the two nodes will be interpreted by applying an ordering; this has no effect on the drawing of endMarkers.
colorGradient?boolean or ColorGradientCreate a color gradient using the stroke color.

The directionForShape type can have the following attributes:

AttributeTypeDescription
ordering?stringName of an order to apply.
cyclic?booleanIf true, will reverse the direction of edges from final element in order to first element in order.This is useful, for examples, when drawing hive plots.
reverse?booleanIf true, reverse the ordering when it is applied.

The MarkerSpec type has the following attributes:

AttributeTypeDescription
stepBack?numberOffset (in pixels) between the end of the edge and the marker.
shapeMarkerShape or LiteralOrFieldOrExpressionThe marker shape.
direction?"forwards" or "reverse"If the direction is set to "reverse" then the marker will point towards the source node (rather than the target node).
fill?stringFill color for the marker.
opacity?numberOpacity of the marker (0 is fully transparent, and 1 is fully opaque).
stroke?stringStroke color for the marker.
size?numberArea of the bounding-box of the marker.

MarkerShape can be one of "triangle", "circle-triangle", "circle", "tee", "vee", "square", "diamond". "triangle-tee", or "triangle-cross".

LinkPathSpecWedge

Represent edges by wedges/triangles.

AttributeTypeDescription
shape"wedge"
stroke?stringStroke color for the wedges.
strokeOpacity?numberOpacity of the stroke around the edge of the wedge (0 is fully transparent, and 1 is fully opaque).
fill?stringFill color for the wedges.
opacity?numberOpacity of the wedge (0 is fully transparent, and 1 is fully opaque).
direction?"forwards" or "reverse"If the direction is set to "reverse" then the wedge will point towards the source node (rather than the target node).
width?numberWidth of the widest past of the wedge.

LinkPathSpecGlyphs

Represent edges by a series of glyphs positioned along their lengths.

AttributeTypeDescription
shape"glyphs"
glyphShapeMarkerShapeThe shape of glyph to be used.
colorGradient?ColorGradientSpecifies a color gradient along the line.
separation?numberDistance between glyphs.
stroke?stringStroke color for outer edge of the glyphs.
strokeWidth?numberStroke width for the outer edge of the glyphs (in pixels).
strokeOpacity?numberOpacity for the outer edge of the glyphs (0 is fully transparent, and 1 is fully opaque).
fill?stringFill color for the line.
opacity?numberOpacity of the line (0 is fully transparent, and 1 is fully opaque).

LinkPathSpecLine

Represent edges by straight lines.

AttributeTypeDescription
shape"line"
colorGradient?ColorGradientSpecifies a color gradient along the line.
stroke?stringStroke color for the line.
strokeDash?[number, number]Dash pattern for the line ([dash length, gap length]).
strokeWidth?numberStroke width for the line (in pixels).
strokeOpacity?numberOpacity for the curve (0 is fully transparent, and 1 is fully opaque).

LinkPathSpecCurveSymmetric

Represent edges by symmetric curves.

AttributeTypeDescription
shape"curveSymmetric"
stroke?stringStroke color for the curve.
strokeDash?[number, number]Dash pattern for the line ([dash length, gap length]).
strokeWidth?numberStroke width for the curve (in pixels).
strokeOpacity?numberOpacity for the curve (0 is fully transparent, and 1 is fully opaque).
swap?boolean or "reverse"If set to true, apply positiveAngle by using positions of two ends only, ignoring which is the source and which is the target.This can be useful if you are drawing an arc diagram and want to draw all arcs on the same side of the line of nodes, regardless of their direction.

LinkPathSpecCurve

Represent edges by asymmetric curves, with curvature distinguishing the source and target nodes.

AttributeTypeDescription
shape"curve"
angle?numberThe angle controls the amount of curvature.The curve is a cubic Bezier curve, with control points positioned at the start and end nodes.The intermediate control point is obtained by taking the line segment from the source node to the midpoint of the source and edge, and rotating from the line joining the source and edge by angle.The angle is in degrees, so a value or 0 or 180 gives a straight line.
stroke?stringStroke color for the curve.
strokeDash?[number, number]Dash pattern for the line ([dash length, gap length])
strokeWidth?numberStroke width for the curve (in pixels).
strokeOpacity?numberOpacity for the curve (0 is fully transparent, and 1 is fully opaque).

LinkPathSpecArc

Represent edges by semi-circular arcs curves.

AttributeTypeDescription
shape"arc"
stroke?stringStroke color for the curve.
strokeDash?[number, number]Dash pattern for the line ([dash length, gap length])
strokeWidth?numberStroke width for the curve (in pixels).
strokeOpacity?numberOpacity for the curve (0 is fully transparent, and 1 is fully opaque).
positiveAngle?booleanIf positiveAngle is true (the default), then sweep-flag=1 for the generated path, and the path will be drawn in a "positive-angle" direction.As defined by the SVG Specification:"(i.e., the ellipse formula x=cx+rxcos(theta) and y=cy+rysin(theta) is evaluated such that theta starts at an angle corresponding to the current point and increases positively until the arc reaches (x,y))"
swap?boolean or "reverse"If set to true, apply positiveAngle by using positions of two ends only, ignoring which is the source and which is the target.This can be useful if you are drawing an arc diagram and want to draw all arcs on the same side of the line of nodes, regardless of their direction.

LinkPathSpecDiagonal

Represent edges by sigmoidal curves (the Vega LinkPath transform calls this a "diagonal").

AttributeTypeDescription
shape"diagonal"
orientation?"vertical" or "horizontal"This parameter determines the orientation of the asymptotes of the sigmoid.
stroke?stringStroke color for the curve.
strokeDash?[number, number]Dash pattern for the line ([dash length, gap length])
strokeWidth?numberStroke width for the curve (in pixels).
strokeOpacity?numberOpacity for the curve (0 is fully transparent, and 1 is fully opaque).

LinkPathSpecOrthogonal

Represent edges by a pair of vertical and horizontal lines.

AttributeTypeDescription
shape"orthogonal"
orientation?"vertical" or "horizontal"Which direction to move first.
stroke?stringStroke color for the curve.
strokeDash?[number, number]Dash pattern for the line ([dash length, gap length])
strokeWidth?numberStroke width for the curve (in pixels).
strokeOpacity?numberOpacity for the curve (0 is fully transparent, and 1 is fully opaque).

LinkPathSpecSquiggle

Represent edges by AbySS-Explorer style squiggles. The number of oscillations cna be set directly (as n), or indirectly by setting the spacing between them.

AttributeTypeDescription
shape"squiggle"
n?numberThe number of squiggles.
spacing?numberThe spacing between squiggles.
amplitude?numberThe amplitude of the squiggles
stroke?stringStroke color for the curve.
strokeDash?[number, number]Dash pattern for the line ([dash length, gap length])
strokeWidth?numberStroke width for the curve (in pixels).
strokeOpacity?numberOpacity for the curve (0 is fully transparent, and 1 is fully opaque).