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.

55 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) {
  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. // TODO: values overwritten by updateBoundingBox(); is this bit necessary?
  25. this.boundingBox.top = y - values.size;
  26. this.boundingBox.left = x - values.size;
  27. this.boundingBox.right = x + values.size;
  28. this.boundingBox.bottom = y + values.size;
  29. this.updateBoundingBox(x,y);
  30. this.labelModule.draw(ctx, this.left + this.textSize.width / 2 + this.margin.left,
  31. y, selected, hover);
  32. }
  33. updateBoundingBox(x,y) {
  34. this.boundingBox.top = y - this.options.size;
  35. this.boundingBox.left = x - this.options.size;
  36. this.boundingBox.right = x + this.options.size;
  37. this.boundingBox.bottom = y + this.options.size;
  38. }
  39. distanceToBorder(ctx, angle) {
  40. this.resize(ctx);
  41. return this.width * 0.5;
  42. }
  43. }
  44. export default Circle;