Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
- <html> <head>
- <title></title>
- <script src="d3.v2.js" type="text/javascript"></script>
- </head>
- <body>
- <h1>Test d3</h1>
- <div id="container">
- <p>This is a paragraphi 0 </p>
- <p>This is a paragraphi 1 </p>
- <p>This is a paragraphi 2 </p>
- <p>This is a paragraphi 3 </p>
- </div>
- <div>
- nothing here
- </div>
- <script>
- console.log("-----------------------testing paragraphs");
- if( d3.selectAll("div")[0].length == 2){
- console.log("1st test passed");
- }
- if( d3.selectAll("p")[0].length == 4){
- console.log("2nd test passed");
- }
- // because nth-child's are 1-based
- var numOfPs = d3.select("body").selectAll("p")[0].length;
- for(var i=1; i <= numOfPs; i++){
- if( d3.selectAll("p:nth-child(" + i + ")")[0].length > 0){
- console.log("3." + i + " test passed");
- }else{
- console.log("3." + i + " test failed");
- }
- }
- // verify that there's not an extra one
- if( d3.selectAll("p:nth-child(" + (numOfPs + 1) + ")")[0].length == 0){
- console.log("Extra 3 test passed");
- }else{
- console.log("Extra 3 test failed");
- }
- /////////////
- console.log("-----------------------testing divs");
- var numOfDIVs = d3.selectAll("div")[0].length;
- // because nth-child's are 1-based
- for(var i=1; i <= d3.selectAll("div")[0].length; i++){
- if( d3.selectAll("div:nth-child(" + i + ")")[0].length > 0){
- console.log("4." + i + " test passed");
- }else{
- // this fails for the first element... indicating the addition of an extra div ..
- console.log("4." + i + " test failed");
- }
- }
- // verify that there's not an extra one
- if( d3.selectAll("div:nth-child(" + (numOfDIVs + 1) + ")")[0].length == 0){
- console.log("Extra 4 test passed");
- }else{
- // this fails ... indicating the addition of an extra div ... somehow
- console.log("Extra 4 test failed");
- }
- </script>
- </body> </html>
Add Comment
Please, Sign In to add comment