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
2.3 KiB

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