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.

71 lines
2.0 KiB

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