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.

46 lines
1.2 KiB

  1. 'use strict';
  2. import CircleImageBase from '../util/CircleImageBase'
  3. class Circle extends CircleImageBase {
  4. constructor(options, body, labelModule) {
  5. super(options, body, labelModule)
  6. }
  7. resize(ctx, selected) {
  8. if (this.width === undefined) {
  9. var margin = 5;
  10. var textSize = this.labelModule.getTextSize(ctx, selected);
  11. var diameter = Math.max(textSize.width, textSize.height) + 2 * margin;
  12. this.options.size = diameter / 2;
  13. this.width = diameter;
  14. this.height = diameter;
  15. }
  16. }
  17. draw(ctx, x, y, selected, hover) {
  18. this.resize(ctx, selected);
  19. this.left = x - this.width / 2;
  20. this.top = y - this.height / 2;
  21. this._drawRawCircle(ctx, x, y, selected, hover, this.options.size);
  22. this.boundingBox.top = y - this.options.size;
  23. this.boundingBox.left = x - this.options.size;
  24. this.boundingBox.right = x + this.options.size;
  25. this.boundingBox.bottom = y + this.options.size;
  26. this.labelModule.draw(ctx, x, y, selected);
  27. }
  28. distanceToBorder(ctx, angle) {
  29. this.resize(ctx);
  30. var a = this.width / 2;
  31. var b = this.height / 2;
  32. var w = (Math.sin(angle) * a);
  33. var h = (Math.cos(angle) * b);
  34. return a * b / Math.sqrt(w * w + h * h);
  35. }
  36. }
  37. export default Circle;