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