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.

54 lines
1.6 KiB

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