Skip to content

Commit e3d8f13

Browse files
authored
feat: add GraphView supports (#7)
* feat: add GraphView supports * feat: Add cache mode for GraphView && Add both edge cache for Graph. * perf: optimize code of getting related nodes. * feat: add tree traversing * feat: update README and docs * fix: reduce changes for data replacing
1 parent 97ff366 commit e3d8f13

22 files changed

+4300
-129
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/dist
1616

1717
# docs
18-
/docs
18+
# /docs
1919

2020
# Bundle visualizer
2121
stats.html

README.md

+8-25
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,21 @@
66
77
![build status](https://img.shields.io/github/workflow/status/antvis/graphlib/Build) ![coverage status](https://img.shields.io/codecov/c/github/antvis/graphlib)
88

9-
## Content of Package
9+
## Features
1010

11-
### Namespaces
11+
- Manage graph structure data with simple APIs.
12+
- Easily batch multiple changes for performance optimization.
13+
- GraphView for efficient data transformation.
1214

13-
- [algorithm](docs/modules/algorithm.md)
14-
- [comparision](docs/modules/comparision.md)
15-
- [essence](docs/modules/essence.md)
16-
- [generate](docs/modules/generate.md)
15+
## API
1716

1817
### Classes
1918

2019
- [Graph](docs/classes/Graph.md)
21-
- [GraphWithEvent](docs/classes/GraphWithEvent.md)
20+
- [GraphView](docs/classes/GraphView.md)
2221

2322
## Change Log
2423

25-
#### 1.2.0
24+
#### 2.0
2625

27-
- 🎉 `GraphWithEvent` now you can use graph with event listener
28-
- 🎉 `essece` module for graph basic essence property check
29-
- 🎉 `generate` module for graph generate new graph, now support graph's complement;
30-
-
31-
32-
#### 1.1.0
33-
34-
- 🎉 Now we have comparision module for graph comparing with nodes/edges/options even subgraph
35-
- 💪 Add isGraph to check if a object is a "Graph", and add a self loop checking function
36-
37-
#### 1.0.1
38-
39-
- 🔨 Completes test and bring all to 100%
40-
41-
#### 1.0.0
42-
43-
- 🎉 Release new graphlib with graph and algorithm
26+
- 🎉 Release new version

__tests__/graph.spec.ts

+43
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ test('reduceChanges', () => {
4747
oldValue: 2,
4848
newValue: 3,
4949
},
50+
{
51+
type: 'NodeDataUpdated',
52+
id: 'B',
53+
propertyName: 'foo',
54+
oldValue: 1,
55+
newValue: 2,
56+
},
57+
{
58+
type: 'NodeDataUpdated',
59+
id: 'B',
60+
oldValue: {
61+
foo: 2,
62+
},
63+
newValue: {
64+
bar: 3,
65+
},
66+
},
5067
{
5168
type: 'EdgeDataUpdated',
5269
id: 'A',
@@ -70,6 +87,16 @@ test('reduceChanges', () => {
7087
oldValue: 1,
7188
newValue: 3,
7289
},
90+
{
91+
type: 'NodeDataUpdated',
92+
id: 'B',
93+
oldValue: {
94+
foo: 2,
95+
},
96+
newValue: {
97+
bar: 3,
98+
},
99+
},
73100
{
74101
type: 'EdgeDataUpdated',
75102
id: 'A',
@@ -250,6 +277,14 @@ test('bsf', () => {
250277
nodeIdList.push(node.id);
251278
});
252279
expect(nodeIdList).toEqual([0, 1, 2, 3]);
280+
281+
// Abort on 1.
282+
nodeIdList.length = 0;
283+
graph.bfs(0, (node) => {
284+
nodeIdList.push(node.id);
285+
if (node.id === 1) return true;
286+
});
287+
expect(nodeIdList).toEqual([0, 1]);
253288
});
254289

255290
test('dsf', () => {
@@ -273,6 +308,14 @@ test('dsf', () => {
273308
nodeIdList.push(node.id);
274309
});
275310
expect(nodeIdList).toEqual([0, 1, 3, 2]);
311+
312+
// Abort on 1.
313+
nodeIdList.length = 0;
314+
graph.dfs(0, (node) => {
315+
nodeIdList.push(node.id);
316+
if (node.id === 1) return true;
317+
});
318+
expect(nodeIdList).toEqual([0, 1]);
276319
});
277320

278321
test('clone', () => {

0 commit comments

Comments
 (0)