advancedcoordinates.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright 2007 The Closure Library Authors. All Rights Reserved.
  5. Use of this source code is governed by the Apache License, Version 2.0.
  6. See the COPYING file for details.
  7. -->
  8. <head>
  9. <title>Graphics Advanced Coordinates Demo Page</title>
  10. <script type="text/javascript" src="../../base.js"></script>
  11. <script type="text/javascript">
  12. goog.require('goog.dom');
  13. goog.require('goog.graphics');
  14. goog.require('goog.graphics.ext');
  15. </script>
  16. <script type="text/javascript">
  17. var group;
  18. function drawElements() {
  19. var graphics = new goog.graphics.ext.Graphics(2000, 2000);
  20. group = new goog.graphics.ext.Group(graphics);
  21. group.setLeft(20, true);
  22. group.setTop(20, true);
  23. group.setWidth(600, true);
  24. group.setHeight(200);
  25. // Basic shapes
  26. var fill = new goog.graphics.SolidFill('yellow');
  27. var stroke = new goog.graphics.Stroke(2, 'green');
  28. var bg = new goog.graphics.SolidFill('#eeeeee');
  29. var outline = new goog.graphics.Stroke(1, '#333333');
  30. var background = new goog.graphics.ext.Rectangle(group);
  31. background.setLeft(0, true);
  32. background.setTop(0, true);
  33. background.setWidth('100%', true);
  34. background.setHeight('100%');
  35. background.setStroke(outline);
  36. background.setFill(bg);
  37. var rect = new goog.graphics.ext.Rectangle(group);
  38. rect.setLeft('-5px', true);
  39. rect.setTop('-5px', true);
  40. rect.setWidth('10px', true);
  41. rect.setHeight('10px');
  42. rect.setStroke(stroke);
  43. rect.setFill(fill);
  44. rect = new goog.graphics.ext.Rectangle(group);
  45. rect.setRight('-5px', true);
  46. rect.setTop('-5px', true);
  47. rect.setWidth('10px', true);
  48. rect.setHeight('10px');
  49. rect.setStroke(stroke);
  50. rect.setFill(fill);
  51. rect = new goog.graphics.ext.Rectangle(group);
  52. rect.setRight('-5px', true);
  53. rect.setBottom('-5px', true);
  54. rect.setWidth('10px', true);
  55. rect.setHeight('10px');
  56. rect.setStroke(stroke);
  57. rect.setFill(fill);
  58. rect = new goog.graphics.ext.Rectangle(group);
  59. rect.setLeft('-5px', true);
  60. rect.setBottom('-5px', true);
  61. rect.setWidth('10px', true);
  62. rect.setHeight('10px');
  63. rect.setStroke(stroke);
  64. rect.setFill(fill);
  65. var image = new goog.graphics.ext.Image(group,
  66. 'http://www.google.com/intl/en_ALL/images/logo.gif');
  67. image.setRight(10, true);
  68. image.setTop(10, true);
  69. image.setWidth('276px', true);
  70. image.setHeight('110px');
  71. var ellipse = new goog.graphics.ext.Ellipse(group);
  72. ellipse.setCenter(0, true);
  73. ellipse.setMiddle(0, true);
  74. ellipse.setWidth('10%', true);
  75. ellipse.setHeight('80%');
  76. ellipse.setStroke(stroke);
  77. ellipse.setFill(fill);
  78. ellipse = new goog.graphics.ext.Ellipse(group);
  79. ellipse.setCenter(0, true);
  80. ellipse.setMiddle(0, true);
  81. ellipse.setWidth(120, true);
  82. ellipse.setHeight(60);
  83. ellipse.setStroke(stroke);
  84. ellipse.setFill(fill);
  85. var path = new goog.graphics.ext.Path().moveTo(0, 0).lineTo(20, 0).
  86. lineTo(10, 20).close();
  87. var shape = new goog.graphics.ext.Shape(group, path);
  88. shape.setLeft(10, true);
  89. shape.setTop(10, true);
  90. shape.setWidth('10%', true);
  91. shape.setHeight('10%');
  92. shape.setStroke(stroke);
  93. shape.setFill(fill);
  94. shape = new goog.graphics.ext.Shape(group, path, true);
  95. shape.setLeft(40, true);
  96. shape.setTop(10, true);
  97. shape.setWidth('10%', true);
  98. shape.setHeight('10%');
  99. shape.setStroke(stroke);
  100. shape.setFill(fill);
  101. graphics.render(document.body);
  102. }
  103. </script>
  104. </head>
  105. <body onload="drawElements()">
  106. <div style="position: absolute; top: 400px">
  107. <p>
  108. W: <input type="text" name="width" value="600"
  109. onchange="group.setWidth(this.value)">
  110. H: <input type="text" name="height" value="200"
  111. onchange="group.setHeight(this.value)">
  112. R: <input type="text" name="rotation" value="0"
  113. onchange="group.setRotation(this.value)">
  114. </p>
  115. <p>The front ellipse is sized based on absolute units. The back ellipse is
  116. sized based on percentage of the parent.</p>
  117. </div>
  118. </body>
  119. </html>