Skip to content

Commit e4bcfe1

Browse files
committed
feat: migrate more samples
1 parent f1bb844 commit e4bcfe1

24 files changed

+530
-571
lines changed

docs/examples/dendeogram.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { ChartConfiguration } from 'chart.js';
2+
import type {} from '../../src';
3+
4+
// #region data
5+
import nodes from './tree.json';
6+
7+
export const data: ChartConfiguration<'dendrogram'>['data'] = {
8+
labels: nodes.map((d) => d.name),
9+
datasets: [
10+
{
11+
pointBackgroundColor: 'steelblue',
12+
pointRadius: 5,
13+
data: nodes.map((d) => Object.assign({}, d)),
14+
},
15+
],
16+
};
17+
// #endregion data
18+
// #region config
19+
export const config: ChartConfiguration<'dendrogram'> = {
20+
type: 'dendrogram',
21+
data,
22+
};
23+
// #endregion config

docs/examples/dendrogram.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: Dendrogram
3+
---
4+
5+
# Dendrogram
6+
7+
<script setup>
8+
import {config as tree} from './tree';
9+
</script>
10+
11+
## Force Directed Graph
12+
13+
<ForceDirectedGraphChart
14+
:options="force.options"
15+
:data="force.data"
16+
/>
17+
18+
### Code
19+
20+
:::code-group
21+
22+
<<< ./force.ts#config [config]
23+
24+
<<< ./force.ts#data [data]
25+
26+
:::
27+
28+
29+
## Tree
30+
31+
<TreeChart
32+
:options="tree.options"
33+
:data="tree.data"
34+
/>
35+
36+
### Code
37+
38+
:::code-group
39+
40+
<<< ./tree.ts#tree [config]
41+
42+
<<< ./tree.ts#data [data]
43+
44+
:::

docs/examples/directed.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: Directed Tree
3+
---
4+
5+
# Directed Tree
6+
7+
<script setup>
8+
import {config} from './directed';
9+
</script>
10+
11+
<TreeChart
12+
:options="config.options"
13+
:data="config.data"
14+
/>
15+
16+
### Code
17+
18+
:::code-group
19+
20+
<<< ./directed.ts#config [config]
21+
22+
<<< ./directed.ts#data [data]
23+
24+
:::

docs/examples/directed.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { ChartConfiguration } from 'chart.js';
2+
import type {} from '../../src';
3+
4+
// #region data
5+
import nodes from './tree.json';
6+
7+
export const data: ChartConfiguration<'tree'>['data'] = {
8+
labels: nodes.map((d) => d.name),
9+
datasets: [
10+
{
11+
pointBackgroundColor: 'steelblue',
12+
pointRadius: 5,
13+
directed: true,
14+
data: nodes.map((d) => Object.assign({}, d)),
15+
},
16+
],
17+
};
18+
// #endregion data
19+
// #region config
20+
export const config: ChartConfiguration<'tree'> = {
21+
type: 'tree',
22+
data,
23+
};
24+
// #endregion config

docs/examples/force.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,41 @@ import type { ChartConfiguration } from 'chart.js';
22
import type {} from '../../src';
33

