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.

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