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.6 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. this._setMargins(labelModule);
  7. }
  8. resize(ctx, selected) {
  9. if (this.width === undefined) {
  10. this.textSize = this.labelModule.getTextSize(ctx, selected);
  11. var diameter = Math.max(this.textSize.width + this.margin.right + this.margin.left,
  12. this.textSize.height + this.margin.top + this.margin.bottom);
  13. this.options.size = diameter / 2;
  14. this.width = diameter;
  15. this.height = diameter;
  16. this.radius = this.width / 2;
  17. }
  18. }
  19. draw(ctx, x, y, selected, hover) {
  20. this.resize(ctx, selected);
  21. this.left = x - this.width / 2;
  22. this.top = y - this.height / 2;
  23. this._drawRawCircle(ctx, x, y, selected, hover, this.options.size);
  24. this.boundingBox.top = y - this.options.size;
  25. this.boundingBox.left = x - this.options.size;
  26. this.boundingBox.right = x + this.options.size;
  27. this.boundingBox.bottom = y + this.options.size;
  28. this.updateBoundingBox(x,y);
  29. this.labelModule.draw(ctx, this.left + this.textSize.width / 2 + this.margin.left,
  30. this.top + this.textSize.height / 2 + this.margin.top, selected);
  31. }
  32. updateBoundingBox(x,y) {
  33. this.boundingBox.top = y - this.options.size;
  34. this.boundingBox.left = x - this.options.size;
  35. this.boundingBox.right = x + this.options.size;
  36. this.boundingBox.bottom = y + this.options.size;
  37. }
  38. distanceToBorder(ctx, angle) {
  39. this.resize(ctx);
  40. return this.width * 0.5;
  41. }
  42. }
  43. export default Circle;