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.

42 lines
1.2 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.boundingBox.top = this.top;
  17. this.boundingBox.left = this.left;
  18. this.boundingBox.right = this.left + this.width;
  19. this.boundingBox.bottom = this.top + this.height;
  20. this._drawImageLabel(ctx, x, y, selected || hover);
  21. this.boundingBox.left = Math.min(this.boundingBox.left, this.labelModule.size.left);
  22. this.boundingBox.right = Math.max(this.boundingBox.right, this.labelModule.size.left + this.labelModule.size.width);
  23. this.boundingBox.bottom = Math.max(this.boundingBox.bottom, this.boundingBox.bottom + this.labelModule.size.height);
  24. }
  25. distanceToBorder(ctx, angle) {
  26. this.resize(ctx);
  27. var a = this.width / 2;
  28. var b = this.height / 2;
  29. var w = (Math.sin(angle) * a);
  30. var h = (Math.cos(angle) * b);
  31. return a * b / Math.sqrt(w * w + h * h);
  32. }
  33. }
  34. export default Image;