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.

55 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. this.radius = 0.5*this.width;
  16. }
  17. }
  18. draw(ctx, x, y, selected, hover) {
  19. this.resize(ctx, selected);
  20. this.left = x - this.width / 2;
  21. this.top = y - this.height / 2;
  22. this._drawRawCircle(ctx, x, y, selected, hover, this.options.size);
  23. this.boundingBox.top = y - this.options.size;
  24. this.boundingBox.left = x - this.options.size;
  25. this.boundingBox.right = x + this.options.size;
  26. this.boundingBox.bottom = y + this.options.size;
  27. this.updateBoundingBox(x,y);
  28. this.labelModule.draw(ctx, x, y, selected);
  29. }
  30. updateBoundingBox(x,y) {
  31. this.boundingBox.top = y - this.options.size;
  32. this.boundingBox.left = x - this.options.size;
  33. this.boundingBox.right = x + this.options.size;
  34. this.boundingBox.bottom = y + this.options.size;
  35. }
  36. distanceToBorder(ctx, angle) {
  37. this.resize(ctx);
  38. var a = this.width / 2;
  39. var b = this.height / 2;
  40. var w = (Math.sin(angle) * a);
  41. var h = (Math.cos(angle) * b);
  42. return a * b / Math.sqrt(w * w + h * h);
  43. }
  44. }
  45. export default Circle;