如何在圆圈之间均匀分割d3链接(How to evenly split d3 links between circles)
我有以下数据集
var data = { nodes: [ { addr: '1', address: '1', x: 100, y: 200 }, { addr: '2', address: '2', x: 200, y: 0 }, { addr: '3', address: '3', x: 200, y: 150 }, { addr: '4', address: '4', x: 200, y: 240 }, { addr: '5', address: '5', x: 200, y: 360 } ], links: [ { source: 0, target: 1 }, { source: 0, target: 2 }, { source: 0, target: 3 }, { source: 0, target: 4 } ] }
目前看起来像这样:
我试图找到一个公式,允许我为任何给定数量的圆计算正确的Y值(在合理范围内,如果有1,2或10个圆,公式应该有效)。
我想尝试这样的事情:
这看起来很对称。
第一个圆圈(蓝色)的我的X和Y是已知的并且是静态的。
I have the following data set
var data = { nodes: [ { addr: '1', address: '1', x: 100, y: 200 }, { addr: '2', address: '2', x: 200, y: 0 }, { addr: '3', address: '3', x: 200, y: 150 }, { addr: '4', address: '4', x: 200, y: 240 }, { addr: '5', address: '5', x: 200, y: 360 } ], links: [ { source: 0, target: 1 }, { source: 0, target: 2 }, { source: 0, target: 3 }, { source: 0, target: 4 } ] }
Which currently looks like this:
I'm trying to find a formula that will allow me to calculate the correct Y value for any given number of circles (within reason, the formula should work if there are 1, 2 or even 10 circles).
I'm trying to get to something like this:
That will look symmetrical.
My X and Y for the first circle (in blue) are known and are static.
原文:https://stackoverflow.com/questions/35050109
最满意答案
-s
开关禁用每次测试捕获。The
-s
switch disables per-test capturing.
相关问答
更多-
这很简单,你只需要正确构造: def main(): # argument parsing stuff here ... if __name__ == '__main__': main() 现在在测试中直接调用main()函数。 没有必要运行单独的python进程。 要模拟参数解析,您只需要修补sys.argv 。 如果您的脚本依赖于任何配置文件或环境变量,那么您也必须模拟/修补它们。 It's very easy, you just have to structure corr ...
-
默认情况下, py.test捕获标准输出的结果,以便它可以控制它如何打印出来。 如果没有这样做,它会排除大量的文本,而没有打印该文本的测试的上下文。 但是,如果测试失败,它将在结果报告中包含一个部分,显示在该特定测试中打印到标准的内容。 例如, def test_good(): for i in range(1000): print(i) def test_bad(): print('this should fail!') assert False 结果如下输出: ...
-
-s开关禁用每次测试捕获。 The -s switch disables per-test capturing.
-
使用pytest 3.x有一种简单的方法可以暂时禁用捕获(请参阅有关capsys.disabled()的部分。 还有pytest-warnings插件,它在专门的报告部分显示警告。 I've done it by manually redirecting stderr: import os import sys import warnings import pytest def test(): stderr = sys.stderr sys.stderr = open(os.devnull ...
-
对于你的pytest-cov版本需要pytest==3.4.2这么简单编辑requirements.txt到 urllib3==1.22 cx_freeze==6.0b1 pytest==3.4.2 pytest-cov==2.5.1 pytest-dependency==0.2 第一次它帮助我,但现在它甚至工作3.2.2 $ workon ptest (ptest) $ python -V Python 3.5.3 看看安装 (ptest) $ pip freeze attrs==17.4.0 cov ...
-
为什么我用pytest得到pytest AssertionError?(Why I am getting pytest AssertionError with pytest?)[2023-09-01]
Decimal((205 / 100) + 1).quantize(Decimal(10) ** -2) == Decimal('3.05') # --> True Decimal((205 / 100) + 1).quantize(Decimal(10) ** -2) == 3.05 # --> False 由于浮点算术的限制,即使它们具有相同的repr,也不能保证十进制值等于float值。 在这种情况下, 3.05不能精确地以二进制表示,所以当比较两个值时, 3.05被转换为 Decimal(3.0 ... -
有没有理由你不想在conftest.py文件中使用@pytest.fixture(scope='session')而不是编写自己的插件? 这可以实现在运行时更改灯具的功能吗? 在任何情况下,如果您更改缩进并将self添加到new_fixture的参数,它应该工作。 @pytest.fixture def new_fixture(): return new_fixture_value 至 @pytest.fixture(scope='sessi ...
-
你可以使用py.io 就像是: capture = py.io.StdCapture() pytest.main(['--collect-only', '-q']) std, err = capture.reset() print(std) 会给你你想要的标准输出。 You could use py.io for this. something like: capture = py.io.StdCapture() pytest.main(['--collect-only', '-q']) std, err ...
-
如果我正确理解您的评论,项目布局如下: ~/customersites/ ~/customersites/automation/ ~/customersites/automation/pytest.ini 然后按如下方式调用py.test: ~/customersites$ py.test --markers 将使py.test在~/customersites/查找配置文件,然后查找所有父项: ~/ , /home/ , / 。 在这种情况下,这不会使它找到pytest.ini 。 但是,当您使用一个或 ...
-
pytest_xdist有额外的钩子,可以在conftest.py( 钩子列表 )中使用。 为此目的的相关钩子是pytest_configure_node(node) ,它在每个新节点可用并且开始运行测试之前运行。 pytest_xdist has additional hooks that can be used in the conftest.py (list of hooks). The relevant hook for this purpose is pytest_configure_node(n ...