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.

53 lines
1.5 KiB

  1. 'use strict';
  2. import CircleImageBase from '../util/CircleImageBase'
  3. class Image extends CircleImageBase {
  4. constructor (options, body, labelModule, imageObj) {
  5. super(options, body, labelModule);
  6. this.imageObj = imageObj;
  7. }
  8. resize() {
  9. this._resizeImage();
  10. }
  11. draw(ctx, x, y, selected, hover) {
  12. this.resize();
  13. this.left = x - this.width / 2;
  14. this.top = y - this.height / 2;
  15. this._drawImageAtPosition(ctx);
  16. this._drawImageLabel(ctx, x, y, selected || hover);
  17. this.updateBoundingBox(x,y);
  18. }
  19. updateBoundingBox(x,y) {
  20. this.resize();
  21. this.left = x - this.width / 2;
  22. this.top = y - this.height / 2;
  23. this.boundingBox.top = this.top;
  24. this.boundingBox.left = this.left;
  25. this.boundingBox.right = this.left + this.width;
  26. this.boundingBox.bottom = this.top + this.height;
  27. if (this.options.label !== undefined && this.labelModule.size.width > 0) {
  28. this.boundingBox.left = Math.min(this.boundingBox.left, this.labelModule.size.left);
  29. this.boundingBox.right = Math.max(this.boundingBox.right, this.labelModule.size.left + this.labelModule.size.width);
  30. this.boundingBox.bottom = Math.max(this.boundingBox.bottom, this.boundingBox.bottom + this.labelOffset);
  31. }
  32. }
  33. distanceToBorder(ctx, angle) {
  34. this.resize(ctx);
  35. var a = this.width / 2;
  36. var b = this.height / 2;
  37. var w = (Math.sin(angle) * a);
  38. var h = (Math.cos(angle) * b);
  39. return a * b / Math.sqrt(w * w + h * h);
  40. }
  41. }
  42. export default Image;