-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
650 additions
and
439 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
140 changes: 140 additions & 0 deletions
140
jscomponents/codegraph/_headless_exporter_browser_code.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// | ||
// PUPPETEER IN-BROWSER CODE | ||
// | ||
|
||
console.log(`Executing in-browser code now`); | ||
|
||
function isStrict() { return !this; } | ||
if (!isStrict()) { | ||
console.error(`Not strict mode!`); | ||
throw new Error(`Not strict mode!`); | ||
} | ||
|
||
// ----- | ||
|
||
import debugm from 'debug'; const debug = debugm('_headless_exporter_browser_code'); | ||
|
||
import loMerge from 'lodash/merge.js'; | ||
|
||
import { load_eczoodb_from_data } from './setup_eczoodb.js'; | ||
|
||
import { EczCodeGraph } from './index.js'; | ||
import { EczCodeGraphViewController } from './eczcodegraphviewcontroller.js'; | ||
|
||
import cytoscape from 'cytoscape'; | ||
import cySvg from 'cytoscape-svg'; | ||
cytoscape.use( cySvg ); | ||
|
||
|
||
async function _loadCodeGraph(eczoodbData, displayOptions) | ||
{ | ||
const eczoodb = await load_eczoodb_from_data(eczoodbData); | ||
|
||
let eczCodeGraph = new EczCodeGraph({ | ||
eczoodb, | ||
}); | ||
|
||
await eczCodeGraph.initialize(); | ||
|
||
let eczCodeGraphViewController = new EczCodeGraphViewController(eczCodeGraph, displayOptions); | ||
|
||
await eczCodeGraphViewController.initialize(); | ||
|
||
return { eczoodb, eczCodeGraph, eczCodeGraphViewController }; | ||
} | ||
|
||
async function _prepareCodeGraphAndLayout( | ||
eczoodbData, { displayOptions, updateLayoutOptions, cyStyleOptions } | ||
) | ||
{ | ||
const { | ||
eczoodb, | ||
eczCodeGraph, | ||
eczCodeGraphViewController, | ||
} = await _loadCodeGraph(eczoodbData, displayOptions); | ||
|
||
debug(`Code graph loaded.`); | ||
|
||
const domNode = window.document.createElement('div'); | ||
window.document.body.appendChild(domNode); | ||
domNode.style.width = 800; | ||
domNode.style.height = 600; | ||
|
||
await eczCodeGraph.mountInDom( | ||
domNode, | ||
{ | ||
styleOptions: Object.assign( | ||
{ | ||
matchWebPageFonts: false, | ||
window: window, | ||
}, | ||
cyStyleOptions, | ||
), | ||
} | ||
); | ||
|
||
debug(`Mounted in DOM!`); | ||
|
||
eczCodeGraphViewController.setDisplayOptions(displayOptions); | ||
|
||
debug(`set display options!`); | ||
|
||
// perform layout ! | ||
await eczCodeGraph.updateLayout(loMerge( | ||
{ | ||
animate: false | ||
}, | ||
updateLayoutOptions | ||
)); | ||
|
||
debug(`ran updateLayout()!`); | ||
|
||
const cy = eczCodeGraph.cy; | ||
|
||
// fit into view | ||
await cy.fit(); | ||
|
||
debug(`fit cy canvas view to graph. Done!`); | ||
|
||
debug(`There are ${cy.nodes().length} nodes in the graph.`); | ||
|
||
return { | ||
eczoodb, | ||
eczCodeGraph, | ||
eczCodeGraphViewController, | ||
}; | ||
} | ||
|
||
async function _loadAndCompileCodeGraphToSvgPromise(eczoodbData, prepareOptions, svgOptions) | ||
{ | ||
//debug('eczoodbData = ', JSON.stringify(eczoodbData)); // ok, works | ||
debug('prepareOptions = ', JSON.stringify(prepareOptions)); | ||
var result = await _prepareCodeGraphAndLayout(eczoodbData, prepareOptions); | ||
|
||
var cy = result.eczCodeGraph.cy; | ||
|
||
var svgData = cy.svg(Object.assign( | ||
{ | ||
full: true | ||
}, | ||
svgOptions | ||
)); | ||
return { | ||
svgData: svgData, | ||
// moredata: { | ||
// cy_data: cy.json(), | ||
// } | ||
}; | ||
} | ||
|
||
window.loadCodeGraph = _loadCodeGraph; | ||
window.prepareCodeGraphAndLayout = _prepareCodeGraphAndLayout; | ||
window.loadAndCompileCodeGraphToSvgPromise = _loadAndCompileCodeGraphToSvgPromise; | ||
|
||
window.localStorage.debug = '*'; | ||
|
||
console.log('Loaded (msg via console.log())'); | ||
debug(`Loaded (msg via debug()).`); | ||
console.debug('Loaded (msg via console.debug())'); | ||
|
||
window.finished_loading = true; |
12 changes: 12 additions & 0 deletions
12
jscomponents/codegraph/_headless_exporter_browser_page.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<script> | ||
window.localStorage.debug = "*"; | ||
window.finished_loading = false; | ||
</script> | ||
<script type="module" src="./_headless_exporter_browser_code.js"></script> | ||
</head> | ||
<body id="body"> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.