简体   繁体   English

绘制用户定义的树

[英]Drawing a user-defined tree

I am making a pretty abstract tree drawing system, but I am having quite a lot of trouble formalizing all the drawing features it should have. 我正在制作一个非常抽象的树图系统,但是在规范它应该具有的所有图图功能时遇到了很多麻烦。 I'd very much appreciate if someone could point me to things to read about this topic, because unfortunately my searches have been in vain. 如果有人能指出我要阅读的有关该主题的内容,我将非常感激,因为不幸的是,我的搜索没有用。

I am looking for/trying to make a meta-language for displaying trees. 我正在寻找/尝试制作用于显示树的元语言。 In these trees each node is an instance of a user-defined Object which have a user-defined graphical representation. 在这些树中,每个节点都是具有用户定义图形表示的用户定义对象的实例。

Each Object is associated with a Name, a graphical representation and has a finite number of childs ( 0+ ), which are only known to be Objects themselves. 每个对象都与一个名称,一个图形表示形式相关联,并且具有有限数量的子代(0+),这些子代仅被称为对象本身。 Object recursion is not allowed. 不允许对象递归。 Each Object may have user-defined Options that are used to trigger conditions which would change their graphical representation ( in user-defined ways ). 每个对象都可以具有用户定义的选项,这些选项用于触发条件(以用户定义的方式更改其图形表示形式)。 Some Options are automatically applied, others may require user interaction ( "Would you like this Object to be A or B?" ), thus explaining why Object trees need to be instanced. 有些选项是自动应用的,其他选项则可能需要用户交互(“您希望该对象是A还是B?”),从而解释了为什么需要实例化对象树。

Object
    Name                // The Object Name
    Childs              // List of Object Childs
        ContextName         // The Name of the Child within this context
        Types               // List of Objects' names. This child may be only one of them. Decided by the user during instancing.
        Options             // List of Options assigned to this child. Some of them may require user interaction, and apply other Options to the Child's childs.
        *Priority           // This is an integer which is used to decide the order in which childs are drawn.
    Symbol Name         // The Graphical representation of the Object

