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.

1626 lines
45 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
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
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
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
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
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
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
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
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
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
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. /**
  2. * TODO - add tests for:
  3. * ====
  4. *
  5. * - html unclosed or unopened tags
  6. * - html tag combinations with no font defined (e.g. bold within mono)
  7. * - Unit tests for bad font shorthands.
  8. * Currently, only "size[px] name color" is valid, always 3 items with this exact spacing.
  9. * All other combinations should either be rejected as error or handled gracefully.
  10. */
  11. var assert = require('assert')
  12. var Label = require('../lib/network/modules/components/shared/Label').default;
  13. var NodesHandler = require('../lib/network/modules/NodesHandler').default;
  14. var util = require('../lib/util');
  15. var jsdom_global = require('jsdom-global');
  16. var canvasMockify = require('./canvas-mock');
  17. var vis = require('../dist/vis');
  18. var Network = vis.network;
  19. /**************************************************************
  20. * Dummy class definitions for minimal required functionality.
  21. **************************************************************/
  22. class DummyContext {
  23. measureText(text) {
  24. return {
  25. width: 12*text.length,
  26. height: 14
  27. };
  28. }
  29. }
  30. class DummyLayoutEngine {
  31. positionInitially() {}
  32. }
  33. /**************************************************************
  34. * End Dummy class definitions
  35. **************************************************************/
  36. describe('Network Label', function() {
  37. /**
  38. * Retrieve options object from a NodesHandler instance
  39. *
  40. * NOTE: these are options at the node-level
  41. */
  42. function getOptions(options = {}) {
  43. var body = {
  44. functions: {},
  45. emitter: {
  46. on: function() {}
  47. }
  48. }
  49. var nodesHandler = new NodesHandler(body, {}, options, new DummyLayoutEngine() );
  50. //console.log(JSON.stringify(nodesHandler.options, null, 2));
  51. return nodesHandler.options;
  52. }
  53. /**
  54. * Check if the returned lines and blocks are as expected.
  55. *
  56. * All width/height fields and font info are ignored.
  57. * Within blocks, only the text is compared
  58. */
  59. function checkBlocks(returned, expected) {
  60. let showBlocks = () => {
  61. return '\nreturned: ' + JSON.stringify(returned, null, 2) + '\n' +
  62. 'expected: ' + JSON.stringify(expected, null, 2);
  63. }
  64. assert.equal(expected.lines.length, returned.lines.length, 'Number of lines does not match, ' + showBlocks());
  65. for (let i = 0; i < returned.lines.length; ++i) {
  66. let retLine = returned.lines[i];
  67. let expLine = expected.lines[i];
  68. assert(retLine.blocks.length === expLine.blocks.length, 'Number of blocks does not match, ' + showBlocks());
  69. for (let j = 0; j < retLine.blocks.length; ++j) {
  70. let retBlock = retLine.blocks[j];
  71. let expBlock = expLine.blocks[j];
  72. assert(retBlock.text === expBlock.text, 'Text does not match, ' + showBlocks());
  73. assert(retBlock.mod !== undefined);
  74. if (retBlock.mod === 'normal' || retBlock.mod === '') {
  75. assert(expBlock.mod === undefined || expBlock.mod === 'normal' || expBlock === '',
  76. 'No mod field expected in returned, ' + showBlocks());
  77. } else {
  78. assert(retBlock.mod === expBlock.mod, 'Mod fields do not match, line: ' + i + ', block: ' + j +
  79. '; ret: ' + retBlock.mod + ', exp: ' + expBlock.mod + '\n' + showBlocks());
  80. }
  81. }
  82. }
  83. }
  84. function checkProcessedLabels(label, text, expected) {
  85. var ctx = new DummyContext();
  86. for (var i in text) {
  87. var ret = label._processLabelText(ctx, false, false, text[i]);
  88. //console.log(JSON.stringify(ret, null, 2));
  89. checkBlocks(ret, expected[i]);
  90. }
  91. }
  92. /**************************************************************
  93. * Test data
  94. **************************************************************/
  95. var normal_text = [
  96. "label text",
  97. "label\nwith\nnewlines",
  98. "OnereallylongwordthatshouldgooverwidthConstraint.maximumifdefined",
  99. "One really long sentence that should go over widthConstraint.maximum if defined",
  100. "Reallyoneenormouslylargelabel withtwobigwordsgoingoverwayovermax"
  101. ]
  102. var html_text = [
  103. "label <b>with</b> <code>some</code> <i>multi <b>tags</b></i>",
  104. "label <b>with</b> <code>some</code> \n <i>multi <b>tags</b></i>\n and newlines" // NB spaces around \n's
  105. ];
  106. var markdown_text = [
  107. "label *with* `some` _multi *tags*_",
  108. "label *with* `some` \n _multi *tags*_\n and newlines" // NB spaces around \n's
  109. ];
  110. /**************************************************************
  111. * Expected Results
  112. **************************************************************/
  113. var normal_expected = [{
  114. // In first item, width/height kept in for reference
  115. width: 120,
  116. height: 14,
  117. lines: [{
  118. width: 120,
  119. height: 14,
  120. blocks: [{
  121. text: "label text",
  122. width: 120,
  123. height: 14,
  124. }]
  125. }]
  126. }, {
  127. lines: [{
  128. blocks: [{text: "label"}]
  129. }, {
  130. blocks: [{text: "with"}]
  131. }, {
  132. blocks: [{text: "newlines"}]
  133. }]
  134. }, {
  135. // From here onward, changes width max width set
  136. lines: [{
  137. blocks: [{text: "OnereallylongwordthatshouldgooverwidthConstraint.maximumifdefined"}]
  138. }]
  139. }, {
  140. lines: [{
  141. blocks: [{text: "One really long sentence that should go over widthConstraint.maximum if defined"}]
  142. }]
  143. }, {
  144. lines: [{
  145. blocks: [{text: "Reallyoneenormouslylargelabel withtwobigwordsgoingoverwayovermax"}]
  146. }]
  147. }];
  148. const indexWidthConstrained = 2; // index of first item that will be different with max width set
  149. var normal_widthConstraint_expected = normal_expected.slice(0, indexWidthConstrained);
  150. Array.prototype.push.apply(normal_widthConstraint_expected, [{
  151. lines: [{
  152. blocks: [{text: "Onereallylongwordthatshoul"}]
  153. }, {
  154. blocks: [{text: "dgooverwidthConstraint.max"}]
  155. }, {
  156. blocks: [{text: "imumifdefined"}]
  157. }]
  158. }, {
  159. lines: [{
  160. blocks: [{text: "One really long"}]
  161. }, {
  162. blocks: [{text: "sentence that should"}]
  163. }, {
  164. blocks: [{text: "go over"}]
  165. }, {
  166. blocks: [{text: "widthConstraint.maximum"}]
  167. }, {
  168. blocks: [{text: "if defined"}]
  169. }]
  170. }, {
  171. lines: [{
  172. blocks: [{text: "Reallyoneenormouslylargela"}]
  173. }, {
  174. blocks: [{text: "bel"}]
  175. }, {
  176. blocks: [{text: "withtwobigwordsgoingoverwa"}]
  177. }, {
  178. blocks: [{text: "yovermax"}]
  179. }]
  180. }]);
  181. var html_unchanged_expected = [{
  182. lines: [{
  183. blocks: [{text: "label <b>with</b> <code>some</code> <i>multi <b>tags</b></i>"}]
  184. }]
  185. }, {
  186. lines: [{
  187. blocks: [{text: "label <b>with</b> <code>some</code> "}]
  188. }, {
  189. blocks: [{text: " <i>multi <b>tags</b></i>"}]
  190. }, {
  191. blocks: [{text: " and newlines"}]
  192. }]
  193. }];
  194. var html_widthConstraint_unchanged = [{
  195. lines: [{
  196. blocks: [{text: "label <b>with</b>"}]
  197. }, {
  198. blocks: [{text: "<code>some</code>"}]
  199. }, {
  200. blocks: [{text: "<i>multi"}]
  201. }, {
  202. blocks: [{text: "<b>tags</b></i>"}]
  203. }]
  204. }, {
  205. lines: [{
  206. blocks: [{text: "label <b>with</b>"}]
  207. }, {
  208. blocks: [{text: "<code>some</code> "}]
  209. }, {
  210. blocks: [{text: " <i>multi"}]
  211. }, {
  212. blocks: [{text: "<b>tags</b></i>"}]
  213. }, {
  214. blocks: [{text: " and newlines"}]
  215. }]
  216. }];
  217. var markdown_unchanged_expected = [{
  218. lines: [{
  219. blocks: [{text: "label *with* `some` _multi *tags*_"}]
  220. }]
  221. }, {
  222. lines: [{
  223. blocks: [{text: "label *with* `some` "}]
  224. }, {
  225. blocks: [{text: " _multi *tags*_"}]
  226. }, {
  227. blocks: [{text: " and newlines"}]
  228. }]
  229. }];
  230. var markdown_widthConstraint_expected= [{
  231. lines: [{
  232. blocks: [{text: "label *with* `some`"}]
  233. }, {
  234. blocks: [{text: "_multi *tags*_"}]
  235. }]
  236. }, {
  237. lines: [{
  238. blocks: [{text: "label *with* `some` "}]
  239. }, {
  240. blocks: [{text: " _multi *tags*_"}]
  241. }, {
  242. blocks: [{text: " and newlines"}]
  243. }]
  244. }];
  245. var multi_expected = [{
  246. lines: [{
  247. blocks: [
  248. {text: "label "},
  249. {text: "with" , mod: 'bold'},
  250. {text: " "},
  251. {text: "some" , mod: 'mono'},
  252. {text: " "},
  253. {text: "multi ", mod: 'ital'},
  254. {text: "tags" , mod: 'boldital'}
  255. ]
  256. }]
  257. }, {
  258. lines: [{
  259. blocks: [
  260. {text: "label "},
  261. {text: "with" , mod: 'bold'},
  262. {text: " "},
  263. {text: "some" , mod: 'mono'},
  264. {text: " "}
  265. ]
  266. }, {
  267. blocks: [
  268. {text: " "},
  269. {text: "multi ", mod: 'ital'},
  270. {text: "tags" , mod: 'boldital'}
  271. ]
  272. }, {
  273. blocks: [{text: " and newlines"}]
  274. }]
  275. }];
  276. /**************************************************************
  277. * End Expected Results
  278. **************************************************************/
  279. before(function() {
  280. this.jsdom_global = jsdom_global(
  281. "<div id='mynetwork'></div>",
  282. { skipWindowCheck: true}
  283. );
  284. canvasMockify(window);
  285. this.container = document.getElementById('mynetwork');
  286. });
  287. after(function() {
  288. this.jsdom_global();
  289. });
  290. it('parses normal text labels', function (done) {
  291. var label = new Label({}, getOptions());
  292. checkProcessedLabels(label, normal_text , normal_expected);
  293. checkProcessedLabels(label, html_text , html_unchanged_expected); // html unchanged
  294. checkProcessedLabels(label, markdown_text, markdown_unchanged_expected); // markdown unchanged
  295. done();
  296. });
  297. it('parses html labels', function (done) {
  298. var options = getOptions(options);
  299. options.font.multi = true; // TODO: also test 'html', also test illegal value here
  300. var label = new Label({}, options);
  301. checkProcessedLabels(label, normal_text , normal_expected); // normal as usual
  302. checkProcessedLabels(label, html_text , multi_expected);
  303. checkProcessedLabels(label, markdown_text, markdown_unchanged_expected); // markdown unchanged
  304. done();
  305. });
  306. it('parses markdown labels', function (done) {
  307. var options = getOptions(options);
  308. options.font.multi = 'markdown'; // TODO: also test 'md', also test illegal value here
  309. var label = new Label({}, options);
  310. checkProcessedLabels(label, normal_text , normal_expected); // normal as usual
  311. checkProcessedLabels(label, html_text , html_unchanged_expected); // html unchanged
  312. checkProcessedLabels(label, markdown_text, multi_expected);
  313. done();
  314. });
  315. it('handles normal text with widthConstraint.maximum', function (done) {
  316. var options = getOptions(options);
  317. //
  318. // What the user would set:
  319. //
  320. // options.widthConstraint = { minimum: 100, maximum: 200};
  321. //
  322. // No sense in adding minWdt, not used when splitting labels into lines
  323. //
  324. // This comment also applies to the usage of maxWdt in the test cases below
  325. //
  326. options.font.maxWdt = 300;
  327. var label = new Label({}, options);
  328. checkProcessedLabels(label, normal_text , normal_widthConstraint_expected);
  329. checkProcessedLabels(label, html_text , html_widthConstraint_unchanged); // html unchanged
  330. // Following is an unlucky selection, because the first line broken on the final character (space)
  331. // So we cheat a bit here
  332. options.font.maxWdt = 320;
  333. label = new Label({}, options);
  334. checkProcessedLabels(label, markdown_text, markdown_widthConstraint_expected); // markdown unchanged
  335. done();
  336. });
  337. it('handles html tags with widthConstraint.maximum', function (done) {
  338. var options = getOptions(options);
  339. options.font.multi = true;
  340. options.font.maxWdt = 300;
  341. var label = new Label({}, options);
  342. checkProcessedLabels(label, normal_text , normal_widthConstraint_expected);
  343. checkProcessedLabels(label, html_text , multi_expected);
  344. // Following is an unlucky selection, because the first line broken on the final character (space)
  345. // So we cheat a bit here
  346. options.font.maxWdt = 320;
  347. label = new Label({}, options);
  348. checkProcessedLabels(label, markdown_text, markdown_widthConstraint_expected);
  349. done();
  350. });
  351. it('handles markdown tags with widthConstraint.maximum', function (done) {
  352. var options = getOptions(options);
  353. options.font.multi = 'markdown';
  354. options.font.maxWdt = 300;
  355. var label = new Label({}, options);
  356. checkProcessedLabels(label, normal_text , normal_widthConstraint_expected);
  357. checkProcessedLabels(label, html_text , html_widthConstraint_unchanged);
  358. checkProcessedLabels(label, markdown_text, multi_expected);
  359. done();
  360. });
  361. describe('Multi-Fonts', function() {
  362. class HelperNode {
  363. constructor(network) {
  364. this.nodes = network.body.nodes;
  365. }
  366. fontOption(index) {
  367. return this.nodes[index].labelModule.fontOptions;
  368. };
  369. modBold(index) {
  370. return this.fontOption(index).bold;
  371. };
  372. }
  373. describe('Node Labels', function() {
  374. function createNodeNetwork(newOptions) {
  375. var dataNodes = [
  376. {id: 0, label: '<b>0</b>'},
  377. {id: 1, label: '<b>1</b>'},
  378. {id: 2, label: '<b>2</b>', group: 'group1'},
  379. {id: 3, label: '<b>3</b>',
  380. font: {
  381. bold: { color: 'green' },
  382. }
  383. },
  384. {id: 4, label: '<b>4</b>', group: 'group1',
  385. font: {
  386. bold: { color: 'green' },
  387. }
  388. },
  389. ];
  390. // create a network
  391. var container = document.getElementById('mynetwork');
  392. var data = {
  393. nodes: new vis.DataSet(dataNodes),
  394. edges: []
  395. };
  396. var options = {
  397. nodes: {
  398. font: {
  399. multi: true
  400. }
  401. },
  402. groups: {
  403. group1: {
  404. font: { color: 'red' },
  405. },
  406. group2: {
  407. font: { color: 'white' },
  408. },
  409. },
  410. };
  411. if (newOptions !== undefined) {
  412. util.deepExtend(options, newOptions);
  413. }
  414. var network = new vis.Network(container, data, options);
  415. return [network, data, options];
  416. }
  417. /**
  418. * Check that setting options for multi-font works as expected
  419. *
  420. * - using multi-font 'bold' for test, the rest should work analogously
  421. * - using multi-font option 'color' for test, the rest should work analogously
  422. */
  423. it('respects the font option precedence', function (done) {
  424. var [network, data, options] = createNodeNetwork();
  425. var h = new HelperNode(network);
  426. assert.equal(h.modBold(0).color, '#343434'); // Default value
  427. assert.equal(h.modBold(1).color, '#343434'); // Default value
  428. assert.equal(h.modBold(2).color, 'red'); // Group value overrides default
  429. assert.equal(h.modBold(3).color, 'green'); // Local value overrides default
  430. assert.equal(h.modBold(4).color, 'green'); // Local value overrides group
  431. done();
  432. });
  433. it('handles dynamic data and option updates', function (done) {
  434. var [network, data, options] = createNodeNetwork();
  435. var h = new HelperNode(network);
  436. //
  437. // Change some node values dynamically
  438. //
  439. data.nodes.update([
  440. {id: 1, group: 'group2'},
  441. {id: 4, font: { bold: { color: 'orange'}}},
  442. ]);
  443. assert.equal(h.modBold(0).color, '#343434'); // unchanged
  444. assert.equal(h.modBold(1).color, 'white'); // new group value
  445. assert.equal(h.modBold(3).color, 'green'); // unchanged
  446. assert.equal(h.modBold(4).color, 'orange'); // new local value
  447. //
  448. // Change group options dynamically
  449. //
  450. network.setOptions({
  451. groups: {
  452. group1: {
  453. font: { color: 'brown' },
  454. },
  455. },
  456. });
  457. assert.equal(h.modBold(0).color, '#343434'); // unchanged
  458. assert.equal(h.modBold(1).color, 'white'); // Unchanged
  459. assert.equal(h.modBold(2).color, 'brown'); // New group values
  460. assert.equal(h.modBold(3).color, 'green'); // unchanged
  461. assert.equal(h.modBold(4).color, 'orange'); // unchanged
  462. network.setOptions({
  463. nodes: {
  464. font: {
  465. multi: true,
  466. bold: {
  467. color: 'black'
  468. }
  469. }
  470. },
  471. });
  472. assert.equal(h.modBold(0).color, 'black'); // nodes default
  473. assert.equal(h.modBold(1).color, 'black'); // more specific bold value overrides group value
  474. assert.equal(h.modBold(2).color, 'black'); // idem
  475. assert.equal(h.modBold(3).color, 'green'); // unchanged
  476. assert.equal(h.modBold(4).color, 'orange'); // unchanged
  477. network.setOptions({
  478. groups: {
  479. group1: {
  480. font: { bold: {color: 'brown'} },
  481. },
  482. },
  483. });
  484. assert.equal(h.modBold(0).color, 'black'); // nodes default
  485. assert.equal(h.modBold(1).color, 'black'); // more specific bold value overrides group value
  486. assert.equal(h.modBold(2).color, 'brown'); // bold group value overrides bold node value
  487. assert.equal(h.modBold(3).color, 'green'); // unchanged
  488. assert.equal(h.modBold(4).color, 'orange'); // unchanged
  489. done();
  490. });
  491. it('handles normal font values in default options', function (done) {
  492. var newOptions = {
  493. nodes: {
  494. font: {
  495. color: 'purple' // Override the default value
  496. }
  497. },
  498. };
  499. var [network, data, options] = createNodeNetwork(newOptions);
  500. var h = new HelperNode(network);
  501. assert.equal(h.modBold(0).color, 'purple'); // Nodes value
  502. assert.equal(h.modBold(1).color, 'purple'); // Nodes value
  503. assert.equal(h.modBold(2).color, 'red'); // Group value overrides nodes
  504. assert.equal(h.modBold(3).color, 'green'); // Local value overrides all
  505. assert.equal(h.modBold(4).color, 'green'); // Idem
  506. done();
  507. });
  508. it('handles multi-font values in default options/groups', function (done) {
  509. var newOptions = {
  510. nodes: {
  511. font: {
  512. color: 'purple' // This set value should be overridden
  513. }
  514. },
  515. };
  516. newOptions.nodes.font.bold = { color: 'yellow'};
  517. newOptions.groups = {
  518. group1: {
  519. font: { bold: { color: 'red'}}
  520. }
  521. };
  522. var [network, data, options] = createNodeNetwork(newOptions);
  523. var h = new HelperNode(network);
  524. assert(options.nodes.font.multi);
  525. assert.equal(h.modBold(0).color, 'yellow'); // bold value
  526. assert.equal(h.modBold(1).color, 'yellow'); // bold value
  527. assert.equal(h.modBold(2).color, 'red'); // Group value overrides nodes
  528. assert.equal(h.modBold(3).color, 'green'); // Local value overrides all
  529. assert.equal(h.modBold(4).color, 'green'); // Idem
  530. done();
  531. });
  532. }); // Node Labels
  533. describe('Edge Labels', function() {
  534. function createEdgeNetwork(newOptions) {
  535. var dataNodes = [
  536. {id: 1, label: '1'},
  537. {id: 2, label: '2'},
  538. {id: 3, label: '3'},
  539. {id: 4, label: '4'},
  540. ];
  541. var dataEdges = [
  542. {id: 1, from: 1, to: 2, label: '<b>1</b>'},
  543. {id: 2, from: 1, to: 4, label: '<b>2</b>',
  544. font: {
  545. bold: { color: 'green' },
  546. }
  547. },
  548. {id: 3, from: 2, to: 3, label: '<b>3</b>',
  549. font: {
  550. bold: { color: 'green' },
  551. }
  552. },
  553. ];
  554. // create a network
  555. var container = document.getElementById('mynetwork');
  556. var data = {
  557. nodes: new vis.DataSet(dataNodes),
  558. edges: new vis.DataSet(dataEdges),
  559. };
  560. var options = {
  561. edges: {
  562. font: {
  563. multi: true
  564. }
  565. },
  566. };
  567. if (newOptions !== undefined) {
  568. util.deepExtend(options, newOptions);
  569. }
  570. var network = new vis.Network(container, data, options);
  571. return [network, data, options];
  572. }
  573. class HelperEdge {
  574. constructor(network) {
  575. this.edges = network.body.edges;
  576. }
  577. fontOption(index) {
  578. return this.edges[index].labelModule.fontOptions;
  579. };
  580. modBold(index) {
  581. return this.fontOption(index).bold;
  582. };
  583. }
  584. /**
  585. * Check that setting options for multi-font works as expected
  586. *
  587. * - using multi-font 'bold' for test, the rest should work analogously
  588. * - using multi-font option 'color' for test, the rest should work analogously
  589. * - edges have no groups
  590. */
  591. it('respects the font option precedence', function (done) {
  592. var [network, data, options] = createEdgeNetwork();
  593. var h = new HelperEdge(network);
  594. assert.equal(h.modBold(1).color, '#343434'); // Default value
  595. assert.equal(h.modBold(2).color, 'green'); // Local value overrides default
  596. assert.equal(h.modBold(3).color, 'green'); // Local value overrides group
  597. done();
  598. });
  599. it('handles dynamic data and option updates', function (done) {
  600. var [network, data, options] = createEdgeNetwork();
  601. var h = new HelperEdge(network);
  602. data.edges.update([
  603. {id: 3, font: { bold: { color: 'orange'}}},
  604. ]);
  605. assert.equal(h.modBold(1).color, '#343434'); // unchanged
  606. assert.equal(h.modBold(2).color, 'green'); // unchanged
  607. assert.equal(h.modBold(3).color, 'orange'); // new local value
  608. network.setOptions({
  609. edges: {
  610. font: {
  611. multi: true,
  612. bold: {
  613. color: 'black'
  614. }
  615. }
  616. },
  617. });
  618. assert.equal(h.modBold(1).color, 'black'); // more specific bold value overrides group value
  619. assert.equal(h.modBold(2).color, 'green'); // unchanged
  620. assert.equal(h.modBold(3).color, 'orange'); // unchanged
  621. done();
  622. });
  623. it('handles font values in default options', function (done) {
  624. var newOptions = {
  625. edges: {
  626. font: {
  627. color: 'purple' // Override the default value
  628. }
  629. },
  630. };
  631. var [network, data, options] = createEdgeNetwork(newOptions);
  632. var h = new HelperEdge(network);
  633. assert.equal(h.modBold(1).color, 'purple'); // Nodes value
  634. assert.equal(h.modBold(2).color, 'green'); // Local value overrides all
  635. assert.equal(h.modBold(3).color, 'green'); // Idem
  636. done();
  637. });
  638. }); // Edge Labels
  639. describe('Shorthand Font Options', function() {
  640. var testFonts = {
  641. 'default': {color: '#343434', face: 'arial' , size: 14},
  642. 'monodef': {color: '#343434', face: 'monospace', size: 15},
  643. 'font1' : {color: '#010101', face: 'Font1' , size: 1},
  644. 'font2' : {color: '#020202', face: 'Font2' , size: 2},
  645. 'font3' : {color: '#030303', face: 'Font3' , size: 3},
  646. 'font4' : {color: '#040404', face: 'Font4' , size: 4},
  647. 'font5' : {color: '#050505', face: 'Font5' , size: 5},
  648. 'font6' : {color: '#060606', face: 'Font6' , size: 6},
  649. 'font7' : {color: '#070707', face: 'Font7' , size: 7},
  650. };
  651. function checkFont(opt, expectedLabel) {
  652. var expected = testFonts[expectedLabel];
  653. util.forEach(expected, (item, key) => {
  654. assert.equal(opt[key], item);
  655. });
  656. };
  657. function createNetwork() {
  658. var dataNodes = [
  659. {id: 1, label: '1'},
  660. {id: 2, label: '2', group: 'group1'},
  661. {id: 3, label: '3', group: 'group2'},
  662. {id: 4, label: '4', font: '5px Font5 #050505'},
  663. ];
  664. var dataEdges = [];
  665. // create a network
  666. var container = document.getElementById('mynetwork');
  667. var data = {
  668. nodes: new vis.DataSet(dataNodes),
  669. edges: new vis.DataSet(dataEdges),
  670. };
  671. var options = {
  672. nodes: {
  673. font: {
  674. multi: true,
  675. bold: '1 Font1 #010101',
  676. ital: '2 Font2 #020202',
  677. }
  678. },
  679. groups: {
  680. group1: {
  681. font: '3 Font3 #030303'
  682. },
  683. group2: {
  684. font: {
  685. bold: '4 Font4 #040404'
  686. }
  687. }
  688. }
  689. };
  690. var network = new vis.Network(container, data, options);
  691. return [network, data];
  692. }
  693. it('handles shorthand options correctly', function (done) {
  694. var [network, data] = createNetwork();
  695. var h = new HelperNode(network);
  696. // NOTE: 'mono' has its own global default font and size, which will
  697. // trump any other font values set.
  698. var opt = h.fontOption(1);
  699. checkFont(opt, 'default');
  700. checkFont(opt.bold, 'font1');
  701. checkFont(opt.ital, 'font2');
  702. checkFont(opt.mono, 'monodef'); // Mono should have defaults
  703. // Node 2 should be using group1 options
  704. opt = h.fontOption(2);
  705. checkFont(opt, 'font3');
  706. checkFont(opt.bold, 'font1'); // bold retains nodes default options
  707. checkFont(opt.ital, 'font2'); // ital retains nodes default options
  708. assert.equal(opt.mono.color, '#030303'); // New color
  709. assert.equal(opt.mono.face, 'monospace'); // own global default font
  710. assert.equal(opt.mono.size, 15); // Own global default size
  711. // Node 3 should be using group2 options
  712. opt = h.fontOption(3);
  713. checkFont(opt, 'default');
  714. checkFont(opt.bold, 'font4');
  715. checkFont(opt.ital, 'font2');
  716. checkFont(opt.mono, 'monodef'); // Mono should have defaults
  717. // Node 4 has its own base font definition
  718. opt = h.fontOption(4);
  719. checkFont(opt, 'font5');
  720. checkFont(opt.bold, 'font1');
  721. checkFont(opt.ital, 'font2');
  722. assert.equal(opt.mono.color, '#050505'); // New color
  723. assert.equal(opt.mono.face, 'monospace');
  724. assert.equal(opt.mono.size, 15);
  725. done();
  726. });
  727. function dynamicAdd1(network, data) {
  728. // Add new shorthand at every level
  729. data.nodes.update([
  730. {id: 1, font: '5 Font5 #050505'},
  731. {id: 4, font: { bold: '6 Font6 #060606'} }, // kills node instance base font
  732. ]);
  733. network.setOptions({
  734. nodes: {
  735. font: {
  736. multi: true,
  737. ital: '4 Font4 #040404',
  738. }
  739. },
  740. groups: {
  741. group1: {
  742. font: {
  743. bold: '7 Font7 #070707' // Kills node instance base font
  744. }
  745. },
  746. group2: {
  747. font: '6 Font6 #060606' // Note: 'bold' removed by this
  748. }
  749. }
  750. });
  751. }
  752. function dynamicAdd2(network, data) {
  753. network.setOptions({
  754. nodes: {
  755. font: '7 Font7 #070707' // Note: this kills the font.multi, bold and ital settings!
  756. }
  757. });
  758. }
  759. it('deals with dynamic data and option updates for shorthand', function (done) {
  760. var [network, data] = createNetwork();
  761. var h = new HelperNode(network);
  762. dynamicAdd1(network, data);
  763. var opt = h.fontOption(1);
  764. checkFont(opt, 'font5'); // New base font
  765. checkFont(opt.bold, 'font1');
  766. checkFont(opt.ital, 'font4'); // New global node default
  767. assert.equal(opt.mono.color, '#050505'); // New color
  768. assert.equal(opt.mono.face, 'monospace');
  769. assert.equal(opt.mono.size, 15);
  770. opt = h.fontOption(2);
  771. checkFont(opt, 'default');
  772. checkFont(opt.bold, 'font7');
  773. checkFont(opt.ital, 'font4'); // New global node default
  774. checkFont(opt.mono, 'monodef'); // Mono should have defaults again
  775. opt = h.fontOption(3);
  776. checkFont(opt, 'font6'); // New base font
  777. checkFont(opt.bold, 'font1'); // group bold option removed, using global default node
  778. checkFont(opt.ital, 'font4'); // New global node default
  779. assert.equal(opt.mono.color, '#060606'); // New color
  780. assert.equal(opt.mono.face, 'monospace');
  781. assert.equal(opt.mono.size, 15);
  782. opt = h.fontOption(4);
  783. checkFont(opt, 'default');
  784. checkFont(opt.bold, 'font6');
  785. checkFont(opt.ital, 'font4');
  786. assert.equal(opt.mono.face, 'monospace');
  787. assert.equal(opt.mono.size, 15);
  788. done();
  789. });
  790. it('deals with dynamic change of global node default', function (done) {
  791. var [network, data] = createNetwork();
  792. var h = new HelperNode(network);
  793. dynamicAdd1(network, data); // Accumulate data of dynamic add
  794. dynamicAdd2(network, data);
  795. var opt = h.fontOption(1);
  796. checkFont(opt, 'font5'); // Node instance value
  797. checkFont(opt.bold, 'font5'); // bold def removed from global default node
  798. checkFont(opt.ital, 'font5'); // idem
  799. assert.equal(opt.mono.color, '#050505'); // New color
  800. assert.equal(opt.mono.face, 'monospace');
  801. assert.equal(opt.mono.size, 15);
  802. opt = h.fontOption(2);
  803. checkFont(opt, 'font7'); // global node default applies for all settings
  804. checkFont(opt.bold, 'font7');
  805. checkFont(opt.ital, 'font7');
  806. assert.equal(opt.mono.color, '#070707');
  807. assert.equal(opt.mono.face, 'monospace');
  808. assert.equal(opt.mono.size, 15);
  809. opt = h.fontOption(3);
  810. checkFont(opt, 'font6'); // Group base font
  811. checkFont(opt.bold, 'font6'); // idem
  812. checkFont(opt.ital, 'font6'); // idem
  813. assert.equal(opt.mono.color, '#060606'); // idem
  814. assert.equal(opt.mono.face, 'monospace');
  815. assert.equal(opt.mono.size, 15);
  816. opt = h.fontOption(4);
  817. checkFont(opt, 'font7'); // global node default
  818. checkFont(opt.bold, 'font6'); // node instance bold
  819. checkFont(opt.ital, 'font7'); // global node default
  820. assert.equal(opt.mono.color, '#070707'); // idem
  821. assert.equal(opt.mono.face, 'monospace');
  822. assert.equal(opt.mono.size, 15);
  823. done();
  824. });
  825. it('deals with dynamic delete of shorthand options', function (done) {
  826. var [network, data] = createNetwork();
  827. var h = new HelperNode(network);
  828. dynamicAdd1(network, data); // Accumulate data of previous dynamic steps
  829. dynamicAdd2(network, data); // idem
  830. data.nodes.update([
  831. {id: 1, font: null},
  832. {id: 4, font: { bold: null}},
  833. ]);
  834. var opt;
  835. /*
  836. // Interesting: following flagged as error in options parsing, avoiding it for that reason
  837. network.setOptions({
  838. nodes: {
  839. font: {
  840. multi: true,
  841. ital: null,
  842. }
  843. },
  844. });
  845. */
  846. network.setOptions({
  847. groups: {
  848. group1: {
  849. font: {
  850. bold: null
  851. }
  852. },
  853. group2: {
  854. font: null
  855. }
  856. }
  857. });
  858. // global defaults for all
  859. for (let n = 1; n <= 4; ++ n) {
  860. opt = h.fontOption(n);
  861. checkFont(opt, 'font7');
  862. checkFont(opt.bold, 'font7');
  863. checkFont(opt.ital, 'font7');
  864. assert.equal(opt.mono.color, '#070707');
  865. assert.equal(opt.mono.face, 'monospace');
  866. assert.equal(opt.mono.size, 15);
  867. }
  868. /*
  869. // Not testing following because it is an error in options parsing
  870. network.setOptions({
  871. nodes: {
  872. font: null
  873. },
  874. });
  875. */
  876. done();
  877. });
  878. }); // Shorthand Font Options
  879. it('sets and uses font.multi in group options', function (done) {
  880. /**
  881. * Helper function for easily accessing font options in a node
  882. */
  883. var fontOption = (index) => {
  884. var nodes = network.body.nodes;
  885. return nodes[index].labelModule.fontOptions;
  886. };
  887. /**
  888. * Helper function for easily accessing bold options in a node
  889. */
  890. var modBold = (index) => {
  891. return fontOption(index).bold;
  892. };
  893. var dataNodes = [
  894. {id: 1, label: '<b>1</b>', group: 'group1'},
  895. {
  896. // From example 1 in #3408
  897. id: 6,
  898. label: '<i>\uf286</i> <b>\uf2cd</b> colored glyph icon',
  899. shape: 'icon',
  900. group: 'colored',
  901. icon : { color: 'blue' },
  902. font:
  903. {
  904. bold : { color : 'blue' },
  905. ital : { color : 'green' }
  906. }
  907. },
  908. ];
  909. // create a network
  910. var container = document.getElementById('mynetwork');
  911. var data = {
  912. nodes: new vis.DataSet(dataNodes),
  913. edges: []
  914. };
  915. var options = {
  916. groups: {
  917. group1: {
  918. font: {
  919. multi: true,
  920. color: 'red'
  921. },
  922. },
  923. colored :
  924. {
  925. // From example 1 in 3408
  926. icon :
  927. {
  928. face : 'FontAwesome',
  929. code : '\uf2b5',
  930. },
  931. font:
  932. {
  933. face : 'FontAwesome',
  934. multi: true,
  935. bold : { mod : '' },
  936. ital : { mod : '' }
  937. }
  938. },
  939. },
  940. };
  941. var network = new vis.Network(container, data, options);
  942. assert.equal(modBold(1).color, 'red'); // Group value
  943. assert(fontOption(1).multi); // Group value
  944. assert.equal(modBold(6).color, 'blue'); // node instance value
  945. assert(fontOption(6).multi); // Group value
  946. network.setOptions({
  947. groups: {
  948. group1: {
  949. //font: { color: 'brown' }, // Can not just change one field, entire font object is reset
  950. font: {
  951. multi: true,
  952. color: 'brown'
  953. },
  954. },
  955. },
  956. });
  957. assert.equal(modBold(1).color, 'brown'); // New value
  958. assert(fontOption(1).multi); // Group value
  959. assert.equal(modBold(6).color, 'blue'); // unchanged
  960. assert(fontOption(6).multi); // unchanged
  961. network.setOptions({
  962. groups: {
  963. group1: {
  964. font: null, // Remove font from group
  965. },
  966. },
  967. });
  968. // console.log("===============");
  969. // console.log(fontOption(1));
  970. assert.equal(modBold(1).color, '#343434'); // Reverts to default
  971. assert(!fontOption(1).multi); // idem
  972. assert.equal(modBold(6).color, 'blue'); // unchanged
  973. assert(fontOption(6).multi); // unchanged
  974. done();
  975. });
  976. it('compresses spaces for Multi-Font', function (done) {
  977. var options = getOptions(options);
  978. var text = [
  979. "Too many spaces here!",
  980. "one two three four five six .",
  981. "This thing:\n - could be\n - a kind\n - of list", // multifont: 2 spaces at start line reduced to 1
  982. ];
  983. //
  984. // multifont disabled: spaces are preserved
  985. //
  986. var label = new Label({}, options);
  987. var expected = [{
  988. lines: [{
  989. blocks: [{text: "Too many spaces here!"}],
  990. }]
  991. }, {
  992. lines: [{
  993. blocks: [{text: "one two three four five six ."}],
  994. }]
  995. }, {
  996. lines: [{
  997. blocks: [{text: "This thing:"}],
  998. }, {
  999. blocks: [{text: " - could be"}],
  1000. }, {
  1001. blocks: [{text: " - a kind"}],
  1002. }, {
  1003. blocks: [{text: " - of list"}],
  1004. }]
  1005. }];
  1006. checkProcessedLabels(label, text, expected);
  1007. //
  1008. // multifont disabled width maxwidth: spaces are preserved
  1009. //
  1010. options.font.maxWdt = 300;
  1011. var label = new Label({}, options);
  1012. var expected_maxwidth = [{
  1013. lines: [{
  1014. blocks: [{text: "Too many spaces"}],
  1015. }, {
  1016. blocks: [{text: " here!"}],
  1017. }]
  1018. }, {
  1019. lines: [{
  1020. blocks: [{text: "one two three "}],
  1021. }, {
  1022. blocks: [{text: "four five six"}],
  1023. }, {
  1024. blocks: [{text: " ."}],
  1025. }]
  1026. }, {
  1027. lines: [{
  1028. blocks: [{text: "This thing:"}],
  1029. }, {
  1030. blocks: [{text: " - could be"}],
  1031. }, {
  1032. blocks: [{text: " - a kind"}],
  1033. }, {
  1034. blocks: [{text: " - of list"}],
  1035. }]
  1036. }];
  1037. checkProcessedLabels(label, text, expected_maxwidth);
  1038. //
  1039. // multifont enabled: spaces are compressed
  1040. //
  1041. options = getOptions(options);
  1042. options.font.multi = true;
  1043. var label = new Label({}, options);
  1044. var expected_multifont = [{
  1045. lines: [{
  1046. blocks: [{text: "Too many spaces here!"}],
  1047. }]
  1048. }, {
  1049. lines: [{
  1050. blocks: [{text: "one two three four five six ."}],
  1051. }]
  1052. }, {
  1053. lines: [{
  1054. blocks: [{text: "This thing:"}],
  1055. }, {
  1056. blocks: [{text: " - could be"}],
  1057. }, {
  1058. blocks: [{text: " - a kind"}],
  1059. }, {
  1060. blocks: [{text: " - of list"}],
  1061. }]
  1062. }];
  1063. checkProcessedLabels(label, text, expected_multifont);
  1064. //
  1065. // multifont enabled with max width: spaces are compressed
  1066. //
  1067. options.font.maxWdt = 300;
  1068. var label = new Label({}, options);
  1069. var expected_multifont_maxwidth = [{
  1070. lines: [{
  1071. blocks: [{text: "Too many spaces"}],
  1072. }, {
  1073. blocks: [{text: "here!"}],
  1074. }]
  1075. }, {
  1076. lines: [{
  1077. blocks: [{text: "one two three four"}],
  1078. }, {
  1079. blocks: [{text: "five six ."}],
  1080. }]
  1081. }, {
  1082. lines: [{
  1083. blocks: [{text: "This thing:"}],
  1084. }, {
  1085. blocks: [{text: " - could be"}],
  1086. }, {
  1087. blocks: [{text: " - a kind"}],
  1088. }, {
  1089. blocks: [{text: " - of list"}],
  1090. }]
  1091. }];
  1092. checkProcessedLabels(label, text, expected_multifont_maxwidth);
  1093. done();
  1094. });
  1095. }); // Multi-Fonts
  1096. it('parses single huge word on line with preceding whitespace when max width set', function (done) {
  1097. var options = getOptions(options);
  1098. options.font.maxWdt = 300;
  1099. assert.equal(options.font.multi, false);
  1100. /**
  1101. * Split a string at the given location, return either first or last part
  1102. *
  1103. * Allows negative indexing, counting from back (ruby style)
  1104. */
  1105. let splitAt = (text, pos, getFirst) => {
  1106. if (pos < 0) pos = text.length + pos;
  1107. if (getFirst) {
  1108. return text.substring(0, pos);
  1109. } else {
  1110. return text.substring(pos);
  1111. }
  1112. };
  1113. var label = new Label({}, options);
  1114. var longWord = "asd;lkfja;lfkdj;alkjfd;alskfj";
  1115. var text = [
  1116. "Mind the space!\n " + longWord,
  1117. "Mind the empty line!\n\n" + longWord,
  1118. "Mind the dos empty line!\r\n\r\n" + longWord
  1119. ];
  1120. var expected = [{
  1121. lines: [{
  1122. blocks: [{text: "Mind the space!"}]
  1123. }, {
  1124. blocks: [{text: ""}]
  1125. }, {
  1126. blocks: [{text: splitAt(longWord, -3, true)}]
  1127. }, {
  1128. blocks: [{text: splitAt(longWord, -3, false)}]
  1129. }]
  1130. }, {
  1131. lines: [{
  1132. blocks: [{text: "Mind the empty"}]
  1133. }, {
  1134. blocks: [{text: "line!"}]
  1135. }, {
  1136. blocks: [{text: ""}]
  1137. }, {
  1138. blocks: [{text: splitAt(longWord, -3, true)}]
  1139. }, {
  1140. blocks: [{text: splitAt(longWord, -3, false)}]
  1141. }]
  1142. }, {
  1143. lines: [{
  1144. blocks: [{text: "Mind the dos empty"}]
  1145. }, {
  1146. blocks: [{text: "line!"}]
  1147. }, {
  1148. blocks: [{text: ""}]
  1149. }, {
  1150. blocks: [{text: splitAt(longWord, -3, true)}]
  1151. }, {
  1152. blocks: [{text: splitAt(longWord, -3, false)}]
  1153. }]
  1154. }];
  1155. checkProcessedLabels(label, text, expected);
  1156. //
  1157. // Multi font enabled. For current case, output should be identical to no multi font
  1158. //
  1159. options.font.multi = true;
  1160. var label = new Label({}, options);
  1161. checkProcessedLabels(label, text, expected);
  1162. done();
  1163. });
  1164. /**
  1165. *
  1166. * The test network is derived from example `network/nodeStyles/widthHeight.html`,
  1167. * where the associated issue (i.e. widthConstraint values not copied) was most poignant.
  1168. *
  1169. * NOTE: boolean shorthand values for widthConstraint and heightConstraint do nothing.
  1170. */
  1171. it('Sets the width/height constraints in the font label options', function (done) {
  1172. var nodes = [
  1173. { id: 100, label: 'node 100'},
  1174. { id: 210, group: 'group1', label: 'node 210'},
  1175. { id: 211, widthConstraint: { minimum: 120 }, label: 'node 211'},
  1176. { id: 212, widthConstraint: { minimum: 120, maximum: 140 }, group: 'group1', label: 'node 212'}, // group override
  1177. { id: 220, widthConstraint: { maximum: 170 }, label: 'node 220'},
  1178. { id: 200, font: { multi: true }, widthConstraint: 150, label: 'node <b>200</b>'},
  1179. { id: 201, widthConstraint: 150, label: 'node 201'},
  1180. { id: 202, group: 'group2', label: 'node 202'},
  1181. { id: 203, heightConstraint: { minimum: 75, valign: 'bottom'}, group: 'group2', label: 'node 203'}, // group override
  1182. { id: 204, heightConstraint: 80, group: 'group2', label: 'node 204'}, // group override
  1183. { id: 300, heightConstraint: { minimum: 70 }, label: 'node 300'},
  1184. { id: 400, heightConstraint: { minimum: 100, valign: 'top' }, label: 'node 400'},
  1185. { id: 401, heightConstraint: { minimum: 100, valign: 'middle' }, label: 'node 401'},
  1186. { id: 402, heightConstraint: { minimum: 100, valign: 'bottom' }, label: 'node 402'}
  1187. ];
  1188. var edges = [
  1189. { id: 1, from: 100, to: 210, label: "edge 1"},
  1190. { id: 2, widthConstraint: 80, from: 210, to: 211, label: "edge 2"},
  1191. { id: 3, heightConstraint: 90, from: 100, to: 220, label: "edge 3"},
  1192. { id: 4, from: 401, to: 402, widthConstraint: { maximum: 150 }, label: "edge 12"},
  1193. ];
  1194. var container = document.getElementById('mynetwork');
  1195. var data = {
  1196. nodes: nodes,
  1197. edges: edges
  1198. };
  1199. var options = {
  1200. edges: {
  1201. font: {
  1202. size: 12
  1203. },
  1204. widthConstraint: {
  1205. maximum: 90
  1206. }
  1207. },
  1208. nodes: {
  1209. shape: 'box',
  1210. margin: 10,
  1211. widthConstraint: {
  1212. maximum: 200
  1213. }
  1214. },
  1215. groups: {
  1216. group1: {
  1217. shape: 'dot',
  1218. widthConstraint: {
  1219. maximum: 130
  1220. }
  1221. },
  1222. // Following group serves to test all font options
  1223. group2: {
  1224. shape: 'dot',
  1225. widthConstraint: {
  1226. minimum: 150,
  1227. maximum: 180,
  1228. },
  1229. heightConstraint: {
  1230. minimum: 210,
  1231. valign: 'top',
  1232. }
  1233. },
  1234. },
  1235. physics: {
  1236. enabled: false
  1237. }
  1238. };
  1239. var network = new vis.Network(container, data, options);
  1240. var nodes_expected = [
  1241. { nodeId: 100, minWdt: -1, maxWdt: 200, minHgt: -1, valign: 'middle'},
  1242. { nodeId: 210, minWdt: -1, maxWdt: 130, minHgt: -1, valign: 'middle'},
  1243. { nodeId: 211, minWdt: 120, maxWdt: 200, minHgt: -1, valign: 'middle'},
  1244. { nodeId: 212, minWdt: 120, maxWdt: 140, minHgt: -1, valign: 'middle'},
  1245. { nodeId: 220, minWdt: -1, maxWdt: 170, minHgt: -1, valign: 'middle'},
  1246. { nodeId: 200, minWdt: 150, maxWdt: 150, minHgt: -1, valign: 'middle'},
  1247. { nodeId: 201, minWdt: 150, maxWdt: 150, minHgt: -1, valign: 'middle'},
  1248. { nodeId: 202, minWdt: 150, maxWdt: 180, minHgt: 210, valign: 'top'},
  1249. { nodeId: 203, minWdt: 150, maxWdt: 180, minHgt: 75, valign: 'bottom'},
  1250. { nodeId: 204, minWdt: 150, maxWdt: 180, minHgt: 80, valign: 'middle'},
  1251. { nodeId: 300, minWdt: -1, maxWdt: 200, minHgt: 70, valign: 'middle'},
  1252. { nodeId: 400, minWdt: -1, maxWdt: 200, minHgt: 100, valign: 'top'},
  1253. { nodeId: 401, minWdt: -1, maxWdt: 200, minHgt: 100, valign: 'middle'},
  1254. { nodeId: 402, minWdt: -1, maxWdt: 200, minHgt: 100, valign: 'bottom'},
  1255. ];
  1256. // For edge labels, only maxWdt is set. We check the rest anyway, be it for
  1257. // checking incorrect settings or for future code changes.
  1258. //
  1259. // There is a lot of repetitiveness here. Perhaps using a direct copy of the
  1260. // example should be let go.
  1261. var edges_expected = [
  1262. { id: 1, minWdt: -1, maxWdt: 90, minHgt: -1, valign: 'middle'},
  1263. { id: 2, minWdt: 80, maxWdt: 80, minHgt: -1, valign: 'middle'},
  1264. { id: 3, minWdt: -1, maxWdt: 90, minHgt: 90, valign: 'middle'},
  1265. { id: 4, minWdt: -1, maxWdt: 150, minHgt: -1, valign: 'middle'},
  1266. ];
  1267. let assertConstraints = (expected, fontOptions, label) => {
  1268. assert.equal(expected.minWdt, fontOptions.minWdt, 'Incorrect min width' + label);
  1269. assert.equal(expected.maxWdt, fontOptions.maxWdt, 'Incorrect max width' + label);
  1270. assert.equal(expected.minHgt, fontOptions.minHgt, 'Incorrect min height' + label);
  1271. assert.equal(expected.valign, fontOptions.valign, 'Incorrect valign' + label);
  1272. }
  1273. // Check nodes
  1274. util.forEach(nodes_expected, function(expected) {
  1275. let networkNode = network.body.nodes[expected.nodeId];
  1276. assert(networkNode !== undefined && networkNode !== null, 'node not found for id: ' + expected.nodeId);
  1277. let fontOptions = networkNode.labelModule.fontOptions;
  1278. var label = ' for node id: ' + expected.nodeId;
  1279. assertConstraints(expected, fontOptions, label);
  1280. });
  1281. // Check edges
  1282. util.forEach(edges_expected, function(expected) {
  1283. let networkEdge = network.body.edges[expected.id];
  1284. var label = ' for edge id: ' + expected.id;
  1285. assert(networkEdge !== undefined, 'Edge not found' + label);
  1286. let fontOptions = networkEdge.labelModule.fontOptions;
  1287. assertConstraints(expected, fontOptions, label);
  1288. });
  1289. done();
  1290. });
  1291. it('deals with null labels and other awkward values', function (done) {
  1292. var ctx = new DummyContext();
  1293. var options = getOptions({});
  1294. var checkHandling = (label, index, text) => {
  1295. assert.doesNotThrow(() => {label.getTextSize(ctx, false, false)}, "Unexpected throw for " + text + " " + index);
  1296. //label.getTextSize(ctx, false, false); // Use this to determine the error thrown
  1297. // There should not be a label for any of the cases
  1298. //
  1299. let labelVal = label.elementOptions.label;
  1300. let validLabel = (typeof labelVal === 'string' && labelVal !== '');
  1301. assert(!validLabel, "Unexpected label value '" + labelVal+ "' for " + text +" " + index);
  1302. };
  1303. var nodes = [
  1304. {id: 1},
  1305. {id: 2, label: null},
  1306. {id: 3, label: undefined},
  1307. {id: 4, label: {a: 42}},
  1308. {id: 5, label: [ 'an', 'array']},
  1309. {id: 6, label: true},
  1310. {id: 7, label: 3.419},
  1311. ];
  1312. var edges = [
  1313. {from: 1, to: 2, label: null},
  1314. {from: 1, to: 3, label: undefined},
  1315. {from: 1, to: 4, label: {a: 42}},
  1316. {from: 1, to: 5, label: ['an', 'array']},
  1317. {from: 1, to: 6, label: false},
  1318. {from: 1, to: 7, label: 2.71828},
  1319. ];
  1320. // Isolate the specific call where a problem with null-label was detected
  1321. // Following loops should plain not throw
  1322. // Node labels
  1323. for (let i = 0; i < nodes.length; ++i) {
  1324. let label = new Label(null, nodes[i], false);
  1325. checkHandling(label, i, 'node');
  1326. }
  1327. // Edge labels
  1328. for (let i = 0; i < edges.length; ++i) {
  1329. let label = new Label(null, edges[i], true);
  1330. checkHandling(label, i, 'edge');
  1331. }
  1332. //
  1333. // Following extracted from example 'nodeLegend', where the problem was detected.
  1334. //
  1335. // In the example, only `label:null` was present. The weird thing is that it fails
  1336. // in the example, but succeeds in the unit tests.
  1337. // Kept in for regression testing.
  1338. var container = document.getElementById('mynetwork');
  1339. var data = {
  1340. nodes: new vis.DataSet(nodes),
  1341. edges: new vis.DataSet(edges)
  1342. };
  1343. var options = {};
  1344. var network = new vis.Network(container, data, options);
  1345. done();
  1346. });
  1347. });