Advertisement
Guest User

Untitled

a guest
May 4th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.45 KB | None | 0 0
  1. //---------------------nadeesha-----------------------
  2.  
  3. //var data = [{name : "192.168.1.1", value :10000},{name : "192.168.1.2", value : 15000}];
  4.  
  5.  
  6.  
  7. //for (i = 0; i < 6; i++) {
  8.  
  9.  
  10.  
  11. //var address = 8080 + (Math.random()*10)%5;
  12.  
  13. //var count2 = 5000 + Math.random() * 25000;
  14.  
  15. //data.push({name : address, value : count2});
  16.  
  17. //drowChart();
  18.  
  19. //drowpie();
  20.  
  21.  
  22.  
  23. // i++;
  24.  
  25.  
  26.  
  27. //if (count2 > 25000) {
  28.  
  29.  
  30.  
  31.  
  32.  
  33. //drowAlertChart('www.google.com','admin account','30000 data','5 accounts');
  34.  
  35.  
  36.  
  37. //}
  38.  
  39.  
  40.  
  41.  
  42.  
  43. //}
  44.  
  45.  
  46.  
  47. //window.setInterval("refreshDiv()", 1000);
  48.  
  49. // function refreshDiv(){
  50.  
  51. //counter = counter + 1;
  52.  
  53. //document.getElementById("chart").innerHTML;
  54.  
  55. //window.location.reload();
  56.  
  57. // }
  58.  
  59. //----------------------------nadeesha end--------------------------------
  60.  
  61.  
  62.  
  63.  
  64.  
  65. var data = [];
  66.  
  67.  
  68.  
  69. function drowChart(){
  70.  
  71.  
  72.  
  73. // var data = [{name : a, value :10},{name : b, value : 5}];
  74.  
  75. // var data = [{name : "192.168.1.1", value :0},{name : "192.168.1.2", value : 0}];
  76.  
  77.  
  78.  
  79.  
  80.  
  81. var index=0;
  82.  
  83.  
  84.  
  85. while(true)
  86.  
  87. {
  88.  
  89. console.log("debug");
  90.  
  91. if(sessionStorage.key(index)!=null)
  92.  
  93. {
  94.  
  95. console.log(sessionStorage.key(index)+ sessionStorage.getItem(sessionStorage.key(index)).split(',').length+"session data");
  96.  
  97. data.push({name : sessionStorage.key(index), value : sessionStorage.getItem(sessionStorage.key(index)).split(',').length});
  98.  
  99.  
  100.  
  101. index++;
  102.  
  103.  
  104.  
  105. }
  106.  
  107. else
  108.  
  109. {
  110.  
  111. break;
  112.  
  113. }
  114.  
  115.  
  116.  
  117. }
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. var margin = {top: 20, right: 30, bottom: 30, left: 40},
  128.  
  129. width = 960 - margin.left - margin.right,
  130.  
  131. height = 500 - margin.top - margin.bottom;
  132.  
  133.  
  134.  
  135. var x = d3.scale.ordinal()
  136.  
  137. .rangeRoundBands([0, width], .1);
  138.  
  139.  
  140.  
  141. var y = d3.scale.linear()
  142.  
  143. .range([height, 0]);
  144.  
  145.  
  146.  
  147. var xAxis = d3.svg.axis()
  148.  
  149. .scale(x)
  150.  
  151. .orient("bottom");
  152.  
  153.  
  154.  
  155. var yAxis = d3.svg.axis()
  156.  
  157. .scale(y)
  158.  
  159. .orient("left");
  160.  
  161.  
  162.  
  163.  
  164.  
  165. //when new data comes remove existing svg bar chart
  166.  
  167. var chart = d3.select("svg").remove();
  168.  
  169.  
  170.  
  171. //var chart = d3.select(".chart")
  172.  
  173. var chart = d3.select("#chart").append('svg')
  174.  
  175. .attr("width", width + margin.left + margin.right)
  176.  
  177. .attr("height", height + margin.top + margin.bottom)
  178.  
  179. .append("g")
  180.  
  181. .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
  182.  
  183.  
  184.  
  185.  
  186.  
  187. x.domain(data.map(function(d) { return d.name; }));
  188.  
  189. y.domain([0, d3.max(data, function(d) { return d.value; })]);
  190.  
  191.  
  192.  
  193. chart.append("g")
  194.  
  195. .attr("class", "x axis")
  196.  
  197. .attr("transform", "translate(0," + height + ")")
  198.  
  199. .call(xAxis);
  200.  
  201.  
  202.  
  203. chart.append("g")
  204.  
  205. .attr("class", "y axis")
  206.  
  207. .call(yAxis);
  208.  
  209.  
  210.  
  211. chart.selectAll(".bar")
  212.  
  213. .data(data)
  214.  
  215. .enter().append("rect")
  216.  
  217. .attr("class", "bar")
  218.  
  219. .attr("x", function(d) { return x(d.name); })
  220.  
  221. .attr("y", function(d) { return y(d.value); })
  222.  
  223. .attr("height", function(d) { return height - y(d.value); })
  224.  
  225. .attr("width", x.rangeBand())
  226.  
  227. .on('mouseover', function(d){
  228.  
  229.  
  230.  
  231. d3.selectAll('p').remove();
  232.  
  233.  
  234.  
  235. d3.select(this)
  236.  
  237. .style('opacity',.5);
  238.  
  239.  
  240.  
  241. document.getElementById('info').style.backgroundColor = "lightblue";
  242.  
  243. document.getElementById('info').style.border="3px solid gray";
  244.  
  245. document.getElementById('info').style.borderRadius="5px";
  246.  
  247. document.getElementById('info').style.paddingLeft="20px";
  248.  
  249. document.getElementById('info').style.paddingBottom="5px";
  250.  
  251. document.getElementById('info').style.paddingTop="5px";
  252.  
  253. document.getElementById('info').style.zIndex="10";
  254.  
  255. document.getElementById('info').style.position="absolute";
  256.  
  257. document.getElementById('info').style.marginTop="20%";
  258.  
  259. document.getElementById('info').style.marginLeft="50px";
  260.  
  261.  
  262.  
  263. var split=sessionStorage.getItem(d.name).split(',');
  264.  
  265.  
  266.  
  267. for(var x=0;x<sessionStorage.getItem(d.name).split(',').length;x++)
  268.  
  269. {
  270.  
  271. d3.select("#info")
  272.  
  273. .append('p')
  274.  
  275. .text(split[x]);
  276.  
  277.  
  278.  
  279. }
  280.  
  281. //nadeesha
  282.  
  283.  
  284.  
  285. d3.select("#info")
  286.  
  287. .append('p')
  288.  
  289. .text("number of counts : "+count2);
  290.  
  291.  
  292.  
  293. d3.select(this)
  294.  
  295. .style("background-color","lightblue")
  296.  
  297. .append("div")
  298.  
  299. .style("position", "absolute")
  300.  
  301. .style("z-index", "10")
  302.  
  303. .style("visibility", "hidden")
  304.  
  305. .text("a simple tooltip");
  306.  
  307.  
  308.  
  309.  
  310.  
  311. //
  312.  
  313. })
  314.  
  315.  
  316.  
  317.  
  318.  
  319. .on('mouseout', function(d){
  320.  
  321.  
  322.  
  323. d3.select(this)
  324.  
  325. .style('opacity',1);
  326.  
  327.  
  328.  
  329. //d3.selectAll('p').remove();
  330.  
  331.  
  332.  
  333. //d3.select("#alert")
  334.  
  335.  
  336.  
  337.  
  338.  
  339. });
  340.  
  341.  
  342.  
  343. //.on('click', function(d,i){
  344.  
  345.  
  346.  
  347.  
  348.  
  349. //d3.select(this)
  350.  
  351. // .style('opacity',1);
  352.  
  353. //});
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361. };
  362.  
  363.  
  364.  
  365.  
  366.  
  367. var alert=0;
  368.  
  369.  
  370.  
  371. function drowAlertChart(webSiteUrl,accessdata,accesscount,avgaccessdata,avgaccesscount){
  372.  
  373.  
  374.  
  375. //nadeesha
  376.  
  377. document.getElementById('chart').style.opacity="0.3";
  378.  
  379. document.getElementById('info').style.opacity="0";
  380.  
  381.  
  382.  
  383. alert++;
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391. //
  392.  
  393.  
  394.  
  395. var margin = {top: 20, right: 40, bottom: 30, left: 70},
  396.  
  397. width = 1500 - margin.left - margin.right,
  398.  
  399. height = 500 - margin.top - margin.bottom;
  400.  
  401.  
  402.  
  403. var x = d3.scale.ordinal()
  404.  
  405. .rangeRoundBands([0, width], .1);
  406.  
  407.  
  408.  
  409. var y = d3.scale.linear()
  410.  
  411. .range([height, 0]);
  412.  
  413.  
  414.  
  415. var xAxis = d3.svg.axis()
  416.  
  417. .scale(x)
  418.  
  419. .orient("bottom");
  420.  
  421.  
  422.  
  423. var yAxis = d3.svg.axis()
  424.  
  425. .scale(y)
  426.  
  427. .orient("center");
  428.  
  429.  
  430.  
  431.  
  432.  
  433. //when new data comes remove existing svg bar chart
  434.  
  435. var chart = d3.select('svgalert').remove();
  436.  
  437.  
  438.  
  439. //var chart = d3.select(".chart")
  440.  
  441.  
  442.  
  443. //nadeesha
  444.  
  445. //var s = document.createElement('style');
  446.  
  447. //s.type = "text/css";
  448.  
  449. //s.styleSheet.cssText = "body { background: red}";
  450.  
  451. //document.getElementsById('alert').appendChild(s);
  452.  
  453. //
  454.  
  455.  
  456.  
  457. createAlert(webSiteUrl, accessdata, accesscount,avgaccessdata, avgaccesscount)
  458.  
  459.  
  460.  
  461.  
  462.  
  463. function createAlert(webSiteUrl, accessdata, accesscount,avgaccessdata, avgaccesscount){
  464.  
  465.  
  466.  
  467. var chart = d3.select("#alert").append('svgalert');
  468.  
  469.  
  470.  
  471. //$('#alert').css("background-color", "#F31912");
  472.  
  473. document.getElementById('alert').style.backgroundColor = "#F31912";
  474.  
  475. document.getElementById('alert').style.border="8px solid gray";
  476.  
  477. document.getElementById('alert').style.borderRadius="5px";
  478.  
  479. document.getElementById('alert').style.marginTop="70px";
  480.  
  481. document.getElementById('alert').style.paddingLeft="80px";
  482.  
  483. document.getElementById('alert').style.paddingBottom="40px";
  484.  
  485. document.getElementById('alert').style.paddingTop="20px";
  486.  
  487. document.getElementById('alert').style.zIndex="10";
  488.  
  489. document.getElementById('alert').style.position="absolute";
  490.  
  491. document.getElementById('alert').style.marginLeft="250px";
  492.  
  493. document.getElementById('alert').style.color="#F6DCDC";
  494.  
  495. //document.getElementById('alert').style.
  496.  
  497. //chart.innerHTML = "strong { color: blue }";
  498.  
  499.  
  500.  
  501. //d3.select("#alert")
  502.  
  503. chart.append('h2')
  504.  
  505. .text("Alert").style.color="blue";
  506.  
  507. chart.append('h2').text("");
  508.  
  509. chart.append('h4')
  510.  
  511. .text("Web Url :" +webSiteUrl);
  512.  
  513. //d3.select("#alert")
  514.  
  515. chart.append('h4')
  516.  
  517. .text("Access Data : " +accessdata);
  518.  
  519. //d3.select("#alert")
  520.  
  521. chart.append('h4')
  522.  
  523. .text("Access Count : " +accesscount);
  524.  
  525. //d3.select("#alert")
  526.  
  527. chart.append('h4')
  528.  
  529. .text("Maximum Access Data : " +avgaccessdata);
  530.  
  531. //d3.select("#alert")
  532.  
  533. chart.append('h4')
  534.  
  535. .text("Maximum Access Count : " +avgaccesscount);
  536.  
  537.  
  538.  
  539. chart.append("div").attr("id","btnContainer");
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547. //var element = document.getElementByID("alert");
  548.  
  549. //element.setAttribute("type", "button");
  550.  
  551. //element.setAttribute("value", "invert");
  552.  
  553. //element.setAttribute("name", "button3");
  554.  
  555. //element.setAttribute("onclick", "foo()");
  556.  
  557. //chart.appendChild(element);
  558.  
  559.  
  560.  
  561. //if(alert==1)
  562.  
  563. //{
  564.  
  565.  
  566.  
  567. var btn1 = document.createElement("BUTTON");
  568.  
  569. var btn2 = document.createElement("BUTTON");
  570.  
  571. var btn3 = document.createElement("BUTTON");
  572.  
  573.  
  574.  
  575.  
  576.  
  577. //var btn1 = document.createElement("BUTTON"); // Create a <button> element
  578.  
  579. //btn1.style.marginTop="5px";
  580.  
  581. btn1.style.padding="7px";
  582.  
  583. btn1.style.marginLeft="0px";
  584.  
  585. btn1.style.borderRadius="3px";
  586.  
  587. btn1.style.backgroundColor="gray";
  588.  
  589. btn1.style.borderColor="black";
  590.  
  591. btn1.style.color="black";
  592.  
  593. btn1.style.width="100px";
  594.  
  595. var t = document.createTextNode("More Details"); // Create a text node
  596.  
  597. btn1.appendChild(t); // Append the text to <button>
  598.  
  599. document.getElementById("btnContainer").appendChild(btn1);
  600.  
  601.  
  602.  
  603. //chart.append(btn1);
  604.  
  605.  
  606.  
  607. //var btn2 = document.createElement("BUTTON"); // Create a <button> element
  608.  
  609. //btn2.style.marginTop="5px";
  610.  
  611. btn2.style.padding="7px";
  612.  
  613. btn2.style.marginLeft="30px";
  614.  
  615. btn2.style.borderRadius="3px";
  616.  
  617. btn2.style.backgroundColor="gray";
  618.  
  619. btn2.style.borderColor="black";
  620.  
  621. btn2.style.color="black";
  622.  
  623. btn2.style.width="100px";
  624.  
  625. var t = document.createTextNode("Take Action"); // Create a text node
  626.  
  627. btn2.appendChild(t); // Append the text to <button>
  628.  
  629. document.getElementById("btnContainer").appendChild(btn2);
  630.  
  631.  
  632.  
  633. //var btn3 = document.createElement("BUTTON"); // Create a <button> element
  634.  
  635. //btn3.style.marginTop="5px";
  636.  
  637. btn3.style.padding="7px";
  638.  
  639. btn3.style.marginLeft="30px";
  640.  
  641. btn3.style.borderRadius="3px";
  642.  
  643. btn3.style.backgroundColor="gray";
  644.  
  645. btn3.style.borderColor="black";
  646.  
  647. btn3.style.color="black";
  648.  
  649. btn3.style.width="100px";
  650.  
  651. var t = document.createTextNode("Cancel"); // Create a text node
  652.  
  653. btn3.appendChild(t); // Append the text to <button>
  654.  
  655. document.getElementById("btnContainer").appendChild(btn3);
  656.  
  657.  
  658.  
  659. function svgClose(){
  660.  
  661. var chart = d3.select('svgalert').remove();
  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. function type(d) {
  696.  
  697. d.value = +d.value; // coerce to number
  698.  
  699. return d;
  700.  
  701. }
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711. drowChart();
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719. function drowpie(){
  720.  
  721.  
  722.  
  723. //Width and height
  724.  
  725. var w = 300;
  726.  
  727. var h = 300;
  728.  
  729.  
  730.  
  731. var dataset = [ 5, 10, 20, 45, 6, 25 ];
  732.  
  733.  
  734.  
  735. var outerRadius = w / 2;
  736.  
  737. var innerRadius = 0;
  738.  
  739. var arc = d3.svg.arc()
  740.  
  741. .innerRadius(innerRadius)
  742.  
  743. .outerRadius(outerRadius);
  744.  
  745.  
  746.  
  747. var pie = d3.layout.pie();
  748.  
  749.  
  750.  
  751. //Easy colors accessible via a 10-step ordinal scale
  752.  
  753. var color = d3.scale.category10();
  754.  
  755.  
  756.  
  757. //Create SVG element //var chart = d3.select("#chart").append('svg')
  758.  
  759. var svg = d3.select("#pie2")
  760.  
  761. .append("svg")
  762.  
  763. .attr("width", w)
  764.  
  765. .attr("height", h);
  766.  
  767.  
  768.  
  769. //Set up groups
  770.  
  771. var arcs = svg.selectAll("g.arc")
  772.  
  773. .data(pie(dataset))
  774.  
  775. .enter()
  776.  
  777. .append("g")
  778.  
  779. .attr("class", "arc")
  780.  
  781. .attr("transform", "translate(" + outerRadius + "," + outerRadius + ")");
  782.  
  783.  
  784.  
  785. //Draw arc paths
  786.  
  787. arcs.append("path")
  788.  
  789. .attr("fill", function(d, i) {
  790.  
  791. return color(i);
  792.  
  793. })
  794.  
  795. .attr("d", arc);
  796.  
  797.  
  798.  
  799. //Labels
  800.  
  801. arcs.append("text")
  802.  
  803. .attr("transform", function(d) {
  804.  
  805. return "translate(" + arc.centroid(d) + ")";
  806.  
  807. })
  808.  
  809. .attr("text-anchor", "middle")
  810.  
  811. .text(function(d) {
  812.  
  813. return d.value;
  814.  
  815. });
  816.  
  817.  
  818.  
  819.  
  820.  
  821. }
  822.  
  823.  
  824.  
  825.  
  826.  
  827. drowpie();
  828.  
  829.  
  830.  
  831. //pie chart
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.  
  866.  
  867.  
  868.  
  869.  
  870.  
  871.  
  872.  
  873.  
  874.  
  875.  
  876.  
  877.  
  878.  
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.  
  887.  
  888.  
  889.  
  890.  
  891.  
  892.  
  893.  
  894.  
  895.  
  896.  
  897.  
  898.  
  899. /*
  900.  
  901. var margin = {top: 20, right: 30, bottom: 30, left: 40},
  902.  
  903. width = 960 - margin.left - margin.right,
  904.  
  905. height = 500 - margin.top - margin.bottom;
  906.  
  907.  
  908.  
  909. var x = d3.scale.ordinal()
  910.  
  911. .rangeRoundBands([0, width], .1);
  912.  
  913.  
  914.  
  915. var y = d3.scale.linear()
  916.  
  917. .range([height, 0]);
  918.  
  919.  
  920.  
  921. var xAxis = d3.svg.axis()
  922.  
  923. .scale(x)
  924.  
  925. .orient("bottom");
  926.  
  927.  
  928.  
  929. var yAxis = d3.svg.axis()
  930.  
  931. .scale(y)
  932.  
  933. .orient("left");
  934.  
  935.  
  936.  
  937. var chart = d3.select(".chart")
  938.  
  939. .attr("width", width + margin.left + margin.right)
  940.  
  941. .attr("height", height + margin.top + margin.bottom)
  942.  
  943. .append("g")
  944.  
  945. .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
  946.  
  947.  
  948.  
  949.  
  950.  
  951. x.domain(data.map(function(d) { return d.name; }));
  952.  
  953. y.domain([0, d3.max(data, function(d) { return d.value; })]);
  954.  
  955.  
  956.  
  957. chart.append("g")
  958.  
  959. .attr("class", "x axis")
  960.  
  961. .attr("transform", "translate(0," + height + ")")
  962.  
  963. .call(xAxis);
  964.  
  965.  
  966.  
  967. chart.append("g")
  968.  
  969. .attr("class", "y axis")
  970.  
  971. .call(yAxis);
  972.  
  973.  
  974.  
  975. chart.selectAll(".bar")
  976.  
  977. .data(data)
  978.  
  979. .enter().append("rect")
  980.  
  981. .attr("class", "bar")
  982.  
  983. .attr("x", function(d) { return x(d.name); })
  984.  
  985. .attr("y", function(d) { return y(d.value); })
  986.  
  987. .attr("height", function(d) { return height - y(d.value); })
  988.  
  989. .attr("width", x.rangeBand());
  990.  
  991. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement