@@ -2,6 +2,7 @@ import * as echarts from 'echarts'
2
2
import 'echarts-wordcloud'
3
3
import { OptionsType } from './type'
4
4
import { getAPI } from 'obsidian-dataview'
5
+ import { Notice } from 'obsidian'
5
6
6
7
export default class Renderer {
7
8
constructor ( public options : OptionsType , public el : HTMLElement ) { }
@@ -32,17 +33,15 @@ export default class Renderer {
32
33
const myChart = this . initChart ( )
33
34
const { width, height, ...option } = this . options
34
35
const source = option . source
35
- // @ts -ignore
36
- const pages = getAPI ( app ) . pages ( `" ${ source } "` )
37
- //console.log( source, pages )
36
+ const dv = getAPI ( app ) ;
37
+ if ( typeof dv == 'undefined' ) { return new Notice ( 'Dataview is not installed. This plugin requires Dataview to work properly.' , 3000 ) ; }
38
+ const pages = dv . pages ( `" ${ source } "` )
38
39
const data = pages . map ( ( page ) => {
39
- //console.log(page.file.size)
40
40
return {
41
41
name : page . file . name ,
42
42
value : page . file . size
43
43
}
44
44
} )
45
- console . log ( data )
46
45
const chartOption = {
47
46
backgroundColor : '#2c343c' ,
48
47
title : {
@@ -108,36 +107,27 @@ export default class Renderer {
108
107
myChart . on ( 'click' , function ( params ) {
109
108
let prefix : string = ''
110
109
let searchWord : string = ''
111
- function search ( searchWord : string ) {
112
- const tmpLink = window . document . body . createEl ( 'a' , {
113
- href : `obsidian://search?query=${ searchWord } ` ,
114
- } )
115
- tmpLink . click ( )
116
- tmpLink . remove ( )
117
- }
118
110
if ( params . data [ 'search' ] ) {
119
111
let search = params . data [ 'search' ]
120
- if ( search === 'tag' ) prefix = 'tag%3A '
121
- if ( search === 'content' ) prefix = 'content%3A '
122
- if ( search === 'path' ) prefix = 'path%3A '
123
- if ( search === 'file' ) prefix = 'file%3A '
112
+ if ( search === 'tag' ) prefix = 'tag: '
113
+ if ( search === 'content' ) prefix = 'content: '
114
+ if ( search === 'path' ) prefix = 'path: '
115
+ if ( search === 'file' ) prefix = 'file: '
124
116
searchWord = prefix + params . name
125
117
}
126
118
if ( params . data [ 'path' ] ) {
127
- searchWord = searchWord + ' ' + 'path%3A ' + params . data [ 'path' ]
119
+ searchWord = searchWord + ' ' + 'path: ' + params . data [ 'path' ]
128
120
}
129
121
if ( params . data [ 'file' ] ) {
130
- searchWord = searchWord + ' ' + 'file%3A ' + params . data [ 'file' ]
122
+ searchWord = searchWord + ' ' + 'file: ' + params . data [ 'file' ]
131
123
}
132
124
if ( searchWord ) {
133
- search ( searchWord )
125
+ app . internalPlugins . getPluginById ( 'global- search' ) ?. instance . openGlobalSearch ( searchWord ) ;
134
126
} else {
135
- //@ts -ignore
136
127
const filePath = app . metadataCache . getFirstLinkpathDest (
137
128
params . name ,
138
- params . name
129
+ ""
139
130
)
140
- //@ts -ignore
141
131
app . workspace . getUnpinnedLeaf ( ) . openFile ( filePath )
142
132
}
143
133
} )
0 commit comments