0

carrto2で使用されているような円グラフを作成する方法を知っている人はいますか?

4

2 に答える 2

1

mbostock /d3 ギャラリーには、Carrot2 出力の優れた視覚化があります。

このCarrot2用のcarrot2-rb ruby​​クライアントは、clusters配列を持つオブジェクトを返します。スコアとフレーズの属性は、単純なドーナツ チャートで使用できます。

展開可能なデンドログラムのようなより動的な視覚化は、flare.json のようなツリー構造で可能です。

これは、Carrot2 の結果に基づくズーム可能なホイールです。

これは、documents 要素を使用して、flare.json を作成するために私が書いた coffeescript コードです。

clusters = [{"id":0,"size":3,"phrases":["Coupon"],"score":0.06441151442396735,"documents":["0","1","2"],"attributes":{"score":0.06441151442396735}},{"id":1,"size":2,"phrases":["Exclusive"],"score":0.7044284368639101,"documents":["0","1"],"attributes":{"score":0.7044284368639101}},{"id":2,"size":1,"phrases":["Other Topics"],"score":0.0,"documents":["3"],"attributes":{"other-topics":true,"score":0.0}}]

flare = get_flare clusters

get_children = (index, index2, clusters, documents) ->unless index == (clusters.length - 1)    # If not last cluster
  orphans = {'name': ''}
  intr    = _.intersection(documents, clusters[index2].documents);    

  if intr.length > 0    # continue drilling
    if index2 < (clusters.length - 1)    # Up until last element.
       # Get next layer of orphans
      orphan_docs = _.difference(intr, clusters[index2 + 1].documents)
      if orphan_docs.length > 0
        orphans = {'name': orphan_docs, 'size': orphan_docs.length}

      if _.intersection(intr, clusters[index2 + 1].documents).length > 0
        return [orphans, {'name': clusters[index2+1].phrases[0], 'children': get_children(index, (index2 + 1), clusters, intr)}]
      else 
        return [orphans]
    else
      # At second to last cluster, so terminate here
      return [{'name': inter}]  
  else                                # No intersection, so return bundle of current documents.
    return [{'name': documents}]  

  return [{'name': _.intersection(clusters[index].documents, clusters[index2].documents)}]



get_flare = (clusters) ->
  # Make root object
  flare =
    name: "root"
    children: []

  children = flare.children
  _.each(clusters[0..(clusters.length - 2)], (cluster, index) ->   # All clusters but the last. (It has already been compared to previous ones)
    #All documents for all remaining clusters in array
    remaining_documents =  _.flatten(_.map clusters[(index + 1)..clusters.length], (c) ->
      c.documents
    )

    root_child = {'name':  cluster.phrases[0], 'children': []}

    # Get first layer of orphans
    orphan_docs = _.difference(cluster.documents, remaining_documents)

    if orphan_docs.length > 0
      root_child.children.push {'name': orphan_docs, size: orphan_docs.length}

    for index2 in [(index + 1)..(clusters.length - 1)] by 1
      if _.intersection(cluster.documents, clusters[index2].documents).length > 0
        root_child.children.push {'name': clusters[index2].phrases[0], 'children': get_children(index, (index2), clusters, cluster.documents)}

    children.push root_child
  )  
  flare
于 2014-07-23T00:43:37.660 に答える