var t = `
graph view
display
forces
` import Pane from './pane.js' import Icon from './icon.js' import GraphD3 from './graph-d3.js' export default { components: { Pane, Icon, GraphD3 }, props: ['activeTabId', 'lastSave'], emits: ['note-open'], data() { return { graphData: null, initialTransform: null, query: '', showSettings: false, display: { showTitles: { value: true, title: 'show titles' }, scaleTitles: { value: true, title: 'auto-scale titles' }, dynamicNodeRadius: { value: false, title: 'size nodes per links' }, emphasizeActive: { value: true, title: 'emphasize active note' }, }, forces: { chargeStrength: { value: -30, min: -100, max: 0, step: 1, title: 'repel force' }, collideRadius: { value: 1, min: 1, max: 50, step: 1, title: 'collide radius' }, collideStrength: { value: 0.5, min: 0, max: 1, step: 0.05, title: 'collide strength' }, }, } }, methods: { fetchGraph() { fetch("/api/notes") .then(r => r.ok ? r.json() : r.json().then(e => Promise.reject(e))) .then(response => { let nodes = []; let links = []; const notes = Object.values(response); notes.forEach(note => { nodes.push({ id: note.Filename, title: note.Title, isLabel: note.IsLabel }); if (note.OutgoingLinks) { note.OutgoingLinks.forEach(link => { if (link.Title !== '') links.push({ source: note.Filename, target: link.Filename }); }); } }); this.graphData = { nodes, links }; }) .catch(e => { console.error(e); }); }, }, computed: { emphasizeNodeIds() { if (this.showSettings && this.query) { const queryWords = this.query.toLowerCase().split(' '); return this.graphData.nodes.filter(node => queryWords.every(queryWord => node.title.toLowerCase().includes(queryWord))).map(node => node.id); } return (this.display.emphasizeActive.value && this.activeTabId) ? [this.activeTabId] : null; }, }, created() { this.fetchGraph(); }, watch: { 'lastSave': function() { this.initialTransform = this.$refs.forcegraph.zoomTransform; this.graphData = null; this.fetchGraph(); }, }, template: t }