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.

83 lines
2.5 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. // draw shadow if enabled
  37. this.enableShadow(ctx);
  38. ctx.fill();
  39. // disable shadows for other elements.
  40. this.disableShadow(ctx);
  41. ctx.stroke();
  42. }
  43. _drawImageAtPosition(ctx) {
  44. if (this.imageObj.width != 0) {
  45. // draw the image
  46. ctx.globalAlpha = 1.0;
  47. // draw shadow if enabled
  48. this.enableShadow(ctx);
  49. ctx.drawImage(this.imageObj, this.left, this.top, this.width, this.height);
  50. // disable shadows for other elements.
  51. this.disableShadow(ctx);
  52. }
  53. }
  54. _drawImageLabel(ctx, x, y, selected) {
  55. var yLabel;
  56. var offset = 0;
  57. if (this.height !== undefined) {
  58. offset = this.height * 0.5;
  59. var labelDimensions = this.labelModule.getTextSize(ctx);
  60. if (labelDimensions.lineCount >= 1) {
  61. offset += labelDimensions.height / 2;
  62. }
  63. }
  64. yLabel = y + offset;
  65. this.labelModule.draw(ctx, x, yLabel, selected, 'hanging');
  66. }
  67. }
  68. export default CircleImageBase;