Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions d3_graph_generator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# generated files
/src/utilities/packwerk_graph.json

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
16 changes: 16 additions & 0 deletions d3_graph_generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# modularity-graph

A d3 graph to visualize packwerk modularity.

## Setup

Environment variables required to start the graph:

- `RELATIVE_PATH_TO_REPOSITORY`: the path to your packwerk enabled repo relative to wherever you run the ruby script e.g. `../my_repo`
- `GITHUB_REPO_SLUG`: the uri identifying your repository on Github, e.g. for `https://github.com/MyOrg/myrepo/` the variable would be `MyOrg/myrepo`

To start the graph in `modularity-graph`:

1. Run `ruby parse_packwerk_integration.rb` from the command line
2. Run `yarn start`
3. Go to `http://localhost:3000/`
40 changes: 40 additions & 0 deletions d3_graph_generator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@observablehq/stdlib": "^3.19.8",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
"d3": "^7.6.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
36 changes: 36 additions & 0 deletions d3_graph_generator/parse_packwerk_integration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'bundler/inline'
require 'json'

gemfile do
source 'https://rubygems.org'
gem 'parse_packwerk'
gem 'pry'
end

d3_json = nil
Dir.chdir(ENV['RELATIVE_PATH_TO_REPOSITORY']) do
d3_json = {
"nodes" => ParsePackwerk.all.reject {|package| package.name === "."}.map do |package|
readme_link = package.directory.join("README.md")
readme = readme_link.exist? ? readme_link : nil
{
"id" => package.name,
"group" => package.dependencies.length,
"metadata" => {
"README" => "https://github.com/#{ENV['GITHUB_REPO_SLUG']}/blob/main/#{readme}"
}
}
end,
"links" => ParsePackwerk.all.reject {|package| package.name === "."}.flat_map do |package|
package.dependencies.map do |dependency|
{
"source" => package.name,
"target" => dependency,
"value" => 1
}
end
end
}
end

Pathname('src/utilities/packwerk_graph.json').write(d3_json.to_json)
43 changes: 43 additions & 0 deletions d3_graph_generator/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<script src="http://d3js.org/d3.v3.min.js"></script>
<meta
name="description"
content="A packwerk modularity graph"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Modularity Graph</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
4 changes: 4 additions & 0 deletions d3_graph_generator/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"short_name": "Modularity Graph",
"name": "Packwerk Modularity Graph"
}
3 changes: 3 additions & 0 deletions d3_graph_generator/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
13 changes: 13 additions & 0 deletions d3_graph_generator/src/components/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import ForceGraph from "./ForceGraph";
import NodeDetails from "./NodeDetails";

const App = () => {
return (
<div className="flex">
<NodeDetails />
<ForceGraph />
</div>
);
};

export default App;
29 changes: 29 additions & 0 deletions d3_graph_generator/src/components/ForceGraph.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useEffect } from "react";
import data from "../utilities/packwerk_graph.json";
import buildGraph from "../utilities/buildGraph.js";

const ForceGraph = () => {
useEffect(() => {
buildGraph(data, {
nodeId: (d) => d.id,
nodeGroup: (d) => d.group,
nodeTitle: (d) => `${d.id}\n${d.group}`,
});
}, []);

return (
<svg
width="1000"
height="800"
style={{
backgroundColor: "white",
borderRadius: "0.4rem",
border: "0.1rem solid #dcdcdc",
}}
>
<g />
</svg>
);
};

export default ForceGraph;
39 changes: 39 additions & 0 deletions d3_graph_generator/src/components/NodeDetails.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const NodeDetails = () => {
return (
<div
style={{
width: 200,
height: 400,
marginRight: "1em",
backgroundColor: "white",
borderRadius: "0.4rem",
border: "0.1rem solid #dcdcdc",
padding: "1em",
overflow: "wrap",
fontSize: "10px",
}}
>
<div style={{ fontSize: "14px", marginBottom: "1em" }}>
<b>Pack Information</b>
</div>
<div
style={{
display: "flex",
flexDirection: "column",
}}
>
<div>Name: </div>
<div id="name" style={{ marginBottom: "1em" }}></div>
<div># of Dependencies: </div>
<div id="dependencies" style={{ marginBottom: "1em" }}></div>
<div id="readme" style={{ display: "none" }}>
<a href="/" id="readmelink" target="_blank">
README
</a>
</div>
</div>
</div>
);
};

export default NodeDetails;
20 changes: 20 additions & 0 deletions d3_graph_generator/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
body {
margin: 0;
background-color: #FFF;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}

.flex {
display: flex;
justify-content: center;
margin: 2em .5em;
}
11 changes: 11 additions & 0 deletions d3_graph_generator/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./components/App";

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
Loading