如何使用 HTML CSS 绘制家谱线?

发布于 2024-08-09 21:39:12 字数 469 浏览 3 评论 0原文

我正在尝试实现类似于 http://www.ancestry.com 的东西,但我不知道如何画线。

这是我想要做的粗略的 ASCII 草图:

                 +----GrDAD1
                 |
     +----DAD----+
     |           +----GrMOM1
ME --+
     |           +----GrDAD2
     +----MOM----+
                 |
                 +----GrMOM2

我认为一种方法是创建一个单元格表,并创建线条图像, 将每个孩子与他们的父母联系起来。 我猜想有一种更简单的方法可以做到这一点,但我对 CSS 的了解非常有限。 有人对我如何实现这个有建议吗?

I'm trying to implement something similar to what http://www.ancestry.com has, but I'm not sure how to draw the lines.

Here is a rough ascii sketch of what I want to do:

                 +----GrDAD1
                 |
     +----DAD----+
     |           +----GrMOM1
ME --+
     |           +----GrDAD2
     +----MOM----+
                 |
                 +----GrMOM2

I think one way to do this is to create a table of cells, and create images of the lines,
connecting each of the children to their parents.
I'm guessing there's an easier way to do this though, but my knowledge of CSS is quite limited.
Does anyone have a suggestion on how I can implement this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

爱的十字路口 2024-08-16 21:39:12

你可以用纯CSS来做到这一点。这是一个示例:

http://thecodeplayer.com/walkthrough/css3-family-tree

You can do it with pure css. Here is an example :

http://thecodeplayer.com/walkthrough/css3-family-tree

雅心素梦 2024-08-16 21:39:12

我会再提出一个答案,尽管上面的答案都是大致的。

假设您想在所有浏览器上工作。如果您需要在 Internet Explorer 上工作,并且编写了自己的 Canvas 解决方案,则可能需要包含 ExplorerCanvas

家谱本质上是二叉树——我知道,现实生活中的收养、离婚很棘手,呃,但我们暂时假设它们是从某个特定的人向一个方向(祖先)发展的二元树。

JavaScript InfoVis Toolkit 是一个使用 Canvas 的好工具,具有在 IE 上工作的桥梁,并使用简单且通用的数据格式。

查看示例:
http://thejit.org/static/v20/Jit/Examples/ Spacetree/example2.html

它可能不完全是您想要的现成的,但您可以调整外观和感觉。

插件的数据负载非常简单,您的示例看起来像这样:

var tree = {
  id: "ME",   // Needs to be internally unique 
  name: "ME", // Visual label, does not need to match id 
  data: {},   // not really used here, but parameter needed
  children: [
    {id: "DAD", 
    name: "DAD", 
    data: {},
    children: [
      {id: "GrDAD1", 
      name: "GrDAD1", 
      data: {},
      children: []},
      {id: "GrMOM1", 
      name: "GrMOM1", 
      data: {},
      children: []},          
    ]},
    {id: "MOM", 
    name: "MOM", 
    data: {},
    children: [
      {id: "GrDAD2", 
      name: "GrDAD2", 
      data: {},
      children: []},
      {id: "GrMOM2", 
      name: "GrMOM2", 
      data: {},
      children: []},          
    ]}
  ]
};

我确信还有其他解决方案,我希望您找到适合您的解决方案。

I'll throw one more answer in, although the answers above are all in the ballpark.

Let's assume you want to work on all browsers. If you need to work on Internet Explorer, and you code your own Canvas solution, you may want to include ExplorerCanvas.

Family trees are essentially binary trees -- I know, real life is tricky with adoptions, divorces, ugh, but let's just assume for a second that they're binary going in one direction (ancestors) from a particular person.

A good tool that uses Canvas, has the bridge to work on IE included, and uses a simple and general data format is the JavaScript InfoVis Toolkit.

Check out the sample at:
http://thejit.org/static/v20/Jit/Examples/Spacetree/example2.html

It may not be exactly what you want out of the box, but you can tweak the look and feel.

The data payload to plug-in is very simple, and your example would look something like this:

