Skip to content

Commit

Permalink
2.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
MuiseDestiny committed Mar 26, 2023
1 parent 3e5815e commit 06803ee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
23 changes: 19 additions & 4 deletions src/modules/graphView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default class GraphView {
private renderer: any;
private container!: HTMLDivElement;
private resizer!: HTMLDivElement;
private graph!: Graph;
private urls: any = {
Zotero: "https://www.zotero.org/",
Style: "https://github.com/MuiseDestiny/zotero-style",
Expand Down Expand Up @@ -204,6 +205,7 @@ export default class GraphView {
if (cache && (this.cache[this.mode] ??= {})[collectionKey]) { return this.cache[this.mode][collectionKey]}
const graph = await this.modeFunction[this.mode](items);
(this.cache[this.mode] ??= {})[collectionKey] = graph
this.graph = graph
return graph
}

Expand All @@ -221,7 +223,6 @@ export default class GraphView {
Theme: { links: { Style: true }, type: "tag" },
light: { links: { Theme: true }, type: "function" },
dark: { links: { Theme: true }, type: "function" }

}
}
}
Expand Down Expand Up @@ -283,8 +284,8 @@ export default class GraphView {
}

private getGraphByRelatedLink(items: Zotero.Item[]) {
let nodes: { [key: string]: any } = {}
let graph: { [key: string]: any } = { nodes }
let nodes: Graph["nodes"] = {}
let graph: Graph = { nodes: {} }
items.forEach((item, i) => {
let id = item.id
nodes[id] = { links: {}, type: "item"}
Expand Down Expand Up @@ -323,7 +324,6 @@ export default class GraphView {
console.log(sharedValues)
const countArr = Object.values(sharedValues).map(i => i.items.size).filter(i=>i>1).sort()
const limit = countArr[parseInt((countArr.length * pct).toFixed(0))]
console.log(limit)
// 创建节点对象
Object.keys(sharedValues).forEach((value: string) => {
const items = [...sharedValues[value].items]
Expand Down Expand Up @@ -569,6 +569,12 @@ export default class GraphView {
Zotero.launchURL(this.urls[id]);
} else if (type == "function"){
this.functions[id]()
} else if (type == "tag") {
// 查找tag对应的链接的条目,进行过滤
let ids = Object.keys(this.graph.nodes[id].links).filter(id => {
return this.graph.nodes[id].type == "item"
})
ZoteroPane.selectItems(ids.map(Number))
}
}
/**
Expand Down Expand Up @@ -612,4 +618,13 @@ export default class GraphView {
this.renderer.changed()
this.renderer.onResize()
}
}

interface Graph {
nodes: {
[id: string]: {
links: { [id: string]: boolean },
type: string;
};
};
}
3 changes: 1 addition & 2 deletions src/modules/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -968,8 +968,7 @@ export default class Views {
page = Number(this.storage.get(item, "readingTime").page) ||
(this.cache[key] ??= (await Zotero.Fulltext.getPages(pdfItem.id)).total) ||
page
} catch (e) { console.log(e) }
console.log(page)
} catch (e) { }
let annoRecord: any = { page, data: {} }
const annoArray = pdfItem.getAnnotations()
annoArray.forEach((anno: any) => {
Expand Down

0 comments on commit 06803ee

Please sign in to comment.