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.

51 lines
1.9 KiB

  1. /**
  2. * Created by Alex on 3/19/2015.
  3. */
  4. import BaseNode from '../util/baseNode'
  5. class ShapeUtil extends BaseNode {
  6. constructor(options, body, labelModule) {
  7. super(options, body, labelModule)
  8. }
  9. _resizeShape() {
  10. if (this.width === undefined) {
  11. var size = 2 * this.options.size;
  12. this.width = size;
  13. this.height = size;
  14. }
  15. }
  16. _drawShape(ctx, shape, sizeMultiplier, x, y, selected, hover) {
  17. this._resizeShape();
  18. this.left = x - this.width / 2;
  19. this.top = y - this.height / 2;
  20. var borderWidth = this.options.borderWidth;
  21. var selectionLineWidth = this.options.borderWidthSelected || 2 * this.options.borderWidth;
  22. ctx.strokeStyle = selected ? this.options.color.highlight.border : hover ? this.options.color.hover.border : this.options.color.border;
  23. ctx.lineWidth = (selected ? selectionLineWidth : borderWidth);
  24. ctx.lineWidth /= this.body.view.scale;
  25. ctx.lineWidth = Math.min(this.width, ctx.lineWidth);
  26. ctx.fillStyle = selected ? this.options.color.highlight.background : hover ? this.options.color.hover.background : this.options.color.background;
  27. ctx[shape](x, y, this.options.size);
  28. ctx.fill();
  29. ctx.stroke();
  30. this.boundingBox.top = y - this.options.size;
  31. this.boundingBox.left = x - this.options.size;
  32. this.boundingBox.right = x + this.options.size;
  33. this.boundingBox.bottom = y + this.options.size;
  34. if (this.options.label!== undefined) {
  35. this.labelModule.draw(ctx, x, y + 0.5* this.height, selected, 'hanging');
  36. this.boundingBox.left = Math.min(this.boundingBox.left, this.labelModule.size.left);
  37. this.boundingBox.right = Math.max(this.boundingBox.right, this.labelModule.size.left + this.labelModule.size.width);
  38. this.boundingBox.bottom = Math.max(this.boundingBox.bottom, this.boundingBox.bottom + this.labelModule.size.height);
  39. }
  40. }
  41. }
  42. export default ShapeUtil;