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.

45 lines
1.3 KiB

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