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.

59 lines
1.5 KiB

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