Once an Object Tree has been instanced, it has to be drawn without any addictional user input, and this is where I am having some trouble. 实例化对象树后,就必须在没有任何令人上瘾的用户输入的情况下进行绘制,这是我遇到麻烦的地方。 The instancing of an Object tree assigns to each Object a particular graphical representation ( let's call it Symbol ). 对象树的实例化为每个对象分配了特定的图形表示形式(我们称为Symbol)。 The assignment is however not known before the instancing. 但是,该实例在实例化之前未知。 Different Objects may also have the same Symbol, which may be drawn differently depending on the Object's Options. 不同的对象也可能具有相同的符号,根据对象的选项,其绘制方式可能有所不同。

Because of this, Symbols must be defined separately from Objects, and must have a series of abstract mechanisms to be able to draw themselves ( and thir assigned childs ) correctly, following the user-specified rules. 因此,符号必须与对象分开定义,并且必须具有一系列抽象机制,以便能够遵循用户指定的规则正确绘制自身(以及分配给它们的子代)。

Each Symbol is represented by an image ( or no image ) plus a finite number of Attachments. 每个符号均由图像(或无图像)加上有限数量的附件表示。 Attachments are relative positions to the Symbol's coordinates which tell the drawing code where to draw the Symbols of the Object's childs. 附件是符号坐标的相对位置,用于告诉绘图代码在何处绘制对象子级的符号。 Each one of them may have particular conditions to be used ( eg this Attachment may only be used by a Symbol that has a particular Option, or if N Symbols have already been drawn, no collisions with already drawn Symbols etc etc ). 它们中的每一个都可能具有要使用的特定条件(例如,此附件只能由具有特定选项的符号使用,或者如果已经绘制了N个符号,则与已经绘制的符号没有冲突等)。

The algorithm has to find a free Attachment for each Object's child, following the order specified by their Priority. 该算法必须按照每个对象的子对象的优先级指定的顺序为其找到免费的附件。 If it is not possible to find an Attachment for a Child the user may specify beforehand rules that allow some automatic retries, but if they also fail then the whole tree drawing fails. 如果无法找到“儿童附件”,则用户可以预先指定允许某些自动重试的规则,但是如果它们也失败了,则整个树图绘制都会失败。 Some of these rules allow for adding addictional child Symbols and/or assigning child Symbols to other childs ( making them grandChildren ) etc. 这些规则中的某些规则允许添加成瘾的子符号和/或将子符号分配给其他子符号(使它们成为grandChildren)等。

Symbol
    Name
    Main Image      // Image Path, Height, Width
    Attachments     // List of the attachments, their position, requirements and addictional infos
    Fail Rules      // List of actions to do if it is not possible to successfully assign each Child to an Attachment

My main problem is that the number of variables that a Symbol should be able to access is pretty high. 我的主要问题是,Symbol应该可以访问的变量数量非常高。 Each Symbol, which I'll again remind should be defined using this meta-language, should be able to access its child Symbols' informations ( not others to avoid deadlocks and circular referencing ): for example the user may want the heigth and width of a Symbol to be equal to the sum of the heigth and width of all the Child's Symbols, or to use the same picture, and so on. 我将再次提醒每个符号,都应使用此元语言进行定义,它们应该能够访问其子符号的信息(为了避免死锁和循环引用,不能访问其他符号):例如,用户可能希望使用以下符号的高度和宽度:一个符号等于所有“儿童”符号的高度和宽度之和,或者使用相同的图片,依此类推。 This is also caused by the fact that the user writes Symbols' rules independently from the final structure. 这也是由于用户独立于最终结构编写Symbols的规则而造成的。

At the same time, since the tree must be drawn from top to bottom, some of these informations may not be available from the start, and may require a great deal of backtracking. 同时,由于必须从上到下绘制树,因此其中某些信息可能从一开始就不可用,并且可能需要大量回溯。

Also, since all of this has to be defined within a meta-language which I have to be able formalize and parse, I have to define which are the functions that the meta-language requires to allow the maximum grade of freedom to the language-writing user without being overly complex ( this is a vague limit, but essentially I don't want to have Tikz as a subset of my meta-language ). 同样,由于所有这些都必须在我必须能够形式化和解析的元语言中定义,因此我必须定义元语言需要的功能,以最大程度地提高语言的自由度,在不过于复杂的情况下编写用户(这是一个模糊的限制,但是从本质上讲,我不想让Tikz作为我的元语言的子集)。 I am having however quite a bit of trouble identifying them. 但是,我在识别它们时遇到了很多麻烦。

As I said before, I am looking for informations about this kind of topic and/or methods for completing a project like this. 如前所述,我正在寻找有关此类主题和/或完成此类项目的方法的信息。 Once I'll be able to fully complete the meta-language I think I won't have too much trouble implementing the code to do all of this, my problems are for the most part theoretical. 一旦我能够完全完成元语言,我认为实现代码来完成所有这些工作不会有太多麻烦,我的问题大部分是理论上的。

I have done a few similar projects with hierarchical data. 我已经使用分层数据完成了一些类似的项目。 I point you to where I started: 我向您指出我的起点:

Joe Celko is the king of tree data. Joe Celko是树数据之王。 I recommend you start with his book. 我建议您从他的书开始。 It is a mix of logic and business case. 它是逻辑和业务案例的结合。 Trees and Hierarchies in SQL for Smarties even has a new edition out. SQL for Smarties中的树和层次结构甚至有新版本。 There is a language for describing the hierarchies there, too. 也有一种语言描述那里的层次结构。

I have used Oracle for storing my hierarchies which has a very efficient system for pulling and storing tree data. 我已经使用Oracle来存储我的层次结构,该层次结构具有用于提取和存储树数据的非常有效的系统。 Look up "connect by" either in documentation or in the book: Mastering Oracle SQL by Mishra and Beaulieu. 在文档或本书中查找“连接依据”:Mishra和Beaulieu的Mastering Oracle SQL。

You can use pointers to pull the images from the server so you wouldn't store them in the database. 您可以使用指针从服务器提取图像,这样就不会将其存储在数据库中。 I have built several systems that use hierarchical displays of data with graphical objects, it keeps the overhead down this way. 我建立了几个系统,这些系统使用带有图形对象的数据分层显示,这样可以降低开销。 DevExpress and Telerik both have great viewers for displaying the trees and I have mine build the next levels dynamically. DevExpress和Telerik都有很好的查看器来显示树,我让我动态构建下一个层次。 It doesn't know how many or what the next level is going to be until it is drilled down on. 在深入研究之前,它不知道下一个级别是多少或什么级别。 Try these examples and read the docs and you will be able to put this together in not time. 尝试这些示例并阅读文档,您将可以很快将它们放在一起。

For telerik this link will show you multiple load on demand views: http://demos.telerik.com/aspnet-ajax/treeview/examples/programming/loadondemandmodes/defaultcs.aspx 对于Telerik,此链接将向您显示按需加载的多个视图: http : //demos.telerik.com/aspnet-ajax/treeview/examples/programming/loadondemandmodes/defaultcs.aspx

For Devexpress: http://demos.devexpress.com/ASPxTreeListDemos/Data/VirtualMode.aspx 对于Devexpress: http ://demos.devexpress.com/ASPxTreeListDemos/Data/VirtualMode.aspx

Think in HTML/DOM. 以HTML / DOM进行思考。

I was surprised, when I found, that the file format of the outliner I am using, NoteCase, is plain HTML. 当我发现我正在使用的大纲工具 NoteCase的文件格式是纯HTML时,我感到很惊讶。 NoteCase can be found here: http://notecase.sourceforge.net/index1.html 注意案例可以在这里找到: http ://notecase.sourceforge.net/index1.html

If you don't familiar with it, outliner is an application type, which you can organize mainly text nodes in hierarchical tree. 如果您不熟悉它,则大纲器是一种应用程序类型,您可以将其主要组织为分层树中的文本节点。 There are task outliners, too. 也有任务概述。 When an outliner has graphical representation, it's called mind mapping . 当大纲器具有图形表示形式时,称为思维导图 Anyway, the directory structure of a filesystem is an outline, too. 无论如何,文件系统的目录结构也是一个概要。 There are lot of outliners for various areas. 各个领域都有很多轮廓绘制器。 See Wikipedia for more details. 有关更多详细信息,请参见Wikipedia。

Notecase uses DL/DT/DD: DL is the list, DT is the item, and DD is the description of an item. 记事本使用DL / DT / DD:DL是列表,DT是项目,而DD是项目的描述。 They can be nested, of course. 当然,它们可以嵌套。

  1. If the format is HTML, you need only a CSS to show it in a browser easy readable for human eyes. 如果格式是HTML,则只需一个CSS即可在浏览器中将其显示为人眼易读的格式。

  2. If you have additional properties, you can define additional tags or attributes, which browser will not show, but your renderer can. 如果您具有其他属性,则可以定义其他标签或属性,浏览器将不会显示,而渲染器可以。

  3. You should write a converter, which transforms your source HTML file format to a more detailed HTML format, which contains computed fields (eg which sums of values from the sub-nodes, or replaces "inherit" marks in a sub-node with the inherited value from parent node), some additional formatting, or you can transform attributes into HTML nodes: 您应该编写一个转换器,将您的源HTML文件格式转换为更详细的HTML格式,其中包含计算字段(例如,子节点的值之和,或用继承的子节点替换“继承”标记)父节点的值),一些其他格式,或者您可以将属性转换为HTML节点:

    <node type="x" size="y" />

    to

    <div class="node">
    <div class="param"> type: x </div>
    <div class="param"> size: y </div>
    </div>

  4. Your data representation is a kinda DOM, and you should process it similar way. 您的数据表示形式是一种DOM,您应该以类似的方式处理它。 First, parse and read values from the file. 首先,解析并从文件中读取值。 Then, you should run some additional rounds (walk the tree) to fill missing values with defaults, calculate inherited and summarized values etc. 然后,您应该进行一些额外的回合(遍历树)以使用默认值填充缺失值,计算继承值和汇总值等。

    I think, you can't use standard DOM parsers, because you mentioned custom sorting of stuff depending on parameters, which DOM modell doesn't really support. 我认为,您不能使用标准的DOM解析器,因为您提到了根据参数对内容进行自定义排序 ,而DOM modell并不真正支持这些参数。

  5. Don't afraid to walk the object tree just as many passes as many operation you want to perform on it. 不要害怕走对象树就像许多通行证要对其执行尽可能多的操作。 You can play with changing the order of the passes, enabling and disabling passes... as your have more and more features, it will articulated as new processing passes. 您可以更改通行证的顺序,启用和禁用通行证...随着您具有越来越多的功能,它将随着新的处理通行证而清晰地表达出来。

    You may have passes, which must be run several times, eg if one pass can't calculate a value (because it's source should be calculated first), it may return a flag that "I've not done yet", and it should run again on the tree, until it results "no change mades, I've done". 您可能有通行证,该通行证必须运行几次,例如,如果一个通行证不能计算值(因为应该先计算其来源),它可能会返回“我还没做完”的标志,并且应该在树上再次运行,直到结果为“我没有做任何改变”。

I hope I've push you a bit. 希望我能对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM