vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

  1. 'use strict';
  2. import NodeBase from '../util/NodeBase'
  3. class Ellipse extends NodeBase {
  4. constructor(options, body, labelModule) {
  5. super(options, body, labelModule);
  6. }
  7. resize(ctx, selected = this.selected, hover = this.hover) {
  8. if (this.needsRefresh(selected, hover)) {
  9. var textSize = this.labelModule.getTextSize(ctx, selected, hover);
  10. this.height = textSize.height * 2;
  11. this.width = textSize.width + this.height;
  12. this.radius = 0.5*this.width;
  13. }
  14. }
  15. draw(ctx, x, y, selected, hover, values) {
  16. this.resize(ctx, selected, hover);
  17. this.left = x - this.width * 0.5;
  18. this.top = y - this.height * 0.5;
  19. this.initContextForDraw(ctx, values);
  20. ctx.ellipse_vis(this.left, this.top, this.width, this.height);
  21. this.performFill(ctx, values);
  22. this.updateBoundingBox(x, y, ctx, selected, hover);
  23. this.labelModule.draw(ctx, x, y, selected, hover);
  24. }
  25. distanceToBorder(ctx, angle) {
  26. this.resize(ctx);
  27. var a = this.width * 0.5;
  28. var b = this.height * 0.5;
  29. var w = (Math.sin(angle) * a);
  30. var h = (Math.cos(angle) * b);
  31. return a * b / Math.sqrt(w * w + h * h);
  32. }
  33. }
  34. export default Ellipse;