| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>GFX Test: Test the basic utils functions</title> |
| 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"> |
| 10 | dojoConfig = { |
| 11 | isDebug:true, |
| 12 | packages:[{ |
| 13 | name:'doh', |
| 14 | location:'../util/doh' |
| 15 | }] |
| 16 | } |
| 17 | </script> |
| 18 | <script type="text/javascript" src="../../../dojo/dojo.js"></script> |
| 19 | <script type="text/javascript"> |
| 20 | require([ |
| 21 | "doh/runner", |
| 22 | "dojox/gfx", |
| 23 | "dojox/gfx/matrix", |
| 24 | "dojo/ready" |
| 25 | ], function(doh, gfx, matrix, ready){ |
| 26 | ready(function(){ |
| 27 | var drawing, g; |
| 28 | doh.register("Container.getBoundingBox test", [ |
| 29 | { |
| 30 | name: "Default state", |
| 31 | timeout: 1000, |
| 32 | setUp: function(){ |
| 33 | if(!drawing){ |
| 34 | drawing = gfx.createSurface("gfxObject", 300, 300); |
| 35 | } |
| 36 | drawing.clear(); |
| 37 | g = drawing.createGroup(); |
| 38 | }, |
| 39 | runTest: function(){ |
| 40 | // surface |
| 41 | var bbox = drawing.getBoundingBox(); |
| 42 | doh.assertTrue(bbox === null, "Unexpected value for empty surface bbox."); |
| 43 | // empty group -> null bbox |
| 44 | bbox = g.getBoundingBox(); |
| 45 | doh.assertTrue(bbox === null, "Unexpected value for empty group bbox."); |
| 46 | } |
| 47 | }, { |
| 48 | name: "Group with children", |
| 49 | timeout: 1000, |
| 50 | setUp: function(){ |
| 51 | if(!drawing){ |
| 52 | drawing = gfx.createSurface("gfxObject", 300, 300); |
| 53 | } |
| 54 | drawing.clear(); |
| 55 | g = drawing.createGroup(); |
| 56 | }, |
| 57 | runTest: function(){ |
| 58 | // child |
| 59 | var r = g.createRect(); |
| 60 | var bbox = g.getBoundingBox(); |
| 61 | doh.assertTrue(bbox.x === 0 && bbox.y === 0 && bbox.width === 100 && bbox.height === 100, "Unexpected bbox value."); |
| 62 | // children |
| 63 | g.createRect({x:200,y:300}); |
| 64 | bbox = g.getBoundingBox(); |
| 65 | doh.assertTrue(bbox.x === 0 && bbox.y === 0 && bbox.width === 300 && bbox.height === 400, "Unexpected composite bbox value."); |
| 66 | // child with null bbox |
| 67 | r = g.createRect(); |
| 68 | r.getBoundingBox = function(){return null;}; |
| 69 | var err = false; |
| 70 | bbox = null; |
| 71 | try{ |
| 72 | bbox = g.getBoundingBox(); |
| 73 | }catch(e){ |
| 74 | err = true; |
| 75 | } |
| 76 | doh.assertFalse(err, "getBoundingBox fails with null bbox."); |
| 77 | doh.assertTrue(bbox.x === 0 && bbox.y === 0 && bbox.width === 300 && bbox.height === 400, "Unexpected composite bbox value with null bbox."); |
| 78 | // surface |
| 79 | bbox = drawing.getBoundingBox(); |
| 80 | doh.assertTrue(bbox.x === 0 && bbox.y === 0 && bbox.width === 300 && bbox.height === 400, "Unexpected surface bbox value."); |
| 81 | |
| 82 | } |
| 83 | },{ |
| 84 | name: "children with transform", |
| 85 | timeout: 1000, |
| 86 | setUp: function(){ |
| 87 | if(!drawing){ |
| 88 | drawing = gfx.createSurface("gfxObject", 300, 300); |
| 89 | } |
| 90 | drawing.clear(); |
| 91 | g = drawing.createGroup(); |
| 92 | }, |
| 93 | runTest: function(){ |
| 94 | // child |
| 95 | var r = g.createRect(); |
| 96 | var bbox = g.getBoundingBox(); |
| 97 | doh.assertTrue(bbox.x === 0 && bbox.y === 0 && bbox.width === 100 && bbox.height === 100, "Unexpected bbox value."); |
| 98 | // child with transform |
| 99 | r.setTransform(matrix.translate(10,0)); |
| 100 | bbox = g.getBoundingBox(); |
| 101 | doh.assertTrue(bbox.x === 10 && bbox.y === 0 && bbox.width === 100 && bbox.height === 100, "Unexpected bbox value with child transform."); |
| 102 | // the group has a transform -> getBoundingBox should not be modified |
| 103 | g.setTransform(matrix.translate(10,20)); |
| 104 | bbox = g.getBoundingBox(); |
| 105 | doh.assertTrue(bbox.x === 10 && bbox.y === 0 && bbox.width === 100 && bbox.height === 100, "Unexpected bbox value with Group transform."); |
| 106 | // surface |
| 107 | bbox = null; |
| 108 | bbox = drawing.getBoundingBox(); |
| 109 | doh.assertTrue(bbox.x === 20 && bbox.y === 20 && bbox.width === 100 && bbox.height === 100, "Unexpected surface bbox value."); |
| 110 | } |
| 111 | },{ |
| 112 | name: "Nested container", |
| 113 | timeout: 1000, |
| 114 | setUp: function(){ |
| 115 | if(!drawing){ |
| 116 | drawing = gfx.createSurface("gfxObject", 300, 300); |
| 117 | } |
| 118 | drawing.clear(); |
| 119 | g = drawing.createGroup(); |
| 120 | }, |
| 121 | runTest: function(){ |
| 122 | var r = g.createRect(); |
| 123 | g.createRect({x:200,y:300}); |
| 124 | var g2 = g.createGroup(); |
| 125 | g2.createRect(); |
| 126 | g2.createRect({x:500}); |
| 127 | g2.setTransform(matrix.translate(100,200)); |
| 128 | bbox = g.getBoundingBox(); |
| 129 | doh.assertTrue(bbox.x === 0 && bbox.y === 0 && bbox.width === 700 && bbox.height === 400, "Unexpected composite bbox value."); |
| 130 | } |
| 131 | } |
| 132 | ]); |
| 133 | doh.run(); |
| 134 | }); |
| 135 | }); |
| 136 | |
| 137 | </script> |
| 138 | </head> |
| 139 | <body class="tundra"> |
| 140 | <h1>Test of Group.getBoundingBox</h1> |
| 141 | <div id="gfxObject"></div> |
| 142 | </body> |
| 143 | </html> |