1
+ /*import { createElement, ClassAttributes } from 'react';
2
+ import * as ReactDOM from 'react-dom';
3
+
4
+ import { Workspace, WorkspaceProps, DemoDataProvider } from '../index';
5
+ */
6
+ var data = require ( "./relatedGraph.json" )
7
+
8
+ var sigma = require ( "linkurious" )
9
+ require ( "imports-loader?sigma=linkurious,this=>window!linkurious/dist/plugins" )
10
+
11
+
12
+ var _ = require ( "lodash" )
13
+
14
+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
15
+ const container = document . createElement ( 'div' ) ;
16
+ container . id = 'root' ;
17
+ document . body . appendChild ( container ) ;
18
+
19
+ /*fetch("related/patient").then(function(response) {
20
+ console.log(response.json);
21
+ });*/
22
+
23
+ var g = {
24
+ nodes : [ ] ,
25
+ edges : [ ]
26
+ } ;
27
+ var stopNodes = [ 0 ] ; //[0, 871, 213, 1059]
28
+ _ . each ( data . graph . nodes , node => {
29
+ if ( ! _ . includes ( stopNodes , node . id ) ) {
30
+ g . nodes . push ( {
31
+ id : node . id ,
32
+ label : node . label + ' ' + node . id ,
33
+ x : Math . random ( ) ,
34
+ y : Math . random ( ) ,
35
+ size : node . entities . frequency / 1000 ,
36
+ color : '#aaa'
37
+ } )
38
+ }
39
+ } ) ;
40
+
41
+ var colors = { related : '#ff0000' , similar : '#0000FF' } ;
42
+
43
+ _ . each ( data . graph . edges , edge => {
44
+ if ( ! ( _ . includes ( stopNodes , edge . origin ) || _ . includes ( stopNodes , edge . destination ) ) ) {
45
+ g . edges . push ( {
46
+ id : 'e' + edge . origin + 'to' + edge . destination ,
47
+ source : edge . origin ,
48
+ target : edge . destination ,
49
+ /*size: Math.random(),*/
50
+ color : colors [ edge . type ]
51
+ } ) ;
52
+ }
53
+ } ) ;
54
+
55
+ // Instantiate sigma:
56
+ var s = new sigma ( {
57
+ graph : g ,
58
+ container : 'root'
59
+ } ) ;
60
+
61
+ var fa = s . startForceAtlas2 ( { worker : true , scalingRatio : 100 , gravity : 1 , barnesHutOptimize : true , adjustSizes : false , strongGravityMode : true } ) ;
62
+ window . setTimeout ( function ( ) { s . stopForceAtlas2 ( ) }
63
+ , 2000 ) ;
64
+
65
+ /*var props = {
66
+ ref: function(browser) {
67
+ // if you reuse this code you should check for workspace to be null on unmount
68
+ if (browser) {
69
+ const model = workspace.getModel();
70
+ model.graph.on('action:iriClick', (iri: string) => {
71
+ console.log(iri);
72
+ });
73
+ model.importLayout({
74
+ dataProvider: new DemoDataProvider(),
75
+ preloadedElements: {},
76
+ preloadedLinks: [],
77
+ layoutData: undefined,
78
+ });
79
+ }
80
+ },
81
+ };
82
+
83
+ ReactDOM.render(createElement(Workspace, props), container);
84
+ */
85
+ } ) ;
0 commit comments