# Network - edges

Handles the creation and deletion of edges and contains the global edge options and styles.

### Options

The options for the edges have to be contained in an object titled 'edges'. All of these options can be supplied per edge as well. Obviously, 'id' should not be defined globally but per edge. Options defined in the global edges object, are applied to all edges. If an edge has options of its own, those will be used instead of the global options.

When you have given an edge an option, you will override the global option for that property. If you then set that option to `null`, it will revert back to the default value.

Click on the full options or shorthand options to show how these options are supposed to be used.

    // these are all options in full.
    var options = {
      edges:{
        arrows: {
          to: {
            enabled: false,
            imageHeight: undefined,
            imageWidth: undefined,
            scaleFactor: 1,
            src: undefined,
            type: "arrow"
          },
          middle: {
            enabled: false,
            imageHeight: 32,
            imageWidth: 32,
            scaleFactor: 1,
            src: "https://visjs.org/images/visjs_logo.png",
            type: "image"
          },
          from: {
            enabled: false,
            imageHeight: undefined,
            imageWidth: undefined,
            scaleFactor: 1,
            src: undefined,
            type: "arrow"
          }
        },
        endPointOffset: {
          from: 0,
          to: 0
        },
        arrowStrikethrough: true,
        chosen: true,
        color: {
          color:'#848484',
          highlight:'#848484',
          hover: '#848484',
          inherit: 'from',
          opacity:1.0
        },
        dashes: false,
        font: {
          color: '#343434',
          size: 14, // px
          face: 'arial',
          background: 'none',
          strokeWidth: 2, // px
          strokeColor: '#ffffff',
          align: 'horizontal',
          multi: false,
          vadjust: 0,
          bold: {
            color: '#343434',
            size: 14, // px
            face: 'arial',
            vadjust: 0,
            mod: 'bold'
          },
          ital: {
            color: '#343434',
            size: 14, // px
            face: 'arial',
            vadjust: 0,
            mod: 'italic',
          },
          boldital: {
            color: '#343434',
            size: 14, // px
            face: 'arial',
            vadjust: 0,
            mod: 'bold italic'
          },
          mono: {
            color: '#343434',
            size: 15, // px
            face: 'courier new',
            vadjust: 2,
            mod: ''
          }
        },
        hidden: false,
        hoverWidth: 1.5,
        label: undefined,
        labelHighlightBold: true,
        length: undefined,
        physics: true,
        scaling:{
          min: 1,
          max: 15,
          label: {
            enabled: true,
            min: 14,
            max: 30,
            maxVisible: 30,
            drawThreshold: 5
          },
          customScalingFunction: function (min,max,total,value) {
            if (max === min) {
              return 0.5;
            }
            else {
              var scale = 1 / (max - min);
              return Math.max(0,(value - min)*scale);
            }
          }
        },
        selectionWidth: 1,
        selfReferenceSize: 20,
        selfReference:{
            size: 20,
            angle: Math.PI / 4,
            renderBehindTheNode: true
        },
        shadow:{
          enabled: false,
          color: 'rgba(0,0,0,0.5)',
          size:10,
          x:5,
          y:5
        },
        smooth: {
          enabled: true,
          type: "dynamic",
          roundness: 0.5
        },
        title:undefined,
        value: undefined,
        width: 1,
        widthConstraint: false
      }
    }

    network.setOptions(options);

    // here all options that have shorthand notations are shown.
    var options = {
      edges:{
        arrows: 'to, from',
        color: 'red',
        font: '12px arial #ff0000',
        scaling:{
          label: true,
        },
        shadow: true,
        smooth: true,
      }
    }

    network.setOptions(options);

These options can also be set per individual edge.

