1+ <!DOCTYPE html>
2+ < html lang ="en-US ">
3+
14< head >
25 < link rel ="stylesheet " href ="styles.css ">
36 < script src ="https://unpkg.com/3d-force-graph "> </ script >
47</ head >
58
69< body >
7- < div id ="idea-web "> </ div >
8- < button id ="btn-add " onclick ="onAddItemClick() "> Add Idea</ button >
10+ < div id ="idea-graph "> </ div >
11+
12+ < button id ="button-add " onclick ="onAddItemClick() "> Add Idea</ button >
13+
914 < div id ="modal-idea-new ">
10- < button class ="exit- button " onclick ="onModalCloseClick(this) "> X</ button >
15+ < button class ="button-modal-close " onclick ="onModalCloseClick(this) "> X</ button >
1116 < form id ="form-idea-new " onsubmit ="onModalSubmitClick(event, this) ">
1217 Idea Name:< br >
1318 < input type ="text " name ="idea-name ">
2631 </ div >
2732
2833 < div id ="modal-idea-detail ">
29- < button class ="exit- button " onclick ="onModalCloseClick(this) "> X</ button >
34+ < button class ="button-modal-close " onclick ="onModalCloseClick(this) "> X</ button >
3035 < b > < span id ="detail-name "> </ span > </ b > < br >
3136 < span id ="detail-creator "> </ span > < br > < br >
3237 < span id ="detail-description "> </ span > < br > < br >
3338 Topics: < span id ="detail-tags "> </ span >
3439 </ div >
40+ </ body >
3541
36- < script >
37- displayGraph ( ) ;
38-
39- async function displayGraph ( ) {
40- const web = document . getElementById ( 'idea-web' ) ;
41- let newData
42- try {
43- newData = await getData ( )
44- const Graph = ForceGraph3D ( )
45- ( web )
46- . graphData ( newData )
47- . nodeLabel ( 'name' )
48- . onNodeHover ( node => web . style . cursor = node ? 'pointer' : null )
49- . onNodeClick ( node => {
50- // Aim at node from outside it
51- const distance = 40 ;
52- const distRatio = 1 + distance / Math . hypot ( node . x , node . y , node . z ) ;
53-
54- Graph . cameraPosition (
55- { x : node . x * distRatio , y : node . y * distRatio , z : node . z * distRatio } , // new position
56- node , // lookAt ({ x, y, z })
57- 3000 // ms transition duration
58- ) ;
59- detailDisplay ( node ) ;
60- } ) ;
61- }
62- catch ( error ) {
63- console . log ( error )
64- }
65- }
66-
67- function getData ( ) {
68- return fetch ( 'https://syar2tbuna.execute-api.us-east-1.amazonaws.com/dev/data' )
69- . then ( response => {
70- if ( response . ok ) {
71- return response . json ( )
72- } throw new Error ( response . statusText )
73- } )
74- . catch ( error => { throw new Error ( error . message ) } ) ;
75- }
76-
77- function onAddItemClick ( ) {
78- const modal = document . getElementById ( "modal-idea-new" ) ;
79- modal . style . display = "block" ;
80- }
81-
82- function onModalSubmitClick ( event , form ) {
83- event . preventDefault ( ) ;
84- const modal = document . getElementById ( "modal-idea-new" ) ;
85- const ideaName = form [ "idea-name" ] ;
86- const ideaTags = form [ "tags" ] ;
87- const ideaDescription = form [ "description" ] ;
88- const creatorName = form [ "creator-name" ] ;
89-
90- const { nodes, links } = Graph . graphData ( ) ;
91- const id = nodes . length ;
92-
93- const newIdea = {
94- id : id ,
95- name : ideaName . value ,
96- tags : new Set ( ideaTags . value . split ( "," ) . map ( tag => tag . trim ( ) . toLowerCase ( ) ) ) ,
97- creator : creatorName . value ,
98- description : ideaDescription . value ,
99- } ;
100-
101- modal . style . display = "none" ;
102- form . reset ( ) ;
103-
104- var newLinks = [ ] ;
105-
106- for ( idea of nodes ) {
107- var intersection = new Set ( [ ...idea . tags ] . filter ( x => newIdea . tags . has ( x ) ) ) ;
108- if ( intersection . size != 0 ) {
109- newLinks = [ ...newLinks , { source : newIdea . id , target : idea . id } ]
110- }
111- }
112-
113- Graph . graphData ( {
114- nodes : [ ...nodes , { ...newIdea } ] ,
115- links : [ ...links , ...newLinks ]
116- } ) ;
117- }
118-
119- function detailDisplay ( node ) {
120- const modal = document . getElementById ( "modal-idea-detail" ) ;
121- const detailName = document . getElementById ( "detail-name" ) ;
122- const detailTags = document . getElementById ( "detail-tags" ) ;
123- const detailCreator = document . getElementById ( "detail-creator" ) ;
124- const detailDescription = document . getElementById ( "detail-description" ) ;
125-
126- detailName . textContent = node . name ;
127- detailTags . textContent = [ ...node . tags ] . join ( ', ' ) ;
128- detailCreator . textContent = node . creator ;
129- detailDescription . textContent = node . description ;
130-
131- modal . style . top = event . pageY ;
132- modal . style . left = event . pageX ;
133- modal . style . display = 'block' ;
134- }
135-
136- function onModalCloseClick ( modal ) {
137- modal . parentElement . style . display = 'none' ;
138- }
139-
140- window . onclick = function ( event ) {
141- if ( event . target == document . getElementById ( "modal-idea-detail" ) ) {
142- document . getElementById ( "modal-idea-detail" ) . style . display = "none" ;
143- }
144- }
42+ < script src ="api.js "> </ script >
43+ < script src ="graph.js "> </ script >
14544
146- </ script >
147- </ body >
45+ </ html >
0 commit comments