Guest User

Untitled

a guest
Oct 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
  2. <html> <head>
  3. <title></title>
  4.  
  5. <script src="d3.v2.js" type="text/javascript"></script>
  6. </head>
  7.  
  8. <body>
  9. <h1>Test d3</h1>
  10.  
  11. <div id="container">
  12. <p>This is a paragraphi 0 </p>
  13. <p>This is a paragraphi 1 </p>
  14. <p>This is a paragraphi 2 </p>
  15. <p>This is a paragraphi 3 </p>
  16. </div>
  17.  
  18. <div>
  19. nothing here
  20.  
  21. </div>
  22.  
  23.  
  24. <script>
  25. console.log("-----------------------testing paragraphs");
  26. if( d3.selectAll("div")[0].length == 2){
  27. console.log("1st test passed");
  28. }
  29. if( d3.selectAll("p")[0].length == 4){
  30. console.log("2nd test passed");
  31. }
  32. // because nth-child's are 1-based
  33. var numOfPs = d3.select("body").selectAll("p")[0].length;
  34. for(var i=1; i <= numOfPs; i++){
  35. if( d3.selectAll("p:nth-child(" + i + ")")[0].length > 0){
  36. console.log("3." + i + " test passed");
  37. }else{
  38. console.log("3." + i + " test failed");
  39. }
  40. }
  41. // verify that there's not an extra one
  42. if( d3.selectAll("p:nth-child(" + (numOfPs + 1) + ")")[0].length == 0){
  43. console.log("Extra 3 test passed");
  44. }else{
  45. console.log("Extra 3 test failed");
  46. }
  47.  
  48. /////////////
  49. console.log("-----------------------testing divs");
  50.  
  51. var numOfDIVs = d3.selectAll("div")[0].length;
  52. // because nth-child's are 1-based
  53. for(var i=1; i <= d3.selectAll("div")[0].length; i++){
  54. if( d3.selectAll("div:nth-child(" + i + ")")[0].length > 0){
  55. console.log("4." + i + " test passed");
  56. }else{
  57. // this fails for the first element... indicating the addition of an extra div ..
  58. console.log("4." + i + " test failed");
  59. }
  60. }
  61.  
  62. // verify that there's not an extra one
  63. if( d3.selectAll("div:nth-child(" + (numOfDIVs + 1) + ")")[0].length == 0){
  64. console.log("Extra 4 test passed");
  65. }else{
  66. // this fails ... indicating the addition of an extra div ... somehow
  67. console.log("Extra 4 test failed");
  68. }
  69.  
  70.  
  71. </script>
  72. </body> </html>
Add Comment
Please, Sign In to add comment