Carrot2圆图

时间:2013-04-02 15:46:04

标签: user-interface charts

任何人都知道如何创建像carrto2?

中使用的圆形图一样的圆形图

2 个答案:

答案 0 :(得分:1)

mbostock/d3 gallery具有良好的Carrot2输出可视化效果。

Carrot2的这个carrot2-rb ruby​​客户端返回一个带有簇数组的对象。分数和短语属性可以在简单的圆环图中使用。

像flare.json这样的树结构可以实现更多动态可视化,例如可扩展的树形图。

以下是基于Carrot2结果的zoomable wheel

这是我写的用于使用文档元素创建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

答案 1 :(得分:0)

您可以购买他们的圈子Javascript组件:http://carrotsearch.com/circles-overview