@@ -124,16 +124,6 @@ let busy = false
124
124
*/
125
125
let selectedAlgorithm
126
126
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
-
137
127
/**
138
128
* @returns {!Promise }
139
129
*/
@@ -221,10 +211,10 @@ function configureUserInteraction(graphComponent) {
221
211
222
212
// when an edge is created, run the algorithm again except for the k-means and hierarchical
223
213
// because these two are independent of the edges of the graph
224
- mode . createEdgeInputMode . addEdgeCreatedListener ( ( source , args ) => {
214
+ mode . createEdgeInputMode . addEdgeCreatedListener ( ( _ , args ) => {
225
215
if (
226
216
selectedAlgorithm === ClusteringAlgorithm . EDGE_BETWEENNESS &&
227
- getElementById ( ' directed' ) . checked
217
+ document . querySelector ( `# directed` ) . checked
228
218
) {
229
219
graphComponent . graph . setStyle ( args . item , directedEdgeStyle )
230
220
}
@@ -257,7 +247,7 @@ function configureUserInteraction(graphComponent) {
257
247
// add the hover listener
258
248
mode . itemHoverInputMode . hoverItems = GraphItemTypes . NODE
259
249
mode . itemHoverInputMode . discardInvalidItems = false
260
- mode . itemHoverInputMode . addHoveredItemChangedListener ( ( sender , event ) => {
250
+ mode . itemHoverInputMode . addHoveredItemChangedListener ( ( _ , event ) => {
261
251
// if a node is hovered and the algorithm is HIERARCHICAL clustering, hover the corresponding dendrogram node
262
252
if ( selectedAlgorithm === ClusteringAlgorithm . HIERARCHICAL ) {
263
253
const node = event . item
@@ -285,7 +275,7 @@ function configureUserInteraction(graphComponent) {
285
275
* @param {!DendrogramComponent } dendrogramComponent
286
276
*/
287
277
function 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
289
279
dendrogramComponent . addDragFinishedListener ( cutOffValue => {
290
280
removeClusterVisuals ( )
291
281
runHierarchicalClustering ( cutOffValue )
@@ -341,26 +331,26 @@ function runEdgeBetweennessClustering() {
341
331
const graph = graphComponent . graph
342
332
343
333
// 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 )
346
336
347
337
if ( minClusterCount > maxClusterCount ) {
348
338
alert (
349
339
'Desired minimum number of clusters cannot be larger than the desired maximum number of clusters.'
350
340
)
351
- getElementById ( ' ebMinClusterNumber' ) . value = maxClusterCount . toString ( )
341
+ document . querySelector ( `# ebMinClusterNumber` ) . value = maxClusterCount . toString ( )
352
342
minClusterCount = maxClusterCount
353
343
} else if ( minClusterCount > graph . nodes . size ) {
354
344
alert (
355
345
'Desired minimum number of clusters cannot be larger than the number of nodes in the graph.'
356
346
)
357
- getElementById ( ' ebMinClusterNumber' ) . value = graph . nodes . size . toString ( )
347
+ document . querySelector ( `# ebMinClusterNumber` ) . value = graph . nodes . size . toString ( )
358
348
minClusterCount = graph . nodes . size
359
349
}
360
350
361
351
// run the algorithm
362
352
result = new EdgeBetweennessClustering ( {
363
- directed : getElementById ( ' directed' ) . checked ,
353
+ directed : document . querySelector ( `# directed` ) . checked ,
364
354
minimumClusterCount : minClusterCount ,
365
355
maximumClusterCount : maxClusterCount ,
366
356
weights : getEdgeWeight
@@ -378,7 +368,7 @@ function runKMeansClustering() {
378
368
379
369
// get the algorithm preferences from the right panel
380
370
let distanceMetric
381
- switch ( getElementById ( ' distance-metrics' ) . selectedIndex ) {
371
+ switch ( document . querySelector ( `# distance-metrics` ) . selectedIndex ) {
382
372
default :
383
373
case 0 :
384
374
distanceMetric = DistanceMetric . EUCLIDEAN
@@ -394,8 +384,8 @@ function runKMeansClustering() {
394
384
// run the clustering algorithm
395
385
result = new KMeansClustering ( {
396
386
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 )
399
389
} ) . run ( graphComponent . graph )
400
390
401
391
// visualize the result
@@ -413,7 +403,7 @@ function runHierarchicalClustering(cutoff) {
413
403
const graph = graphComponent . graph
414
404
// get the algorithm preferences from the right panel
415
405
let linkage
416
- switch ( getElementById ( ' linkage' ) . selectedIndex ) {
406
+ switch ( document . querySelector ( `# linkage` ) . selectedIndex ) {
417
407
default :
418
408
case 0 :
419
409
linkage = LinkageMethod . SINGLE
@@ -556,7 +546,7 @@ function visualizeClusteringResult() {
556
546
* Called when the clustering algorithm changes
557
547
*/
558
548
function onAlgorithmChanged ( ) {
559
- const algorithmsComboBox = getElementById ( ' algorithms' )
549
+ const algorithmsComboBox = document . querySelector ( `# algorithms` )
560
550
selectedAlgorithm = algorithmsComboBox . selectedIndex
561
551
562
552
// determine the file name that will be used for loading the graph
@@ -586,12 +576,12 @@ function loadGraph(sampleData) {
586
576
587
577
const isEdgeBetweenness = selectedAlgorithm === ClusteringAlgorithm . EDGE_BETWEENNESS
588
578
const styleFactory =
589
- isEdgeBetweenness && getElementById ( ' directed' ) . checked
579
+ isEdgeBetweenness && document . querySelector ( `# directed` ) . checked
590
580
? ( ) => directedEdgeStyle
591
581
: ( ) => undefined // tell GraphBuilder to use default styles
592
582
593
583
const labelsFactory =
594
- isEdgeBetweenness && getElementById ( ' edgeCosts' ) . checked
584
+ isEdgeBetweenness && document . querySelector ( `# edgeCosts` ) . checked
595
585
? ( ) => Math . floor ( Math . random ( ) * 200 + 1 ) . toString ( )
596
586
: ( ) => undefined // tell GraphBuilder not to create any labels
597
587
@@ -628,14 +618,14 @@ function loadGraph(sampleData) {
628
618
function initializeUI ( ) {
629
619
const graph = graphComponent . graph
630
620
631
- const samplesComboBox = getElementById ( ' algorithms' )
621
+ const samplesComboBox = document . querySelector ( `# algorithms` )
632
622
addNavigationButtons ( samplesComboBox ) . addEventListener ( 'change' , onAlgorithmChanged )
633
623
634
624
// edge-betweenness menu
635
- const minInput = getElementById ( ' ebMinClusterNumber' )
636
- minInput . addEventListener ( 'change' , input => {
625
+ const minInput = document . querySelector ( `# ebMinClusterNumber` )
626
+ minInput . addEventListener ( 'change' , _ => {
637
627
const value = parseFloat ( minInput . value )
638
- const maximumClusterNumber = parseFloat ( getElementById ( ' ebMaxClusterNumber' ) . value )
628
+ const maximumClusterNumber = parseFloat ( document . querySelector ( `# ebMaxClusterNumber` ) . value )
639
629
if ( isNaN ( value ) || value < 1 ) {
640
630
alert ( 'Number of clusters should be non-negative.' )
641
631
minInput . value = '1'
@@ -656,10 +646,10 @@ function initializeUI() {
656
646
runAlgorithm ( )
657
647
} )
658
648
659
- const maxInput = getElementById ( ' ebMaxClusterNumber' )
660
- maxInput . addEventListener ( 'change' , input => {
649
+ const maxInput = document . querySelector ( `# ebMaxClusterNumber` )
650
+ maxInput . addEventListener ( 'change' , _ => {
661
651
const value = parseFloat ( maxInput . value )
662
- const minimumClusterNumber = parseFloat ( getElementById ( ' ebMinClusterNumber' ) . value )
652
+ const minimumClusterNumber = parseFloat ( document . querySelector ( `# ebMinClusterNumber` ) . value )
663
653
if ( isNaN ( value ) || value < minimumClusterNumber || minimumClusterNumber < 1 ) {
664
654
const message =
665
655
value < minimumClusterNumber
@@ -672,7 +662,7 @@ function initializeUI() {
672
662
runAlgorithm ( )
673
663
} )
674
664
675
- const considerEdgeDirection = getElementById ( ' directed' )
665
+ const considerEdgeDirection = document . querySelector ( `# directed` )
676
666
considerEdgeDirection . addEventListener ( 'click' , ( ) => {
677
667
const isChecked = considerEdgeDirection . checked
678
668
graph . edges . forEach ( edge => {
@@ -682,7 +672,7 @@ function initializeUI() {
682
672
runAlgorithm ( )
683
673
} )
684
674
685
- const considerEdgeCosts = getElementById ( ' edgeCosts' )
675
+ const considerEdgeCosts = document . querySelector ( `# edgeCosts` )
686
676
considerEdgeCosts . addEventListener ( 'click' , ( ) => {
687
677
graph . edges . forEach ( edge => {
688
678
if ( considerEdgeCosts . checked ) {
@@ -702,20 +692,20 @@ function initializeUI() {
702
692
} )
703
693
704
694
// k-Means
705
- const distanceCombobox = getElementById ( ' distance-metrics' )
695
+ const distanceCombobox = document . querySelector ( `# distance-metrics` )
706
696
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 )
710
700
if ( isNaN ( value ) || value < 1 ) {
711
701
alert ( 'Desired maximum number of clusters should be greater than zero.' )
712
- kmeansInput . value = '1'
702
+ kMeansInput . value = '1'
713
703
return
714
704
}
715
705
runAlgorithm ( )
716
706
} )
717
- const iterationInput = getElementById ( ' iterations' )
718
- iterationInput . addEventListener ( 'change' , input => {
707
+ const iterationInput = document . querySelector ( `# iterations` )
708
+ iterationInput . addEventListener ( 'change' , _ => {
719
709
const value = parseFloat ( iterationInput . value )
720
710
if ( isNaN ( value ) || value < 0 ) {
721
711
alert ( 'Desired maximum number of iterations should be non-negative.' )
@@ -750,13 +740,13 @@ function removeClusterVisuals() {
750
740
* @returns {number } The edge weight
751
741
*/
752
742
function getEdgeWeight ( edge ) {
753
- if ( ! getElementById ( ' edgeCosts' ) . checked ) {
743
+ if ( ! document . querySelector ( `# edgeCosts` ) . checked ) {
754
744
return 1
755
745
}
756
746
757
747
// if edge has at least one label...
758
748
if ( edge . labels . size > 0 ) {
759
- // ..try to return it's value
749
+ // ... try to return its value
760
750
const edgeWeight = parseFloat ( edge . labels . first ( ) . text )
761
751
if ( ! isNaN ( edgeWeight ) ) {
762
752
return edgeWeight > 0 ? edgeWeight : 1
@@ -770,7 +760,7 @@ function getEdgeWeight(edge) {
770
760
* @param {boolean } disabled
771
761
*/
772
762
function setUIDisabled ( disabled ) {
773
- const samplesComboBox = getElementById ( ' algorithms' )
763
+ const samplesComboBox = document . querySelector ( `# algorithms` )
774
764
samplesComboBox . disabled = disabled
775
765
graphComponent . inputMode . waiting = disabled
776
766
busy = disabled
@@ -782,13 +772,13 @@ function setUIDisabled(disabled) {
782
772
*/
783
773
function updateInformationPanel ( panelId ) {
784
774
// 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'
792
782
}
793
783
794
784
/**
0 commit comments