OrbChartsOrbCharts

NetworkPlot

NetworkPlot is the core Plugin for the graph data format. It arranges nodes and links with a force-directed layout, and can draw relationship graphs and force-directed bubble charts by switching its internal Layers.

Data format: graph

Supported charts

NetworkPlot renders different charts through different Layer combinations:

Quick start

A minimal configuration draws a force graph. NetworkPlot shows the ForceDirected Layer by default:

import { OrbCharts } from '@orbcharts/core'
import type { RawData } from '@orbcharts/core'
import { NetworkPlot, Tooltip, Legend } from '@orbcharts/plugin-basic'
 
const data: RawData = [
  { id: 'id0', name: 'label0', value: 19800000, series: 'series1' },
  { id: 'id2', name: 'label2', value: 9800000, series: 'series1' },
  { id: 'id14', name: 'label8', series: 'series2', source: 'id0', target: 'id2', value: 100 },
]
 
const chart = new OrbCharts(document.querySelector('#chart')!, {
  data,
  plugins: [
    new NetworkPlot(),
    new Tooltip(),
    new Legend(),
  ],
})
 
// chart.destroy()

Tip: The chart fills its container by default, so set a width and height on the #chart container. See Core Concepts.

graph data contains both "nodes" and "links": records with id, name, value, and series represent nodes; records that also carry source and target represent a link from source to target, and series is used for grouping and coloring.

How layer visibility works

NetworkPlot is composed of multiple Layers, and the Layer names you list in the params are the Layers that get shown. If you specify no Layers (new NetworkPlot()), it shows ForceDirected by default (a force graph). You can also switch Layers dynamically with show/hide/showOnly after creation.

new NetworkPlot()                          // force graph (default)
new NetworkPlot({ ForceDirectedBubble: {} })  // force-directed bubble chart

Tip: Layer visibility and the show/hide/showOnly/toggle methods are common to all Plugins. See Plugin API for the full explanation.

Chart examples

All examples below use the same graph data—just swap the Layer to change the chart type.

Force Graph

new NetworkPlot({ ForceDirected: {} })

ForceDirected draws nodes as fixed-radius dots and the relationships between them as arrowed links, with node positions arranged automatically by a force simulation.

Network Bubble

new NetworkPlot({ ForceDirectedBubble: {} })

ForceDirectedBubble draws nodes as bubbles whose size varies with the value, with labels inside the bubbles showing the node names.

Tip: Pair it with Legend and Tooltip for interactivity—added the same way as in GridPlot.

Plugin parameters

These parameters affect the whole NetworkPlot's behavior, listed alongside Layer names in the same params object:

ParameterTypeDefaultDescription
datasetIndexnumber0Which dataset to use when data is multi-dataset
stylesGraphicStylespadding is { 20, 20, 20, 20 }Shared visual styles (see Plugin API)
visibleFilter(datum) => boolean | null() => trueFilter which data to show (see Plugin API)

Note: styles and visibleFilter are shared by all chart Plugins; their structure and usage are documented centrally in Plugin API. Only NetworkPlot's default differences are noted here (styles.padding defaults to { top: 20, right: 20, bottom: 20, left: 20 }, and transitionDuration defaults to 800).

Layer parameters

Each Layer has its own parameters. The main parameters and defaults of each Layer are listed below.

About ColorType: color-related parameters use ColorType ('data', 'primary', etc.), mapping to the colors defined in the Theme. See Theme for the full explanation.

ForceDirected

ParameterTypeDefaultDescription
point.radiusnumber10Node dot radius
point.fillColorTypeColorType'data'Node fill color
point.strokeColorTypeColorType'data'Node stroke color
point.strokeWidthnumber1Node stroke width
pointLabel.colorTypeColorType'primary'Node label color
pointLabel.sizeFixedbooleanfalseWhether the label size is fixed (does not scale with zoom)
arrow.colorTypeColorType'primary'Link arrow color
arrow.strokeWidthnumber1.5Link line width
arrow.pointerWidthnumber5Arrowhead width
arrow.pointerHeightnumber5Arrowhead height
arrowLabel.colorTypeColorType'primary'Link label color
arrowLabel.sizeFixedbooleanfalseWhether the link label size is fixed
force.nodeStrengthnumber-500Force between nodes (negative is repulsion)
force.linkDistancenumber100Link length
force.velocityDecaynumber0.1Velocity decay factor
force.alphaDecaynumber0.05Simulation convergence decay factor
zoomablebooleantrueWhether zooming and panning are allowed
transform{ x, y, scale }{ x: 0, y: 0, scale: 1 }Initial offset and zoom level
scaleExtent{ min, max }{ min: 0, max: Infinity }Zoom level range

Tip: point, pointLabel, arrow, and arrowLabel each also have a styleFn function parameter that returns a CSS string to customize individual elements.

ForceDirectedBubble

ParameterTypeDefaultDescription
bubble.radiusMinnumber15Bubble radius for the minimum value
bubble.radiusMaxnumber45Bubble radius for the maximum value
bubble.arcScaleType'area' | 'radius''area'Value mapping method (area or radius)
bubble.fillColorTypeColorType'data'Bubble fill color
bubble.strokeColorTypeColorType'data'Bubble stroke color
bubble.strokeWidthnumber1Bubble stroke width
bubbleLabel.fillRatenumber0.9Ratio of the label filling the bubble
bubbleLabel.lineHeightnumber1Label line height
bubbleLabel.maxLineLengthnumber6Maximum characters per line
bubbleLabel.wordBreakAllbooleantrueWhether to allow breaking at any position
bubbleLabel.colorTypeColorType'dataContrast'Label text color
arrow.colorTypeColorType'primary'Link arrow color
arrow.strokeWidthMinnumber1.5Link line width for the minimum value
arrow.strokeWidthMaxnumber4.5Link line width for the maximum value
arrow.pointerWidthnumber5Arrowhead width
arrow.pointerHeightnumber5Arrowhead height
arrowLabel.colorTypeColorType'primary'Link label color
arrowLabel.sizeFixedbooleanfalseWhether the link label size is fixed
force.nodeStrengthnumber-500Force between nodes (negative is repulsion)
force.linkDistancenumber130Link length
force.velocityDecaynumber0.1Velocity decay factor
force.alphaDecaynumber0.05Simulation convergence decay factor
zoomablebooleantrueWhether zooming and panning are allowed
transform{ x, y, scale }{ x: 0, y: 0, scale: 1 }Initial offset and zoom level
scaleExtent{ min, max }{ min: 0, max: Infinity }Zoom level range

Tip: bubble, bubbleLabel, arrow, and arrowLabel each also have a styleFn function parameter that returns a CSS string to customize individual elements.

Full TypeScript interface

interface NetworkPlotPluginParams {
  styles: GraphicStyles
  visibleFilter: (datum: ModelDatumGraph) => boolean | null
  datasetIndex: number
}
 
interface NetworkPlotAllLayerParams {
  ForceDirected: ForceDirectedParams
  ForceDirectedBubble: ForceDirectedBubbleParams
}
 
// The constructor accepts a DeepPartial of both (Layer names alongside Plugin params)
new NetworkPlot(params?: DeepPartial<NetworkPlotPluginParams & NetworkPlotAllLayerParams>)