Skip to content

Commit

Permalink
Merge pull request #4285 from GordonSmith/V3_GRAPH
Browse files Browse the repository at this point in the history
feat: Upgrade graph, html and react to v3
  • Loading branch information
GordonSmith authored Nov 11, 2024
2 parents c6496af + a1aa027 commit b5bb00d
Show file tree
Hide file tree
Showing 86 changed files with 3,023 additions and 2,404 deletions.
1,814 changes: 616 additions & 1,198 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"xpackages/eclwatch",
"packages/esbuild-plugins",
"xpackages/form",
"xpackages/graph",
"xpackages/html",
"packages/graph",
"packages/html",
"xpackages/layout",
"xpackages/leaflet-shim",
"xpackages/loader",
Expand All @@ -38,8 +38,8 @@
"xpackages/other",
"packages/phosphor",
"packages/phosphor-shim",
"xpackages/preact-shim",
"xpackages/react",
"packages/preact-shim",
"packages/react",
"xpackages/requirejs-shim",
"xpackages/timeline",
"xpackages/tree",
Expand Down
10 changes: 3 additions & 7 deletions packages/common/tests/coreTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@ export function classDef<T extends Class>(module: string, WidgetClass: { new():
while (constructorName.length && constructorName[0] === "_") {
constructorName = constructorName.substr(1);
}
// Remove any trailing numerics
while (constructorName.length && !isNaN(parseInt(constructorName[constructorName.length - 1], 10))) {
constructorName = constructorName.substr(0, constructorName.length - 1);
}
const widget = new WidgetClass();
const classID = widget.classID();
if (classID.indexOf(".") >= 0) {
expect(classID.indexOf(`${module}_`), `Correct module: ${module}`).to.equal(0);
expect(classID.indexOf(`.${constructorName}`), `Correct constructorName: ${constructorName}`).to.equal(classID.length - constructorName.length - 1);
expect(classID.indexOf(`${module}_`), `Incorrect module: ${module}`).to.equal(0);
expect(classID.indexOf(`.${constructorName}`), `Incorrect constructorName: ${constructorName}`).to.equal(classID.length - constructorName.length - 1);
} else {
expect(`${module}_${constructorName}` === classID, `Correct classID: ${module}_${constructorName} === ${classID}`).to.be.true;
expect(`${module}_${constructorName}` === classID, `Incorrect classID: ${module}_${constructorName} === ${classID}`).to.be.true;
}
});
});
Expand Down
55 changes: 25 additions & 30 deletions packages/graph/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,47 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Dev",
"name": "test-browser",
"type": "msedge",
"request": "launch",
"url": "file:///${workspaceRoot}/index.html",
"runtimeArgs": [
"--allow-file-access-from-files",
"--disable-web-security"
"url": "http://localhost:8888",
"webRoot": "${workspaceFolder}",
"outFiles": [
"${workspaceFolder}/**/*.js",
"!**/node_modules/**"
],
"webRoot": "${workspaceRoot}"
},
{
"name": "lws",
"type": "msedge",
"name": "test-node",
"type": "node",
"request": "launch",
"url": "http://localhost:8080/../packages/graph/index.html",
"runtimeArgs": [
"--allow-file-access-from-files",
"--disable-web-security"
"run-script",
"test-node"
],
"webRoot": "${workspaceRoot}"
},
{
"type": "msedge",
"request": "launch",
"name": "index.md",
"url": "${workspaceFolder}/../../website/index.html?debug=1#packages/graph/docs/index.md",
"runtimeArgs": [
"--allow-file-access-from-files",
"--disable-web-security"
"runtimeExecutable": "npm",
"skipFiles": [
"<node_internals>/**"
],
"outFiles": [
"${workspaceFolder}/**/*.js",
"!**/node_modules/**"
],
"webRoot": "${workspaceFolder}/../../website"
},
{
"type": "msedge",
"name": "index.html",
"request": "launch",
"name": "http index.md",
"url": "http://localhost:8080/${workspaceFolder}/../../website/index.html?debug=1#packages/graph/docs/index.md",
"type": "msedge",
"url": "file:///${workspaceFolder}/index.html",
"runtimeArgs": [
"--allow-file-access-from-files",
"--disable-web-security"
],
"webRoot": "${workspaceFolder}/../../website"
"webRoot": "${workspaceFolder}",
"outFiles": [
"${workspaceFolder}/**/*.js",
"!**/node_modules/**"
]
}
]
}
25 changes: 6 additions & 19 deletions packages/graph/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"version": "2.0.0",
"tasks": [
{
"label": "es6 watch",
"label": "gen-types-watch",
"type": "npm",
"script": "compile-es6-watch",
"script": "gen-types-watch",
"problemMatcher": [
"$tsc-watch"
],
Expand All @@ -13,18 +13,7 @@
}
},
{
"label": "umd watch",
"type": "npm",
"script": "compile-umd-watch",
"problemMatcher": [
"$tsc-watch"
],
"presentation": {
"group": "group-build"
}
},
{
"label": "bundle watch",
"label": "bundle-watch",
"type": "npm",
"script": "bundle-watch",
"problemMatcher": [],
Expand All @@ -35,15 +24,13 @@
{
"label": "build",
"dependsOn": [
"es6 watch",
"umd watch",
"bundle watch"
"gen-types-watch",
"bundle-watch",
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
}
]
}
30 changes: 30 additions & 0 deletions packages/graph/esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { browserTpl } from "@hpcc-js/esbuild-plugins";
import pkg from "./package.json" with { type: "json" };

