返回 social-analyzer
visualize.js
根目录 / modules / visualize.js
1 import {QBIxora} from 'ixora'
2 import helper from './helper.js'
3
4 async function visualize_force_graph (req, detected, type) {
5 try {
6 const graph = new QBIxora('Social-Analyzer', false)
7 const temp_filtered = detected.filter(item => item.status === 'good')
8 if (temp_filtered.length > 0) {
9 if (req.body.group) {
10 graph.add_node(req.body.string, req.body.string, {
11 header: req.body.string
12 })
13
14 req.body.string.split(',').forEach(username => {
15 graph.add_node(username, username, {
16 header: username
17 })
18
19 graph.add_edge(username, req.body.string, {
20 width: 1
21 })
22 })
23 } else {
24 graph.add_node(req.body.string, req.body.string, {
25 header: req.body.string
26 })
27 }
28
29 temp_filtered.forEach(site => {
30 graph.add_node(site.link, site.link, {
31 header: site.link
32 })
33
34 graph.add_edge(site.username, site.link, {
35 width: 1
36 })
37
38 if ('metadata' in site) {
39 if (site.metadata !== 'unavailable' && site.metadata.length > 0) {
40 site.metadata.forEach(meta => {
41 if ('content' in meta) {
42 let temp_string = ''
43 if ('name' in meta) {
44 temp_string = meta.name + ' -> ' + meta.content
45 } else if ('itemprop' in meta) {
46 temp_string = meta.itemprop + ' -> ' + meta.content
47 } else if ('property' in meta) {
48 temp_string = meta.property + ' -> ' + meta.content
49 }
50
51 if (temp_string.length > 70) {
52 temp_string = temp_string.substring(0, 70).replace(/\r?\n|\r/g, '') + '..'
53 } else {
54 temp_string = temp_string.replace(/\r?\n|\r/g, '')
55 }
56
57 if (temp_string !== '' && temp_string.length > 0) {
58 graph.add_node(temp_string, temp_string, {
59 header: temp_string
60 })
61
62 graph.add_edge(site.link, temp_string, {
63 width: 1
64 })
65 }
66 }
67 })
68 }
69 }
70 })
71 }
72
73 const ret_graph = graph.create_graph('#ixora-graph', 'Ixora random nodes exmaple', 'Search Box', 'Search in extracted patterns', 'https://github.com/qeeqbox/ixora', 'Qeeqbox-ixora', ['search', 'tooltip'], 10, 100, graph.graph, 'object', undefined, undefined)
74 return ret_graph
75 } catch (err) {
76 helper.verbose && console.log(err)
77 }
78
79 return {
80 graph: {
81 nodes: [],
82 links: []
83 }
84 }
85 }
86 export default{
87 visualize_force_graph
88 }
89
89 lines JAVASCRIPT