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.

70 lines
1.9 KiB

  1. /**
  2. * Created by Alex on 3/18/2015.
  3. */
  4. 'use strict';
  5. import drawUtil from '../util/drawUtil'
  6. class CircularImage extends drawUtil {
  7. constructor (options, body, labelModule, imageObj) {
  8. super(options, body, labelModule);
  9. this.imageObj = imageObj;
  10. }
  11. resize(ctx) {
  12. if (this.imageObj.src !== undefined || this.imageObj.width !== undefined || this.imageObj.height !== undefined ) {
  13. if (!this.width) {
  14. var diameter = this.options.size * 2;
  15. this.width = diameter;
  16. this.height = diameter;
  17. this._swapToImageResizeWhenImageLoaded = true;
  18. }
  19. }
  20. else {
  21. if (this._swapToImageResizeWhenImageLoaded) {
  22. this.width = 0;
  23. this.height = 0;
  24. delete this._swapToImageResizeWhenImageLoaded;
  25. }
  26. this._resizeImage(ctx);
  27. }
  28. }
  29. draw(ctx, x, y, selected, hover) {
  30. this.resize(ctx);
  31. this.left = x - this.width / 2;
  32. this.top = y - this.height / 2;
  33. var size = Math.abs(this.height / 2);
  34. this._drawRawCircle(ctx, x, y, selected, hover, size);
  35. ctx.save();
  36. ctx.circle(x, y, size);
  37. ctx.stroke();
  38. ctx.clip();
  39. this._drawImageAtPosition(ctx);
  40. ctx.restore();
  41. this.boundingBox.top = y - this.options.size;
  42. this.boundingBox.left = x - this.options.size;
  43. this.boundingBox.right = x + this.options.size;
  44. this.boundingBox.bottom = y + this.options.size;
  45. this._drawImageLabel(ctx, x, y, selected);
  46. this.boundingBox.left = Math.min(this.boundingBox.left, this.labelModule.size.left);
  47. this.boundingBox.right = Math.max(this.boundingBox.right, this.labelModule.size.left + this.labelModule.size.width);
  48. this.boundingBox.bottom = Math.max(this.boundingBox.bottom, this.boundingBox.bottom + this.labelModule.size.height);
  49. }
  50. distanceToBorder(ctx, angle) {
  51. this.resize(ctx);
  52. return this._distanceToBorder(angle);
  53. }
  54. }
  55. export default CircularImage;