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.

51 lines
1.4 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. return this.width * 0.5;
  39. }
  40. }
  41. export default Circle;