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.

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