1
- import { Plugin } from 'obsidian' ;
1
+ import { Plugin , WorkspaceLeaf , Notice } from 'obsidian' ;
2
2
import { getAPI } from 'obsidian-dataview' ;
3
3
4
4
export default class UniqueMetadataKeysPlugin extends Plugin {
@@ -11,6 +11,11 @@ export default class UniqueMetadataKeysPlugin extends Plugin {
11
11
name : 'Print Unique Metadata Keys' ,
12
12
callback : ( ) => this . printUniqueMetadataKeys ( )
13
13
} ) ;
14
+ this . addCommand ( {
15
+ id : 'print-graph-leaf' ,
16
+ name : 'Print Graph Leaf' ,
17
+ callback : ( ) => this . findGraphLeaf ( )
18
+ } ) ;
14
19
}
15
20
16
21
printUniqueMetadataKeys ( ) {
@@ -28,10 +33,10 @@ export default class UniqueMetadataKeysPlugin extends Plugin {
28
33
29
34
// Define a list of categorical colors as single integers
30
35
const colors = [
31
- 9991159 , 13948116 , 16772608 , 4280421 , 16113345 ,
32
- 9474192 , 4617584 , 15790320 , 12320668 , 16185078 ,
33
- 32896 , 15132410 , 10040346 , 16777128 , 8388608 ,
34
- 11184895 , 8421376 , 16761035 , 255 , 8421504
36
+ 16343842 , 7260435 , 11226103 , 8810003 , 1997538 ,
37
+ 11796368 , 9731429 , 16177103 , 15601550 , 7601461 ,
38
+ 1066150 , 6197085 , 5122908 , 1339852 , 2975129 ,
39
+ 1364806 , 3203221 , 14122353 , 7027020 , 8280444
35
40
] ;
36
41
37
42
// Map each unique key to a color
@@ -44,7 +49,10 @@ export default class UniqueMetadataKeysPlugin extends Plugin {
44
49
this . keyColorMap . forEach ( ( color , key ) => console . log ( `${ key } : ${ color } ` ) ) ;
45
50
}
46
51
47
- getColorForKey ( key : string ) : number | undefined {
52
+ getColorForKey ( key : string | null ) : number | undefined {
53
+ if ( key === null ) {
54
+ return 0 ;
55
+ }
48
56
return this . keyColorMap . get ( key ) ;
49
57
}
50
58
@@ -66,4 +74,34 @@ export default class UniqueMetadataKeysPlugin extends Plugin {
66
74
isLink ( value : any ) : boolean {
67
75
return typeof value === 'object' && value . hasOwnProperty ( 'path' ) ;
68
76
}
77
+
78
+ findGraphLeaf ( ) : WorkspaceLeaf | null {
79
+ let graphLeaves = this . app . workspace . getLeavesOfType ( 'graph' ) ;
80
+ if ( graphLeaves . length != 1 ) {
81
+ if ( graphLeaves . length < 1 ) {
82
+ new Notice ( 'No graph view open' ) ;
83
+ } else {
84
+ new Notice ( 'More than one graph view open, please choose an active one' ) ;
85
+ }
86
+ return null ;
87
+ }
88
+ const links = graphLeaves [ 0 ] . view . renderer . links ;
89
+
90
+ for ( let i = 0 ; i < 2 ; i ++ ) {
91
+ const sourceId = links [ i ] . source . id ;
92
+ const targetId = links [ i ] . target . id ;
93
+ console . log ( sourceId ) ;
94
+ console . log ( targetId ) ;
95
+ const linkKey = this . getMetadataKeyForLink ( sourceId , targetId ) ;
96
+ const linkColor = this . getColorForKey ( linkKey ) ;
97
+ console . log ( linkColor ) ;
98
+ console . log ( links [ i ] . renderer ) ;
99
+ links [ i ] . line . _tintRGB = linkColor ;
100
+ links [ i ] . renderer . colors . line . rgb = links [ i ] . line . _tintRGB ;
101
+
102
+ }
103
+
104
+
105
+ return graphLeaves [ 0 ]
106
+ }
69
107
}
0 commit comments