# 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, scaleFactor:1},
          middle: {enabled: false, scaleFactor:1},
          from:   {enabled: false, scaleFactor:1}
        },
        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'
        },
        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,
        shadow:{
          enabled: false,
          size:10,
          x:5,
          y:5
        },
        smooth: {
          enabled: true,
          type: "dynamic",
          roundness: 0.5
        },
        title:undefined,
        width: 1,
        value: undefined
      }
    }

    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.scaleFactor | Number | `1` | The scale factor allows you to change the size of the arrowhead.
arrows.middle | Object or Boolean | `Object` | Exactly the same as the to object but with an arrowhead in the center of the edge.
arrows.from | Object or Boolean | `Object` | Exactly the same as the to object but with an arrowhead at the from node of the edge.
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 border of the node 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.
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 settigns. 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.
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.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 then 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'`. Take a look at our example 26 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.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 | `undefined` | The title is shown in a pop-up when the mouse moves over the edge.
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.