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.

85 lines
2.8 KiB

Network: Fix handling of multi-fonts (#3486) * The next fix on Travis unit test failure This is the next escalation on the war against the Travis unit tests failing (which came into being by yours truly). By accident, I could recreate the unit test failure on my development machine. This led to a more directed effort to squash the bug. The insight here is that test `(window === undefined)` fails, but `(typeof window === 'undefined`)` succeeds. This undoubtedly has to do with the special status `window` has as a global object. Changes: - Added check on presence of `window` in `Canvas._requestNextFrame()`, fixed local source errors. - Added catch clause in `CanvasRendered._determinePixelRatio()` - small fix: raised timeout for the network `worldCup2014` unit test * Preliminary refactoring in utils.js * Added unit tests for extend routines, commenting and small fixes * More unit tests for extend routines * - Completed unit tests for extend routines in - Small fixes and cleanup in `util.js` - Removed `util.protoExtend()`, not used anywhere * Added unit tests for known font options * Interim save before trying out another proto chain strategy * Fixed problem in first example #3408 * Removed silly file that shouldn't be there * Added unit test for multi-fonts * Comment edits * Verufy unit tests, small adjustments for groups * Further work on getting unit tests to work. PARTS NEED TO BE CLEANED UP! * Further tweaks to get unit tests working * All unit tests passing * Fixes due to linting * Small edits * Removed prototype handling from font pile * Fixes during testing examples of #3408 * Added unit test for edge labels, small fixes * Added unit tests for shorthand string fonts; some tests still failing * All unit tests pass * Removed Label.parseOptions() * Completed shorthand font tests, code cleanup, fixed choosify for edges * Addressed review comments * Addressed review comments, cleanup
7 years ago
Network: Fix handling of multi-fonts (#3486) * The next fix on Travis unit test failure This is the next escalation on the war against the Travis unit tests failing (which came into being by yours truly). By accident, I could recreate the unit test failure on my development machine. This led to a more directed effort to squash the bug. The insight here is that test `(window === undefined)` fails, but `(typeof window === 'undefined`)` succeeds. This undoubtedly has to do with the special status `window` has as a global object. Changes: - Added check on presence of `window` in `Canvas._requestNextFrame()`, fixed local source errors. - Added catch clause in `CanvasRendered._determinePixelRatio()` - small fix: raised timeout for the network `worldCup2014` unit test * Preliminary refactoring in utils.js * Added unit tests for extend routines, commenting and small fixes * More unit tests for extend routines * - Completed unit tests for extend routines in - Small fixes and cleanup in `util.js` - Removed `util.protoExtend()`, not used anywhere * Added unit tests for known font options * Interim save before trying out another proto chain strategy * Fixed problem in first example #3408 * Removed silly file that shouldn't be there * Added unit test for multi-fonts * Comment edits * Verufy unit tests, small adjustments for groups * Further work on getting unit tests to work. PARTS NEED TO BE CLEANED UP! * Further tweaks to get unit tests working * All unit tests passing * Fixes due to linting * Small edits * Removed prototype handling from font pile * Fixes during testing examples of #3408 * Added unit test for edge labels, small fixes * Added unit tests for shorthand string fonts; some tests still failing * All unit tests pass * Removed Label.parseOptions() * Completed shorthand font tests, code cleanup, fixed choosify for edges * Addressed review comments * Addressed review comments, cleanup
7 years ago
  1. let util = require("../../../../util");
  2. let Node = require("../Node").default;
  3. /**
  4. * A Cluster is a special Node that allows a group of Nodes positioned closely together
  5. * to be represented by a single Cluster Node.
  6. *
  7. * @extends Node
  8. */
  9. class Cluster extends Node {
  10. /**
  11. * @param {Object} options
  12. * @param {Object} body
  13. * @param {Array.<HTMLImageElement>}imagelist
  14. * @param {Array} grouplist
  15. * @param {Object} globalOptions
  16. * @param {Object} defaultOptions Global default options for nodes
  17. */
  18. constructor(options, body, imagelist, grouplist, globalOptions, defaultOptions) {
  19. super(options, body, imagelist, grouplist, globalOptions, defaultOptions);
  20. this.isCluster = true;
  21. this.containedNodes = {};
  22. this.containedEdges = {};
  23. }
  24. /**
  25. * Transfer child cluster data to current and disconnect the child cluster.
  26. *
  27. * Please consult the header comment in 'Clustering.js' for the fields set here.
  28. *
  29. * @param {string|number} childClusterId id of child cluster to open
  30. */
  31. _openChildCluster(childClusterId) {
  32. let childCluster = this.body.nodes[childClusterId];
  33. if (this.containedNodes[childClusterId] === undefined) {
  34. throw new Error('node with id: ' + childClusterId + ' not in current cluster');
  35. }
  36. if (!childCluster.isCluster) {
  37. throw new Error('node with id: ' + childClusterId + ' is not a cluster');
  38. }
  39. // Disconnect child cluster from current cluster
  40. delete this.containedNodes[childClusterId];
  41. util.forEach(childCluster.edges, (edge) => {
  42. delete this.containedEdges[edge.id];
  43. });
  44. // Transfer nodes and edges
  45. util.forEach(childCluster.containedNodes, (node, nodeId) => {
  46. this.containedNodes[nodeId] = node;
  47. });
  48. childCluster.containedNodes = {};
  49. util.forEach(childCluster.containedEdges, (edge, edgeId) => {
  50. this.containedEdges[edgeId] = edge;
  51. });
  52. childCluster.containedEdges = {};
  53. // Transfer edges within cluster edges which are clustered
  54. util.forEach(childCluster.edges, (clusterEdge) => {
  55. util.forEach(this.edges, (parentClusterEdge) => {
  56. // Assumption: a clustered edge can only be present in a single clustering edge
  57. // Not tested here
  58. let index = parentClusterEdge.clusteringEdgeReplacingIds.indexOf(clusterEdge.id);
  59. if (index === -1) return;
  60. util.forEach(clusterEdge.clusteringEdgeReplacingIds, (srcId) => {
  61. parentClusterEdge.clusteringEdgeReplacingIds.push(srcId);
  62. // Maintain correct bookkeeping for transferred edge
  63. this.body.edges[srcId].edgeReplacedById = parentClusterEdge.id;
  64. });
  65. // Remove cluster edge from parent cluster edge
  66. parentClusterEdge.clusteringEdgeReplacingIds.splice(index, 1);
  67. });
  68. });
  69. childCluster.edges = [];
  70. }
  71. }
  72. export default Cluster;