Skip to content

Commit 581b3d3

Browse files
committed
Support graph visualizations on Windows
1 parent be82aa6 commit 581b3d3

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,19 @@ Here are some reports that utilize Neo4j's [Graph Data Science Library](https://
4646
```
4747
To run Jupyter notebooks, create an `.env` file in the folder from where you open the notebook containing for example: `NEO4J_INITIAL_PASSWORD=neo4j_password_of_my_choice`
4848

49-
### Further Prerequisites for Python Jupyter Notebooks
49+
### Further Prerequisites for Python and Jupyter Notebooks
5050

5151
- Python is required for Jupyter Notebook reports.
5252
- A conda package manager like [Miniconda](https://docs.conda.io/projects/miniconda/en/latest) or [Anaconda](https://www.anaconda.com/download)(Recommended for Windows) is required for Jupyter Notebook reports.
5353
- Chromium will automatically be downloaded if needed for Jupyter Notebook PDF reports generation.
5454

55+
### Further Prerequisites for Graph Visualization
56+
57+
These tools are needed to run the graph visualization scripts of directory [graph-visualization](./graph-visualization):
58+
59+
- [Node.js](https://nodejs.org/en)
60+
- [npm](https://www.npmjs.com)
61+
5562
### Hints for Windows
5663

5764
- Add this line to your `~/.bashrc` file if you are using Anaconda3: `/c/ProgramData/Anaconda3/etc/profile.d/conda.sh`. Try to find a similar script for other conda package managers or versions.

graph-visualization/renderVisualizations.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import jimp from "jimp";
99
const indexOfScriptFilePathArgument = 1;
1010
const __filename = process.argv[indexOfScriptFilePathArgument];
1111
const __dirname = dirname(__filename);
12+
console.log(`renderVisualizations.js: dirname=${__dirname}`);
1213

1314
/**
1415
* Crops the image in the buffer so that there is no empty frame around it.
@@ -88,14 +89,17 @@ let browser;
8889
* and takes a screenshot of the canvas elements using {@link takeCanvasScreenshots}.
8990
*/
9091
(async () => {
92+
console.log('renderVisualizations.js: Starting headless browser...');
9193
browser = await puppeteer.launch({ headless: "new" }); // { headless: false } for testing
9294

9395
// Get all *.html files in this (script) directory and its subdirectories
94-
const htmlFiles = globSync(`${__dirname}/**/*.html`, { ignore: `${__dirname}/node_modules/**` });
96+
// The separate filter is needed to ignore the "node_modules" directory.
97+
// Glob's build-in filter doesn't seem to work on Windows.
98+
const htmlFiles = globSync(`${__dirname}/**/*.html`, { absolute: true }).filter(file => !file.includes('node_modules'));
9599
for (const htmlFile of htmlFiles) {
96100
await takeCanvasScreenshots(browser, htmlFile);
97101
}
98-
console.log(`Successfully rendered ${htmlFiles.length} html file(s)`);
102+
console.log(`renderVisualizations.js: Successfully rendered ${htmlFiles.length} html file(s)`);
99103
})()
100104
.catch((err) => console.error(err))
101105
.finally(() => browser?.close());

scripts/reports/GraphVisualization.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ echo "GraphVisualization: SCRIPTS_DIR=${SCRIPTS_DIR}"
2424

2525
# Get the "graph-visualization" directory by taking the path of this script and going two directory up and then to "visualization".
2626
GRAPH_VISUALIZATION_DIRECTORY=${GRAPH_VISUALIZATION_DIRECTORY:-"${SCRIPTS_DIR}/../graph-visualization"} # Repository directory containing the Jupyter Notebooks
27-
echo "GraphVisualization: GRAPH_VISUALIZATION_DIRECTORY=$GRAPH_VISUALIZATION_DIRECTORY"
27+
echo "GraphVisualization: GRAPH_VISUALIZATION_DIRECTORY=${GRAPH_VISUALIZATION_DIRECTORY}"
28+
29+
# Execute "npm ci" to get all required node modules from npm package manager
30+
if [ ! -d "${GRAPH_VISUALIZATION_DIRECTORY}/node_modules" ] ; then
31+
echo "GraphVisualization: Resolving node_modules..."
32+
(cd "${GRAPH_VISUALIZATION_DIRECTORY}" && exec npm ci)
33+
fi
2834

2935
# Execute the node.js script to render the graph visualizations as image files
30-
(cd "${REPORTS_DIRECTORY}" && exec node ${GRAPH_VISUALIZATION_DIRECTORY}/renderVisualizations.js)
36+
(cd "${REPORTS_DIRECTORY}" && exec node "${GRAPH_VISUALIZATION_DIRECTORY}/renderVisualizations.js")

0 commit comments

Comments
 (0)