17
17
* under the License.
18
18
*/
19
19
20
- import * as zrUtil from 'zrender/src/core/util' ;
21
20
import SymbolDraw , { ListForSymbolDraw } from '../helper/SymbolDraw' ;
22
21
import LineDraw from '../helper/LineDraw' ;
23
22
import RoamController , { RoamControllerHost } from '../../component/helper/RoamController' ;
@@ -38,6 +37,9 @@ import Line from '../helper/Line';
38
37
import { getECData } from '../../util/innerStore' ;
39
38
import Thumbnail from './Thumbnail' ;
40
39
40
+ import { simpleLayoutEdge } from './simpleLayoutHelper' ;
41
+ import { circularLayout , rotateNodeLabel } from './circularLayoutHelper' ;
42
+
41
43
function isViewCoordSys ( coordSys : CoordinateSystem ) : coordSys is View {
42
44
return coordSys . type === 'view' ;
43
45
}
@@ -61,9 +63,7 @@ class GraphView extends ChartView {
61
63
62
64
private _layouting : boolean ;
63
65
64
- private _thumbanil : Thumbnail ;
65
-
66
- private _isForceLayout = false ;
66
+ private _thumbnail : Thumbnail ;
67
67
68
68
private _mainGroup : graphic . Group ;
69
69
@@ -91,6 +91,7 @@ class GraphView extends ChartView {
91
91
92
92
render ( seriesModel : GraphSeriesModel , ecModel : GlobalModel , api : ExtensionAPI ) {
93
93
const coordSys = seriesModel . coordinateSystem ;
94
+ let isForceLayout = false ;
94
95
95
96
this . _model = seriesModel ;
96
97
@@ -126,10 +127,12 @@ class GraphView extends ChartView {
126
127
const forceLayout = seriesModel . forceLayout ;
127
128
const layoutAnimation = seriesModel . get ( [ 'force' , 'layoutAnimation' ] ) ;
128
129
if ( forceLayout ) {
129
- this . _isForceLayout = true ;
130
+ isForceLayout = true ;
130
131
this . _startForceLayoutIteration ( forceLayout , api , layoutAnimation ) ;
131
132
}
132
133
134
+ const layout = seriesModel . get ( 'layout' ) ;
135
+
133
136
data . graph . eachNode ( ( node ) => {
134
137
const idx = node . dataIndex ;
135
138
const el = node . getGraphicEl ( ) as Symbol ;
@@ -143,14 +146,31 @@ class GraphView extends ChartView {
143
146
el . off ( 'drag' ) . off ( 'dragend' ) ;
144
147
const draggable = itemModel . get ( 'draggable' ) ;
145
148
if ( draggable ) {
146
- el . on ( 'drag' , ( ) => {
147
- if ( forceLayout ) {
148
- forceLayout . warmUp ( ) ;
149
- ! this . _layouting
150
- && this . _startForceLayoutIteration ( forceLayout , api , layoutAnimation ) ;
151
- forceLayout . setFixed ( idx ) ;
152
- // Write position back to layout
153
- data . setItemLayout ( idx , [ el . x , el . y ] ) ;
149
+ el . on ( 'drag' , ( e ) => {
150
+ switch ( layout ) {
151
+ case 'force' :
152
+ forceLayout . warmUp ( ) ;
153
+ ! this . _layouting
154
+ && this . _startForceLayoutIteration ( forceLayout , api , layoutAnimation ) ;
155
+ forceLayout . setFixed ( idx ) ;
156
+ // Write position back to layout
157
+ data . setItemLayout ( idx , [ el . x , el . y ] ) ;
158
+ break ;
159
+ case 'circular' :
160
+ data . setItemLayout ( idx , [ el . x , el . y ] ) ;
161
+ // mark node fixed
162
+ node . setLayout ( { fixed : true } , true ) ;
163
+ // recalculate circular layout
164
+ circularLayout ( seriesModel , 'symbolSize' , node , [ e . offsetX , e . offsetY ] ) ;
165
+ this . updateLayout ( seriesModel ) ;
166
+ break ;
167
+ case 'none' :
168
+ default :
169
+ data . setItemLayout ( idx , [ el . x , el . y ] ) ;
170
+ // update edge
171
+ simpleLayoutEdge ( seriesModel . getGraph ( ) , seriesModel ) ;
172
+ this . updateLayout ( seriesModel ) ;
173
+ break ;
154
174
}
155
175
} ) . on ( 'dragend' , ( ) => {
156
176
if ( forceLayout ) {
@@ -187,41 +207,12 @@ class GraphView extends ChartView {
187
207
&& seriesModel . get ( [ 'circular' , 'rotateLabel' ] ) ;
188
208
const cx = data . getLayout ( 'cx' ) ;
189
209
const cy = data . getLayout ( 'cy' ) ;
190
- data . eachItemGraphicEl ( function ( el : Symbol , idx ) {
191
- const itemModel = data . getItemModel < GraphNodeItemOption > ( idx ) ;
192
- let labelRotate = itemModel . get ( [ 'label' , 'rotate' ] ) || 0 ;
193
- const symbolPath = el . getSymbolPath ( ) ;
194
- if ( circularRotateLabel ) {
195
- const pos = data . getItemLayout ( idx ) ;
196
- let rad = Math . atan2 ( pos [ 1 ] - cy , pos [ 0 ] - cx ) ;
197
- if ( rad < 0 ) {
198
- rad = Math . PI * 2 + rad ;
199
- }
200
- const isLeft = pos [ 0 ] < cx ;
201
- if ( isLeft ) {
202
- rad = rad - Math . PI ;
203
- }
204
- const textPosition = isLeft ? 'left' as const : 'right' as const ;
205
-
206
- symbolPath . setTextConfig ( {
207
- rotation : - rad ,
208
- position : textPosition ,
209
- origin : 'center'
210
- } ) ;
211
- const emphasisState = symbolPath . ensureState ( 'emphasis' ) ;
212
- zrUtil . extend ( emphasisState . textConfig || ( emphasisState . textConfig = { } ) , {
213
- position : textPosition
214
- } ) ;
215
- }
216
- else {
217
- symbolPath . setTextConfig ( {
218
- rotation : labelRotate *= Math . PI / 180
219
- } ) ;
220
- }
210
+ data . graph . eachNode ( ( node ) => {
211
+ rotateNodeLabel ( node , circularRotateLabel , cx , cy ) ;
221
212
} ) ;
222
213
223
214
this . _firstRender = false ;
224
- this . _isForceLayout || this . _renderThumbnail ( seriesModel , api ) ;
215
+ isForceLayout || this . _renderThumbnail ( seriesModel , api , this . _symbolDraw , this . _lineDraw ) ;
225
216
}
226
217
227
218
dispose ( ) {
@@ -238,8 +229,7 @@ class GraphView extends ChartView {
238
229
( function step ( ) {
239
230
forceLayout . step ( function ( stopped ) {
240
231
if ( stopped ) {
241
- self . _isForceLayout = false ;
242
- self . _renderThumbnail ( self . _model , api ) ;
232
+ self . _renderThumbnail ( self . _model , api , self . _symbolDraw , self . _lineDraw ) ;
243
233
}
244
234
self . updateLayout ( self . _model ) ;
245
235
( self . _layouting = ! stopped ) && (
@@ -286,7 +276,7 @@ class GraphView extends ChartView {
286
276
dx : e . dx ,
287
277
dy : e . dy
288
278
} ) ;
289
- this . _thumbanil . _updateSelectedRect ( 'pan' ) ;
279
+ this . _thumbnail . _updateSelectedRect ( 'pan' ) ;
290
280
} )
291
281
. on ( 'zoom' , ( e ) => {
292
282
roamHelper . updateViewOnZoom ( controllerHost , e . scale , e . originX , e . originY ) ;
@@ -302,7 +292,7 @@ class GraphView extends ChartView {
302
292
this . _lineDraw . updateLayout ( ) ;
303
293
// Only update label layout on zoom
304
294
api . updateLabelLayout ( ) ;
305
- this . _thumbanil . _updateSelectedRect ( 'zoom' ) ;
295
+ this . _thumbnail . _updateSelectedRect ( 'zoom' ) ;
306
296
} ) ;
307
297
}
308
298
@@ -327,14 +317,19 @@ class GraphView extends ChartView {
327
317
remove ( ecModel : GlobalModel , api : ExtensionAPI ) {
328
318
this . _symbolDraw && this . _symbolDraw . remove ( ) ;
329
319
this . _lineDraw && this . _lineDraw . remove ( ) ;
330
- this . _thumbanil && this . group . remove ( this . _thumbanil . group ) ;
320
+ this . _thumbnail && this . group . remove ( this . _thumbnail . group ) ;
331
321
}
332
322
333
- private _renderThumbnail ( seriesModel : GraphSeriesModel , api : ExtensionAPI ) {
334
- if ( this . _thumbanil ) {
335
- this . _thumbanil . remove ( ) ;
323
+ private _renderThumbnail (
324
+ seriesModel : GraphSeriesModel ,
325
+ api : ExtensionAPI ,
326
+ symbolDraw : SymbolDraw ,
327
+ lineDraw : LineDraw
328
+ ) {
329
+ if ( this . _thumbnail ) {
330
+ this . group . remove ( this . _thumbnail . group ) ;
336
331
}
337
- ( this . _thumbanil = new Thumbnail ( this . group ) ) . render ( seriesModel , api ) ;
332
+ ( this . _thumbnail = new Thumbnail ( this . group ) ) . render ( seriesModel , api , symbolDraw , lineDraw , this . _mainGroup ) ;
338
333
}
339
334
}
340
335
0 commit comments