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.

73 lines
2.3 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. this.radius = 0.5*this.width;
  15. }
  16. }
  17. draw(ctx, x, y, selected, hover) {
  18. this.resize(ctx, selected);
  19. this.left = x - this.width / 2;
  20. this.top = y - this.height / 2;
  21. var borderWidth = this.options.borderWidth;
  22. var selectionLineWidth = this.options.borderWidthSelected || 2 * this.options.borderWidth;
  23. ctx.strokeStyle = selected ? this.options.color.highlight.border : hover ? this.options.color.hover.border : this.options.color.border;
  24. ctx.lineWidth = (this.selected ? selectionLineWidth : borderWidth);
  25. ctx.lineWidth *= this.networkScaleInv;
  26. ctx.lineWidth = Math.min(this.width, ctx.lineWidth);
  27. ctx.fillStyle = selected ? this.options.color.highlight.background : hover ? this.options.color.hover.background : this.options.color.background;
  28. ctx.database(x - this.width / 2, y - this.height * 0.5, this.width, this.height);
  29. // draw shadow if enabled
  30. this.enableShadow(ctx);
  31. // draw the background
  32. ctx.fill();
  33. // disable shadows for other elements.
  34. this.disableShadow(ctx);
  35. //draw dashed border if enabled, save and restore is required for firefox not to crash on unix.
  36. ctx.save();
  37. this.enableBorderDashes(ctx);
  38. //draw the border
  39. ctx.stroke();
  40. //disable dashed border for other elements
  41. this.disableBorderDashes(ctx);
  42. ctx.restore();
  43. this.updateBoundingBox(x,y,ctx,selected);
  44. this.labelModule.draw(ctx, x, y, selected);
  45. }
  46. updateBoundingBox(x,y,ctx, selected) {
  47. this.resize(ctx, selected);
  48. this.left = x - this.width * 0.5;
  49. this.top = y - this.height * 0.5;
  50. this.boundingBox.left = this.left;
  51. this.boundingBox.top = this.top;
  52. this.boundingBox.bottom = this.top + this.height;
  53. this.boundingBox.right = this.left + this.width;
  54. }
  55. distanceToBorder(ctx, angle) {
  56. return this._distanceToBorder(ctx,angle);
  57. }
  58. }
  59. export default Database;