boundarybox.html 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Boundary Box Example</title>
  5. <!-- 正式发布的时候, 只需替换掉相应的脚本文件即可 -->
  6. <!-- dev 版本 示例所需脚本文件 start -->
  7. <script src="../dev-lib/sea.js"></script>
  8. <script>
  9. seajs.config({
  10. base: '../src'
  11. });
  12. </script>
  13. <script src="../dev-lib/exports.js"></script>
  14. <script src="../dev-lib/dev-start.js"></script>
  15. <!-- dev 版本 示例所需脚本文件 end -->
  16. <!-- 正式版本 示例所需脚本文件 start -->
  17. <!--<script src="../dist/kitygraph.all.min.js"></script>-->
  18. <!-- 正式版本 示例所需脚本文件 end -->
  19. <script>
  20. window.onload = function () {
  21. var paper = new kity.Paper(document.body);
  22. function bbox(shape) {
  23. var box = shape.getBoundaryBox();
  24. return new kity.Rect(box.width | 0, box.height | 0, (box.x | 0) + .5, (box.y | 0) + .5).stroke('red');
  25. }
  26. paper.setWidth(600).setHeight(400);
  27. var rect = new kity.Rect(100, 50, 30, 30).fill('blue').setOpacity(0.5);
  28. var triangle = new kity.RegularPolygon(3, 50, 200, 50).fill('blue').setOpacity(0.5);
  29. var circle = new kity.Circle(40, 305, 60).fill('blue').setOpacity(0.5);
  30. paper.addShapes([rect, triangle, circle]);
  31. paper.addShapes([rect, triangle, circle].map(bbox));
  32. };
  33. </script>
  34. </head>
  35. <body>
  36. </body>
  37. </html>