Skip to content

Commit 2e28ac6

Browse files
committed
Visualize internal dependencies with GraphViz
1 parent 3b7ea0a commit 2e28ac6

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// List of all artifacts and their dependencies with build levels for GraphViz Visualization
2+
3+
MATCH (:Java:Artifact)-[dependencyForStatistics:DEPENDS_ON]->(:Java:Artifact)
4+
WITH min(dependencyForStatistics.weight) AS minWeight
5+
,max(dependencyForStatistics.weight) AS maxWeight
6+
MATCH (source:Java:Artifact)
7+
OPTIONAL MATCH (source)-[dependency:DEPENDS_ON]->(target:Java:Artifact)
8+
//RETURN a, b, d
9+
WITH *, toFloat(dependency.weight - minWeight) / toFloat(maxWeight - minWeight) AS normalizedWeight
10+
WITH *, round((normalizedWeight * 5) + 1, 2) AS penWidth
11+
WITH *, source.name + '\\n(level ' + source.maxDistanceFromSource + ')' AS fullSourceName
12+
WITH *, target.name + '\\n(level ' + target.maxDistanceFromSource + ')' AS fullTargetName
13+
WITH *, "\" -> \"" + fullTargetName
14+
+ "\" [label = " + dependency.weight + ";"
15+
+ " penwidth = " + penWidth + ";"
16+
+ " ];" AS graphVizDotNotationEdge
17+
WITH *, "\"" + fullSourceName + coalesce(graphVizDotNotationEdge, "\" [];") AS graphVizDotNotationLine
18+
RETURN graphVizDotNotationLine
19+
//Debugging
20+
//,source.name AS sourceName
21+
//,target.name AS targetName
22+
//,penWidth
23+
//,normalizedWeight
24+
//,dependency.weight AS weight
25+
//,minWeight
26+
//,maxWeight
27+
LIMIT 200
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// List of all Typescript modules and their dependencies with build levels for GraphViz Visualization
2+
3+
MATCH (:TS:Module)-[dependencyForStatistics:DEPENDS_ON]->(:TS:Module)
4+
WITH min(dependencyForStatistics.weight) AS minWeight
5+
,max(dependencyForStatistics.weight) AS maxWeight
6+
MATCH (source:TS:Module)
7+
OPTIONAL MATCH (source)-[dependency:DEPENDS_ON]->(target:TS:Module)
8+
//RETURN a, b, d
9+
WITH *, toFloat(dependency.cardinality - minWeight) / toFloat(maxWeight - minWeight) AS normalizedWeight
10+
WITH *, round((normalizedWeight * 5) + 1, 2) AS penWidth
11+
WITH *, source.name + '\\n(level ' + source.maxDistanceFromSource + ')' AS fullSourceName
12+
WITH *, target.name + '\\n(level ' + target.maxDistanceFromSource + ')' AS fullTargetName
13+
WITH *, "\" -> \"" + fullTargetName
14+
+ "\" [label = " + dependency.cardinality + ";"
15+
+ " penwidth = " + penWidth + ";"
16+
+ " ];" AS graphVizDotNotationEdge
17+
WITH *, "\"" + fullSourceName + coalesce(graphVizDotNotationEdge, "\" [];") AS graphVizDotNotationLine
18+
RETURN graphVizDotNotationLine
19+
//Debugging
20+
//,source.name AS sourceName
21+
//,target.name AS targetName
22+
//,penWidth
23+
//,normalizedWeight
24+
//,dependency.cardinality AS weight
25+
//,minWeight
26+
//,maxWeight
27+
LIMIT 200
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
3+
# Executes selected "Artifact_Dependencies" Cypher queries for GraphViz visualization.
4+
# It contains lists of dependencies across artifacts and their build levels (topologically sorted).
5+
# It requires an already running Neo4j graph database with already scanned and analyzed artifacts.
6+
# The reports (csv, dot and svg files) will be written into the sub directory reports/internal-dependencies-visualization.
7+
8+
# Requires executeQueryFunctions.sh, visualizeQueryResults.sh, cleanupAfterReportGeneration.sh
9+
10+
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
11+
set -o errexit -o pipefail
12+
13+
# Overrideable Constants (defaults also defined in sub scripts)
14+
REPORTS_DIRECTORY=${REPORTS_DIRECTORY:-"reports"}
15+
16+
## Get this "scripts/reports" directory if not already set
17+
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
18+
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
19+
# This way non-standard tools like readlink aren't needed.
20+
REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )}
21+
echo "InternalDependenciesVisualization: REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR}"
22+
23+
# Get the "scripts" directory by taking the path of this script and going one directory up.
24+
SCRIPTS_DIR=${SCRIPTS_DIR:-"${REPORTS_SCRIPT_DIR}/.."} # Repository directory containing the shell scripts
25+
echo "InternalDependenciesVisualization SCRIPTS_DIR=${SCRIPTS_DIR}"
26+
27+
# Get the "scripts/visualization" directory.
28+
VISUALIZATION_SCRIPTS_DIR=${VISUALIZATION_SCRIPTS_DIR:-"${SCRIPTS_DIR}/visualization"} # Repository directory containing the shell scripts for visualization
29+
echo "InternalDependenciesVisualization VISUALIZATION_SCRIPTS_DIR=${VISUALIZATION_SCRIPTS_DIR}"
30+
31+
# Get the "cypher" directory by taking the path of this script and going two directory up and then to "cypher".
32+
CYPHER_DIR=${CYPHER_DIR:-"${REPORTS_SCRIPT_DIR}/../../cypher"}
33+
echo "InternalDependenciesVisualization CYPHER_DIR=${CYPHER_DIR}"
34+
35+
INTERNAL_DEPENDENCIES_CYPHER_DIR="${CYPHER_DIR}/Internal_Dependencies"
36+
37+
# Define functions to execute cypher queries from within a given file
38+
source "${SCRIPTS_DIR}/executeQueryFunctions.sh"
39+
40+
# Create report directory
41+
REPORT_NAME="internal-dependencies-visualization"
42+
FULL_REPORT_DIRECTORY="${REPORTS_DIRECTORY}/${REPORT_NAME}"
43+
mkdir -p "${FULL_REPORT_DIRECTORY}"
44+
45+
# Java Artifacts: Dependencies Visualization
46+
reportName="${FULL_REPORT_DIRECTORY}/JavaArtifactBuildLevels"
47+
execute_cypher "${INTERNAL_DEPENDENCIES_CYPHER_DIR}/Java_Artifact_build_levels_for_graphviz.cypher" > "${reportName}.csv"
48+
source "${VISUALIZATION_SCRIPTS_DIR}/visualizeQueryResults.sh" "${reportName}.csv"
49+
50+
# TypeScript Modules: Dependencies Visualization
51+
reportName="${FULL_REPORT_DIRECTORY}/TypeScriptModuleBuildLevels"
52+
execute_cypher "${INTERNAL_DEPENDENCIES_CYPHER_DIR}/Typescript_Module_build_levels_for_graphviz.cypher" > "${reportName}.csv"
53+
source "${VISUALIZATION_SCRIPTS_DIR}/visualizeQueryResults.sh" "${reportName}.csv"
54+
55+
# Clean-up after report generation. Empty reports will be deleted.
56+
source "${SCRIPTS_DIR}/cleanupAfterReportGeneration.sh" "${FULL_REPORT_DIRECTORY}"

0 commit comments

Comments
 (0)