自定义 JavaScript 可视化工具包 Spacetree 节点

发布于 2024-10-07 15:47:00 字数 1067 浏览 4 评论 0原文

我看到很多人推荐用于组织结构图的 JavaScript 可视化工具包(The JIT)。我正在尝试使用 JavaScript InfoVis Toolkit 的 SpaceTree 来制作组织结构图。我的组织结构图中的节点本身就像一个组件,其中包含员工个人资料图片、单击时显示叠加的两个不同图标以及大约 3 行简单文本,其中包含名称、标题和报告数量……每行都是分开的通过一条浅水平线。比如:

我的问题是,是否可以将空间树节点自定义到这种程度?我可以让 Node 几乎像另一个“组件”或 JavaScript 对象一样拥有自己的渲染方法吗?

我在论坛上进行了研究,我考虑的一些选项是:

  1. $jit.ST.NodeTypes.implement() ...但根据我看到的示例,这 似乎有助于在形状等方面定制节点,但是 不像上面画的布局。我指的是定制 像这样的东西: http://groups.google.com/group/javascript-information-visualization-toolkit/browse_thread/thread/a4a059cbeb10ba23/ebf472366cdbbdef?lnk=gst&q=spacetree+nodetype#ebf472366cdbbdef
  2. 我尝试设置innerHtml在 example5.js 的 onCreateLabel 方法中: 但它似乎什么也没做。虽然,我不确定是否是这样 将是节点定制的一个好方法。示例 5 位于 JIT 网站(我不允许发布多个超链接)
  3. 扩展 Graph.Node ...我仍在研究此选项,它 此时此刻,我不知道拥有空间有多复杂 树使用 Graph.myNode ,Graph.myNode 会是什么样子?我 需要在这些方面进行更多思考,看看它是否可行。

I saw many people recommend JavaScript Visualization Toolkit (The JIT) for org chart. I am trying to use SpaceTree of JavaScript InfoVis Toolkit for org chart. The nodes in my org chart is like a component in itself that has employee profile pic, two different icons that show up overlays on click and some 3 lines of simple text having name, title, and number of reports ... each line is separated by a light horizontal line. Something like:

My question is, is it possible to customize the spacetree nodes to such an extent? Can I have Node almost like another "component" or JavaScript object that has its own render method?

I researched on forums and some options I considered are:

  1. $jit.ST.NodeTypes.implement() ... but based on examples I saw, this
    seem to be helping in customizing node in terms of shapes etc but
    not like layout drawn above. I am referring to customization
    something like:
    http://groups.google.com/group/javascript-information-visualization-toolkit/browse_thread/thread/a4a059cbeb10ba23/ebf472366cdbbdef?lnk=gst&q=spacetree+nodetype#ebf472366cdbbdef
  2. I tried to set innerHtml in onCreateLabel method in example5.js at:
    but it seems to be doing nothing. Although, I'm not sure if that
    will be a good way of node customization. Example5 is at the JIT website (I am not allowed to post more than one hyperlink)
  3. Extending Graph.Node ... I am still looking into this option and it
    this point of time, I don't know how complicated it is to have space
    tree use Graph.myNode and what will Graph.myNode even look like? I
    need to think more on those lines and see if it is even feasible.

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

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

发布评论

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

