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.

55 lines
1.8 KiB

  1. 'use strict';
  2. import NodeBase from '../util/NodeBase'
  3. class Database extends NodeBase {
  4. constructor (options, body, labelModule) {
  5. super(options, body, labelModule);
  6. }
  7. resize(ctx, selected) {
  8. if (this.width === undefined) {
  9. var margin = 5;
  10. var textSize = this.labelModule.getTextSize(ctx, selected);
  11. var size = textSize.width + 2 * margin;
  12. this.width = size;
  13. this.height = size;
  14. }
  15. }
  16. draw(ctx, x, y, selected, hover) {
  17. this.resize(ctx, selected);
  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 = (this.selected ? selectionLineWidth : borderWidth);
  24. ctx.lineWidth *= this.networkScaleInv;
  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.database(x - this.width / 2, y - this.height * 0.5, this.width, this.height);
  28. ctx.fill();
  29. ctx.stroke();
  30. this.boundingBox.top = this.top;
  31. this.boundingBox.left = this.left;
  32. this.boundingBox.right = this.left + this.width;
  33. this.boundingBox.bottom = this.top + this.height;
  34. this.labelModule.draw(ctx, x, y, selected);
  35. }
  36. distanceToBorder(ctx, angle) {
  37. this.resize(ctx);
  38. var a = this.width / 2;
  39. var b = this.height / 2;
  40. var w = (Math.sin(angle) * a);
  41. var h = (Math.cos(angle) * b);
  42. return a * b / Math.sqrt(w * w + h * h);
  43. }
  44. }
  45. export default Database;