D3js力布局:根据Levenshtein距离函数的动态linkDistance

时间:2013-09-09 09:56:22

标签: dynamic d3.js distance force-layout

var t0 = [  "site",        "how", "social",     "create", "membership"],
    t1 = [ "forum",       "site", "social", "membership", "networking"],
    t2 = ["social",    "network", "create",        "how",       "free"],
    t3 = ["social", "membership",   "site",    "website",       "make"] ;

    function levenshteinDistance (a, b) {
        if (!a.length) return b.length;
        if (!b.length) return a.length;
        return Math.min(
            levenshteinDistance(a.slice(1), b) + 1,
            levenshteinDistance(b.slice(1), a) + 1,
            levenshteinDistance(a.slice(1), b.slice(1)) + (a[0] !== b[0] ? 1 : 0)
        );
    }
    console.log(levenshteinDistance (t0, t1));
    console.log(levenshteinDistance (t0, t2));

    .linkDistance(levenshteinDistance (t0, t1))

我需要一个根据Levenshtein距离函数之前给出的数据提供动态距离的函数。我想根据我的功能创建动态linkDistance。我把Levenshtein距离函数放在同一页面上。我是新来的,如果我弄错了,请确认我。如果您需要,我会在这里回答您的问题。

0 个答案:

没有答案