@@ -37,6 +37,9 @@ import SeriesData from '../../data/SeriesData';
3737import Line from '../helper/Line' ;
3838import { getECData } from '../../util/innerStore' ;
3939
40+ import { simpleLayoutEdge } from './simpleLayoutHelper' ;
41+ import { circularLayout , rotateNodeLabel } from './circularLayoutHelper' ;
42+
4043function isViewCoordSys ( coordSys : CoordinateSystem ) : coordSys is View {
4144 return coordSys . type === 'view' ;
4245}
@@ -122,6 +125,8 @@ class GraphView extends ChartView {
122125 this . _startForceLayoutIteration ( forceLayout , layoutAnimation ) ;
123126 }
124127
128+ const layout = seriesModel . get ( 'layout' ) ;
129+
125130 data . graph . eachNode ( ( node ) => {
126131 const idx = node . dataIndex ;
127132 const el = node . getGraphicEl ( ) as Symbol ;
@@ -130,22 +135,39 @@ class GraphView extends ChartView {
130135 el . off ( 'drag' ) . off ( 'dragend' ) ;
131136 const draggable = itemModel . get ( 'draggable' ) ;
132137 if ( draggable ) {
133- el . on ( 'drag' , ( ) => {
134- if ( forceLayout ) {
135- forceLayout . warmUp ( ) ;
136- ! this . _layouting
137- && this . _startForceLayoutIteration ( forceLayout , layoutAnimation ) ;
138- forceLayout . setFixed ( idx ) ;
139- // Write position back to layout
140- data . setItemLayout ( idx , [ el . x , el . y ] ) ;
138+ el . on ( 'drag' , ( e ) => {
139+ switch ( layout ) {
140+ case 'force' :
141+ forceLayout . warmUp ( ) ;
142+ ! this . _layouting
143+ && this . _startForceLayoutIteration ( forceLayout , layoutAnimation ) ;
144+ forceLayout . setFixed ( idx ) ;
145+ // Write position back to layout
146+ data . setItemLayout ( idx , [ el . x , el . y ] ) ;
147+ break ;
148+ case 'circular' :
149+ data . setItemLayout ( idx , [ el . x , el . y ] ) ;
150+ // mark node fixed
151+ node . setLayout ( { fixed : true } , true ) ;
152+ // recalculate circular layout
153+ circularLayout ( seriesModel , 'symbolSize' , node , [ e . offsetX , e . offsetY ] ) ;
154+ this . updateLayout ( seriesModel ) ;
155+ break ;
156+ case 'none' :
157+ default :
158+ data . setItemLayout ( idx , [ el . x , el . y ] ) ;
159+ // update edge
160+ simpleLayoutEdge ( seriesModel . getGraph ( ) , seriesModel ) ;
161+ this . updateLayout ( seriesModel ) ;
162+ break ;
141163 }
142164 } ) . on ( 'dragend' , ( ) => {
143165 if ( forceLayout ) {
144166 forceLayout . setUnfixed ( idx ) ;
145167 }
146168 } ) ;
147169 }
148- el . setDraggable ( draggable && ! ! forceLayout ) ;
170+ el . setDraggable ( draggable ) ;
149171
150172 const focus = itemModel . get ( [ 'emphasis' , 'focus' ] ) ;
151173
@@ -170,37 +192,8 @@ class GraphView extends ChartView {
170192 && seriesModel . get ( [ 'circular' , 'rotateLabel' ] ) ;
171193 const cx = data . getLayout ( 'cx' ) ;
172194 const cy = data . getLayout ( 'cy' ) ;
173- data . eachItemGraphicEl ( function ( el : Symbol , idx ) {
174- const itemModel = data . getItemModel < GraphNodeItemOption > ( idx ) ;
175- let labelRotate = itemModel . get ( [ 'label' , 'rotate' ] ) || 0 ;
176- const symbolPath = el . getSymbolPath ( ) ;
177- if ( circularRotateLabel ) {
178- const pos = data . getItemLayout ( idx ) ;
179- let rad = Math . atan2 ( pos [ 1 ] - cy , pos [ 0 ] - cx ) ;
180- if ( rad < 0 ) {
181- rad = Math . PI * 2 + rad ;
182- }
183- const isLeft = pos [ 0 ] < cx ;
184- if ( isLeft ) {
185- rad = rad - Math . PI ;
186- }
187- const textPosition = isLeft ? 'left' as const : 'right' as const ;
188-
189- symbolPath . setTextConfig ( {
190- rotation : - rad ,
191- position : textPosition ,
192- origin : 'center'
193- } ) ;
194- const emphasisState = symbolPath . ensureState ( 'emphasis' ) ;
195- zrUtil . extend ( emphasisState . textConfig || ( emphasisState . textConfig = { } ) , {
196- position : textPosition
197- } ) ;
198- }
199- else {
200- symbolPath . setTextConfig ( {
201- rotation : labelRotate *= Math . PI / 180
202- } ) ;
203- }
195+ data . graph . eachNode ( ( node ) => {
196+ rotateNodeLabel ( node , circularRotateLabel , cx , cy ) ;
204197 } ) ;
205198
206199 this . _firstRender = false ;
0 commit comments