/
attributs.js
238 lines (225 loc) · 9.6 KB
/
attributs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
var Hash = require( './core_ext/hash' ).Hash,
sys = require('sys');
var attrs = {
"Damping" : { "usage" : "G", "type" : "double" },
"K" : { "usage" : "GC", "type" : "double" },
"URL" : { "usage" : "ENGC", "type" : "escString" },
"arrowhead" : { "usage" : "E", "type" : "arrowType" },
"arrowsize" : { "usage" : "E", "type" : "double" },
"arrowtail" : { "usage" : "E", "type" : "arrowType" },
"aspect" : { "usage" : "G", "type" : "aspectType" },
"bb" : { "usage" : "G", "type" : "rect" },
"bgcolor" : { "usage" : "GC", "type" : "color" },
"center" : { "usage" : "G", "type" : "bool" },
"charset" : { "usage" : "G", "type" : "string" },
"clusterrank" : { "usage" : "G", "type" : "clusterMode" },
"color" : { "usage" : "ENC", "type" : "color" },
"colorscheme" : { "usage" : "ENCG", "type" : "string" },
"comment" : { "usage" : "ENG", "type" : "string" },
"compound" : { "usage" : "G", "type" : "bool" },
"concentrate" : { "usage" : "G", "type" : "bool" },
"constraint" : { "usage" : "E", "type" : "bool" },
"decorate" : { "usage" : "E", "type" : "bool" },
"defaultdist" : { "usage" : "G", "type" : "double" },
"dim" : { "usage" : "G", "type" : "int" },
"dimen" : { "usage" : "G", "type" : "int" },
"dir" : { "usage" : "E", "type" : "dirType" },
"diredgeconstraints" : { "usage" : "G", "type" : "string" },
"distortion" : { "usage" : "N", "type" : "double" },
"dpi" : { "usage" : "G", "type" : "double" },
"edgeURL" : { "usage" : "E", "type" : "escString" },
"edgehref" : { "usage" : "E", "type" : "escString" },
"edgetarget" : { "usage" : "E", "type" : "escString" },
"edgetooltip" : { "usage" : "E", "type" : "escString" },
"epsilon" : { "usage" : "G", "type" : "double" },
"esep" : { "usage" : "G", "type" : "double" },
"fillcolor" : { "usage" : "NC", "type" : "color" },
"fixedsize" : { "usage" : "N", "type" : "bool" },
"fontcolor" : { "usage" : "ENGC", "type" : "color" },
"fontname" : { "usage" : "ENGC", "type" : "string" },
"fontnames" : { "usage" : "G", "type" : "string" },
"fontpath" : { "usage" : "G", "type" : "string" },
"fontsize" : { "usage" : "ENGC", "type" : "double" },
"group" : { "usage" : "N", "type" : "string" },
"headURL" : { "usage" : "E", "type" : "escString" },
"headclip" : { "usage" : "E", "type" : "bool" },
"headhref" : { "usage" : "E", "type" : "escString" },
"headlabel" : { "usage" : "E", "type" : "lblString" },
"headport" : { "usage" : "E", "type" : "portPos" },
"headtarget" : { "usage" : "E", "type" : "escString" },
"headtooltip" : { "usage" : "E", "type" : "escString" },
"height" : { "usage" : "N", "type" : "double" },
"href" : { "usage" : "E", "type" : "escString" },
"id" : { "usage" : "GNE", "type" : "lblString" },
"image" : { "usage" : "N", "type" : "string" },
"imagescale" : { "usage" : "N", "type" : "string" },
"label" : { "usage" : "ENGC", "type" : "lblString" },
"labelURL" : { "usage" : "E", "type" : "escString" },
"labelangle" : { "usage" : "E", "type" : "double" },
"labeldistance" : { "usage" : "E", "type" : "double" },
"labelfloat" : { "usage" : "E", "type" : "bool" },
"labelfontcolor" : { "usage" : "E", "type" : "color" },
"labelfontname" : { "usage" : "E", "type" : "string" },
"labelfontsize" : { "usage" : "E", "type" : "double" },
"labelhref" : { "usage" : "E", "type" : "escString" },
"labeljust" : { "usage" : "GC", "type" : "string" },
"labelloc" : { "usage" : "NGC", "type" : "string" },
"labeltarget" : { "usage" : "E", "type" : "escString" },
"labeltooltip" : { "usage" : "E", "type" : "escString" },
"landscape" : { "usage" : "G", "type" : "bool" },
"layer" : { "usage" : "EN", "type" : "layerRange" },
"layers" : { "usage" : "G", "type" : "layerList" },
"layersep" : { "usage" : "G", "type" : "string" },
"layout" : { "usage" : "G", "type" : "string" },
"len" : { "usage" : "E", "type" : "double" },
"levels" : { "usage" : "G", "type" : "int" },
"levelsgap" : { "usage" : "G", "type" : "double" },
"lhead" : { "usage" : "E", "type" : "string" },
"lheight" : { "usage" : "GC", "type" : "double" },
"lp" : { "usage" : "EGC", "type" : "point" },
"ltail" : { "usage" : "E", "type" : "string" },
"lwidth" : { "usage" : "GC", "type" : "double" },
"margin" : { "usage" : "NG", "type" : "pointf" },
"maxiter" : { "usage" : "G", "type" : "int" },
"mclimit" : { "usage" : "G", "type" : "double" },
"mindist" : { "usage" : "G", "type" : "double" },
"minlen" : { "usage" : "E", "type" : "int" },
"mode" : { "usage" : "G", "type" : "string" },
"model" : { "usage" : "G", "type" : "string" },
"mosek" : { "usage" : "G", "type" : "bool" },
"nodesep" : { "usage" : "G", "type" : "double" },
"nojustify" : { "usage" : "GCNE", "type" : "bool" },
"normalize" : { "usage" : "G", "type" : "bool" },
"nslimit" : { "usage" : "G", "type" : "double" },
"nslimit1" : { "usage" : "G", "type" : "double" },
"ordering" : { "usage" : "G", "type" : "string" },
"orientation" : { "usage" : "N", "type" : "double" },
"orientation" : { "usage" : "G", "type" : "string" },
"outputorder" : { "usage" : "G", "type" : "outputMode" },
"overlap" : { "usage" : "G", "type" : "string" },
"overlap_scaling" : { "usage" : "G", "type" : "double" },
"pack" : { "usage" : "G", "type" : "int" },
"packmode" : { "usage" : "G", "type" : "packMode" },
"pad" : { "usage" : "G", "type" : "pointf" },
"page" : { "usage" : "G", "type" : "pointf" },
"pagedir" : { "usage" : "G", "type" : "pagedir" },
"pencolor" : { "usage" : "C", "type" : "color" },
"penwidth" : { "usage" : "CNE", "type" : "double" },
"peripheries" : { "usage" : "NC", "type" : "int" },
"pin" : { "usage" : "N", "type" : "bool" },
"pos" : { "usage" : "EN", "type" : "point" },
"quadtree" : { "usage" : "G", "type" : "quadType" },
"quantum" : { "usage" : "G", "type" : "double" },
"rank" : { "usage" : "S", "type" : "rankType" },
"rankdir" : { "usage" : "G", "type" : "rankdir" },
"ranksep" : { "usage" : "G", "type" : "double" },
"ratio" : { "usage" : "G", "type" : "string" },
"rects" : { "usage" : "N", "type" : "rect" },
"regular" : { "usage" : "N", "type" : "bool" },
"remincross" : { "usage" : "G", "type" : "bool" },
"repulsiveforce" : { "usage" : "G", "type" : "double" },
"resolution" : { "usage" : "G", "type" : "double" },
"root" : { "usage" : "GN", "type" : "string" },
"rotate" : { "usage" : "G", "type" : "int" },
"samehead" : { "usage" : "E", "type" : "string" },
"sametail" : { "usage" : "E", "type" : "string" },
"samplepoints" : { "usage" : "N", "type" : "int" },
"searchsize" : { "usage" : "G", "type" : "int" },
"sep" : { "usage" : "G", "type" : "double" },
"shape" : { "usage" : "N", "type" : "shape" },
"shapefile" : { "usage" : "N", "type" : "string" },
"showboxes" : { "usage" : "ENG", "type" : "int" },
"sides" : { "usage" : "N", "type" : "int" },
"size" : { "usage" : "G", "type" : "pointf" },
"skew" : { "usage" : "N", "type" : "double" },
"smoothing" : { "usage" : "G", "type" : "smoothType" },
"sortv" : { "usage" : "GCN", "type" : "int" },
"splines" : { "usage" : "G", "type" : "string" },
"start" : { "usage" : "G", "type" : "startType" },
"style" : { "usage" : "ENC", "type" : "style" },
"stylesheet" : { "usage" : "G", "type" : "string" },
"tailURL" : { "usage" : "E", "type" : "escString" },
"tailclip" : { "usage" : "E", "type" : "bool" },
"tailhref" : { "usage" : "E", "type" : "escString" },
"taillabel" : { "usage" : "E", "type" : "lblString" },
"tailport" : { "usage" : "E", "type" : "portPos" },
"tailtarget" : { "usage" : "E", "type" : "escString" },
"tailtooltip" : { "usage" : "E", "type" : "escString" },
"target" : { "usage" : "ENGC", "type" : "escString" },
"tooltip" : { "usage" : "NEC", "type" : "escString" },
"truecolor" : { "usage" : "G", "type" : "bool" },
"vertices" : { "usage" : "N", "type" : "pointfList" },
"viewport" : { "usage" : "G", "type" : "viewPort" },
"voro_margin" : { "usage" : "G", "type" : "double" },
"weight" : { "usage" : "E", "type" : "double" },
"width" : { "usage" : "N", "type" : "double" },
"z" : { "usage" : "N", "type" : "double" }
};
var gType = {
"E" : "edge",
"N" : "node",
"G" : "graph",
"C" : "cluster"
};
var quotedTypes = [
"escString",
"rect",
"color",
"colorList",
"string",
"lblString",
"portPos",
"point",
"pointf",
"pointfList",
"splineType",
"style",
"viewPort"
];
function mustBeQuoted(data) {
return( quotedTypes.indexOf(attrs[data]["type"]) != -1 )
}
function quoteMe(attr, value) {
if( mustBeQuoted(attr) ) {
return( '"'+value+'"' );
} else {
return( value );
}
}
function validateAttribut(name, type) {
if( attrs[name] ) {
return( attrs[name]["usage"].indexOf(type) > -1 );
} else {
return( false );
}
}
var Attributs = exports.Attributs = function(t) {
this._type = t;
this.attributs = new Hash();
}
Attributs.prototype.length = function() {
return( this.attributs.length );
}
Attributs.prototype.set = function( name, value ) {
if( validateAttribut(name, this._type) == false ) {
sys.debug( "Warning : Invalid attribut `"+name+"' for a "+gType[this._type] );
// throw "Invalid attribut `"+name+"' for a "+gType[this._type]
}
this.attributs.setItem(name, value);
}
Attributs.prototype.get = function( name ) {
return this.attributs.items[name];
}
Attributs.prototype.to_dot = function(link) {
var attrsOutput = "";
var sep = "";
if( this.attributs.length > 0 ) {
attrsOutput = attrsOutput + " [ "
for( var name in this.attributs.items ) {
attrsOutput = attrsOutput + sep + name + " = " + quoteMe(name, this.attributs.items[name])
sep = ", "
}
attrsOutput = attrsOutput + " ]"
}
return attrsOutput;
}