1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-09 09:35:02 +09:00

graph node radius logarithmic scale and steps limit update

This commit is contained in:
Andrew Simachev 2024-07-26 13:39:11 +02:00
parent 45f67ec4aa
commit ff7103494c
No known key found for this signature in database
GPG key ID: 49A163D0D14E6FD8
5 changed files with 30 additions and 22 deletions

21
dist/workers/graph.js vendored
View file

@ -83,7 +83,7 @@ let rootId = '';
let root = null;
let paused = false;
let isOver = '';
let maxEdges = 0;
let maxDegree = 0;
let clusters = {};
addEventListener('message', ({ data }) => {
@ -251,10 +251,10 @@ updateForces = () => {
simulation.force('cluster', d3.forceCluster()
.centers(d => clusters.find(c => c.id == d.type))
.strength(1)
.centerInertia(0.5));
.centerInertia(0.75));
simulation.
force('collide', d3.forceCollide(d => getRadius(d)));
force('collide', d3.forceCollide(d => getRadius(d) * 2));
};
let map = getNodeMap();
@ -840,18 +840,21 @@ const getRadius = (d) => {
k = 2;
};
let e = 0;
let degree = 0;
if (settings.link) {
e += d.linkCnt
degree += d.linkCnt
};
if (settings.relation) {
e += d.relationCnt;
degree += d.relationCnt;
};
maxEdges = Math.max(maxEdges, e);
maxDegree = Math.max(maxDegree, degree);
if (maxEdges > 0) {
k += Math.min(1, e / maxEdges);
if (maxDegree > 0) {
const logDegree = Math.log(degree + 1);
const logMaxDegree = Math.log(maxDegree + 1);
k += (logDegree / logMaxDegree) * 0.9;
};
return d.radius / transform.k * k;

View file

@ -34,6 +34,7 @@ export default {
widgets: 20,
space: 10,
notification: 20,
graphDepth: 5,
},
default: {

View file

@ -143,10 +143,12 @@ class Drag extends React.Component<Props> {
if (strictSnap && snaps.length && (this.value < snaps[0] / 2)) {
this.value = 0;
} else {
for (const s of snaps) {
const d = strictSnap ? s / 2 : SNAP;
if ((this.value >= s - d) && (this.value < s + d)) {
this.value = s;
const step = 1 / snaps.length;
for (const snap of snaps) {
const d = strictSnap ? step / 2 : SNAP;
if ((this.value >= snap - d) && (this.value < snap + d)) {
this.value = snap;
break;
};
};

View file

@ -1,11 +1,9 @@
import * as React from 'react';
import $ from 'jquery';
import { observer } from 'mobx-react';
import { I, S, keyboard, translate } from 'Lib';
import { I, S, J, keyboard, translate } from 'Lib';
import { MenuItemVertical, Drag } from 'Component';
const MAX_DEPTH = 2;
const MenuGraphSettings = observer(class MenuGraphSettings extends React.Component<I.Menu> {
node = null;
@ -18,12 +16,13 @@ const MenuGraphSettings = observer(class MenuGraphSettings extends React.Compone
};
render () {
const { graphDepth } = J.Constant.limit;
const values = this.getValues();
const sections = this.getSections();
const snaps = [];
for (let i = 1; i <= MAX_DEPTH; i++) {
snaps.push(i / MAX_DEPTH);
for (let i = 1; i <= graphDepth; i++) {
snaps.push(i / graphDepth);
};
const Section = (item: any) => (
@ -40,7 +39,7 @@ const MenuGraphSettings = observer(class MenuGraphSettings extends React.Compone
</div>
<div className="drag">
<Drag
value={(values[item.id] - 1) / MAX_DEPTH}
value={values[item.id] / graphDepth}
snaps={snaps}
strictSnap={true}
onMove={(e: any, v: number) => this.onDragMove(item.id, v)}
@ -137,7 +136,7 @@ const MenuGraphSettings = observer(class MenuGraphSettings extends React.Compone
};
getDepth (v: number) {
return Math.floor(v * MAX_DEPTH) + 1;
return Math.max(1, Math.floor(v * J.Constant.limit.graphDepth));
};
getKey () {

View file

@ -332,12 +332,15 @@ const Graph = observer(class Graph extends React.Component<Props> {
};
case 'onMouseMove': {
if (this.isDragging || !settings.preview) {
if (this.isDragging) {
break;
};
this.subject = this.nodes.find(d => d.id == data.node);
this.subject ? this.onPreviewShow(data) : this.onPreviewHide();
if (settings.preview) {
this.subject ? this.onPreviewShow(data) : this.onPreviewHide();
};
break;
};