ellipse.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2007 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview A thick wrapper around ellipses.
  16. * @author robbyw@google.com (Robby Walker)
  17. */
  18. goog.provide('goog.graphics.ext.Ellipse');
  19. goog.require('goog.graphics.ext.StrokeAndFillElement');
  20. /**
  21. * Wrapper for a graphics ellipse element.
  22. * @param {goog.graphics.ext.Group} group Parent for this element.
  23. * @constructor
  24. * @extends {goog.graphics.ext.StrokeAndFillElement}
  25. * @final
  26. */
  27. goog.graphics.ext.Ellipse = function(group) {
  28. // Initialize with some stock values.
  29. var wrapper = group.getGraphicsImplementation().drawEllipse(
  30. 1, 1, 2, 2, null, null, group.getWrapper());
  31. goog.graphics.ext.StrokeAndFillElement.call(this, group, wrapper);
  32. };
  33. goog.inherits(
  34. goog.graphics.ext.Ellipse, goog.graphics.ext.StrokeAndFillElement);
  35. /**
  36. * Redraw the ellipse. Called when the coordinate system is changed.
  37. * @protected
  38. * @override
  39. */
  40. goog.graphics.ext.Ellipse.prototype.redraw = function() {
  41. goog.graphics.ext.Ellipse.superClass_.redraw.call(this);
  42. // Our position is already transformed in transform_, but because this is an
  43. // ellipse we need to position the center.
  44. var xRadius = this.getWidth() / 2;
  45. var yRadius = this.getHeight() / 2;
  46. var wrapper = this.getWrapper();
  47. wrapper.setCenter(xRadius, yRadius);
  48. wrapper.setRadius(xRadius, yRadius);
  49. };