graphview
graphview copied to clipboard
GraphView Widget doesn't use `paint` parameter. Cannot specify all Edge's paint style at one time
Hi, I am using GraphView to paint a directed graph and want to specify all Edge to be grey at one time, however I found I can only specify each edge paint style every time I add edge to graph.
void addEdge(String a, String b) {
a = Uri.decodeComponent(a);
b = Uri.decodeComponent(b);
if(a == b){
return;
}
if((a.endsWith('/') || a.endsWith('.html')) && (b.endsWith('/') || b.endsWith('.html'))){
graph.addEdge(
_nodes.putIfAbsent(a, () => Node.Id(a)),
_nodes.putIfAbsent(b, () => Node.Id(b)),
paint: Paint()
..color = Colors.grey
..strokeWidth = 0.2
..style = PaintingStyle.stroke
);
notifyListeners();
}
}
Then I read the source code and found that GrapView Widget doesn't use paint parameter at all !
here is my code
return GraphView(
graph: notifier.graph,
algorithm: FruchtermanReingoldAlgorithm(
attractionRate: 0.014,
repulsionRate: 1,
repulsionPercentage: 1,
iterations: 1000,
),
paint: Paint()
..color = Colors.grey
..strokeWidth = 0.2
..style = PaintingStyle.stroke,
builder: (Node node) {
// I can decide what widget should be shown here based on the id
var a = node.key?.value as String;
return rectangleWidget(a);
},
);
paint goes down to GraphView then _GraphViewState, _GraphViewAnimated, finally _GraphViewAnimatedState. _GraphViewAnimatedState doesn't use paint that I specified. Instead, In _GraphViewAnimatedState’s build method, I found this
CustomPaint(
size: MediaQuery.of(context).size,
painter: EdgeRender(algorithm, graph, Offset(20, 20)),
),
In EdgeRender's paint method, it just constructs a new paint with some configuration
@override
void paint(Canvas canvas, Size size) {
var edgePaint = (Paint()
..color = Colors.black
..strokeWidth = 3)
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.butt;
canvas.save();
canvas.translate(offset.dx, offset.dy);
algorithm.renderer!.render(canvas, graph, edgePaint);
canvas.restore();
}
So I think the paint parameter of GraphView widget has no meaning, could you please fix it?