Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
94e0950
modify package.json to prepare for release
harchcode Oct 6, 2020
4e43431
Merge branch 'master' of https://github.com/harchcode/web-digraph
harchcode Oct 7, 2020
1b4f648
Merge branch 'master' of https://github.com/harchcode/web-digraph
harchcode Oct 7, 2020
97074a4
fix package description
harchcode Oct 13, 2020
6a877f1
bump version
harchcode Oct 13, 2020
447012f
update package and use tsdx
harchcode Apr 2, 2022
7204fe1
remove cache and add to gitignore
harchcode Apr 2, 2022
2dacfe8
initial, draw background
harchcode Apr 6, 2022
c5519e5
draw node and edge
harchcode Apr 11, 2022
993d43b
basic action example
harchcode Apr 12, 2022
bc1ce48
add more shapes, intersections, and fixes
harchcode Apr 13, 2022
29871c5
fix edge
harchcode Apr 14, 2022
ed2cbbb
fix intersection
harchcode Apr 16, 2022
35f34ea
render shape contents
harchcode Apr 18, 2022
8eb9b62
reset to empty proj with updated dependencies
harchcode Nov 11, 2022
cd22f63
draw background (fail)
harchcode Nov 12, 2022
426263c
basic node and edge
harchcode Nov 12, 2022
3f5f1e6
add generate on example and try experiment with get intersection point
harchcode Nov 13, 2022
905f3f9
update
harchcode Nov 13, 2022
fac2c6f
adjust default shape and draw content
harchcode Nov 13, 2022
64547fd
hover and refactor
harchcode Nov 13, 2022
a1ff6c3
add move node, create edge, and some adjustments
harchcode Nov 14, 2022
74cc560
update create path and example
harchcode Nov 14, 2022
ae41793
refactor
harchcode Nov 14, 2022
ac1a447
update and refactor
harchcode Nov 14, 2022
1b7d735
only draw node and edge if in view
harchcode Nov 14, 2022
a5ed13c
refactor and update
harchcode Nov 15, 2022
1ea3e86
use 4 canvases
harchcode Nov 15, 2022
0a7f37c
use resizeobserver
harchcode Nov 15, 2022
a1eb870
updates
harchcode Nov 16, 2022
e58c2bb
move node and try draw region
harchcode Nov 16, 2022
ac69f5e
update
harchcode Nov 16, 2022
17958c7
quad tree first attempt
harchcode Nov 17, 2022
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
6 changes: 3 additions & 3 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules
dist
dist-*
node_modules
dist
dist-*
56 changes: 20 additions & 36 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,36 +1,20 @@
module.exports = {
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
extends: [
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin
"prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: "module" // Allows for the use of imports
},
rules: {
// Error
"arrow-parens": ["error", "as-needed", { requireForBlockBody: false }],
"comma-dangle": ["error", "never"],
"max-lines": ["error", 600],
"no-console": ["error", { allow: ["warn", "error", "info"] }],
"no-param-reassign": ["error", { props: false }],
"@typescript-eslint/no-use-before-define": ["error", { functions: false }]
},
overrides: [
{
files: ["*.js", "*.jsx"],
rules: {
"@typescript-eslint/no-var-requires": "off"
}
},
{
files: ["*.js", "*.jsx", "*.ts", "*.tsx"],
rules: {
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/explicit-function-return-type": "off"
}
}
]
};
module.exports = {
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
extends: [
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: "module" // Allows for the use of imports
},
rules: {
// Error
"arrow-parens": ["error", "as-needed", { requireForBlockBody: false }],
"comma-dangle": ["error", "never"],
"max-lines": ["error", 5000],
"no-console": ["error", { allow: ["warn", "error", "info"] }],
"no-param-reassign": "off",
"@typescript-eslint/no-use-before-define": ["error", { functions: false }]
}
};
41 changes: 41 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI

on: [pull_request]

env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

