| 1 | <!DOCTYPE html> |
| 2 | <head> |
| 3 | <title>Testing polyline points initialization</title> |
| 4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 5 | <style type="text/css"> |
| 6 | @import "../../../dojo/resources/dojo.css"; |
| 7 | @import "../../../dijit/tests/css/dijitTests.css"; |
| 8 | </style> |
| 9 | <script type="text/javascript" src="../../../dojo/dojo.js" data-dojo-config="gfxRenderer:'canvas', isDebug: true"></script> |
| 10 | <script type="text/javascript"> |
| 11 | dojo.require("dojox.gfx"); |
| 12 | dojo.require("dojox.gfx.shape"); |
| 13 | dojo.require("dojox.gfx.path"); |
| 14 | dojo.require("dojox.gfx.arc"); |
| 15 | |
| 16 | createSurface = function(){ |
| 17 | surface = dojox.gfx.createSurface("test", 500, 200); |
| 18 | surface.whenLoaded(makeShapes); |
| 19 | }; |
| 20 | |
| 21 | logBBox = function(shape, msg){ |
| 22 | var bbox = shape.getBoundingBox(), t = shape.getTransform(); |
| 23 | if (bbox) |
| 24 | surface.createText({ |
| 25 | text:msg + " bbox: [" + bbox.x+","+bbox.y+","+bbox.width+","+bbox.height+"]", |
| 26 | align:"middle", |
| 27 | x:bbox.x+bbox.width/2, |
| 28 | y:bbox.y+bbox.height+20 |
| 29 | }).setFill("black").setTransform(t); |
| 30 | else |
| 31 | dojo.byId("o1").innerHTML = msg + " bbox: null"; |
| 32 | return bbox; |
| 33 | }; |
| 34 | |
| 35 | makeShapes = function(surface){ |
| 36 | var poly1 = surface.createPolyline([{x: 150, y: 50}, {x: 200, y: 100}, {x: 150, y: 150}, {x: 100, y: 100}, {x: 150, y: 50}]) |
| 37 | .setStroke({color:"blue"}) |
| 38 | , |
| 39 | bbox1 = logBBox(poly1,"Polyline1"); |
| 40 | |
| 41 | var poly2 = surface.createPolyline([150, 50, 200, 100, 150, 150, 100, 100, 150, 50]) |
| 42 | .setStroke({color:"blue"}) |
| 43 | .setTransform(dojox.gfx.matrix.translate(200,0)) |
| 44 | , |
| 45 | bbox2 = logBBox(poly2,"Polyline2"); |
| 46 | |
| 47 | var poly3 = surface.createPolyline(), |
| 48 | bbox3 = logBBox(poly3,"Polyline3"); |
| 49 | |
| 50 | var t = bbox1.x === bbox2.x && |
| 51 | bbox1.y === bbox2.y && |
| 52 | bbox1.width === bbox2.width && |
| 53 | bbox1.height === bbox2.height; |
| 54 | var s; |
| 55 | if(t){ |
| 56 | s = "OK"; |
| 57 | }else{ |
| 58 | s = "KO"; |
| 59 | dojo.style("o3","color","red"); |
| 60 | } |
| 61 | dojo.byId("o3").innerHTML = "Test Result : " + (t ? "OK" : "KO"); |
| 62 | }; |
| 63 | |
| 64 | dojo.addOnLoad(createSurface); |
| 65 | |
| 66 | </script> |
| 67 | </head> |
| 68 | <body> |
| 69 | <h1>dojox.gfx Polyline points initialization test </h1> |
| 70 | <div id="test" style="width: 500px; height: 200px;"></div> |
| 71 | <p id="o1"></p> |
| 72 | <p id="o3" style="font-weight:bold"></p> |
| 73 | </body> |
| 74 | </html> |