Name | Type | Default | Description
--- | --- | --- | ---
arrows | Object or String | `undefined` | To draw an arrow with default settings a string can be supplied. For example: `arrows:'to, from, middle'` or `'to;from'`, any combination with any seperating symbol is fine. If you want to control the size of the arrowheads, you can supply an object.
arrows.to | Object or Boolean | `Object` | When true, an arrowhead on the 'to' side of the edge is drawn, pointing to the 'to' node with default settings. To customize the size of the arrow, supply an object.
arrows.to.enabled | Boolean | `false` | Toggle the arrow on or off. This option is optional, if undefined and the scaleFactor property is set, enabled will be set to true.
arrows.to.imageHeight | Number | `undefined` | The height of the image arrow. The height of the image file is used if this isn't defined. .
arrows.to.imageWidth | Number | `undefined` | The width of the image arrow. The width of the image file is used if this isn't defined. .
arrows.to.scaleFactor | Number | `1` | The scale factor allows you to change the size of the arrowhead.
arrows.to.src | String | `undefined` | The URL for the image arrow type. .
arrows.to.type | String | `arrow` | The type of endpoint. Possible values are: `arrow`, `bar`, `circle` and `image`. The default is `arrow` .
arrows.middle | Object or Boolean | `Object` | Similar to the 'to' object, but with an arrowhead in the center of the edge. The direction of the arrow can be flipped by using a negative value for `arrows.middle.scaleFactor`.
arrows.from | Object or Boolean | `Object` | Exactly the same as the to object but with an arrowhead at the from node of the edge.
endPointOffset | Object | `undefined` | Adjust the endpoints. It can be useful if you want to have the endpoints placed on the nodes borders. This feature is only possible when the arrowStrikethrough is true.
endPointOffset.from | Number | `0` | A negative number move the endpoint nearer the node's midpoint, and a positive number does the opposite.
endPointOffset.to | Number | `0` | A negative number move the endpoint nearer the node's midpoint, and a positive number does the opposite.
arrowStrikethrough | Boolean | `true` | When false, the edge stops at the arrow. This can be useful if you have thick lines and you want the arrow to end in a point. Middle arrows are not affected by this.
chosen | Object or Boolean | `true` | When true, selecting or hovering on an edge will change it and its label's characteristics according to the default. When false, no change to the edge or its label will occur when the edge is chosen. If an object is supplied, finer-grained adjustment of edge and label characteristics is available when an edge is chosen.
chosen.edge | Function or Boolean | undefined | When true, selecting or hovering on an edge will change its characteristics according to the default. When false, no change to the edge will occur when the edge is chosen. If a function is supplied, it is called when the edge is chosen.
      function(values, id, selected, hovering) {
        values.property = chosenValue;
      }
Any of the incoming arguments may be used to determine characteristic changes. If a property is not specifically assigned by the supplied function, it will be left unchanged. A specific function may be assigned to each particular edge in its options, or to all in the network's `edges` options. The properties define the characteristics that can be changed as follows:
Property | Edge Reference
--- | ---
dashes | see dashes
toArrow | see arrows.to.enabled
toArrowScale | see arrows.to.scaleFactor
toArrowType | see arrows.to.type
middleArrow | see arrows.middle.enabled
middleArrowScale | see arrows.middle.scaleFactor
middleArrowType | see arrows.middle.type
fromArrow | see arrows.from.enabled
fromArrowScale | see arrows.from.scaleFactor
fromArrowType | see arrows.from.type
arrowStrikethrough | see arrowStrikethrough
color | see color.color
inheritsColor | see color.inherit
opacity | see color.opacity
hidden | see hidden
length | see length
shadow | see shadow.enabled
shadowColor | see shadow.color
shadowSize | see shadow.size
shadowX | see shadow.x
shadowY | see shadow.y
width | see width
chosen.label | Function or Boolean | undefined | When true, selecting or hovering on an edge will change its label's characteristics according to the default. When false, no change to the edge's label will occur when the edge is chosen. If a function is supplied, it is called when the edge is chosen.
      function(values, id, selected, hovering) {
        values.property = chosenValue;
      }
Any of the incoming arguments may be used to determine characteristic changes. If a property is not specifically assigned by the supplied function, it will be left unchanged. A specific function may be assigned to each particular edge in its options, or to all in the network's `edges` options. The properties define the characteristics that can be changed as follows:
Property | Edge Reference
--- | ---
color | see font.color
size | see font.size
face | see font.face
mod | font modifier ('bold', 'italic', etc.)
vadjust | see font.vadjust
strokeWidth | see font.strokeWidth
strokeColor | see font.strokeColor
color | Object or String | `Object` | The color object contains the color information of the edge in every situation. When the edge only needs a single color, a color value like `'rgb(120,32,14)'`, `'#ffffff'` or `'red'` can be supplied instead of an object.
color.color | String | `'#848484'` | The color of the edge when it is not selected or hovered over (assuming hover is enabled in the interaction module).
color.highlight | String | `'#848484'` | The color the edge when it is selected.
color.hover | String | `'#848484'` | The color the edge when the mouse hovers over it (assuming hover is enabled in the interaction module).
color.inherit | String or Boolean | `'from'` | When color, highlight or hover are defined, inherit is set to false! Supported options are: `true, false, 'from','to','both'`. The default value is 'from' which does the same as true: the edge will inherit the color from the border of the node on the 'from' side. When set to 'to', the border color from the 'to' node will be used. When set to 'both', the color will fade from the from color to the to color. 'both' is computationally intensive because the gradient is recomputed every redraw. This is required because the angles change when the nodes move.
color.opacity | Number | `1.0` | It can be useful to set the opacity of an edge without manually changing all the colors. The opacity option will convert all colors (also when using inherit) to adhere to the supplied opacity. The allowed range of the opacity option is between `0 and 1`. This is only done once so the performance impact is not too big.
dashes | Array or Boolean | `false` | When true, the edge will be drawn as a dashed line. You can customize the dashes by supplying an Array. Array formart: Array of numbers, gap length, dash length, gap length, dash length, ... etc. The array is repeated until the distance is filled. When using dashed lines in IE versions older than 11, the line will be drawn straight, not smooth.
font | Object or String | `false` | This object defines the details of the label. A shorthand is also supported in the form `'size face color'` for example: `'14px arial red'`.
font.color | String | `'#343434'` | Color of the label text.
font.size | Number | `14` | Size of the label text.
font.face | String | `'arial'` | Font face (or font family) of the label text.
font.background | String | `undefined` | When not `undefined` but a color string, a background rectangle will be drawn behind the label in the supplied color.
font.strokeWidth | Number | `2` | As an alternative to the background rectangle, a stroke can be drawn around the text. When a value higher than 0 is supplied, the stroke will be drawn.
font.strokeColor | String | `'#ffffff'` | This is the color of the stroke assuming the value for stroke is higher than 0.
font.align | String | `'horizontal'` | Possible options: `'horizontal','top','middle','bottom'`. The alignment determines how the label is aligned over the edge. The default value `horizontal` aligns the label horizontally, regardless of the orientation of the edge. When an option other than `horizontal` is chosen, the label will align itself according to the edge.
font.vadjust | Number | `0` | A font-specific correction to the vertical positioning of the base font in the label text. (Positive is down.)
font.multi | Boolean or String | `false` | If `false`, the label is treated as pure text drawn with the base font. If `true` or `'html'` the label may be multifonted, with bold, italic and code markup, interpreted as html. If the value is `'markdown'` or `'md'` the label may be multifonted, with bold, italic and code markup, interpreted as markdown. The bold, italic, bold-italic and monospaced fonts may be set up under in the font.bold, font.ital, font.boldital and font.mono properties, respectively.
font.bold | Object or String | `false` | This object defines the details of the bold font in the label. A shorthand is also supported in the form `'size face color'` for example: `'14px arial red'`.
font.bold.color | String | `'#343434'` | Color of the bold font in the label text. Defaults to the base font's color.
font.bold.size | Number | `14` | Size of the bold font in the label text. Defaults to the base font's size.
font.bold.face | String | `'arial'` | Font face (or font family) of the bold font in the label text. Defaults to the base font's face.
font.bold.mod | String | `'bold'` | A string added to the face and size when determining the bold font in the label text.
font.bold.vadjust | Number | `0` | A font-specific correction to the vertical positioning of the bold font in the label text. (Positive is down.) Defaults to the base font's valign.
font.ital | Object or String | `false` | This object defines the details of the italic font in the label. A shorthand is also supported in the form `'size face color'` for example: `'14px arial red'`.
font.ital.color | String | `'#343434'` | Color of the italic font in the label text. Defaults to the base font's color.
font.ital.size | Number | `14` | Size of the italic font in the label text. Defaults to the base font's size.
font.ital.face | String | `'arial'` | Font face (or font family) of the italic font in the label text. Defaults to the base font's face.
font.ital.mod | String | `'italic'` | A string added to the face and size when determining the italic font in the label text.
font.ital.vadjust | Number | `0` | A font-specific correction to the vertical positioning of the italic font in the label text. (Positive is down.) Defaults to the base font's valign.
font.boldital | Object or String | `false` | This object defines the details of the bold italic font in the label. A shorthand is also supported in the form `'size face color'` for example: `'14px arial red'`.
font.boldital.color | String | `'#343434'` | Color of the bold italic font in the label text. Defaults to the base font's color.
font.boldital.size | Number | `14` | Size of the bold italic font in the label text. Defaults to the base font's size.
font.boldital.face | String | `'arial'` | Font face (or font family) of the bold italic font in the label text. Defaults to the base font's face.
font.boldital.mod | String | `'bold'` | A string added to the face and size when determining the bold italic font in the label text.
font.boldital.vadjust | Number | `0` | A font-specific correction to the vertical positioning of the bold italic font in the label text. (Positive is down.) Defaults to the base font's valign.
font.mono | Object or String | `false` | This object defines the details of the monospaced font in the label. A shorthand is also supported in the form `'size face color'` for example: `'15px courier red'`.
font.mono.color | String | `'#343434'` | Color of the monospaced font in the label text. Defaults to the base font's color.
font.mono.size | Number | `15` | Size of the monospaced font in the label text. Defaults to the base font's size.
font.mono.face | String | `'courier new'` | Font face (or font family) of the monospaced font in the label text.
font.mono.mod | String | `''` | A string added to the face and size when determining the monospaced font in the label text.
font.mono.vadjust | Number | `2` | A font-specific correction to the vertical positioning of the monospaced font in the label text. (Positive is down.) Defaults to the base font's valign.
from | Number or String |  | Edges are between two nodes, one to and one from. This is where you define the from node. You have to supply the corresponding node ID. This naturally only applies to individual edges.
hidden | Boolean | `false` | When true, the edge is not drawn. It is part still part of the physics simulation however!
hoverWidth | Number or Function | `0.5` | Assuming the hover behaviour is enabled in the interaction module, the hoverWidth determines the width of the edge when the user hovers over it with the mouse. If a number is supplied, this number will be added to the width. Because the width can be altered by the value and the scaling functions, a constant multiplier or added value may not give the best results. To solve this, you can supply a function. Example:
    var options: {
      edges: {
        hoverWidth: function (width) {return width+1;}
      }
    }
It receives the `Number width` of the edge. In this simple example we add 1 to the width. You can taylor the logic in the function as long as it returns a `Number`.
id | String | `undefined` | The id of the edge. The id is optional for edges. When not supplied, an UUID will be assigned to the edge. This naturally only applies to individual edges.
label | String | `undefined` | The label of the edge. HTML does not work in here because the network uses HTML5 Canvas.
labelHighlightBold | Boolean | `true` | Determines whether or not the label becomes bold when the edge is selected.
length | Number | `undefined` | The physics simulation gives edges a spring length. This value can override the length of the spring in rest.
physics | Boolean | `true` | When true, the edge is part of the physics simulation. When false, it will not act as a spring.
scaling | Object | `Object` | If the `value` option is specified, the width of the edges will be scaled according to the properties in this object. Keep in mind that when using scaling, the `width` option is neglected.
scaling.min | Number | `1` | If edges have a value, their widths are determined by the value, the scaling function and the min max values. The min value is the minimum allowed value.
scaling.max | Number | `15` | This is the maximum allowed width when the edges are scaled using the value option.
scaling.label | Object or Boolean | `Object` | When false, the label is not allowed to scale with the edge. If true it will scale using default settings. For further customization, you can supply an object.
scaling.label.enabled | Boolean | `false` | Toggle the scaling of the label on or off. If this option is not defined, it is set to true if any of the properties in this object are defined.
scaling.label.min | Number | `14` | The minimum font-size used for labels when scaling.
scaling.label.max | Number | `30` | The maximum font-size used for labels when scaling.
scaling.label.maxVisible | Number | `30` | When zooming in, the font is drawn larger as well. You can limit the perceived font size using this option. If set to 30, the font will never look larger than size 30 zoomed at 100%.
scaling.label.drawThreshold | Number | `5` | When zooming out, the font will be drawn smaller. This defines a lower limit for when the font is drawn. When using font scaling, you can use this together with the maxVisible to first show labels of important edges when zoomed out and only show the rest when zooming in.
scaling.customScalingFunction | Function | in description | If edges have `value` fields, this function determines how the size of the nodes are scaled based on their values. The default function is:
    function (min,max,total,value) {
      if (max === min) {
        return 0.5;
      }
      else {
        var scale = 1 / (max - min);
        return Math.max(0,(value - min)*scale);
      }
    }
The function receives the minimum value of the set, the maximum value, the total sum of all values and finally the value of the node or edge it works on. It has to return a value between 0 and 1. The nodes and edges then calculate their size as follows:
    var scale = customScalingFunction(min,max,total,value);
    var diff = maxWidth - minWidth;
    myWidth = minWidth + diff * scale;
Please note: `maxWidth` and `minWidth` are the values `scaling.max` and `scaling.min` provided in the options.
selectionWidth | Number or Function | `1` | The selectionWidth determines the width of the edge when the edge is selected. If a number is supplied, this number will be added to the width. Because the width can be altered by the value and the scaling functions, a constant multiplier or added value may not give the best results. To solve this, you can supply a function. Example:
    var options: {
      edges: {
        selectionWidth: function (width) {return width*2;}
      }
    }
It receives the `Number width` of the edge. In this simple example multiply the width by 2. You can taylor the logic in the function as long as it returns a `Number`.
selfReferenceSize | Number | `false` | When the to and from nodes are the same, a circle is drawn. This is the radius of that circle. This property is deprecated please use selfReference instead.
selfReference | Object | `Object` | When the to and from nodes are the same, a circle is drawn. This provides radius of circle and position.
selfReference.size | Number | `20` | This is the radius of circle.
selfReference.angle | Number | `π / 4` | This is the angle (Provided in radians) to indicate position for the circle. If position is not provided then it will be top-right (π / 4) corner.
selfReference.renderBehindTheNode | Boolean | `true` | This is a flag that indicates whether self reference circle should be drawn as a full circle or rather should not overlap with parent node. parentOptions.selfReference
shadow | Object or Boolean | `Object` | When true, the edge casts a shadow using the default settings. This can be further refined by supplying an object.
shadow.enabled | Boolean | `false` | Toggle the casting of shadows. If this option is not defined, it is set to true if any of the properties in this object are defined.
shadow.color | String | `'rgba(0,0,0,0.5)'` | The color size of the shadow as a string. Supported formats are 'rgb(255,255,255)', 'rgba(255,255,255,1)' and '#FFFFFF'.
shadow.size | Number | `10` | The blur size of the shadow.
shadow.x | Number | `5` | The x offset.
shadow.y | Number | `5` | The y offset.
smooth | Object or Boolean | `Object` | When true, the edge is drawn as a dynamic quadratic bezier curve. The drawing of these curves takes longer than that of straight curves but it looks better. There is a difference between dynamic smooth curves and static smooth curves. The dynamic smooth curves have an invisible support node that takes part in the physics simulation. If you have a lot of edges, you may want to consider picking a different type of smooth curves than dynamic for better performance.
smooth.enabled | Boolean | `true` | Toggle smooth curves on and off. This is an optional option. If any of the other properties in this object are set, this option will be set to true.
smooth.type | String | `'dynamic'` | Possible options: `'dynamic', 'continuous', 'discrete', 'diagonalCross', 'straightCross', 'horizontal', 'vertical', 'curvedCW', 'curvedCCW', 'cubicBezier'`. Take a look at this example to see what these look like and pick the one that you like best! When using dynamic, the edges will have an invisible support node guiding the shape. This node is part of the physics simulation.
smooth.forceDirection | String or Boolean | `false` | Accepted options: `['horizontal', 'vertical', 'none']`. This options is only used with the cubicBezier curves. When true, horizontal is chosen, when false, the direction that is larger (x distance between nodes vs y distance between nodes) is used. If the x distance is larger, horizontal. This is ment to be used with hierarchical layouts.
smooth.roundness | Number | `0.5` | Accepted range: `0 .. 1.0`. This parameter tweaks the roundness of the smooth curves for all types EXCEPT dynamic.
title | String or Element | `undefined` | Title to be displayed in a pop-up when the user hovers over the edge. The title can be an HTML element or a string containing plain text. See HTML in titles exmample if you want to parse HTML.
to | Number or String |  | Edges are between two nodes, one to and one from. This is where you define the to node. You have to supply the corresponding node ID. This naturally only applies to individual edges.
value | Number | `undefined` | When a value is set, the edges' width will be scaled using the options in the scaling object defined above.
width | Number | `1` | The width of the edge. If value is set, this is not used.
widthConstraint | Number, Boolean or Object | `false` | If false, no widthConstraint is applied. If a number is specified, the maximum width of the edge's label is set to the value. The edge's label's lines will be broken on spaces to stay below the maximum.
widthConstraint.maximum | Number | `undefined` | If a number is specified, the maximum width of the edge's label is set to the value. The edge's label's lines will be broken on spaces to stay below the maximum.

Third party docs: