Compare commits

...

15 Commits

Author SHA1 Message Date
Arsen Mirzaev Tatyano-Muradovich 0300f33765 remove `default` 2025-01-11 22:37:40 +07:00
Arsen Mirzaev Tatyano-Muradovich 15c0a70534 remove `default` 2025-01-11 22:37:09 +07:00
Arsen Mirzaev Tatyano-Muradovich cc43bf3538 reminified + from mjs.min to min.mjs 2025-01-11 20:57:34 +07:00
Arsen Mirzaev Tatyano-Muradovich 3cc96d7715 added important fragments of the code 2025-01-11 16:20:32 +07:00
Arsen Mirzaev Tatyano-Muradovich 186c54733d added screenshotes of the code 2025-01-11 16:17:00 +07:00
Arsen Mirzaev Tatyano-Muradovich 3b55f62b46 js to mjs 2025-01-11 16:07:09 +07:00
Arsen Mirzaev Tatyano-Muradovich 448dca798d minified version 2.0.0 2025-01-11 16:05:12 +07:00
Arsen Mirzaev Tatyano-Muradovich d7d6bfbcd8 updated for 2.0.0 release 2025-01-11 15:41:09 +07:00
Arsen Mirzaev Tatyano-Muradovich 3a41f38c11 added the graph 2.0.0 demonstration 2025-01-11 15:36:18 +07:00
Arsen Mirzaev Tatyano-Muradovich 2ff5ef536c resolved #6, resolved #10, resolved #11, resolved #4, resolved #8, resolved #5, and #3 2025-01-11 15:23:54 +07:00
Arsen Mirzaev Tatyano-Muradovich 53ee5648bb added example 2024-12-22 23:43:10 +07:00
Arsen Mirzaev Tatyano-Muradovich 7c3a48bbbc added timer for synchronization and intervally node handler 2022-12-11 18:37:49 +10:00
Arsen Mirzaev Tatyano-Muradovich a50a144a8b optimization, delete collisions and transit to css animation 2022-12-11 17:19:54 +10:00
Arsen Mirzaev Tatyano-Muradovich 3fe61ac509 huge update on progress and insane optimization (from js to css animation) 2022-12-10 20:41:11 +10:00
Arsen Mirzaev Tatyano-Muradovich bb51a6869a rebuild nodes move from js to css transition (not completed) 2022-12-07 19:31:35 +10:00
7 changed files with 2099 additions and 1479 deletions

155
README.md Normal file
View File

@ -0,0 +1,155 @@
# graph.mjs
Module for creating smart graphs
## Example
### JavaScript
```js
import("/js/modules/graph.mjs").then((graph) => {
// Imported the graph.mjs module
// Initializing the graph instance
const instance = new graph.core(document.getElementById('graph'));
// Writing settings of the graph instance
instance.living = 3000;
instance.camera = true;
instance.operate = true;
// Initializing and registering nodes
const genesis = instance.node(new graph.node(document.getElementById('genesis')));
const food = instance.node(new graph.node(document.getElementById('food')));
const tofu = instance.node(new graph.node(document.getElementById('tofu')));
const broccoli = instance.node(new graph.node(document.getElementById('broccoli')));
const wtf = instance.node(new graph.node(document.getElementById('wtf')));
const bebra = instance.node(new graph.node(document.getElementById('bebra')));
const feet = instance.node(new graph.node(document.getElementById('feet')));
const anarchy = instance.node(new graph.node(document.getElementById('anarchy')));
// Writing settings for every node
instance.nodes.forEach((node) => { node.variables.get("inputs").type = "deg" });
// Initializing and registering edges
instance.edge(new graph.edge(feet, bebra));
instance.edge(new graph.edge(bebra, genesis));
instance.edge(new graph.edge(anarchy, genesis));
instance.edge(new graph.edge(food, genesis));
instance.edge(new graph.edge(tofu, food));
instance.edge(new graph.edge(broccoli, food));
instance.edge(new graph.edge(wtf, tofu));
instance.edge(new graph.edge(wtf, broccoli));
});
```
### HTML
```html
<section id='graph'>
<article id="genesis" class="node unselectable"><a>genesis</a></article>
<article id="food" class="node unselectable"><a>food</a></article>
<article id="tofu" class="node unselectable"><a>tofu</a></article>
<article id="broccoli" class="node unselectable"><a>broccoli</a></article>
<article id="wtf" class="node unselectable"><a>tofu with broccoli</a></article>
<article id="bebra" class="node unselectable"><a>bebra</a></article>
<article id="feet" class="node unselectable"><a>feet</a></article>
<article id="anarchy" class="node unselectable"><a>anarchy</a></article>
</section>
```
### CSS
```css
@keyframes node-movement {
0% {
left: var(--graph-node-from-left);
top: var(--graph-node-from-top);
}
100% {
left: var(--graph-node-to-left);
top: var(--graph-node-to-top);
}
}
.unselectable {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
body {
height: 100vh;
margin: 0;
overflow: hidden;
}
body:active {
cursor: move;
}
section#graph {
left: var(--graph-shell-left);
top: var(--graph-shell-top);
width: 100vw;
height: 100vh;
position: absolute;
}
article.node {
z-index: calc(500 + var(--graph-node-layer, 0) - var(--graph-node-inputs, 0));
left: var(--graph-node-from-left, var(--graph-node-left));
top: var(--graph-node-from-top, var(--graph-node-top));
width: var(--graph-node-augmented, 100px);
height: var(--graph-node-augmented, 100px);
position: absolute;
display: flex;
cursor: grab;
border-radius: 100%;
background-color: #33dd6d;
filter: hue-rotate(calc(0deg + var(--graph-node-inputs) * -15));
}
article.node.movement {
animation-name: node-movement;
animation-fill-mode: forwards;
animation-duration: 0.6s;
/* animation-duration: 5.5s; */
animation-timing-function: cubic-bezier(0, 1, 1, 1);
}
article.node:active {
cursor: grabbing;
}
article.node > a:first-of-type {
margin: auto;
text-align: center;
text-decoration: unset;
font-weight: bold;
cursor: pointer;
color: black;
}
svg.edge {
z-index: -500;
position: absolute;
width: 100%;
height: 100%;
}
svg.edge > line {
stroke: #816262;
stroke-width: 8px;
}
```
### Result
![graph 2.0.0 preview](preview/graph_demonstration_2_0_0.gif)<br><br>
[Try it on CodePen](https://codepen.io/mirzaev-sexy/pen/Rwyxprz)
## Important fragments of the code
Iterating over nodes<br>
![iterating over nodes](preview/code/1.png)<br><br>
Pushing and pulling<br>
![pushing and pulling](preview/code/2.png)

1479
graph.js

File diff suppressed because it is too large Load Diff

69
graph.min.mjs Normal file

File diff suppressed because one or more lines are too long

1875
graph.mjs Normal file

File diff suppressed because it is too large Load Diff

BIN
preview/code/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

BIN
preview/code/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 MiB