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.7 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 = this.selected, hover = this.hover, values = { size: this.options.size}) {
  9. if ((this.width === undefined) || (this.labelModule.differentState(selected, hover))) {
  10. this.textSize = this.labelModule.getTextSize(ctx, selected, hover);
  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, values) {
  20. this.resize(ctx, selected, hover);
  21. this.left = x - this.width / 2;
  22. this.top = y - this.height / 2;
  23. this._drawRawCircle(ctx, x, y, selected, hover, values);
  24. this.boundingBox.top = y - values.size;
  25. this.boundingBox.left = x - values.size;
  26. this.boundingBox.right = x + values.size;
  27. this.boundingBox.bottom = y + values.size;
  28. this.updateBoundingBox(x,y);
  29. this.labelModule.draw(ctx, this.left + this.textSize.width / 2 + this.margin.left,
  30. y, selected, hover);
  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;