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.

52 lines
1.4 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.left = x - this.width / 2;
  21. this.top = y - this.height / 2;
  22. this.boundingBox.top = this.top;
  23. this.boundingBox.left = this.left;
  24. this.boundingBox.right = this.left + this.width;
  25. this.boundingBox.bottom = this.top + this.height;
  26. if (this.options.label !== undefined) {
  27. this.boundingBox.left = Math.min(this.boundingBox.left, this.labelModule.size.left);
  28. this.boundingBox.right = Math.max(this.boundingBox.right, this.labelModule.size.left + this.labelModule.size.width);
  29. this.boundingBox.bottom = Math.max(this.boundingBox.bottom, this.boundingBox.bottom + this.labelOffset);
  30. }
  31. }
  32. distanceToBorder(ctx, angle) {
  33. this.resize(ctx);
  34. var a = this.width / 2;
  35. var b = this.height / 2;
  36. var w = (Math.sin(angle) * a);
  37. var h = (Math.cos(angle) * b);
  38. return a * b / Math.sqrt(w * w + h * h);
  39. }
  40. }
  41. export default Image;