jobs:
build:
name: CI on Node ${{ matrix.node }} and ${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
node: ["14.x"]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1

- name: Lint
run: npm run lint

- name: Test
run: npm test --ci --coverage --maxWorkers=2

- name: Build
run: npm run build

- name: Check size
run: npm run size
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on:
push:
# Sequence of patterns matched against refs/tags
tags:
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10

env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

jobs:
build:
name: Build and publish to NPM
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1

- name: Build
run: npm run build

- name: Publish
run: |
echo -e "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ${{ github.workspace }}/.npmrc
npm publish
48 changes: 21 additions & 27 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
.nyc_output
coverage

# production
/build
/dist
/dist-*

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

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

.cache
.rts2_cache_cjs
.rts2_cache_es
.rts2_cache_umd
node_modules
dist
dist-ssr
*.local
coverage
docs

# Editor directories and files
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint-staged
6 changes: 0 additions & 6 deletions .npmignore

This file was deleted.

1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.10.0
10 changes: 10 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
printWidth: 80,
semi: true,
singleQuote: false,
trailingComma: "none",
useTabs: false,
bracketSpacing: true,
arrowParens: "avoid",
endOfLine: "auto"
};
9 changes: 0 additions & 9 deletions .prettierrc.js

This file was deleted.

17 changes: 10 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"editor.tabSize": 2,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript", "typescript"],
}
{
"editor.tabSize": 2,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript", "typescript"],
"typescript.tsdk": "node_modules/typescript/lib"
}
147 changes: 147 additions & 0 deletions example/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import { createGraphView, GraphEdge, GraphNode, GraphView } from "../src";
import { edgeShapes, nodeShapes } from "./shapes";

function getRandomInt(min: number, max: number) {
min = Math.ceil(min);
max = Math.floor(max);

return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive
}

const graphDiv = document.getElementById("graph") as HTMLDivElement;
const nodeCountInput = document.getElementById(
"node-count-input"
) as HTMLInputElement;
const generateButton = document.getElementById(
"generate-button"
) as HTMLButtonElement;
const toggleModeButton = document.getElementById(
"toggle-mode-button"
) as HTMLButtonElement;
const deleteButton = document.getElementById(
"delete-button"
) as HTMLButtonElement;

let graphView: GraphView<GraphNode, GraphEdge>;

let lastId = 0;
let mode: "move" | "create" = "move";

function generate(nodeCount = 100) {
let id = 1;

graphView.clear();

const columns = Math.ceil(Math.sqrt(nodeCount));

for (let i = 0; i < nodeCount; i++) {
const row = (i / columns) | 0;
const col = i % columns;

graphView.addNode(
{
id,
x: col * 320,
y: row * 320
},
nodeShapes[getRandomInt(0, nodeShapes.length)]
);

id++;

if (i > 0) {
graphView.addEdge(
{
id,
sourceId: id - (i > 1 ? 3 : 2),
targetId: id - 1
},
edgeShapes[getRandomInt(0, edgeShapes.length)]
);

id++;
}
}

lastId = id - 1;
}

function main() {
graphView = createGraphView(graphDiv);

generate(100);

generateButton.addEventListener("click", () => {
const len = parseInt(nodeCountInput.value, 10);

generate(len);
});

toggleModeButton.addEventListener("click", () => {
if (mode === "create") mode = "move";
else mode = "create";
});

deleteButton.addEventListener("click", () => {
const selectedIds = graphView.getSelection();

for (const id of selectedIds) {
graphView.remove(id);
}
});

graphDiv.addEventListener("mousedown", e => {
const pos = graphView.getViewPosFromWindowPos(e.x, e.y);
const hoveredId = graphView.getHoveredId();

if (hoveredId) {
graphView.addSelection(hoveredId);
// graphView.select(hoveredId);
} else {
graphView.clearSelection();
}

if (mode === "move") {
if (!hoveredId) graphView.beginMoveView();
else
graphView.beginMoveNodes(
graphView.getSelectedNodeIds(),
pos[0],
pos[1]
);
} else if (mode === "create") {
if (!hoveredId) {
lastId++;

graphView.addNode(
{ id: lastId, x: pos[0], y: pos[1] },
nodeShapes[getRandomInt(0, nodeShapes.length)]
);
} else {
graphView.beginDragLine();
}
}
});

graphDiv.addEventListener("mouseup", () => {
graphView.endMoveView();
graphView.endMoveNodes();

const dragLineNodes = graphView.endDragLine();

if (dragLineNodes) {
lastId++;

graphView.addEdge(
{
id: lastId,
sourceId: dragLineNodes[0].id,
targetId: dragLineNodes[1].id
},
edgeShapes[getRandomInt(0, edgeShapes.length)]
);
}
});
}

main();
Loading