搜索插件、代码仓与 APP 分类

flutter_graph_view 封面
插件详情v2.1.0

flutter_graph_view

用于美观的图形数据结构的组件,例如力导向图。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
3110
喜欢数
93
Pub 分数
160

安装插件

flutter pub add flutter_graph_view

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Flutter Graph View 是一个可视化包,可创建视觉上吸引人的图数据结构,包括力导向图。它提供可自定义的组件,用于渲染节点和边,并支持平滑动画和交互行为。非常适合显示网络、树或依赖关系图中的复杂关系,支持移动、Web 和桌面等多种平台。该包利用高效的布局算法,即使在大数据集下也能确保响应迅速的性能。其简洁的 API 简化了在需要动态可视化的 Flutter 应用中集成的过程。

适合场景

  • 可视化网络拓扑
  • 显示依赖关系图
  • 创建交互式思维导图
  • 渲染层次数据结构
  • 显示实时数据流

主要特点

  • 力导向布局算法
  • 可自定义的节点和边样式
  • 交互式拖放支持
  • 流畅的动画和过渡
  • 跨平台兼容性(Android、iOS、Web、macOS、Windows、Linux)

适合对象

  • 数据可视化应用
  • 教育工具
  • 网络分析软件
  • 具有复杂数据关系的 UI
  • 需要动态图渲染的应用程序

使用建议

  • 性能可能在非常大的图上下降
  • 需要仔细调整布局参数
  • 有限的内置交互功能,仅限基本拖拽
  • 可能需要额外的逻辑来处理高级事件
  • 未针对实时流数据更新进行优化

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Flutter Graph View

GitHub stars GitHub forks

Widgets for beautiful graphic data structures, such as force-oriented diagrams.

image image

image

https://github.com/graph-cn/flutter_graph_view/assets/15630211/a035cd7d-bdac-4ef6-8abf-74594e9d699b

Features

  • [x] Data converter: convert business data into graphic view data.

  • [x] Algorithm: calculate vertex layout.

    • [x] Force directed algorithm.
    • [x] Random algorithm (In example folder).
    • [x] Support algorithm decorator.
      • [x] Breathe decorator (optional).
      • [x] Provide decorators that follow Hooke's Law for related nodes
      • [x] Provide a decorator for Hooke's Law from the center outward for all nodes
      • [x] Provide mutually exclusive Coulomb's law decorators for subgraph root nodes
      • [x] Hooke's Law decorator that provides border buffering collisions for all nodes
      • [x] Add a counter decorator in the figure to convert node forces into motion
  • [x] Data panel embedding.

  • [x] Style configuration.

  • [ ] More graphical interactions.

Getting started

flutter pub add flutter_graph_view

Usage

// Copyright (c) 2023- All flutter_graph_view authors. All rights reserved.
//
// This source code is licensed under Apache 2.0 License.

import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_graph_view/flutter_graph_view.dart';

class DecoratorDemo extends StatelessWidget {
  const DecoratorDemo({super.key});

  @override
  Widget build(BuildContext context) {
    var vertexes = <Map>{};
    var r = Random();
    for (var i = 0; i < 150; i++) {
      vertexes.add(
        {
          'id': 'node$i',
          'tag': 'tag${r.nextInt(9)}',
          'tags': [
            'tag${r.nextInt(9)}',
            if (r.nextBool()) 'tag${r.nextInt(4)}',
            if (r.nextBool()) 'tag${r.nextInt(8)}'
          ],
        },
      );
    }
    var edges = <Map>{};

    for (var i = 0; i < 150; i++) {
      edges.add({
        'srcId': 'node${i % 8 + 8}',
        'dstId': 'node$i',
        'edgeName': 'edge${r.nextInt(3)}',
        'ranking': DateTime.now().millisecond,
      });
    }
    // for (var i = 0; i < 20; i++) {
    //   edges.add({
    //     'srcId': 'node${i % 8}',
    //     'dstId': 'node${r.nextInt(150)}',
    //     'edgeName': 'edge${r.nextInt(3)}',
    //     'ranking': DateTime.now().millisecond,
    //   });
    // }

    var data = {
      'vertexes': vertexes,
      'edges': edges,
    };
    return FlutterGraphWidget(
      data: data,
      algorithm: RandomAlgorithm(
        decorators: [
          CoulombDecorator(),
          // HookeBorderDecorator(),
          HookeDecorator(),
          CoulombCenterDecorator(),
          HookeCenterDecorator(),
          ForceDecorator(),
          ForceMotionDecorator(),
          TimeCounterDecorator(),
        ],
      ),
      convertor: MapConvertor(),
      options: Options()
        ..enableHit = false
        ..panelDelay = const Duration(milliseconds: 500)
        ..graphStyle = (GraphStyle()
          // tagColor is prior to tagColorByIndex. use vertex.tags to get color
          ..tagColor = {'tag8': Colors.orangeAccent.shade200}
          ..tagColorByIndex = [
            Colors.red.shade200,
            Colors.orange.shade200,
            Colors.yellow.shade200,
            Colors.green.shade200,
            Colors.blue.shade200,
            Colors.blueAccent.shade200,
            Colors.purple.shade200,
            Colors.pink.shade200,
            Colors.blueGrey.shade200,
            Colors.deepOrange.shade200,
          ])
        ..useLegend = true // default true
        ..edgePanelBuilder = edgePanelBuilder
        ..vertexPanelBuilder = vertexPanelBuilder
        ..edgeShape = EdgeLineShape() // default is EdgeLineShape.
        ..vertexShape = VertexCircleShape(), // default is VertexCircleShape.
    );
  }

  Widget edgePanelBuilder(Edge edge, Viewfinder viewfinder) {
    var c = viewfinder.localToGlobal(edge.position);

    return Stack(
      children: [
        Positioned(
          left: c.x + 5,
          top: c.y,
          child: SizedBox(
            width: 200,
            child: ColoredBox(
              color: Colors.grey.shade900.withAlpha(200),
              child: ListTile(
                title: Text(
                    '${edge.edgeName} @${edge.ranking}\nDelay controlled by \noptions.panelDelay\ndefault to 300ms'),
              ),
            ),
          ),
        )
      ],
    );
  }

  Widget vertexPanelBuilder(hoverVertex, Viewfinder viewfinder) {
    var c = viewfinder.localToGlobal(hoverVertex.cpn!.position);
    return Stack(
      children: [
        Positioned(
          left: c.x + hoverVertex.radius + 5,
          top: c.y - 20,
          child: SizedBox(
            width: 120,
            child: ColoredBox(
              color: Colors.grey.shade900.withAlpha(200),
              child: ListTile(
                title: Text(
                  'Id: ${hoverVertex.id}',
                ),
                subtitle: Text(
                    'Tag: ${hoverVertex.data['tag']}\nDegree: ${hoverVertex.degree} ${hoverVertex.prevVertex?.id}'),
              ),
            ),
          ),
        )
      ],
    );
  }
}

Licence

flutter_graph_view is under the Apache License, Version 2.0.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。