Index
The HT for Web provides the default line and multicast lines can fit most basic topological graphics applications, however, more types of edge are needed for applications such as drawing flowcharts, organization charts, and mind maps, for which the HT for Web provides a edge type extension library that meets more application requirements.
The edge type described in this section requires the introduction of the ht.js core library and the introduction of a ht-edgetype.js edge type plug-in library.
ht.Default.setEdgeType(type, func, mutual) function can be used to customize the new edge type:
type: String type of edge type, corresponding style edge.type propertiesfunc: Function type, according to the input parameter (edge, gap, graphView, sameSourceWithFirstEdge) to return the line trend informationedge: Current connection objectgap: When multiple edges are bundled, this line object corresponds to the gap of the center edgegraphView: Current corresponding topology component objectsameSourceWithFirstEdge: boolean type, whether the edge is homologous to the first line of the same group{points: new ht.List(...), segments: new ht.List(...)} structure of the edge trend information, segments optional values are as follows:moveTo, occupy 1 point informationlineTo, occupy 1 point informationquadraticCurveTo, occupy 2 point informationbezierCurveTo, occupy 3 point informationclosePath, do not occupy a bit of informationmutual: This parameter determines whether the edge affects all edges on the starting or ending node, and defaults to false represents only the edges in the EdgeGroup of the same source and target, and the HT predefined edge type with the suffix 2 is mutual is a complex edge type for true, refer to Complex Edge chapterht.Default.setEdgeType('custom', function (edge, gap, graphView, sameSourceWithFirstEdge){
var sourcePoint = edge.getSourceAgent().getPosition(),
targetPoint = edge.getTargetAgent().getPosition(),
points = new ht.List();
points.add(sourcePoint);
points.add({
x: (sourcePoint.x + targetPoint.x)/2,
y: (sourcePoint.y + targetPoint.y)/2 + 300
});
points.add(targetPoint);
return {
points: points,
segments: new ht.List([1, 3])
};
});
In the custom connection example above, a central control point is inserted between the sourcePoint and the targetPoint as the inflexion of the curve.
This example uses the graphView.setLayers(['nodeLayer', 'edgeLayer']); layered function, grouped the Node and Edge into different layers by node.setLayer('nodeLayer'); and edge.setLayer('edgeLayer');, because the default nodes will displayed on the line, and through such layering the nodes are rendered under the line.
Moving the mouse over the edge will dynamically change the edge color, which is done by the GraphView.getView() add mousemove event to the special handling, judging ht.Default.isDragging() is to avoid processing when the node is moved, gets the current mouse position under the data by graphView.getDataAt(e);.
var lastFocus = null;
graphView.getView().addEventListener('mousemove', function (e){
if(!ht.Default.isDragging()){
if(lastFocus){
lastFocus.s('edge.color', 'lightgray');
}
var data = graphView.getDataAt(e);
if(data instanceof ht.Edge){
data.s('edge.color', 'red');
lastFocus = data;
}else{
lastFocus = null;
}
}
});
Edge type expansion packs predefined the following selectable types:
boundary: This type of edge is connected only to the edge of the primitive rectangleripple: This type renders a wavy effect edgeedge.offset: Specified edge distance from the center of the dataedge.ripple.size: Specifies the number of ups and downs of the wave, and defaults to 1edge.ripple.length: Specifies the length of the wave, which priority is higher than edge.ripple.sizeedge.ripple.both: Specifies whether bilateral fluctuations, default is falseedge.center: Specifies whether the starting and ending points are aggregated, and defaults to falseedge.ripple.elevation: Specifies the height of the wave undulation, and defaults to -20edge.ripple.straight: Specifies whether the wave is a straight line and defaults to falseh.v: The type from the starting point to the first horizontal to the end point of the directionedge.corner.radius: Control corner curve radiansedge.center: The default is false represents starting from the edge of the rectangle, true represents starting and ending at the centerv.h: The type from the starting point to the vertical level to the end point of the trendedge.corner.radius: Control corner curve radiansedge.center: The default is false represents starting from the edge of the rectangle, true represents starting and ending at the center ortho: This type will turn an intermediate polyline between the starting and ending points of the connectionedge.ortho: The reference specifies the corner position of the middle polyline, and the default value is ' 0.5 ' represents turn a corner from the middle.edge.corner.radius: Control corner curve radiansedge.center: The default is false represents starting from the edge of the rectangle, true represents starting and ending at the centerflex: This type will have a turn at the start and end of the connectionedge.flex: This parameter specifies the position of the corner, with the default value 20 edge.corner.radius: Control corner curve radiansedge.center: The default is false represents starting from the edge of the rectangle, true represents starting and ending at the centerextend.east: This type of edge extends to the eastedge.extend: Control the extended distanceedge.corner.radius: Control corner curve radiansedge.center: The default is false represents starting from the edge of the rectangle, true represents starting and ending at the centerextend.west: This type of edge extends to the westedge.extend: Control the extended distanceedge.corner.radius: Control corner curve radiansedge.center: The default is false represents starting from the edge of the rectangle, true represents starting and ending at the centerextend.north: This type of edge extends to the northedge.extend: Control the extended distanceedge.corner.radius: Control corner curve radiansedge.center: The default is false represents starting from the edge of the rectangle, true represents starting and ending at the centerextend.south: This type of edge extends to the southedge.extend: Control the extended distance edge.corner.radius: Control corner curve radiansedge.center: The default is false represents starting from the edge of the rectangle, true represents starting and ending at the centerThe following example is consistent with the above type model, but adds the start and end arrows to all edges, the HT does not predefined the line arrows, and the user can arbitrarily extend their desired arrowhead style by customizing the vector.
The following code defines the vector arrows for toArrow and then rotates fromArrow through the rotation: Math.PI, and finally through the edge.addStyleIcon function respectively set up two arrow icons in 15 and 19 left and right center position, where keepOrien: true needs to be set, because the arrow and the line are aligned in parallel and need not be adjusted dynamically as label.
ht.Default.setImage('toArrow', {
width: 100,
height: 50,
comps: [
{
type: 'shape',
points: [2, 25, 30, 25],
borderWidth: 4,
borderColor: 'rgba(255, 0, 0, 0.9)'
},
{
type: 'shape',
points: [30, 10, 30, 40, 50, 25, 30, 10],
background: 'rgba(255, 0, 0, 0.9)',
borderWidth: 1,
borderColor: 'red',
gradient: 'spread.vertical',
gradientColor: 'rgba(255, 255, 255, 0.9)'
}
]
});
ht.Default.setImage('fromArrow', {
width: 100,
height: 50,
comps: [
{
type: 'image',
name: 'toArrow',
rect: [0, 0, 100, 50],
rotation: Math.PI
}
]
});
function createEdge(sourceNode, targetNode, count, typeOrStyle){
var edge;
for(var i=0; i<count; i++){
edge = new ht.Edge(sourceNode, targetNode);
if(typeof typeOrStyle === 'object'){
edge.s(typeOrStyle);
}else{
edge.s('edge.type', typeOrStyle);
}
edge.addStyleIcon("fromArrow", {
position: 15,
keepOrien: true,
width: 40,
height: 20,
names: ['fromArrow']
});
edge.addStyleIcon("toArrow", {
position: 19,
keepOrien: true,
width: 40,
height: 20,
names: ['toArrow']
});
dataModel.add(edge);
}
return edge;
}
The Edge Type described earlier enables bundling the edges between the starting and ending nodes, but the edge type layout does not take into account the existence of different edges between the starting and ending nodes, so there is a problem of overlap between the edges of the complex topology, for which HT added a corresponding suffix of 2 for the type of connection: ortho2, flex2, extend.north2, extend.south2, extend.west2, extend.east2, v.h2 and h.v2.