4444 < ul class ="dropdown-menu " role ="menu ">
4545 < li > < a href ="# " data-toggle ="modal " data-target ="#URLmodal "> URL</ a > </ li >
4646 < li > < a href ="# " data-toggle ="modal " data-target ="#Pastemodal "> Paste</ a > </ li >
47- < li > < a href ="# "> File Upload</ a > </ li >
47+ < li > < a href ="# " data-toggle =" modal " data-target =" #Filemodal " > File Upload</ a > </ li >
4848 </ ul >
4949 </ li >
5050 </ ul >
@@ -65,7 +65,6 @@ <h3 class="panel-title pull-left">Graph</h3>
6565< div class ="panel panel-info ">
6666 < div class ="panel-heading "> Info</ div >
6767 < div class ="panel-body " id ="node-info ">
68- Click on a node in the graph to view details.
6968 </ div >
7069</ div >
7170
@@ -160,6 +159,29 @@ <h4 class="modal-title">JSON Data</h4>
160159 </ div >
161160</ div > <!-- /Paste Modal -->
162161
162+ <!-- File Modal -->
163+ < div class ="modal fade " id ="Filemodal " role ="dialog ">
164+ < div class ="modal-dialog ">
165+ <!-- Modal content-->
166+ < div class ="modal-content ">
167+ < div class ="modal-header ">
168+ < button type ="button " class ="close " data-dismiss ="modal "> ×</ button >
169+ < h4 class ="modal-title "> JSON File</ h4 >
170+ </ div >
171+ < div class ="modal-body ">
172+ < label for ="inputFile " class ="col-lg-2 control-label "> File</ label >
173+ < div class ="col-lg-10 ">
174+ < input type ="file " class ="form-control " id ="inputFile ">
175+ </ div >
176+ </ div >
177+ < div class ="modal-footer ">
178+ < button type ="button " class ="btn btn-primary " data-dismiss ="modal " id ="loadFile "> Load</ button >
179+ < button type ="button " class ="btn btn-default " data-dismiss ="modal "> Close</ button >
180+ </ div >
181+ </ div >
182+ </ div >
183+ </ div > <!-- /File Modal -->
184+
163185</ div > <!-- /container-->
164186< script src ="//code.jquery.com/jquery-1.11.3.min.js "> </ script >
165187< script src ="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js "> </ script >
@@ -201,11 +223,15 @@ <h4 class="modal-title">JSON Data</h4>
201223 d3 . select ( "g" ) . selectAll ( "*" ) . remove ( ) ;
202224 createTables ( ) ;
203225
226+ // reset info
227+ var el = document . getElementById ( "node-info" ) ;
228+ el . innerText = "Click on a node in the graph to view details." ;
229+
204230 // redo layout
205231 simulation = d3 . forceSimulation ( )
206232 . force ( "link" , d3 . forceLink ( ) . id ( function ( d ) { return d . id ; } ) )
207233 . force ( "charge" , d3 . forceManyBody ( ) . strength ( - 100 ) )
208- . force ( "center" , d3 . forceCenter ( width / 2 , height / 2 ) ) ;
234+ . force ( "center" , d3 . forceCenter ( width / 2 , height / 2 ) ) ;
209235}
210236
211237function createGraph ( error , graph ) {
@@ -387,7 +413,7 @@ <h4 class="modal-title">JSON Data</h4>
387413 history . pushState ( '' , 'CertGraph' , "?data=" + url ) ;
388414 resetGraph ( ) ;
389415 d3 . json ( url , createGraph ) ;
390- } ;
416+ }
391417
392418// new data from paste
393419d3 . select ( "#loadPaste" ) . on ( "click" , loadPaste ) ;
@@ -397,8 +423,22 @@ <h4 class="modal-title">JSON Data</h4>
397423 resetGraph ( ) ;
398424 var data = JSON . parse ( dataStr ) ;
399425 createGraph ( null , data ) ;
400- } ;
426+ }
401427
428+ // new data from paste
429+ d3 . select ( "#loadFile" ) . on ( "click" , loadFile ) ;
430+ function loadFile ( ) {
431+ var file = document . getElementById ( "inputFile" ) . files [ 0 ] ;
432+ history . pushState ( '' , 'CertGraph' , "?" ) ;
433+ resetGraph ( ) ;
434+ var reader = new FileReader ( ) ;
435+ reader . onload = function ( e ) {
436+ var dataStr = reader . result ;
437+ var data = JSON . parse ( dataStr ) ;
438+ createGraph ( null , data ) ;
439+ }
440+ reader . readAsText ( file ) ;
441+ }
402442
403443// load initial graph data
404444var dataURL = getQueryVariable ( "data" ) ;
0 commit comments