1- var width = 800 , height = 500 ;
2- var svg = d3 . select ( "body" ) . append ( 'svg' ) . attr ( {
1+ let width = 800 , height = 500 ;
2+ let svg = d3 . select ( "body" ) . append ( 'svg' ) . attr ( {
33 width : width ,
44 height : height ,
55 id : "mainsvg"
66} ) ;
7- // var fileList = ["WikiNews","Huffington","CrooksAndLiars","EmptyWheel","Esquire","FactCheck"
7+ // let fileList = ["WikiNews","Huffington","CrooksAndLiars","EmptyWheel","Esquire","FactCheck"
88// ,"VIS_papers","IMDB","PopCha","Cards_PC","Cards_Fries"]
99
10- var fileList = [ "WikiNews" , "Huffington" , "CrooksAndLiars" , "EmptyWheel" , "Esquire" , "FactCheck" , "VIS_papers" , "IMDB" , "PopCha" , "Cards_PC" , "Cards_Fries" ]
10+ let fileList = [ "WikiNews" , "Huffington" , "CrooksAndLiars" , "EmptyWheel" , "Esquire" , "FactCheck" , "VIS_papers" , "IMDB" , "PopCha" , "Cards_PC" , "Cards_Fries" ]
1111
12- var initialDataset = "EmptyWheel" ;
13- var categories = [ "person" , "location" , "organization" , "miscellaneous" ] ;
12+ let initialDataset = "EmptyWheel" ;
13+ let categories = [ "person" , "location" , "organization" , "miscellaneous" ] ;
1414
15- var fileName ;
15+ let fileName ;
1616
1717
1818addDatasetsOptions ( ) ;
1919function addDatasetsOptions ( ) {
20- var select = document . getElementById ( "datasetsSelect" ) ;
21- for ( var i = 0 ; i < fileList . length ; i ++ ) {
22- var opt = fileList [ i ] ;
23- var el = document . createElement ( "option" ) ;
20+ let select = document . getElementById ( "datasetsSelect" ) ;
21+ for ( let i = 0 ; i < fileList . length ; i ++ ) {
22+ let opt = fileList [ i ] ;
23+ let el = document . createElement ( "option" ) ;
2424 el . textContent = opt ;
2525 el . value = opt ;
2626 el [ "data-image" ] = "images2/datasetThumnails/" + fileList [ i ] + ".png" ;
@@ -30,10 +30,10 @@ function addDatasetsOptions() {
3030 fileName = document . getElementById ( "datasetsSelect" ) . value ;
3131 loadData ( ) ;
3232}
33- var spinner ;
33+ let spinner ;
3434function loadData ( ) {
3535 // START: loader spinner settings ****************************
36- var opts = {
36+ let opts = {
3737 lines : 25 , // The number of lines to draw
3838 length : 15 , // The length of each line
3939 width : 5 , // The line thickness
@@ -43,7 +43,7 @@ function loadData(){
4343 trail : 50 , // Afterglow percentage
4444 className : 'spinner' , // The CSS class to assign to the spinner
4545 } ;
46- var target = document . getElementById ( 'loadingSpinner' ) ;
46+ let target = document . getElementById ( 'loadingSpinner' ) ;
4747 spinner = new Spinner ( opts ) . spin ( target ) ;
4848 // END: loader spinner settings ****************************
4949 fileName = "data/" + fileName + ".tsv" ; // Add data folder path
@@ -80,56 +80,56 @@ function loadNewData(event) {
8080
8181function draw ( data ) {
8282 //Layout data
83- var interpolation = "cardinal" ;
84- var axisPadding = 10 ;
85- var margins = { left : 20 , top : 20 , right : 10 , bottom : 30 } ;
86- var ws = d3 . layout . wordStream ( )
83+ let interpolation = "cardinal" ;
84+ let axisPadding = 10 ;
85+ let margins = { left : 20 , top : 20 , right : 10 , bottom : 30 } ;
86+ let ws = d3 . layout . wordStream ( )
8787 . size ( [ width , height ] )
8888 . interpolate ( interpolation )
8989 //.fontScale(d3.scale.pow().exponent(2))
9090 . fontScale ( d3 . scale . linear ( ) )
9191 . minFontSize ( 4 )
9292 . maxFontSize ( 36 )
9393 . data ( data ) ;
94- var boxes = ws . boxes ( ) ;
94+ let boxes = ws . boxes ( ) ;
9595
9696 //Display data
97- var legendFontSize = 12 ;
98- var legendHeight = boxes . topics . length * legendFontSize ;
97+ let legendFontSize = 12 ;
98+ let legendHeight = boxes . topics . length * legendFontSize ;
9999 //set svg data.
100100 svg . attr ( {
101101 width : width + margins . left + margins . top ,
102102 height : height + margins . top + margins . bottom + axisPadding + legendHeight
103103 } ) ;
104104
105- var area = d3 . svg . area ( )
105+ let area = d3 . svg . area ( )
106106 . interpolate ( interpolation )
107107 . x ( function ( d ) { return ( d . x ) ; } )
108108 . y0 ( function ( d ) { return d . y0 ; } )
109109 . y1 ( function ( d ) { return ( d . y0 + d . y ) ; } ) ;
110- var color = d3 . scale . category10 ( ) ;
110+ let color = d3 . scale . category10 ( ) ;
111111 //Display time axes
112- var dates = [ ] ;
112+ let dates = [ ] ;
113113 boxes . data . forEach ( row => {
114114 dates . push ( row . date ) ;
115115 } ) ;
116116
117- var xAxisScale = d3 . scale . ordinal ( ) . domain ( dates ) . rangeBands ( [ 0 , width ] ) ;
118- var xAxis = d3 . svg . axis ( ) . orient ( 'bottom' ) . scale ( xAxisScale ) ;
119- var axisGroup = svg . append ( 'g' ) . attr ( 'transform' , 'translate(' + ( margins . left ) + ',' + ( height + margins . top + axisPadding + legendHeight ) + ')' ) ;
120- var axisNodes = axisGroup . call ( xAxis ) ;
117+ let xAxisScale = d3 . scale . ordinal ( ) . domain ( dates ) . rangeBands ( [ 0 , width ] ) ;
118+ let xAxis = d3 . svg . axis ( ) . orient ( 'bottom' ) . scale ( xAxisScale ) ;
119+ let axisGroup = svg . append ( 'g' ) . attr ( 'transform' , 'translate(' + ( margins . left ) + ',' + ( height + margins . top + axisPadding + legendHeight ) + ')' ) ;
120+ let axisNodes = axisGroup . call ( xAxis ) ;
121121 styleAxis ( axisNodes ) ;
122122 //Display the vertical gridline
123- var xGridlineScale = d3 . scale . ordinal ( ) . domain ( d3 . range ( 0 , dates . length + 1 ) ) . rangeBands ( [ 0 , width + width / boxes . data . length ] ) ;
124- var xGridlinesAxis = d3 . svg . axis ( ) . orient ( 'bottom' ) . scale ( xGridlineScale ) ;
125- var xGridlinesGroup = svg . append ( 'g' ) . attr ( 'transform' , 'translate(' + ( margins . left - width / boxes . data . length / 2 ) + ',' + ( height + margins . top + axisPadding + legendHeight + margins . bottom ) + ')' ) ;
126- var gridlineNodes = xGridlinesGroup . call ( xGridlinesAxis . tickSize ( - height - axisPadding - legendHeight - margins . bottom , 0 , 0 ) . tickFormat ( '' ) ) ;
123+ let xGridlineScale = d3 . scale . ordinal ( ) . domain ( d3 . range ( 0 , dates . length + 1 ) ) . rangeBands ( [ 0 , width + width / boxes . data . length ] ) ;
124+ let xGridlinesAxis = d3 . svg . axis ( ) . orient ( 'bottom' ) . scale ( xGridlineScale ) ;
125+ let xGridlinesGroup = svg . append ( 'g' ) . attr ( 'transform' , 'translate(' + ( margins . left - width / boxes . data . length / 2 ) + ',' + ( height + margins . top + axisPadding + legendHeight + margins . bottom ) + ')' ) ;
126+ let gridlineNodes = xGridlinesGroup . call ( xGridlinesAxis . tickSize ( - height - axisPadding - legendHeight - margins . bottom , 0 , 0 ) . tickFormat ( '' ) ) ;
127127 styleGridlineNodes ( gridlineNodes ) ;
128128 //Main group
129- var mainGroup = svg . append ( 'g' ) . attr ( 'transform' , 'translate(' + margins . left + ',' + margins . top + ')' ) ;
130- var wordStreamG = mainGroup . append ( 'g' ) ;
129+ let mainGroup = svg . append ( 'g' ) . attr ( 'transform' , 'translate(' + margins . left + ',' + margins . top + ')' ) ;
130+ let wordStreamG = mainGroup . append ( 'g' ) ;
131131
132- var topics = boxes . topics ;
132+ let topics = boxes . topics ;
133133 mainGroup . selectAll ( 'path' )
134134 . data ( boxes . layers )
135135 . enter ( )
@@ -144,25 +144,25 @@ function draw(data){
144144 'stroke-width' : 0.3 ,
145145 topic : function ( d , i ) { return topics [ i ] ; }
146146 } ) ;
147- var allWords = [ ] ;
147+ let allWords = [ ] ;
148148 d3 . map ( boxes . data , function ( row ) {
149149 boxes . topics . forEach ( topic => {
150150 allWords = allWords . concat ( row . words [ topic ] ) ;
151151 } ) ;
152152 } ) ;
153- var c20 = d3 . scale . category20b ( ) ;
153+ let c20 = d3 . scale . category20b ( ) ;
154154 //Color based on the topic
155- var topicColorMap = d3 . scale . ordinal ( ) . domain ( topics ) . range ( c20 . range ( ) ) ;
155+ let topicColorMap = d3 . scale . ordinal ( ) . domain ( topics ) . range ( c20 . range ( ) ) ;
156156 //Color based on term
157- var terms = [ ] ;
157+ let terms = [ ] ;
158158 for ( i = 0 ; i < allWords . length ; i ++ ) {
159159 terms . concat ( allWords [ i ] . text ) ;
160160 }
161- var uniqueTerms = d3 . set ( terms ) . values ( ) ;
162- var termColorMap = d3 . scale . ordinal ( )
161+ let uniqueTerms = d3 . set ( terms ) . values ( ) ;
162+ let termColorMap = d3 . scale . ordinal ( )
163163 . domain ( uniqueTerms )
164164 . range ( c20 . range ( ) ) ;
165- var placed = true ;
165+ let placed = true ;
166166 mainGroup . selectAll ( 'g' ) . data ( allWords ) . enter ( ) . append ( 'g' )
167167 . attr ( {
168168 transform : function ( d ) { return 'translate(' + d . x + ', ' + d . y + ')rotate(' + d . rotate + ')' ; }
@@ -180,15 +180,15 @@ function draw(data){
180180 visibility : function ( d , i ) { return d . placed ? ( placed ? "visible" : "hidden" ) : ( placed ? "hidden" : "visible" ) ; }
181181 } ) ;
182182 //Try
183- var prevColor ;
183+ let prevColor ;
184184 //Highlight
185185 mainGroup . selectAll ( 'text' ) . on ( 'mouseenter' , function ( ) {
186- var thisText = d3 . select ( this ) ;
186+ let thisText = d3 . select ( this ) ;
187187 thisText . style ( 'cursor' , 'pointer' ) ;
188188 prevColor = thisText . attr ( 'fill' ) ;
189- var text = thisText . text ( ) ;
190- var topic = thisText . attr ( 'topic' ) ;
191- var allTexts = mainGroup . selectAll ( 'text' ) . filter ( t => {
189+ let text = thisText . text ( ) ;
190+ let topic = thisText . attr ( 'topic' ) ;
191+ let allTexts = mainGroup . selectAll ( 'text' ) . filter ( t => {
192192 return t && t . text === text && t . topic === topic ;
193193 } ) ;
194194 allTexts . attr ( {
@@ -197,11 +197,11 @@ function draw(data){
197197 } ) ;
198198 } ) ;
199199 mainGroup . selectAll ( 'text' ) . on ( 'mouseout' , function ( ) {
200- var thisText = d3 . select ( this ) ;
200+ let thisText = d3 . select ( this ) ;
201201 thisText . style ( 'cursor' , 'default' ) ;
202- var text = thisText . text ( ) ;
203- var topic = thisText . attr ( 'topic' ) ;
204- var allTexts = mainGroup . selectAll ( 'text' ) . filter ( t => {
202+ let text = thisText . text ( ) ;
203+ let topic = thisText . attr ( 'topic' ) ;
204+ let allTexts = mainGroup . selectAll ( 'text' ) . filter ( t => {
205205 return t && ! t . cloned && t . text === text && t . topic === topic ;
206206 } ) ;
207207 allTexts . attr ( {
@@ -211,16 +211,16 @@ function draw(data){
211211 } ) ;
212212 //Click
213213 mainGroup . selectAll ( 'text' ) . on ( 'click' , function ( ) {
214- var thisText = d3 . select ( this ) ;
215- var text = thisText . text ( ) ;
216- var topic = thisText . attr ( 'topic' ) ;
217- var allTexts = mainGroup . selectAll ( 'text' ) . filter ( t => {
214+ let thisText = d3 . select ( this ) ;
215+ let text = thisText . text ( ) ;
216+ let topic = thisText . attr ( 'topic' ) ;
217+ let allTexts = mainGroup . selectAll ( 'text' ) . filter ( t => {
218218 return t && t . text === text && t . topic === topic ;
219219 } ) ;
220220 //Select the data for the stream layers
221- var streamLayer = d3 . select ( "path[topic='" + topic + "']" ) [ 0 ] [ 0 ] . __data__ ;
221+ let streamLayer = d3 . select ( "path[topic='" + topic + "']" ) [ 0 ] [ 0 ] . __data__ ;
222222 //Push all points
223- var points = Array ( ) ;
223+ let points = Array ( ) ;
224224 //Initialize all points
225225 streamLayer . forEach ( elm => {
226226 points . push ( {
@@ -230,20 +230,20 @@ function draw(data){
230230 } ) ;
231231 } ) ;
232232 allTexts [ 0 ] . forEach ( t => {
233- var data = t . __data__ ;
234- var fontSize = data . fontSize ;
233+ let data = t . __data__ ;
234+ let fontSize = data . fontSize ;
235235 //The point
236- var thePoint = points [ data . timeStep + 1 ] ; ; //+1 since we added 1 to the first point and 1 to the last point.
236+ let thePoint = points [ data . timeStep + 1 ] ; ; //+1 since we added 1 to the first point and 1 to the last point.
237237 thePoint . y = - data . streamHeight ;
238238 //Set it to visible.
239239 //Clone the nodes.
240- var clonedNode = t . cloneNode ( true ) ;
240+ let clonedNode = t . cloneNode ( true ) ;
241241 d3 . select ( clonedNode ) . attr ( {
242242 visibility : "visible" ,
243243 stroke : 'none' ,
244244 'stroke-size' : 0 ,
245245 } ) ;
246- var clonedParentNode = t . parentNode . cloneNode ( false ) ;
246+ let clonedParentNode = t . parentNode . cloneNode ( false ) ;
247247 clonedParentNode . appendChild ( clonedNode ) ;
248248
249249 t . parentNode . parentNode . appendChild ( clonedParentNode ) ;
@@ -270,7 +270,7 @@ function draw(data){
270270 wordStream : true
271271 } ) ;
272272 //Hide all other texts
273- var allOtherTexts = mainGroup . selectAll ( 'text' ) . filter ( t => {
273+ let allOtherTexts = mainGroup . selectAll ( 'text' ) . filter ( t => {
274274 return t && ! t . cloned && t . topic === topic ;
275275 } ) ;
276276 allOtherTexts . attr ( 'visibility' , 'hidden' ) ;
@@ -295,8 +295,8 @@ function draw(data){
295295 } ) ;
296296
297297 //Build the legends
298- var legendGroup = svg . append ( 'g' ) . attr ( 'transform' , 'translate(' + margins . left + ',' + ( height + margins . top ) + ')' ) ;
299- var legendNodes = legendGroup . selectAll ( 'g' ) . data ( boxes . topics ) . enter ( ) . append ( 'g' )
298+ let legendGroup = svg . append ( 'g' ) . attr ( 'transform' , 'translate(' + margins . left + ',' + ( height + margins . top ) + ')' ) ;
299+ let legendNodes = legendGroup . selectAll ( 'g' ) . data ( boxes . topics ) . enter ( ) . append ( 'g' )
300300 . attr ( 'transform' , function ( d , i ) { return 'translate(' + 10 + ',' + ( i * legendFontSize ) + ')' ; } ) ;
301301 legendNodes . append ( 'circle' ) . attr ( {
302302 r : 5 ,
0 commit comments