首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Carrot2圆图

Carrot2圆图
EN

Stack Overflow用户
提问于 2013-04-02 23:46:04
回答 2查看 261关注 0票数 0

有人知道如何创建像carrto2?中使用的圆图吗?

EN

回答 2

Stack Overflow用户

发布于 2014-07-23 08:43:38

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

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

更多的动态可视化,比如可扩展的树状图,可以通过像flare.json这样的树结构来实现。

这是一个基于Carrot2结果的zoomable wheel

这是我编写的用于使用文档元素创建flare.json的coffeescript代码。

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2014-03-13 17:43:08

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15768456

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档