// config ---
await Promise.all([
browserTpl("src/index.ts", "dist/index", {
keepNames: true,
alias: {
"d3-array": "@hpcc-js/common",
"d3-brush": "@hpcc-js/common",
"d3-collection": "@hpcc-js/common",
"d3-color": "@hpcc-js/common",
"d3-dispatch": "@hpcc-js/common",
"d3-drag": "@hpcc-js/common",
"d3-dsv": "@hpcc-js/common",
"d3-ease": "@hpcc-js/common",
"d3-format": "@hpcc-js/common",
"d3-interpolate": "@hpcc-js/common",
"d3-scale": "@hpcc-js/common",
"d3-selection": "@hpcc-js/common",
"d3-time-format": "@hpcc-js/common",
"d3-transition": "@hpcc-js/common",
"d3-zoom": "@hpcc-js/common"
},
external: [
...Object.keys(pkg.dependencies),
...Object.keys(pkg.peerDependencies),
]
})
]);
171 changes: 129 additions & 42 deletions packages/graph/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,149 @@
<html>

<head>
<meta charset="utf-8">
<title>@hpcc-js/graph</title>

<script>
const isLocal = window.location.protocol === "file:" || window.location.origin.indexOf("http://localhost") === 0;
if (isLocal) {
document.write('<link rel="stylesheet" href="../../packages/common/font-awesome/css/font-awesome.min.css">');
document.write('<link rel="stylesheet" href="./src/Graph.css">');
document.write('<link rel="stylesheet" href="./src/Vertex.css">');
document.write('<link rel="stylesheet" href="./src/Edge.css">');
document.write('<link rel="stylesheet" href="./src/Subgraph.css">');
document.write('<script type="text/javascript" src="../../packages/loader/dist/index.js"><' + '/script>');
} else {
document.write('<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@hpcc-js/common/font-awesome/css/font-awesome.min.css">');
document.write('<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@hpcc-js/loader"><' + '/script>');
<title>Home</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f0f0f0;
}
</script>

<script>
var hpccLoader = window["@hpcc-js/loader"];
</script>
h1 {
text-align: center;
margin-top: 50px;
}

<style>
#placeholder,
.placeholder {
position: absolute;
left: 8px;
top: 8px;
right: 8px;
bottom: 8px;
#placeholder2 {
width: 100%;
height: 500px;
background-color: #fff;
margin-top: 20px;
}
</style>

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@hpcc-js/[email protected]/dist/index.min.js"></script>
<script type="importmap">
{
"imports": {
"@hpcc-js/util": "../util/dist/index.js",
"@hpcc-js/common": "../common/dist/index.js",
"@hpcc-js/api": "../api/dist/index.js",
"@hpcc-js/chart": "../chart/dist/index.js",
"@hpcc-js/codemirror": "../codemirror/dist/index.js",
"@hpcc-js/comms": "../comms/dist/index.js",
"@hpcc-js/dgrid": "../dgrid/dist/index.js",
"@hpcc-js/react": "../react/dist/index.js",
"@hpcc-js/html": "../html/dist/index.js",
"@hpcc-js/graph": "../graph/dist/index.js",
"xreact":"../../node_modules/preact/compat/dist/compat.module.js",
"xreact-dom/client":"../../node_modules/preact/compat/client.mjs",
"xpreact":"../../node_modules/preact/dist/preact.module.js",
"xpreact/compat":"../../node_modules/preact/compat/dist/compat.module.js",
"xpreact/hooks":"../../node_modules/preact/hooks/dist/hooks.module.js"
}
}
</script>
<link rel="stylesheet" href="../api/dist/index.css">
<link rel="stylesheet" href="../common/dist/index.css">
<link rel="stylesheet" href="../html/dist/index.css">
<link rel="stylesheet" href="../react/dist/index.css">
<link rel="stylesheet" href="./dist/index.css">
</head>

<body onresize="doResize()">
<div id="placeholder">
</div>
<script>
var app;
hpccLoader.amd().then(function (require) {
require(["lib-umd/__tests__/index.js"], function (testMod) {
<h1>ESM Quick Test</h1>
<div id="placeholder"></div>
<script type="module">
import { SankeyGraph } from "@hpcc-js/graph";

new SankeyGraph()
.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],
])
.target("placeholder")
.render()
;
</script>
<div id="placeholder2"></div>
<script type="module">
import { Graph2 } from "@hpcc-js/graph";
const nodeCount = 500;

app = new testMod.Test()
.target("placeholder")
.wasmFolder(isLocal ? "https://cdn.jsdelivr.net/npm/@hpcc-js/wasm/dist" : "./dist")
.render();
const categories = [
{ id: 0, imageChar: "fa-user" },
{ id: 1, imageChar: "fa-home" }
];

new Graph2()
.categories(categories)
.data(createData())
.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>
<script>
function doResize() {
if (app) {
app
.resize()
.lazyRender();
}
window.__widget?.resize()?.render();
}
</script>
</body>
Expand Down
Loading

0 comments on commit b5bb00d

Please sign in to comment.