var tree = {
  id: "ME",   // Needs to be internally unique 
  name: "ME", // Visual label, does not need to match id 
  data: {},   // not really used here, but parameter needed
  children: [
    {id: "DAD", 
    name: "DAD", 
    data: {},
    children: [
      {id: "GrDAD1", 
      name: "GrDAD1", 
      data: {},
      children: []},
      {id: "GrMOM1", 
      name: "GrMOM1", 
      data: {},
      children: []},          
    ]},
    {id: "MOM", 
    name: "MOM", 
    data: {},
    children: [
      {id: "GrDAD2", 
      name: "GrDAD2", 
      data: {},
      children: []},
      {id: "GrMOM2", 
      name: "GrMOM2", 
      data: {},
      children: []},          
    ]}
  ]
};

I'm sure there are other solutions out there, and I hope you find one that works for you.

当梦初醒 2024-08-16 21:39:12

图形界面的另一个选择是画布元素。您可以在此处找到一些相关信息,此处,以及一些有关其功能的演示 此处

就我个人而言,我会选择带有图像映射叠加层的 Canvas 或可能的 Flash。仅使用 div 或表格创建图形布局可能会很快失控并创建巨大且丑陋的代码。虽然这是一个见仁见智的问题。 :)

您可以使用 canvas 来渲染线条,然后为每个节点使用文本绝对定位 div。或者,您可以在画布中渲染整个内容(此时,如果您希望渲染的树具有交互性,则需要图像映射叠加层。)

Another option for a graphical interface would be the canvas element. You can find some info on it here, here, and some demos of what it can do here.

Personally, I would choose Canvas with an image map overlay or possibly Flash. Creating a graphical layout using only divs or tables could get out of hand very quickly and create huge and ugly code. Although that's a matter of opinion. :)

You could use canvas to render the lines, and then absolutely position divs with text for each node. Or you could render the whole thing in canvas (at which point you would need an image map overlay if you want the rendered tree to be interactive.)

花伊自在美 2024-08-16 21:39:12

我喜欢 SlickMap CSS

由于它是为站点地图制作的,因此它设置了链接的嵌套列表的样式,但是修改它以处理每个单元格中的多个链接很简单,就像我在这里所做的那样: http://dl.dropbox.com/u/546793/demo/SlickmapCSS_rich/index.html

I like SlickMap CSS for this.

Since it's made for sitemaps, it styles nested lists of links, but it's trivial to modify it to handle more than links in each cell, like I did here: http://dl.dropbox.com/u/546793/demo/SlickmapCSS_rich/index.html

番薯 2024-08-16 21:39:12

一种选择是使用绝对定位和一些图像。您将需要一条水平线和一条垂直线图像。然后使用定位将项目定位到相应的线条上。

One option is to use absolute positioning and a few images. You will need a horizontal line and a vertical line image. Then use positioning to position the items with the corresponding lines.

深海蓝天 2024-08-16 21:39:12

到目前为止我看到的例子都使用闪存来实现类似的功能。例如 http://academia.edu

否则,我可能会使用绝对定位的 DIV 来组成线条 - 但这需要一些复杂的计算:)

第三种选择 - 如果您愿意使用更多的 javascript 并牺牲一些浏览器兼容性,那就是使用 SVG 元素。您可以查看此库:http://raphaeljs.com/
那里有一个很好的树状演示,您可能会发现它很有用(http://raphaeljs.com/graffle. html)。

The examples I've seen so far use flash for stuff like that. http://academia.edu for example.

Otherwise, I would probably use absolutely positioned DIVs to make up the lines - that would require some complicated calculations, though :)

A third option - if you are willing to use more javascript and sacrifice some browser compatibility is to use the SVG element. You can checkout this library: http://raphaeljs.com/
There is a nice tree-like demo in there that you may find useful (http://raphaeljs.com/graffle.html).

热情消退 2024-08-16 21:39:12

我想使用画布。

看看..也许它能提供一些想法
使用画布绘制图形

I guess using CANVAS.

Have a look.. may be it gives some idea
Drawing Graphics with Canvas

岁吢 2024-08-16 21:39:12

您可以使用 jsPlumb,它非常适合此类内容 http://jsplumbtoolkit.com/demo /chart/mootools.html

You can use jsPlumb, which is pretty good for that kind of stuff http://jsplumbtoolkit.com/demo/chart/mootools.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文