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.

54 lines
1.5 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.updateBoundingBox(x,y);
  27. this.labelModule.draw(ctx, x, y, selected);
  28. }
  29. updateBoundingBox(x,y) {
  30. this.boundingBox.top = y - this.options.size;
  31. this.boundingBox.left = x - this.options.size;
  32. this.boundingBox.right = x + this.options.size;
  33. this.boundingBox.bottom = y + this.options.size;
  34. }
  35. distanceToBorder(ctx, angle) {
  36. this.resize(ctx);
  37. var a = this.width / 2;
  38. var b = this.height / 2;
  39. var w = (Math.sin(angle) * a);
  40. var h = (Math.cos(angle) * b);
  41. return a * b / Math.sqrt(w * w + h * h);
  42. }
  43. }
  44. export default Circle;