Getting Started
Pivotick is a hackable TypeScript graph visualization library built on top of D3 force simulations. It renders directed or undirected graphs with interactive controls, force simulation, tree layout support, and optional UI elements such as sidebars, toolbars, context menus, and tooltips.
Basic Usage
Pivotick can be used either as a modern JavaScript module or directly in the browser via a script tag.
const app = new Pivotick({
container: document.getElementById('app'),
data: {
nodes: [
{ id: 1, data: { label: 'A' } },
{ id: 2, data: { label: 'B' } }
],
edges: [
{ from: 1, to: 2 }
]
}
})Installation
1. Use a GitHub Release (no build required)
If you don’t want to build the project yourself, download the latest release from GitHub.
Steps:
- Go to the Releases page of the repository
- Download the latest dist bundle
- Extract it into your project
You should get files like:
pivotick.es.js
pivotick.umd.js
pivotick.iife.js
pivotick.cssThen use them depending on your environment:
import { Pivotick } from 'pivotick'
import 'pivotick/dist/pivotick.css'
const app = new Pivotick({
container: document.getElementById('app'),
data: {
nodes: [
{ id: 1, data: { label: 'A' } },
{ id: 2, data: { label: 'B' } }
],
edges: [
{ from: 1, to: 2 }
]
}
})<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/assets/pivotick.css" />
<script src="/assets/pivotick.iife.js"></script>
</head>
<body>
<div id="app"></div>
<script>
const app = new Pivotick({
container: document.getElementById('app'),
data: {
nodes: [
{ id: 1, data: { label: 'A' } },
{ id: 2, data: { label: 'B' } }
],
edges: [
{ from: 1, to: 2 }
]
}
})
</script>
</body>
</html>2. Build from source (recommended for development)
Use this if you want full control over the library or need to modify it.
git clone https://github.com/pivotick/pivotick.git
cd pivotick
npm install
npm run buildAfter building, the compiled files will be available in:
dist/You can then import them directly depending on your environment:
import { Pivotick } from 'pivotick'
import 'pivotick/dist/pivotick.css'
const app = new Pivotick({
container: document.getElementById('app'),
data: {
nodes: [
{ id: 1, data: { label: 'A' } },
{ id: 2, data: { label: 'B' } }
],
edges: [
{ from: 1, to: 2 }
]
}
})<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/assets/pivotick.css" />
<script src="/assets/pivotick.iife.js"></script>
</head>
<body>
<div id="app"></div>
<script>
const app = new Pivotick({
container: document.getElementById('app'),
data: {
nodes: [
{ id: 1, data: { label: 'A' } },
{ id: 2, data: { label: 'B' } }
],
edges: [
{ from: 1, to: 2 }
]
}
})
</script>
</body>
</html>Styling
Pivotick comes with default styles included in pivotick.css:
You can customize the look in two ways:
- Use Pivotick's built-in classes.
- Override styles using CSS variables.
:root {
--pvt-node-color: #FDDA24;
--pvt-node-stroke: #000000;
--pvt-edge-stroke: #EF3340;
}
.pvt-node circle {
fill: cyan;
}