Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphView Widget doesn't use paint parameter. Cannot specify all Edge's paint style at one time #123

Open
z2z63 opened this issue Mar 21, 2024 · 0 comments

Comments

@z2z63
Copy link

z2z63 commented Mar 21, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant