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.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. this._setMargins(labelModule);
  7. }
  8. resize(ctx, selected = this.selected, hover = this.hover) {
  9. if (this.needsRefresh(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, values);
  24. this.updateBoundingBox(x,y);
  25. this.labelModule.draw(ctx, this.left + this.textSize.width / 2 + this.margin.left,
  26. y, selected, hover);
  27. }
  28. updateBoundingBox(x,y) {
  29. this.boundingBox.top = y - this.options.size;
  30. this.boundingBox.left = x - this.options.size;
  31. this.boundingBox.right = x + this.options.size;
  32. this.boundingBox.bottom = y + this.options.size;
  33. }
  34. distanceToBorder(ctx, angle) {
  35. this.resize(ctx);
  36. return this.width * 0.5;
  37. }
  38. }
  39. export default Circle;