-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·732 lines (665 loc) · 35.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title>MAHADISCOM</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="ui/css/bootstrap.css">
<!-- end Google Font -->
<link href='http://fonts.googleapis.com/css?family=Raleway:400,500,600,700,800,300' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Oswald:400,500,600,700,800,300' rel='stylesheet' type='text/css'>
<!-- owl carousel SLIDER -->
<link rel="stylesheet" href="ui/css/owl.carousel.css">
<!-- end awesome icons -->
<link rel="stylesheet" href="ui/css/font-awesome.css">
<!-- lightbox -->
<link href="ui/css/prettyPhoto.css" rel="stylesheet">
<!-- Animation Effect CSS -->
<link rel="stylesheet" href="ui/css/animation.css">
<!-- Main Stylesheet CSS -->
<link rel="stylesheet" href="ui/style.css">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
<!-- SLIDER REVOLUTION 4.x CSS SETTINGS -->
<link rel="stylesheet" type="text/css" href="ui/rs-plugin/css/settings.css" media="screen" />
<script type="text/javascript" src="js/jquery-2.1.4.js"></script>
<style>
.node {
stroke: #fff;
stroke-width: 1.5px;
}
.link {
fill: none;
stroke: #bbb;
}
.deleteBtn{
margin: auto;
display: block;
}
.td {
text-align: center;
vertical-align:middle;
margin: auto;
display: block;
}
.btn .btn-primary{
margin: auto;
display: block;
}
</style>
</head>
<body data-spy="scroll" data-offset="25">
<div class="animationload"><div class="loader">Loading...</div></div> <!-- End Preloader -->
<header class="header">
<div class="container">
<div class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="index.html" class="navbar-brand">MAHADISCOM<br> </a>
</div><!-- end navbar-header -->
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a data-scroll href="#features" class="int-collapse-menu">Home</a></li>
<li><a data-scroll href="#graph-location" class="int-collapse-menu">Cities</a></li>
<li><a data-scroll href="#about" class="int-collapse-menu" data-toggle="modal" data-target="#DeleteEdgeModal">Report an Incident</a></li>
<li><a data-scroll href="#" class="int-collapse-menu" data-toggle="modal" data-target="#CreateGridModal">Create New Grid</a></li>
<li><a data-scroll href="#contact" class="int-collapse-menu" >Contact Us</a></li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</div>
</div><!-- end container -->
</header><!-- end header -->
<div id="DeleteEdgeModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">× </button>
<h4 class="modal-title" id="myModalLabel">Choose a road to delete</h4>
</div>
<div class="modal-body">
<table class="table table-striped" style="width:100%" id="delete-edge-table">
<th>
<td>Source</td>
<td>Destination</td>
<td>Distance</td>
<td></td>
</th>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<div id="CreateGridModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">× </button>
<h4 class="modal-title" id="myModalLabel">Add a new power grid</h4>
</div>
<div class="modal-body">
<h4>Format: Source, Destination, Distance (Do not separate edges with new line)</h4>
<textarea rows="10" cols="50" class="form-control" id="add-new-grid"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="add-grid-button" data-dismiss="modal">Save changes</button>
</div>
</div>
</div>
</div>
<div id="ContactModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">× </button>
<h4 class="modal-title" id="myModalLabel">Contact Us</h4>
</div>
<div class="modal-body">
<p>email: [email protected]</p>
<p>phone: +91 94949 49494</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="CostModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">× </button>
<h4 class="modal-title" id="myModalLabel">Cost for laying cables</h4>
</div>
<div class="modal-body">
<p id="cable-cost"></p>
<p id="transfomer-number"></p>
<p id="transformer-cost"></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="EdgeListModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">× </button>
<h4 class="modal-title" id="myModalLabel">List of Roads</h4>
</div>
<div class="modal-body">
<table class="table table-striped" style="width:100%" id="edge-table-list">
<th>
<td>Source</td>
<td>Destination</td>
<td>Distance</td>
</th>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="AddEdgeModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">× </button>
<h4 class="modal-title" id="myModalLabel">Add a connecting road</h4>
</div>
<div class="modal-body">
<div class="input-group">
<h4>Source</h4>
<select id="add-source-dropdown" class="btn"></select>
</div>
<br>
<div class="input-group">
<h4>Destination</h4>
<select id="add-destination-dropdown" class="btn"></select>
</div>
<br>
<div class="input-group col-lg-12 col-md-12 col-sm-12 col-xs-12">
<input type="text" class="form-control" placeholder="Distance" aria-describedby="sizing-addon2" id="add-edge-weight">
</div>
<br>
<div class="alert alert-danger alert-dismissible collapse" role="alert" id="add-edge-error">
<button type="button" class="close" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong>ERROR</strong>
<p id="add-edge-error-field"></p>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="add-edge-button">Save changes</button>
</div>
</div>
</div>
</div>
<div id="AddVillageModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">× </button>
<h4 class="modal-title" id="myModalLabel">Add a connecting road</h4>
</div>
<div class="modal-body">
<div class="input-group col-lg-12 col-md-12 col-sm-12 col-xs-12">
<input type="text" class="form-control" placeholder="Village Name" aria-describedby="sizing-addon2" id="add-village">
</div>
<br>
<div class="alert alert-danger alert-dismissible collapse" role="alert" id="village-IP-error">
<p id="add-village-error-field">Error: Check village input - name cannot be blank</p>
<button type="button" class="close" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="add-village-button">Save changes</button>
</div>
</div>
</div>
</div>
<section id="features" class="feature-wrapper">
<br><br><br>
<div class="container">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="widget">
<h3> What the Grid shows</h3>
<p>A layout depicting the villages and their connectivity by road. Add or remove edges according to your requirements, to find the best route for the cable laying.</p>
<div id="accordion-second" class="clearfix">
<div class="accordion" id="accordion2">
<div id="acc-group-one" class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseZero">
<em class="fa fa-plus icon-fixed-width"></em>Add Village
</a>
</div>
<div id="collapseZero" class="accordion-body collapse">
<div class="accordion-inner">
Add a village to the graph<br>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#AddVillageModal">Add</button>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
<em class="fa fa-plus icon-fixed-width"></em>Add Edge
</a>
</div>
<div id="collapseOne" class="accordion-body collapse">
<div class="accordion-inner">
Add an edge to the graph in the format (edge format)<br>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#AddEdgeModal">Add</button>
</div>
</div>
</div>
</div>
<div id="acc-group-two" class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
<em class="fa fa-plus icon-fixed-width"></em>Delete Edge
</a>
</div>
<div id="collapseTwo" class="accordion-body collapse">
<div class="accordion-inner">
To check how the connectivity will have to be changed if a route fails, delete the edge from the graph to reroute the connectivity<br>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#DeleteEdgeModal">Delete</button>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseThree">
<em class="fa fa-plus icon-fixed-width"></em>Show Edge List
</a>
</div>
<div id="collapseThree" class="accordion-body collapse">
<div class="accordion-inner">
View the current edge list<br>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#EdgeListModal">List edges</button>
</div>
</div>
</div>
</div>
<div id="acc-group-three" class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseSix">
<em class="fa fa-plus icon-fixed-width"></em>Draw Graph
</a>
</div>
<div id="collapseSix" class="accordion-body collapse">
<div class="accordion-inner">
View the complete layout of the villages and all the roads<br>
<button type="button" class="btn btn-primary" id="draw-graph-button">Draw Graph</button><br>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseSeven">
<em class="fa fa-plus icon-fixed-width"></em>Find Optimal Path
</a>
</div>
<div id="collapseSeven" class="accordion-body collapse">
<div class="accordion-inner">
Find the minimum cost fault tolerant layout<br>
<button type="button" class="btn btn-primary" id="draw-mst-button">Generate</button>
</div>
</div>
</div>
</div>
<div id="acc-group-four" class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseFour">
<em class="fa fa-plus icon-fixed-width"></em>Find Other Optimal Path
</a>
</div>
<div id="collapseFour" class="accordion-body collapse">
<div class="accordion-inner">
View an alternative plot which can be implemented to provide a fault tolerant layout for the electricity cables<br>
<button type="button" class="btn btn-primary" id="draw-alt-button">Generate alternative</button>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading" id = "graph-location">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseFive">
<em class="fa fa-plus icon-fixed-width"></em>Calculate Costs
</a>
</div>
<div id="collapseFive" class="accordion-body collapse">
<div class="accordion-inner">
Find the cost for the cable laying and strategic placement of transformers<br>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#CostModal">Calculate</button>
</div>
</div>
</div>
</div>
</div><!-- end accordion -->
</div><!-- end accordion first -->
</div><!-- end widget -->
</div><!-- end col-lg-6 -->
<!-- General error message div -->
<div class="alert alert-danger alert-dismissible collapse col-lg-12 col-md-12 col-sm-12 col-xs-12" role="alert" id="general-error">
<button type="button" class="close" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong>ERROR</strong>
<p id="general-error-message"></p>
</div>
<!-- END General error message div -->
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="widget">
<h3>Current Layout</h3>
<div id="graph-canvas" style="width:100%; height:500px">
</div><!-- end graph-canvas -->
</div><!-- end widget -->
</div><!-- end col-lg-6 -->
</div><!-- end container -->
</section><!-- end grey-wrapper -->
<section id="contact" class="feature-wrapper">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 text-center">
<h2 class="section-heading" style="color: #b20000;">Contact Us</h2>
<hr>
<ul style = "list-style-type: none; color: #b20000;">
<li>We look forward to addressing your concerns or receiving your feedback.</li>
</ul>
</div>
<div class="col-lg-4 col-lg-offset-2 text-center" style="color: #b20000;">
<i class="fa fa-phone fa-3x wow bounceIn" style="color: #b20000;"></i>
<p>123-456-6789</p>
</div>
<div class="col-lg-4 text-center" style="color: #b20000;">
<i class="fa fa-envelope-o fa-3x wow bounceIn" data-wow-delay=".1s" style="color: #b20000"></i>
<p><a href="mailto:[email protected]">[email protected]</a></p>
</div>
</div>
</div>
</section>
<script src="ui/js/bootstrap.js"></script>
<script src="ui/js/smooth-scroll.js"></script>
<script src="ui/js/jquery.parallax-1.1.3.js"></script>
<script src="ui/js/jquery.easypiechart.min.js"></script>
<script src="ui/js/owl.carousel.js"></script>
<script src="ui/js/jquery.jigowatt.js"></script>
<script src="ui/js/custom.js"></script>
<script src="ui/js/jquery.unveilEffects.js"></script>
<script src="ui/js/jquery.isotope.min.js"></script>
<script src="js/d3.js"></script>
<script type="text/javascript" src="js/prims.js"></script>
<script src="js/force-directed-graph.js"></script>
<script>
(function ($) {
var $container = $('.masonry_wrapper'),
colWidth = function () {
var w = $container.width(),
columnNum = 1,
columnWidth = 0;
if (w > 1200) {
columnNum = 3;
} else if (w > 900) {
columnNum = 3;
} else if (w > 600) {
columnNum = 2;
} else if (w > 300) {
columnNum = 1;
}
columnWidth = Math.floor(w/columnNum);
$container.find('.item').each(function() {
var $item = $(this),
multiplier_w = $item.attr('class').match(/item-w(\d)/),
multiplier_h = $item.attr('class').match(/item-h(\d)/),
width = multiplier_w ? columnWidth*multiplier_w[1]-4 : columnWidth-4,
height = multiplier_h ? columnWidth*multiplier_h[1]*0.5-4 : columnWidth*0.5-4;
$item.css({
width: width,
height: height
});
});
return columnWidth;
}
function refreshWaypoints() {
setTimeout(function() {
}, 1000);
}
$('nav.portfolio-filter ul li a').on('click', function() {
var selector = $(this).attr('data-filter');
$container.isotope({ filter: selector }, refreshWaypoints());
$('nav.portfolio-filter ul li a').removeClass('active');
$(this).addClass('active');
return false;
});
function setPortfolio() {
setColumns();
$container.isotope('reLayout');
}
isotope = function () {
$container.isotope({
resizable: true,
itemSelector: '.item',
masonry: {
columnWidth: colWidth(),
gutterWidth: 0
}
});
};
isotope();
$(window).smartresize(isotope);
}(jQuery));
</script>
<script type="text/javascript">
$(document).ready(function() {
var costOfCables = 0, costOfTransformers = 0;
var g = new Graph();
init(g);
var altg = new Graph();
var output = Prim(g);
var resultTree = output.edges,
resultMst = output.mst;
if (g.nodes.length > 10) {
$('#graph-canvas').css("height", ((g.nodes.length - 10) * 10) + 500);
}
populateAndDrawGraph(g);
populateLists();
calculateCosts();
$('#add-village-button').click(function() {
if ($('#add-village').val() == '') {
$('#village-IP-error').show();
} else {
g.addNode($('#add-village').val());
modifierHandler();
populateAndDrawGraph(g);
$('#AddVillageModal').modal('hide');
}
});
$('#add-edge-button').click(function() {
var source = $('#add-source-dropdown').val();
var dest = $('#add-destination-dropdown').val();
var capacity = $('#add-edge-weight').val();
if(source == dest) {
$('#add-edge-error-field').empty();
$('#add-edge-error-field').append('Error: Check source and destination input - cannot be the same');
$('#add-edge-error').show();
}
else if (capacity == '') {
$('#add-edge-error-field').empty();
$('#add-edge-error-field').append('Error: Check distance input - cannot be zero');
$('#add-edge-error').show();
} else {
g.addEdge(source, dest, parseInt(capacity));
modifierHandler();
populateAndDrawGraph(g);
$('#AddEdgeModal').modal('hide');
}
});
$('.close').click(function() {
$('.alert').hide();
$('#add-edge-error-field').empty();
});
$('#draw-graph-button').click(function() {
populateAndDrawGraph(g);
});
$('#draw-mst-button').click(function() {
if (isInputValid(g)) {
populateAndDrawGraph(resultMst);
} else {
$('#general-error').show();
$('#general-error-message').html('The given graph has more than one component.\nNo MST can be drawn.');
}
});
$('#draw-alt-button').click(function() {
altg = new Graph();
altg = jQuery.extend(true, {}, g);
for (var i = 0; i < resultTree.length; i++) {
altg.deleteEdge(resultTree[i][0], resultTree[i][1], resultTree[i][2]);
}
var newoutput = Prim(altg);
if (isInputValid(altg)) {
populateAndDrawGraph(newoutput.mst);
} else {
$('#general-error').show();
$('#general-error-message').html('The alternative graph has more than one component.\nNo MST can be drawn.');
}
});
$('#add-grid-button').click(function() {
g = new Graph();
var data = $('#add-new-grid').val();
var result = data.split(",");
if ((result.length % 3) == 0) {
for (var i = 0; i < result.length; i += 3) {
result[i] = result[i].replace(/^\s+|\s+$/g, ''), result[i + 1] = result[i + 1].replace(/^\s+|\s+$/g, ''), result[i + 2] = result[i + 2].replace(/^\s+|\s+$/g, '');
if (Object.prototype.toString.call(result[i]) == '[object String]') {
if (Object.prototype.toString.call(result[i + 1]) == '[object String]') {
if (!isNaN(parseInt(result[i + 2]))) {
if (g.nodes.indexOf(result[i]) < 0) g.addNode(result[i]);
if (g.nodes.indexOf(result[i + 1]) < 0) g.addNode(result[i + 1]);
g.addEdge(result[i], result[i + 1], result[i + 2]);
} else {
alert(result[i + 2] + " is not a number!");
}
} else {
alert(result[i + 1] + " is not a string/character!");
}
} else {
alert(result[i] + " is not a string/character!");
}
}
} else {
alert("Grid input incorrect!");
}
clearAll();
if (isInputValid(g)) {
modifierHandler();
populateAndDrawGraph(g);
} else {
alert("Graph entered has more than one component!\nPlease re-enter the graph!");
g = new Graph();
init(g);
modifierHandler();
populateAndDrawGraph(g);
}
});
$('#delete-edge-table').on('click', '.deleteBtn', function() {
var result = $(this).val().split(",");
g.deleteEdge(result[0], result[1], result[2]);
modifierHandler();
populateAndDrawGraph(g);
});
function clearAll() {
$('#village-IP-error-field').empty();
$('#add-edge-error-field').empty();
$('#add-source-dropdown').empty();
$('#add-destination-dropdown').empty();
$('#delete-edge-table').empty();
$('#delete-edge-table').append('<th><td>Source</td><td>Destination</td><td>Distance</td><td></td></th>');
$('#edge-table-list').empty();
$('#edge-table-list').append('<th><td>Source</td><td>Destination</td><td>Distance</td></th>');
$('#cable-cost').empty();
$('#transfomer-number').empty();
$('#transformer-cost').empty();
$('#add-village').val('');
$('#add-new-grid').val('');
$('#add-source-dropdown').val('');
$('#add-destination-dropdown').val('');
$('#add-edge-weight').val('');
$('#delete-source-dropdown').val('');
$('#delete-destination-dropdown').val('');
$('#delete-edge-weight').val('');
$('#general-error-message').empty();
}
function modifierHandler() {
clearAll();
var tempOutput = Prim(g);
resultTree = tempOutput.edges, resultMst = tempOutput.mst;
populateLists();
calculateCosts();
if (g.nodes.length > 10) {
$('#graph-canvas').css("height", ((g.nodes.length - 10) * 10) + 500);
}
}
function populateLists() {
for (var i = 0; i < g.nodes.length; i++) {
$('#add-source-dropdown').append('<option value="' + g.nodes[i] + '">' + g.nodes[i] + '</option>');
$('#add-destination-dropdown').append('<option value="' + g.nodes[i] + '">' + g.nodes[i] + '</option>');
}
var k = 0;
for (var i = 0; i < g.nodes.length; i++) {
for (var j = 0; j < g.edges[g.nodes[i]].length; j++, k++) {
$('#edge-table-list').append('<tr><td>' + (k + 1) + '</td><td>' + g.edges[g.nodes[i]][j].source + '</td><td>' + g.edges[g.nodes[i]][j].sink + '</td><td>' + g.edges[g.nodes[i]][j].capacity + '</td></tr>');
$('#delete-edge-table').append('<tr><td>' + (k + 1) + '</td><td>' + g.edges[g.nodes[i]][j].source + '</td><td>' + g.edges[g.nodes[i]][j].sink + '</td><td>' + g.edges[g.nodes[i]][j].capacity + '</td><td><button class="deleteBtn btn" value="' + g.edges[g.nodes[i]][j].source + ',' + g.edges[g.nodes[i]][j].sink + ',' + g.edges[g.nodes[i]][j].capacity + '">Delete</button></td></tr>');
}
}
}
function calculateCosts() {
costOfCables = 0, costOfTransformers = 0;
for (var i = 0; i < resultTree.length; i++) {
costOfCables += resultTree[i][2];
costOfTransformers += Math.floor(resultTree[i][2] / 100);
}
costOfTransformers += output.nodesInPath.length;
costOfTransformers *= 1000;
costOfCables *= 1000;
$('#cable-cost').html('Distance: ' + costOfCables / 1000 + ' kilometres, and cost of cables is: Rs.' + costOfCables);
$('#transfomer-number').html('Number of transformers: ' + costOfTransformers / 1000);
$('#transformer-cost').html('Cost of transformers: Rs.' + costOfTransformers);
}
var graphDetailsErrorChecker = function(graph) {
graphDetails.links.forEach(function(link, index, list) {
if (typeof graphDetails.nodes[link.source] === 'undefined') {
console.log('undefined source', link);
}
if (typeof graphDetails.nodes[link.target] === 'undefined') {
console.log('undefined target', link);
}
});
}
});
</script>
</body>
</html>