Skip to content

Commit

Permalink
feat: add dragged property to VertexComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
CorvusYe committed Oct 20, 2024
1 parent da35b13 commit 6510e83
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 1.1.4
- feat: using tag similarity as a layout element.
example:
```dart
/// @en: Make the repulsion between similar tags smaller
///
/// @zh: 使相似标签之间的排斥力变小
CoulombReverseDecorator(sameTagsFactor: 0.8),
```
- feat: add `dragged` property to `VertexComponent` to indicate whether the vertex is being dragged.
## 1.1.3+1
- fix: the crash issue when force is not a number [ForceMotionDecorator].
Expand Down
20 changes: 20 additions & 0 deletions lib/core/algorithm/decorator/pin_decorator.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2024- All flutter_graph_view authors. All rights reserved.
//
// This source code is licensed under Apache 2.0 License.

import 'package:flutter_graph_view/flutter_graph_view.dart';

/// Pin the points that have been dragged in the fixed graph, preventing them from moving
///
/// 固定图中被拖拽过的点,防止其移动的装饰器
class PinDecorator extends ForceDecorator {
PinDecorator({super.decorators});

@override
bool needContinue(Vertex v) {
if (v.cpn?.dragged == true) {
return false;
}
return true;
}
}
5 changes: 5 additions & 0 deletions lib/core/graph_algorithm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,16 @@ abstract class GraphAlgorithm {
void compute(Vertex v, Graph graph) {
if (decorators != null) {
for (var decorator in decorators!) {
if (!decorator.needContinue(v)) return;
decorator.compute(v, graph);
}
}
}

bool needContinue(Vertex v) {
return true;
}

/// Called when the graph is loaded.
@mustCallSuper
void onLoad(Vertex v) {
Expand Down
4 changes: 4 additions & 0 deletions lib/widgets/vertex_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class VertexComponent extends ShapeComponent
Options? options;
GraphComponent? graphComponent;
ShapeHitbox? hitBox;
bool dragged;

VertexComponent(
this.vertex,
Expand All @@ -38,6 +39,7 @@ class VertexComponent extends ShapeComponent
this.algorithm, {
this.options,
this.graphComponent,
this.dragged = false,
}) : super(
position: vertex.position,
anchor: Anchor.center,
Expand Down Expand Up @@ -135,11 +137,13 @@ class VertexComponent extends ShapeComponent
}
}

@mustCallSuper
void onDrag(Vector2 globalDelta) {
if (hasPanel) {
gameRef.overlays.remove(overlayName);
gameRef.overlays.add(overlayName);
}
dragged = true;
}

@override
Expand Down

0 comments on commit 6510e83

Please sign in to comment.