Skip to content

[桑基图] 优化桑基图 cutoffcircle 逻辑,降低时间复杂度 #2571

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

Merged
merged 4 commits into from
May 24, 2021

Conversation

liuzhenying
Copy link
Member

@liuzhenying liuzhenying commented May 21, 2021

桑基图数据量超过 400 时渲染基本卡死,发现大部分耗时在 cutoffcircle 函数上

屏幕快照 2021-05-21 11 33 48

根据 DFS 算法优化了下逻辑,(参考 https://leetcode-cn.com/problems/course-schedule/solution/course-schedule-tuo-bu-pai-xu-bfsdfsliang-chong-fa/ ),时间复杂度降为 O(n^2)

同样的数据,耗时从 19053 减少为 1

屏幕快照 2021-05-21 14 17 32

(circle 文件因单测覆盖率已达到 100%,此次未增加测试用例)

屏幕快照 2021-05-21 17 49 52

PR includes

  • fixed #0
  • add / modify test cases
  • documents, demos

Screenshot

Before After

@coveralls
Copy link

coveralls commented May 21, 2021

Pull Request Test Coverage Report for Build 870400895

  • 38 of 38 (100.0%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.01%) to 96.177%

Files with Coverage Reduction New Missed Lines %
src/utils/transform/word-cloud.ts 1 97.75%
Totals Coverage Status
Change from base Build 859961788: -0.01%
Covered Lines: 5639
Relevant Lines: 5717

💛 - Coveralls

@hustcc
Copy link
Member

hustcc commented May 24, 2021

之前的时间复杂度算是多少?

@liuzhenying
Copy link
Member Author

之前的时间复杂度算是多少?

没具体算,看了下大概是 O(n^M), M 为连成线的节点数量,主要是耗在了 hasCircle 内部的递归,递归数量随节点增多直线上升

@visiky visiky merged commit 3b84cfd into master May 24, 2021
@visiky visiky deleted the sankey-circle branch May 24, 2021 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants