11import Rect from './graphics/structs/Rect' ;
2- import PaletteItem from './graphics/structs/PaletteItem' ;
3- import { ConnectorPlacementType } from './enums' ;
42import createGraphics from './graphics/createGraphics' ;
5- import { getFixOfPixelAlignment , getInnerSize , getElementOffset } from './graphics/dom' ;
3+ import { getFixOfPixelAlignment , getInnerSize } from './graphics/dom' ;
64import JsonML from './common/jsonml-html' ;
7- import Transform from './graphics/Transform' ;
8- import PolylinesBuffer from './graphics/structs/PolylinesBuffer' ;
9- import ConnectorAnnotationOffsetResolver from './tasks/renders/offsetResolver/ConnectorAnnotationOffsetResolver' ;
10- import ConnectorOffbeat from './graphics/shapes/ConnectorOffbeat' ;
11- import ConnectorStraight from './graphics/shapes/ConnectorStraight' ;
5+ import ConnectorAnnotation from './graphics/annotations/ConnectorAnnotation' ;
126import AnnotationLabelTemplate from './templates/html/AnnotationLabelTemplate' ;
13- import { isNullOrEmpty } from './common' ;
14- import RenderEventArgs from './events/RenderEventArgs' ;
157
168/**
179* Creates JavaScript Connector Annotation Control
@@ -30,7 +22,8 @@ export default function ConnectorAnnotationControl(element, options) {
3022 placeholder : null ,
3123 panelSize : null ,
3224 graphics : null ,
33- labelTemplate : null
25+ labelTemplate : null ,
26+ connector : null
3427 } ;
3528
3629 if ( ! element ) {
@@ -70,6 +63,7 @@ export default function ConnectorAnnotationControl(element, options) {
7063 ) ;
7164
7265 _data . graphics = createGraphics ( _data . element ) ;
66+ _data . connector = new ConnectorAnnotation ( ) ;
7367 } ;
7468
7569 function cleanLayout ( ) {
@@ -106,127 +100,19 @@ export default function ConnectorAnnotationControl(element, options) {
106100 _data . labelTemplate = AnnotationLabelTemplate ( _data . options ) ;
107101 cleanLayout ( ) ;
108102 createLayout ( ) ;
109- redraw ( ) ;
103+ _data . graphics . begin ( ) ;
104+ _data . connector . draw ( _data . options , _data . graphics , _data . panelSize , _data . labelTemplate ) ;
105+ _data . graphics . end ( ) ;
110106 }
111107 else {
112108 updateLayout ( ) ;
113109 _data . graphics . resize ( "placeholder" , _data . panelSize . width , _data . panelSize . height ) ;
114110 _data . graphics . begin ( ) ;
115- redraw ( ) ;
111+ _data . connector . draw ( _data . options , _data . graphics , _data . panelSize , _data . labelTemplate ) ;
116112 _data . graphics . end ( ) ;
117113 }
118114 }
119115
120- function redraw ( ) {
121- var annotationConfig = _data . options ,
122- shape ,
123- uiHash ,
124- transform = new Transform ( ) ,
125- panel = _data . graphics . activate ( "placeholder" ) ,
126- buffer = new PolylinesBuffer ( ) ,
127- connectorAnnotationOffsetResolver = ConnectorAnnotationOffsetResolver ( ) ;
128-
129- transform . size = new Size ( _data . panelSize . width , _data . panelSize . height ) ;
130- transform . setOrientation ( annotationConfig . orientationType ) ;
131-
132- if ( annotationConfig . fromRectangle != null && annotationConfig . toRectangle != null ) {
133- var fromRect = annotationConfig . fromRectangle ,
134- toRect = annotationConfig . toRectangle ;
135-
136- /* translate rectangles to Top orientation */
137- /* from rectangle */
138- transform . transformRect ( fromRect . x , fromRect . y , fromRect . width , fromRect . height , false ,
139- this , function ( x , y , width , height ) {
140- fromRect = new Rect ( x , y , width , height ) ;
141- } ) ;
142-
143- /* to rectangle */
144- transform . transformRect ( toRect . x , toRect . y , toRect . width , toRect . height , false ,
145- this , function ( x , y , width , height ) {
146- toRect = new Rect ( x , y , width , height ) ;
147- } ) ;
148-
149- switch ( annotationConfig . connectorPlacementType ) {
150- case ConnectorPlacementType . Offbeat :
151- shape = new ConnectorOffbeat ( ) ;
152- break ;
153- case ConnectorPlacementType . Straight :
154- shape = new ConnectorStraight ( ) ;
155- break ;
156- }
157-
158- /* rotate label size to user orientation */
159- var labelSize ;
160- transform . transformRect ( 0 , 0 , annotationConfig . labelSize . width , annotationConfig . labelSize . height , false ,
161- this , function ( x , y , width , height ) {
162- labelSize = new Size ( width , height ) ;
163- } ) ;
164-
165- /* rotate panel size to user orientation */
166- var panelSize = null ;
167- transform . transformRect ( 0 , 0 , panel . size . width , panel . size . height , false ,
168- this , function ( x , y , width , height ) {
169- panelSize = new Size ( width , height ) ;
170- } ) ;
171-
172- var linePaletteItem = new PaletteItem ( {
173- lineColor : annotationConfig . color ,
174- lineWidth : annotationConfig . lineWidth ,
175- lineType : annotationConfig . lineType
176- } ) ;
177-
178- var hasLabel = ! isNullOrEmpty ( annotationConfig . label ) ;
179-
180- /* offset rectangles */
181- fromRect = new Rect ( fromRect ) . offset ( annotationConfig . offset ) ;
182- toRect = new Rect ( toRect ) . offset ( annotationConfig . offset ) ;
183-
184- var linesOffset = annotationConfig . lineWidth * 6 ;
185-
186- /* create connection lines */
187- shape . draw ( buffer , linePaletteItem , fromRect , toRect , linesOffset , 0 , labelSize , panelSize ,
188- annotationConfig . connectorShapeType , annotationConfig . labelOffset , annotationConfig . labelPlacementType , hasLabel ,
189- connectorAnnotationOffsetResolver , function ( labelPlacement , labelConfig ) {
190- var hasLabel = ! isNullOrEmpty ( labelConfig . label ) ;
191- if ( hasLabel && labelPlacement != null ) {
192- /* translate result label placement back to users orientation */
193- transform . transformRect ( labelPlacement . x , labelPlacement . y , labelPlacement . width , labelPlacement . height , true ,
194- self , function ( x , y , width , height ) {
195- labelPlacement = new Rect ( x , y , width , height ) ;
196- } ) ;
197-
198- uiHash = new RenderEventArgs ( ) ;
199- uiHash . context = labelConfig ;
200-
201- /* draw label */
202- _data . graphics . template (
203- labelPlacement . x
204- , labelPlacement . y
205- , 0
206- , 0
207- , 0
208- , 0
209- , labelPlacement . width
210- , labelPlacement . height
211- , _data . labelTemplate . template ( )
212- , _data . labelTemplate . getHashCode ( )
213- , _data . labelTemplate . render
214- , uiHash
215- , null
216- ) ;
217- }
218- } , annotationConfig ) ;
219- connectorAnnotationOffsetResolver . resolve ( ) ;
220- }
221-
222- /* translate result polylines back to users orientation */
223- buffer . transform ( transform , true ) ;
224- /* draw background polylines */
225- _data . graphics . polylinesBuffer ( buffer ) ;
226-
227- _data . graphics . end ( ) ;
228- }
229-
230116 function destroy ( ) {
231117 cleanLayout ( ) ;
232118 } ;
0 commit comments