11import type { ChartConfiguration } from 'chart.js' ;
22import type { } from '../../src' ;
3-
3+ import ChartDataLabels from 'chartjs-plugin-datalabels' ;
44// #region data
55import nodes from './tree.json' ;
66
7- export const data : ChartConfiguration < 'forceDirectedGraph ' > [ 'data' ] = {
7+ export const data : ChartConfiguration < 'tree ' > [ 'data' ] = {
88 labels : nodes . map ( ( d ) => d . name ) ,
99 datasets : [
1010 {
@@ -16,8 +16,8 @@ export const data: ChartConfiguration<'forceDirectedGraph'>['data'] = {
1616} ;
1717// #endregion data
1818// #region config
19- export const config : ChartConfiguration < 'forceDirectedGraph ' > = {
20- type : 'forceDirectedGraph ' ,
19+ export const config : ChartConfiguration < 'tree ' > = {
20+ type : 'tree ' ,
2121 data,
2222 options : {
2323 tree : {
@@ -50,3 +50,42 @@ export const config: ChartConfiguration<'forceDirectedGraph'> = {
5050 plugins : [ ChartDataLabels ] ,
5151} ;
5252// #endregion config
53+
54+ // #region radial
55+ export const radial : ChartConfiguration < 'tree' > = {
56+ type : 'tree' ,
57+ data,
58+ options : {
59+ tree : {
60+ orientation : 'radial' ,
61+ } ,
62+ layout : {
63+ padding : 40 ,
64+ } ,
65+ plugins : {
66+ datalabels : {
67+ display : ( context ) => {
68+ // const index = context.dataIndex;
69+ // const value = context.dataset.data[index];
70+ return true ; //value.children.length === 0;
71+ } ,
72+ align : ( context ) => {
73+ const index = context . dataIndex ;
74+ const value = context . dataset . data [ index ] as { angle : number } ;
75+ return ( - value . angle / Math . PI ) * 180 ;
76+ } ,
77+ rotation : ( context ) => {
78+ const index = context . dataIndex ;
79+ const value = context . dataset . data [ index ] as { angle : number } ;
80+ return ( - value . angle / Math . PI ) * 180 ;
81+ } ,
82+ backgroundColor : 'white' ,
83+ formatter : ( v ) => {
84+ return v . name ;
85+ } ,
86+ } ,
87+ } ,
88+ } ,
89+ plugins : [ ChartDataLabels ] ,
90+ } ;
91+ // #endregion radial
0 commit comments