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.

58 lines
1.6 KiB

  1. 'use strict';
  2. import CircleImageBase from '../util/CircleImageBase'
  3. /**
  4. * A Circle Node/Cluster shape.
  5. *
  6. * @param {Object} options
  7. * @param {Object} body
  8. * @param {Label} labelModule
  9. * @constructor Circle
  10. * @extends CircleImageBase
  11. */
  12. class Circle extends CircleImageBase {
  13. constructor(options, body, labelModule) {
  14. super(options, body, labelModule);
  15. this._setMargins(labelModule);
  16. }
  17. resize(ctx, selected = this.selected, hover = this.hover) {
  18. if (this.needsRefresh(selected, hover)) {
  19. this.textSize = this.labelModule.getTextSize(ctx, selected, hover);
  20. var diameter = Math.max(this.textSize.width + this.margin.right + this.margin.left,
  21. this.textSize.height + this.margin.top + this.margin.bottom);
  22. this.options.size = diameter / 2;
  23. this.width = diameter;
  24. this.height = diameter;
  25. this.radius = this.width / 2;
  26. }
  27. }
  28. draw(ctx, x, y, selected, hover, values) {
  29. this.resize(ctx, selected, hover);
  30. this.left = x - this.width / 2;
  31. this.top = y - this.height / 2;
  32. this._drawRawCircle(ctx, x, y, values);
  33. this.updateBoundingBox(x,y);
  34. this.labelModule.draw(ctx, this.left + this.textSize.width / 2 + this.margin.left,
  35. y, selected, hover);
  36. }
  37. updateBoundingBox(x,y) {
  38. this.boundingBox.top = y - this.options.size;
  39. this.boundingBox.left = x - this.options.size;
  40. this.boundingBox.right = x + this.options.size;
  41. this.boundingBox.bottom = y + this.options.size;
  42. }
  43. distanceToBorder(ctx, angle) { // eslint-disable-line no-unused-vars
  44. this.resize(ctx);
  45. return this.width * 0.5;
  46. }
  47. }
  48. export default Circle;