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.

73 lines
2.3 KiB

  1. /**
  2. * Created by Alex on 3/19/2015.
  3. */
  4. import NodeBase from '../util/NodeBase'
  5. class CircleImageBase extends NodeBase {
  6. constructor(options, body, labelModule) {
  7. super(options, body, labelModule);
  8. }
  9. _resizeImage() {
  10. if (!this.width || !this.height) { // undefined or 0
  11. var width, height, ratio;
  12. if (this.imageObj.width && this.imageObj.height) { // not undefined or 0
  13. width = 0;
  14. height = 0;
  15. }
  16. if (this.imageObj.width > this.imageObj.height) {
  17. ratio = this.imageObj.width / this.imageObj.height;
  18. width = this.options.size * 2 * ratio || this.imageObj.width;
  19. height = this.options.size * 2 || this.imageObj.height;
  20. }
  21. else {
  22. ratio = this.imageObj.height / this.imageObj.width;
  23. width = this.options.size * 2 || this.imageObj.width;
  24. height = this.options.size * 2 * ratio || this.imageObj.height;
  25. }
  26. this.width = width;
  27. this.height = height;
  28. }
  29. }
  30. _drawRawCircle(ctx, x, y, selected, hover, size) {
  31. var borderWidth = this.options.borderWidth;
  32. var selectionLineWidth = this.options.borderWidthSelected || 2 * this.options.borderWidth;
  33. ctx.strokeStyle = selected ? this.options.color.highlight.border : hover ? this.options.color.hover.border : this.options.color.border;
  34. ctx.lineWidth = (selected ? selectionLineWidth : borderWidth);
  35. ctx.lineWidth *= this.networkScaleInv;
  36. ctx.lineWidth = Math.min(this.width, ctx.lineWidth);
  37. ctx.fillStyle = selected ? this.options.color.highlight.background : hover ? this.options.color.hover.background : this.options.color.background;
  38. ctx.circle(x, y, size);
  39. ctx.fill();
  40. ctx.stroke();
  41. }
  42. _drawImageAtPosition(ctx) {
  43. if (this.imageObj.width != 0) {
  44. // draw the image
  45. ctx.globalAlpha = 1.0;
  46. ctx.drawImage(this.imageObj, this.left, this.top, this.width, this.height);
  47. }
  48. }
  49. _drawImageLabel(ctx, x, y, selected) {
  50. var yLabel;
  51. var offset = 0;
  52. if (this.height !== undefined) {
  53. offset = this.height * 0.5;
  54. var labelDimensions = this.labelModule.getTextSize(ctx);
  55. if (labelDimensions.lineCount >= 1) {
  56. offset += labelDimensions.height / 2;
  57. }
  58. }
  59. yLabel = y + offset;
  60. this.labelModule.draw(ctx, x, yLabel, selected, 'hanging');
  61. }
  62. }
  63. export default CircleImageBase;