-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
rendered-style.js
138 lines (104 loc) · 3.21 KB
/
rendered-style.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
var BRp = {};
BRp.registerCalculationListeners = function(){
var cy = this.cy;
var elesToUpdate = cy.collection();
var r = this;
var enqueue = function( eles, dirtyStyleCaches = true ){
elesToUpdate.merge( eles );
if( dirtyStyleCaches ){
for( var i = 0; i < eles.length; i++ ){
var ele = eles[i];
var _p = ele._private;
var rstyle = _p.rstyle;
rstyle.clean = false;
}
}
};
r.binder( cy )
.on('bounds.* dirty.*', function onDirtyBounds( e ){
var node = e.target;
enqueue( node );
})
.on('style.* background.*', function onDirtyStyle( e ){
var ele = e.target;
enqueue( ele, false );
})
;
var updateEleCalcs = function( willDraw ){
if( willDraw ){
var fns = r.onUpdateEleCalcsFns;
for( var i = 0; i < elesToUpdate.length; i++ ){
enqueue( elesToUpdate[i].connectedEdges() );
}
if( fns ){ for( var i = 0; i < fns.length; i++ ){
var fn = fns[i];
fn( willDraw, elesToUpdate );
} }
r.recalculateRenderedStyle( elesToUpdate );
elesToUpdate = cy.collection();
}
};
r.flushRenderedStyleQueue = function(){
updateEleCalcs(true);
};
r.beforeRender( updateEleCalcs, r.beforeRenderPriorities.eleCalcs );
};
BRp.onUpdateEleCalcs = function( fn ){
var fns = this.onUpdateEleCalcsFns = this.onUpdateEleCalcsFns || [];
fns.push( fn );
};
BRp.recalculateRenderedStyle = function( eles, useCache ){
var edges = [];
var nodes = [];
// the renderer can't be used for calcs when destroyed, e.g. ele.boundingBox()
if( this.destroyed ){ return; }
// use cache by default for perf
if( useCache === undefined ){ useCache = true; }
for( var i = 0; i < eles.length; i++ ){
var ele = eles[ i ];
var _p = ele._private;
var rstyle = _p.rstyle;
// only update if dirty and in graph
if( (useCache && rstyle.clean) || ele.removed() ){ continue; }
// only update if not display: none
if( ele.pstyle('display').value === 'none' ){ continue; }
if( _p.group === 'nodes' ){
nodes.push( ele );
} else { // edges
edges.push( ele );
}
rstyle.clean = true;
}
// update node data from projections
for( var i = 0; i < nodes.length; i++ ){
var ele = nodes[i];
var _p = ele._private;
var rstyle = _p.rstyle;
var pos = ele.position();
this.recalculateNodeLabelProjection( ele );
rstyle.nodeX = pos.x;
rstyle.nodeY = pos.y;
rstyle.nodeW = ele.pstyle( 'width' ).pfValue;
rstyle.nodeH = ele.pstyle( 'height' ).pfValue;
}
this.recalculateEdgeProjections( edges );
// update edge data from projections
for( var i = 0; i < edges.length; i++ ){
var ele = edges[ i ];
var _p = ele._private;
var rstyle = _p.rstyle;
var rs = _p.rscratch;
this.recalculateEdgeLabelProjections( ele );
// update rstyle positions
rstyle.srcX = rs.arrowStartX;
rstyle.srcY = rs.arrowStartY;
rstyle.tgtX = rs.arrowEndX;
rstyle.tgtY = rs.arrowEndY;
rstyle.midX = rs.midX;
rstyle.midY = rs.midY;
rstyle.labelAngle = rs.labelAngle;
rstyle.sourceLabelAngle = rs.sourceLabelAngle;
rstyle.targetLabelAngle = rs.targetLabelAngle;
}
};
export default BRp;