diff --git a/CHANGELOG.md b/CHANGELOG.md index 34191d7..a8c9e4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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]. diff --git a/lib/core/algorithm/decorator/pin_decorator.dart b/lib/core/algorithm/decorator/pin_decorator.dart new file mode 100644 index 0000000..0927ab0 --- /dev/null +++ b/lib/core/algorithm/decorator/pin_decorator.dart @@ -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; + } +} diff --git a/lib/core/graph_algorithm.dart b/lib/core/graph_algorithm.dart index d2004d1..1792834 100644 --- a/lib/core/graph_algorithm.dart +++ b/lib/core/graph_algorithm.dart @@ -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) { diff --git a/lib/widgets/vertex_component.dart b/lib/widgets/vertex_component.dart index 89d9028..ada0709 100644 --- a/lib/widgets/vertex_component.dart +++ b/lib/widgets/vertex_component.dart @@ -30,6 +30,7 @@ class VertexComponent extends ShapeComponent Options? options; GraphComponent? graphComponent; ShapeHitbox? hitBox; + bool dragged; VertexComponent( this.vertex, @@ -38,6 +39,7 @@ class VertexComponent extends ShapeComponent this.algorithm, { this.options, this.graphComponent, + this.dragged = false, }) : super( position: vertex.position, anchor: Anchor.center, @@ -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