44
// #region data
5-
export const data: ChartConfiguration<'boxplot'>['data'] = {
6-
labels: ['A'],
5+
import miserables from './miserables.json';
6+
export const data: ChartConfiguration<'forceDirectedGraph'>['data'] = {
7+
labels: miserables.nodes.map((d) => d.id),
78
datasets: [
89
{
9-
itemRadius: 2,
10-
data: [[57297214, 57297216, 117540924, 117540928]],
10+
pointBackgroundColor: 'steelblue',
11+
pointRadius: 5,
12+
data: miserables.nodes,
13+
edges: miserables.links,
1114
},
1215
],
1316
};
1417
// #endregion data
1518
// #region config
16-
export const config: ChartConfiguration<'boxplot'> = {
17-
type: 'boxplot',
19+
export const config: ChartConfiguration<'forceDirectedGraph'> = {
20+
type: 'forceDirectedGraph',
1821
data,
1922
options: {
2023
plugins: {
21-
legend: {
22-
display: false,
24+
zoom: {
25+
pan: {
26+
enabled: true,
27+
},
28+
zoom: {
29+
wheel: {
30+
enabled: true,
31+
},
32+
pinch: {
33+
enabled: true,
34+
},
35+
// drag: {
36+
// enabled: true
37+
// },
38+
mode: 'xy',
39+
},
2340
},
2441
},
2542
},

docs/examples/index.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ title: Examples
66

77
<script setup>
88
import {config as force} from './force';
9+
import {config as dendrogram} from './dendrogram';
10+
import {tree} from './tree';
911
</script>
1012

1113
## Force Directed Graph
@@ -24,3 +26,38 @@ import {config as force} from './force';
2426
<<< ./force.ts#data [data]
2527

2628
:::
29+
30+
31+
## Dendrogram
32+
33+
<TreeChart
34+
:options="dendogram.options"
35+
:data="dendogram.data"
36+
/>
37+
38+
### Code
39+
40+
:::code-group
41+
42+
<<< ./dendogram.ts#config [config]
43+
44+
<<< ./dendogram.ts#data [data]
45+
46+
:::
47+
48+
## Tree
49+
50+
<TreeChart
51+
:options="tree.options"
52+
:data="tree.data"
53+
/>
54+
55+
### Code
56+
57+
:::code-group
58+
59+
<<< ./tree.ts#tree [config]
60+
61+
<<< ./tree.ts#data [data]
62+
63+
:::

docs/examples/label.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import type { ChartConfiguration } from 'chart.js';
2+
import type {} from '../../src';
3+
4+
// #region data
5+
import nodes from './tree.json';
6+
7+
export const data: ChartConfiguration<'forceDirectedGraph'>['data'] = {
8+
labels: nodes.map((d) => d.name),
9+
datasets: [
10+
{
11+
pointBackgroundColor: ['#002838', '#ed7d00', '#395c6b', '#d94d15', '#889da6'],
12+
pointRadius: 10,
13+
data: nodes.map((d) => Object.assign({}, d)),
14+
},
15+
],
16+
};
17+
// #endregion data
18+
// #region config
19+
export const config: ChartConfiguration<'forceDirectedGraph'> = {
20+
type: 'forceDirectedGraph',
21+
data,
22+
options: {
23+
tree: {
24+
orientation: 'radial',
25+
},
26+
layout: {
27+
padding: {
28+
left: 20,
29+
top: 20,
30+
bottom: 20,
31+
right: 20,
32+
},
33+
},
34+
plugins: {
35+
legend: {
36+
display: false,
37+
},
38+
datalabels: {
39+
// display: true,
40+
align: 'right',
41+
offset: 6,
42+
formatter: function (value, context) {
43+
return '' + value.name + '';
44+
},
45+
color: 'black',
46+
backgroundColor: 'steelblue',
47+
},
48+
},
49+
},
50+
plugins: [ChartDataLabels],
51+
};
52+
// #endregion config

docs/examples/orientation.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: Tree Orientations
3+
---
4+
5+
# Tree Orientations
6+
7+
<script setup>
8+
import {horizontal, vertical, radial} from './tree';
9+
</script>
10+
11+
## Horizontal
12+
13+
<TreeGraph
14+
:options="horizontal.options"
15+
:data="horizontal.data"
16+
/>
17+
18+
### Code
19+
20+
:::code-group
21+
22+
<<< ./tree.ts#horizontal [config]
23+
24+
<<< ./tee.ts#data [data]
25+
26+
:::
27+
28+
## Vertical
29+
30+
<TreeGraph
31+
:options="vertical.options"
32+
:data="vertical.data"
33+
/>
34+
35+
### Code
36+
37+
:::code-group
38+
39+
<<< ./tree.ts#vertical [config]
40+
41+
<<< ./tee.ts#data [data]
42+
43+
:::
44+
45+
## Radial
46+
47+
<TreeGraph
48+
:options="radial.options"
49+
:data="radial.data"
50+
/>
51+
52+
### Code
53+
54+
:::code-group
55+
56+
<<< ./tree.ts#radial [config]
57+
58+
<<< ./tee.ts#data [data]
59+
60+
:::

0 commit comments

Comments
 (0)