@@ -124,16 +124,6 @@ let busy = false
124124 */
125125let selectedAlgorithm
126126
127- /**
128- * Returns a reference to the first element with the specified ID in the current document.
129- * @returns {!T } A reference to the first element with the specified ID in the current document.
130- * @template {HTMLElement} T
131- * @param {!string } id
132- */
133- function getElementById ( id ) {
134- return document . getElementById ( id )
135- }
136-
137127/**
138128 * @returns {!Promise }
139129 */
@@ -221,10 +211,10 @@ function configureUserInteraction(graphComponent) {
221211
222212 // when an edge is created, run the algorithm again except for the k-means and hierarchical
223213 // because these two are independent of the edges of the graph
224- mode . createEdgeInputMode . addEdgeCreatedListener ( ( source , args ) => {
214+ mode . createEdgeInputMode . addEdgeCreatedListener ( ( _ , args ) => {
225215 if (
226216 selectedAlgorithm === ClusteringAlgorithm . EDGE_BETWEENNESS &&
227- getElementById ( ' directed' ) . checked
217+ document . querySelector ( `# directed` ) . checked
228218 ) {
229219 graphComponent . graph . setStyle ( args . item , directedEdgeStyle )
230220 }
@@ -257,7 +247,7 @@ function configureUserInteraction(graphComponent) {
257247 // add the hover listener
258248 mode . itemHoverInputMode . hoverItems = GraphItemTypes . NODE
259249 mode . itemHoverInputMode . discardInvalidItems = false
260- mode . itemHoverInputMode . addHoveredItemChangedListener ( ( sender , event ) => {
250+ mode . itemHoverInputMode . addHoveredItemChangedListener ( ( _ , event ) => {
261251 // if a node is hovered and the algorithm is HIERARCHICAL clustering, hover the corresponding dendrogram node
262252 if ( selectedAlgorithm === ClusteringAlgorithm . HIERARCHICAL ) {
263253 const node = event . item
@@ -285,7 +275,7 @@ function configureUserInteraction(graphComponent) {
285275 * @param {!DendrogramComponent } dendrogramComponent
286276 */
287277function configureDendrogramComponent ( dendrogramComponent ) {
288- // add a dragging listener to run the hierarchical algorithm's when the dragging of the cutoff line has finished
278+ // add a dragging listener to run the hierarchical algorithm when the dragging of the cutoff line has finished
289279 dendrogramComponent . addDragFinishedListener ( cutOffValue => {
290280 removeClusterVisuals ( )
291281 runHierarchicalClustering ( cutOffValue )
@@ -341,26 +331,26 @@ function runEdgeBetweennessClustering() {
341331 const graph = graphComponent . graph
342332
343333 // get the algorithm preferences from the right panel
344- let minClusterCount = parseFloat ( getElementById ( ' ebMinClusterNumber' ) . value )
345- const maxClusterCount = parseFloat ( getElementById ( ' ebMaxClusterNumber' ) . value )
334+ let minClusterCount = parseFloat ( document . querySelector ( `# ebMinClusterNumber` ) . value )
335+ const maxClusterCount = parseFloat ( document . querySelector ( `# ebMaxClusterNumber` ) . value )
346336
347337 if ( minClusterCount > maxClusterCount ) {
348338 alert (
349339 'Desired minimum number of clusters cannot be larger than the desired maximum number of clusters.'
350340 )
351- getElementById ( ' ebMinClusterNumber' ) . value = maxClusterCount . toString ( )
341+ document . querySelector ( `# ebMinClusterNumber` ) . value = maxClusterCount . toString ( )
352342 minClusterCount = maxClusterCount
353343 } else if ( minClusterCount > graph . nodes . size ) {
354344 alert (
355345 'Desired minimum number of clusters cannot be larger than the number of nodes in the graph.'
356346 )
357- getElementById ( ' ebMinClusterNumber' ) . value = graph . nodes . size . toString ( )
347+ document . querySelector ( `# ebMinClusterNumber` ) . value = graph . nodes . size . toString ( )
358348 minClusterCount = graph . nodes . size
359349 }
360350
361351 // run the algorithm
362352 result = new EdgeBetweennessClustering ( {
363- directed : getElementById ( ' directed' ) . checked ,
353+ directed : document . querySelector ( `# directed` ) . checked ,
364354 minimumClusterCount : minClusterCount ,
365355 maximumClusterCount : maxClusterCount ,
366356 weights : getEdgeWeight
@@ -378,7 +368,7 @@ function runKMeansClustering() {
378368
379369 // get the algorithm preferences from the right panel
380370 let distanceMetric
381- switch ( getElementById ( ' distance-metrics' ) . selectedIndex ) {
371+ switch ( document . querySelector ( `# distance-metrics` ) . selectedIndex ) {
382372 default :
383373 case 0 :
384374 distanceMetric = DistanceMetric . EUCLIDEAN
@@ -394,8 +384,8 @@ function runKMeansClustering() {
394384 // run the clustering algorithm
395385 result = new KMeansClustering ( {
396386 metric : distanceMetric ,
397- maximumIterations : parseFloat ( getElementById ( ' iterations' ) . value ) ,
398- k : parseFloat ( getElementById ( ' kMeansMaxClusterNumber' ) . value )
387+ maximumIterations : parseFloat ( document . querySelector ( `# iterations` ) . value ) ,
388+ k : parseFloat ( document . querySelector ( `# kMeansMaxClusterNumber` ) . value )
399389 } ) . run ( graphComponent . graph )
400390
401391 // visualize the result
@@ -413,7 +403,7 @@ function runHierarchicalClustering(cutoff) {
413403 const graph = graphComponent . graph
414404 // get the algorithm preferences from the right panel
415405 let linkage
416- switch ( getElementById ( ' linkage' ) . selectedIndex ) {
406+ switch ( document . querySelector ( `# linkage` ) . selectedIndex ) {
417407 default :
418408 case 0 :
419409 linkage = LinkageMethod . SINGLE
@@ -556,7 +546,7 @@ function visualizeClusteringResult() {
556546 * Called when the clustering algorithm changes
557547 */
558548function onAlgorithmChanged ( ) {
559- const algorithmsComboBox = getElementById ( ' algorithms' )
549+ const algorithmsComboBox = document . querySelector ( `# algorithms` )
560550 selectedAlgorithm = algorithmsComboBox . selectedIndex
561551
562552 // determine the file name that will be used for loading the graph
@@ -586,12 +576,12 @@ function loadGraph(sampleData) {
586576
587577 const isEdgeBetweenness = selectedAlgorithm === ClusteringAlgorithm . EDGE_BETWEENNESS
588578 const styleFactory =
589- isEdgeBetweenness && getElementById ( ' directed' ) . checked
579+ isEdgeBetweenness && document . querySelector ( `# directed` ) . checked
590580 ? ( ) => directedEdgeStyle
591581 : ( ) => undefined // tell GraphBuilder to use default styles
592582
593583 const labelsFactory =
594- isEdgeBetweenness && getElementById ( ' edgeCosts' ) . checked
584+ isEdgeBetweenness && document . querySelector ( `# edgeCosts` ) . checked
595585 ? ( ) => Math . floor ( Math . random ( ) * 200 + 1 ) . toString ( )
596586 : ( ) => undefined // tell GraphBuilder not to create any labels
597587
@@ -628,14 +618,14 @@ function loadGraph(sampleData) {
628618function initializeUI ( ) {
629619 const graph = graphComponent . graph
630620
631- const samplesComboBox = getElementById ( ' algorithms' )
621+ const samplesComboBox = document . querySelector ( `# algorithms` )
632622 addNavigationButtons ( samplesComboBox ) . addEventListener ( 'change' , onAlgorithmChanged )
633623
634624 // edge-betweenness menu
635- const minInput = getElementById ( ' ebMinClusterNumber' )
636- minInput . addEventListener ( 'change' , input => {
625+ const minInput = document . querySelector ( `# ebMinClusterNumber` )
626+ minInput . addEventListener ( 'change' , _ => {
637627 const value = parseFloat ( minInput . value )
638- const maximumClusterNumber = parseFloat ( getElementById ( ' ebMaxClusterNumber' ) . value )
628+ const maximumClusterNumber = parseFloat ( document . querySelector ( `# ebMaxClusterNumber` ) . value )
639629 if ( isNaN ( value ) || value < 1 ) {
640630 alert ( 'Number of clusters should be non-negative.' )
641631 minInput . value = '1'
@@ -656,10 +646,10 @@ function initializeUI() {
656646 runAlgorithm ( )
657647 } )
658648
659- const maxInput = getElementById ( ' ebMaxClusterNumber' )
660- maxInput . addEventListener ( 'change' , input => {
649+ const maxInput = document . querySelector ( `# ebMaxClusterNumber` )
650+ maxInput . addEventListener ( 'change' , _ => {
661651 const value = parseFloat ( maxInput . value )
662- const minimumClusterNumber = parseFloat ( getElementById ( ' ebMinClusterNumber' ) . value )
652+ const minimumClusterNumber = parseFloat ( document . querySelector ( `# ebMinClusterNumber` ) . value )
663653 if ( isNaN ( value ) || value < minimumClusterNumber || minimumClusterNumber < 1 ) {
664654 const message =
665655 value < minimumClusterNumber
@@ -672,7 +662,7 @@ function initializeUI() {
672662 runAlgorithm ( )
673663 } )
674664
675- const considerEdgeDirection = getElementById ( ' directed' )
665+ const considerEdgeDirection = document . querySelector ( `# directed` )
676666 considerEdgeDirection . addEventListener ( 'click' , ( ) => {
677667 const isChecked = considerEdgeDirection . checked
678668 graph . edges . forEach ( edge => {
@@ -682,7 +672,7 @@ function initializeUI() {
682672 runAlgorithm ( )
683673 } )
684674
685- const considerEdgeCosts = getElementById ( ' edgeCosts' )
675+ const considerEdgeCosts = document . querySelector ( `# edgeCosts` )
686676 considerEdgeCosts . addEventListener ( 'click' , ( ) => {
687677 graph . edges . forEach ( edge => {
688678 if ( considerEdgeCosts . checked ) {
@@ -702,20 +692,20 @@ function initializeUI() {
702692 } )
703693
704694 // k-Means
705- const distanceCombobox = getElementById ( ' distance-metrics' )
695+ const distanceCombobox = document . querySelector ( `# distance-metrics` )
706696 distanceCombobox . addEventListener ( 'change' , runAlgorithm )
707- const kmeansInput = getElementById ( ' kMeansMaxClusterNumber' )
708- kmeansInput . addEventListener ( 'change' , input => {
709- const value = parseFloat ( kmeansInput . value )
697+ const kMeansInput = document . querySelector ( `# kMeansMaxClusterNumber` )
698+ kMeansInput . addEventListener ( 'change' , _ => {
699+ const value = parseFloat ( kMeansInput . value )
710700 if ( isNaN ( value ) || value < 1 ) {
711701 alert ( 'Desired maximum number of clusters should be greater than zero.' )
712- kmeansInput . value = '1'
702+ kMeansInput . value = '1'
713703 return
714704 }
715705 runAlgorithm ( )
716706 } )
717- const iterationInput = getElementById ( ' iterations' )
718- iterationInput . addEventListener ( 'change' , input => {
707+ const iterationInput = document . querySelector ( `# iterations` )
708+ iterationInput . addEventListener ( 'change' , _ => {
719709 const value = parseFloat ( iterationInput . value )
720710 if ( isNaN ( value ) || value < 0 ) {
721711 alert ( 'Desired maximum number of iterations should be non-negative.' )
@@ -750,13 +740,13 @@ function removeClusterVisuals() {
750740 * @returns {number } The edge weight
751741 */
752742function getEdgeWeight ( edge ) {
753- if ( ! getElementById ( ' edgeCosts' ) . checked ) {
743+ if ( ! document . querySelector ( `# edgeCosts` ) . checked ) {
754744 return 1
755745 }
756746
757747 // if edge has at least one label...
758748 if ( edge . labels . size > 0 ) {
759- // ..try to return it's value
749+ // ... try to return its value
760750 const edgeWeight = parseFloat ( edge . labels . first ( ) . text )
761751 if ( ! isNaN ( edgeWeight ) ) {
762752 return edgeWeight > 0 ? edgeWeight : 1
@@ -770,7 +760,7 @@ function getEdgeWeight(edge) {
770760 * @param {boolean } disabled
771761 */
772762function setUIDisabled ( disabled ) {
773- const samplesComboBox = getElementById ( ' algorithms' )
763+ const samplesComboBox = document . querySelector ( `# algorithms` )
774764 samplesComboBox . disabled = disabled
775765 graphComponent . inputMode . waiting = disabled
776766 busy = disabled
@@ -782,13 +772,13 @@ function setUIDisabled(disabled) {
782772 */
783773function updateInformationPanel ( panelId ) {
784774 // set display none to all and then change only the desired one
785- getElementById ( ' edge-betweenness' ) . style . display = 'none'
786- getElementById ( ' k-means' ) . style . display = 'none'
787- getElementById ( ' hierarchical' ) . style . display = 'none'
788- getElementById ( ' biconnected-components' ) . style . display = 'none'
789- getElementById ( ' louvain-modularity' ) . style . display = 'none'
790- getElementById ( ' label-propagation' ) . style . display = 'none'
791- getElementById ( panelId ) . style . display = 'inline-block'
775+ document . querySelector ( `# edge-betweenness` ) . style . display = 'none'
776+ document . querySelector ( `# k-means` ) . style . display = 'none'
777+ document . querySelector ( `# hierarchical` ) . style . display = 'none'
778+ document . querySelector ( `# biconnected-components` ) . style . display = 'none'
779+ document . querySelector ( `# louvain-modularity` ) . style . display = 'none'
780+ document . querySelector ( `# label-propagation` ) . style . display = 'none'
781+ document . querySelector ( `# ${ panelId } ` ) . style . display = 'inline-block'
792782}
793783
794784/**
0 commit comments