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.

77 lines
2.0 KiB

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