评论(5

爺獨霸怡葒院 2024-10-14 15:47:00

Spacetree 可以进行非常多的定制。节点可以显示图像或我们想要的任何内容。我们可以为节点自定义单击事件。要拥有自定义事件,您必须在 onclick 事件中重绘整个树。

这是一个例子。关于点击事件的成功函数。在这里,我将类上的单击事件称为“clickable”。

      $.ajaxSetup({ cache: false });             
           $(".clickable").live("click", function () {              
            $.ajax({
                url: url + "?id=" + parentId + "&ts=" + new Date().getMilliseconds(),
                type: "POST",
                cache: false,
                dataType: "html",
                success: function (html) {                       
                    init(html);                        
                }
              });
            });

name 属性可用于提供如下图像:

{id:"90", name:"<a href='javascript:;' class='clickable' name='90'><img src='images/picture.gif' width='30' height='30' alt='pic' /></a>", data:{}, children:[]}

如果有用,标记为答案。谢谢。

The Spacetree can be customized very much. The nodes can display images or anything we want. We can have custom click events for the nodes. To have custom events, you will have to redraw the whole tree in the onclick event.

Here is an example. On the success function of the click event. Here I have called the click event on the class "clickable"

      $.ajaxSetup({ cache: false });             
           $(".clickable").live("click", function () {              
            $.ajax({
                url: url + "?id=" + parentId + "&ts=" + new Date().getMilliseconds(),
                type: "POST",
                cache: false,
                dataType: "html",
                success: function (html) {                       
                    init(html);                        
                }
              });
            });

The name property can be used to give the image like this:

{id:"90", name:"<a href='javascript:;' class='clickable' name='90'><img src='images/picture.gif' width='30' height='30' alt='pic' /></a>", data:{}, children:[]}

Mark as Answer if useful. thanks.

椵侞 2024-10-14 15:47:00

您可以使 yourNode 成为 Graph.node 的原型祖先,设置所需的插槽,然后添加适当的渲染/强制代码自定义。

You could make yourNode the prototype ancestor of Graph.node, set up the slots you want, then add the appropriate render / force code customizations.

像你 2024-10-14 15:47:00

我使用的是 spacetrees,我只是将标签类型设置为 HTML(这是默认值),您可以使用常规 HTML 和 CSS 来设置标签样式。我有图像、链接、文本等。

请注意,您使用的是标签,而不是节点。节点是图组件;标签是您看到的代表节点的视觉效果。

当您初始化 spacetree 时,传入“onCreateLabel”函数:

var myOnCreateLabel = function(label, node) {
  label.onclick = function(event) {/* setup onclick handler */};
  label.innerHTML = "<img src='myImage.png' />"; // use image in label
};
var myST = new $jit.ST({/*other settings*/ onCreateLabel: myOnCreateLabel});

I'm using spacetrees and I just set the label type to HTML (which is the default) and you can just use regular HTML and CSS to style your labels. I have images, links, text, etc.

Note that you're working with the label and not the node. The node is the graph component; the label is the visual that you see which represents the node.

When you initialize the spacetree pass in a function for "onCreateLabel":

var myOnCreateLabel = function(label, node) {
  label.onclick = function(event) {/* setup onclick handler */};
  label.innerHTML = "<img src='myImage.png' />"; // use image in label
};
var myST = new $jit.ST({/*other settings*/ onCreateLabel: myOnCreateLabel});
ま昔日黯然 2024-10-14 15:47:00

如果您不介意仅使用 HTML5/Canvas,也可以尝试一下 http://orgplot.codeplex.com,界面简单,也支持图像节点。

if you don't mind working with HTML5/Canvas only, try this as well http://orgplot.codeplex.com, simple interface support image node as well.

审判长 2024-10-14 15:47:00
 this.st=new $jit.ST(

{

            onCreateLabel: function (label, node)
            {
                var labelContent = $('<table cellpadding="0" cellspacing="0" class="nodeContainer"><tr><td>' +
                    '<div class="buttonContainer">' +
                    '</div></td></tr><tr><td>' +
                    '<table  class="nodeBox" cellpadding="0" cellspacing="0">' +
                    '<tr>' +
                    '<td class="iconTd"></td>' +
                    '<td class="center nodeName">' + node.name + '</td>' +
                    '</tr></table>' +
                    '</td></tr></table>');
                thisObject.onCreateLabel.raise(thisObject, { labelContent: labelContent, node: node });
                if (node.data && node.data.Icon && node.data.Icon != "")
                {
                    labelContent.find(".iconTd").append($("<img src='" + node.data.Icon + "' alt=''>"));
                }
                else
                {
                    labelContent.find(".iconTd").remove();
                }

                var lblCtl = $(label).append(labelContent);

                if (node.data.Data.ChildrenCount)
                {
                    labelContent.append("<tr><td class='subnode'></td></tr>");
                }
                if (node.name.length > 40)
                {
                    lblCtl.attr("title", node.name);
                    node.name = node.name.substr(0, 37);
                    node.name = node.name + "...";
                }                        
                lblCtl.click(function (sender)
                {
                    //thisObject.isNodeClicked = true;
                    var target = $(sender.target);
                    if (!target.hasClass("subnode"))
                    {
                        if (thisObject.currentSelectedNode)
                        {
                            thisObject.currentSelectedNode.buttonContainer.hide();
                        }
                        var btnContainer = labelContent.find(".buttonContainer");
                        thisObject.currentSelectedNode = { nodeElement: lblCtl, node: node, buttonContainer: btnContainer, event: sender };
                        btnContainer.append(thisObject.$globalButtonContainer.show()).show();
                        var button = target.closest(".chartActionButton");
                        if (button.length > 0)
                        {
                            thisObject.onNodeAction.raise(thisObject, { name: button.attr("name"), nodeElement: lblCtl, node: node, button: target });
                        }
                        else
                        {
                            thisObject.onNodeClick.raise(thisObject, thisObject.currentSelectedNode);
                        }
                    }
                    else
                    {
                        thisObject.st.onClick(node.id);
                    }
                });
                label.id = node.id;
                //set label styles
                thisObject.setNodeStyle(node.data.Style, label.style);
            }

});

 this.st=new $jit.ST(

{

            onCreateLabel: function (label, node)
            {
                var labelContent = $('<table cellpadding="0" cellspacing="0" class="nodeContainer"><tr><td>' +
                    '<div class="buttonContainer">' +
                    '</div></td></tr><tr><td>' +
                    '<table  class="nodeBox" cellpadding="0" cellspacing="0">' +
                    '<tr>' +
                    '<td class="iconTd"></td>' +
                    '<td class="center nodeName">' + node.name + '</td>' +
                    '</tr></table>' +
                    '</td></tr></table>');
                thisObject.onCreateLabel.raise(thisObject, { labelContent: labelContent, node: node });
                if (node.data && node.data.Icon && node.data.Icon != "")
                {
                    labelContent.find(".iconTd").append($("<img src='" + node.data.Icon + "' alt=''>"));
                }
                else
                {
                    labelContent.find(".iconTd").remove();
                }

                var lblCtl = $(label).append(labelContent);

                if (node.data.Data.ChildrenCount)
                {
                    labelContent.append("<tr><td class='subnode'></td></tr>");
                }
                if (node.name.length > 40)
                {
                    lblCtl.attr("title", node.name);
                    node.name = node.name.substr(0, 37);
                    node.name = node.name + "...";
                }                        
                lblCtl.click(function (sender)
                {
                    //thisObject.isNodeClicked = true;
                    var target = $(sender.target);
                    if (!target.hasClass("subnode"))
                    {
                        if (thisObject.currentSelectedNode)
                        {
                            thisObject.currentSelectedNode.buttonContainer.hide();
                        }
                        var btnContainer = labelContent.find(".buttonContainer");
                        thisObject.currentSelectedNode = { nodeElement: lblCtl, node: node, buttonContainer: btnContainer, event: sender };
                        btnContainer.append(thisObject.$globalButtonContainer.show()).show();
                        var button = target.closest(".chartActionButton");
                        if (button.length > 0)
                        {
                            thisObject.onNodeAction.raise(thisObject, { name: button.attr("name"), nodeElement: lblCtl, node: node, button: target });
                        }
                        else
                        {
                            thisObject.onNodeClick.raise(thisObject, thisObject.currentSelectedNode);
                        }
                    }
                    else
                    {
                        thisObject.st.onClick(node.id);
                    }
                });
                label.id = node.id;
                //set label styles
                thisObject.setNodeStyle(node.data.Style, label.style);
            }

});

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