Skip to content

Commit

Permalink
Merge pull request #4331 from GordonSmith/LIT_GRAPH
Browse files Browse the repository at this point in the history
feat: Add lit-html enabled graph
  • Loading branch information
GordonSmith authored Jan 30, 2025
2 parents 81d2379 + 8dec33c commit a4c4a1d
Show file tree
Hide file tree
Showing 65 changed files with 2,052 additions and 1,132 deletions.
1,270 changes: 641 additions & 629 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion packages/comms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"module": "./dist/index.browser.js",
"exports": {
".": {
"types": "./types/index.browser.d.ts",
"types": {
"node": "./types/index.node.d.ts",
"default": "./types/index.browser.d.ts"
},
"node": "./dist/index.node.js",
"import": "./dist/index.browser.js",
"require": "./dist/index.browser.umd.cjs"
Expand Down
103 changes: 23 additions & 80 deletions packages/graph/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
}

#placeholder,
#placeholder2 {
#placeholder1,
#placeholder2,
#placeholder3 {
width: 100%;
height: 500px;
background-color: #fff;
Expand All @@ -26,103 +28,44 @@
</style>

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@hpcc-js/[email protected]/dist/index.min.js"></script>

<script type="module">
import "@hpcc-js/common/font-awesome/css/font-awesome.min.css";
</script>
</head>

<body onresize="doResize()">
<h1>ESM Quick Test</h1>
<div id="placeholder2"></div>
<div id="placeholder1"></div>
<script type="module">
import { Graph2 } from "./src/index.ts";
import { Test6 as Test } from "./tests/index.ts";

import "@hpcc-js/common/font-awesome/css/font-awesome.min.css";

const nodeCount = 500;

const categories = [
{ id: 0, imageChar: "fa-user" },
{ id: 1, imageChar: "fa-home" }
];
new Test()
.target("placeholder1")
.render()
;
</script>
<h1>ESM Quick Test</h1>
<div id="placeholder2"></div>
<script type="module">
import { Test1 as Test } from "./tests/index.ts";

new Graph2()
.categories(categories)
.data(createData())
new Test()
.target("placeholder2")
.layout("ForceDirected")
.applyScaleOnLayout(true)
.allowDragging(false)
.render()
;

function createData() {
const rawData = {
"nodes": Array.from({ length: nodeCount }, (_, i) => {
return { "name": i + 1, "type": "number" }
}),
"links": Array.from({ length: nodeCount }, (_, i) => {
return { "source": Math.floor(Math.sqrt(i)), "target": i };
}).slice(1)
};
const vertices = rawData.nodes.map(function (node, idx) {
return {
categoryID: 0,
id: idx,
text: "" + node.name,
textFontFamily: "monospace"
};
});
return {
vertices: vertices,
edges: rawData.links.map(function (link, idx) {
return {
id: idx,
source: vertices[link.source],
target: vertices[link.target],
label: link.name,
fontFamily: "monospace"
};
}),
};
}
</script>
<div id="placeholder"></div>
<div id="placeholder3"></div>
<script type="module">
import { SankeyGraph } from "./src/index.ts";

import "@hpcc-js/common/font-awesome/css/font-awesome.min.css";
import { Test3 as Test } from "./tests/index.ts";

new SankeyGraph()
.target("placeholder")
.vertexColumns(["category", "id", "label"])
.vertices([
[0, 0, "Year 1"],
[0, 1, "Year 2"],
[0, 2, "Year 3"],
[0, 3, "Year 4"],
[1, 4, "Math"],
[1, 5, "English"],
[1, 6, "Geometry"],
[1, 7, "Science"],
])
.edgeColumns(["source", "target", "weight"])
.edges([
[0, 4, 1],
[1, 4, 1],
[2, 4, 1],
[3, 4, 1],
[0, 5, 1],
[1, 5, 1],
[2, 6, 1],
[3, 6, 1],
[1, 7, 1],
[2, 7, 1],
[3, 7, 1],
])
new Test()
.target("placeholder3")
.render()
;
</script>
<script>
function doResize() {
window.__widget?.resize()?.render();
}
</script>
</body>
Expand Down
3 changes: 2 additions & 1 deletion packages/graph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"d3-shape": "^1",
"d3-tile": "^1",
"d3-transition": "^1",
"dagre": "0.8.5"
"dagre": "0.8.5",
"lit-html": "3.2.1"
},
"peerDependencies": {},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/graph/src/__tests__/test5.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Vertex4, CentroidVertex4 } from "@hpcc-js/react";
import { Graph2 } from "../graph2/graph";
import { GraphReact } from "../react/graphReact.ts";

const VERTEX_ARR = [{
id: 0,
Expand Down
33 changes: 33 additions & 0 deletions packages/graph/src/common/graphT.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.graph_GraphT .graphVertex {
cursor: pointer;
}

.graph_GraphT .allowDragging .graphVertex {
cursor: pointer;
}

.graph_GraphT .allowDragging .graphVertex.grabbed {
cursor: grabbing;
}

.graph_GraphT .graphEdge {
stroke: darkgray;
fill: none;
}

.graph_GraphT .graphEdge>text {
stroke: none;
fill: black;
}

.graph_GraphT .graphEdge.hide-text>text {
display: none;
}

.graph_GraphT g.selected rect {
stroke: navy !important;
}

.graph_GraphT g.selected circle {
stroke: navy !important;
}
Loading

0 comments on commit a4c4a1d

Please sign in to comment.