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.

49 lines
1.3 KiB

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