@@ -19,17 +19,12 @@ qx.Class.define("osparc.workbench.Annotation", {
1919 extend : qx . core . Object ,
2020
2121 /**
22- * @param svgLayer {Object} SVG canvas
2322 * @param data {Object} data containing type, color, attributes and (optional) id
2423 * @param id {String} data
2524 */
26- construct : function ( svgLayer , data , id ) {
25+ construct : function ( data , id ) {
2726 this . base ( ) ;
2827
29- if ( svgLayer ) {
30- this . __svgLayer = svgLayer ;
31- }
32-
3328 if ( id === undefined ) {
3429 id = osparc . utils . Utils . uuidV4 ( ) ;
3530 }
@@ -70,7 +65,6 @@ qx.Class.define("osparc.workbench.Annotation", {
7065 "conversation" , // osparc.workbench.Annotation.TYPES.CONVERSATION
7166 ] ,
7267 nullable : false ,
73- apply : "__drawAnnotation"
7468 } ,
7569
7670 color : {
@@ -86,9 +80,15 @@ qx.Class.define("osparc.workbench.Annotation", {
8680 nullable : false ,
8781 } ,
8882
83+ svgCanvas : {
84+ init : null ,
85+ nullable : false ,
86+ apply : "__drawAnnotation" ,
87+ } ,
88+
8989 representation : {
9090 init : null
91- }
91+ } ,
9292 } ,
9393
9494 events : {
@@ -99,10 +99,8 @@ qx.Class.define("osparc.workbench.Annotation", {
9999 } ,
100100
101101 members : {
102- __svgLayer : null ,
103-
104- __drawAnnotation : function ( ) {
105- if ( this . __svgLayer === null ) {
102+ __drawAnnotation : function ( svgLayer ) {
103+ if ( svgLayer === null ) {
106104 return ;
107105 }
108106
@@ -111,17 +109,17 @@ qx.Class.define("osparc.workbench.Annotation", {
111109 switch ( this . getType ( ) ) {
112110 case this . self ( ) . TYPES . NOTE : {
113111 const user = osparc . store . Groups . getInstance ( ) . getUserByGroupId ( attrs . recipientGid ) ;
114- representation = this . __svgLayer . drawAnnotationNote ( attrs . x , attrs . y , user ? user . getLabel ( ) : "" , attrs . text ) ;
112+ representation = svgLayer . drawAnnotationNote ( attrs . x , attrs . y , user ? user . getLabel ( ) : "" , attrs . text ) ;
115113 break ;
116114 }
117115 case this . self ( ) . TYPES . RECT :
118- representation = this . __svgLayer . drawAnnotationRect ( attrs . width , attrs . height , attrs . x , attrs . y , this . getColor ( ) ) ;
116+ representation = svgLayer . drawAnnotationRect ( attrs . width , attrs . height , attrs . x , attrs . y , this . getColor ( ) ) ;
119117 break ;
120118 case this . self ( ) . TYPES . TEXT :
121- representation = this . __svgLayer . drawAnnotationText ( attrs . x , attrs . y , attrs . text , this . getColor ( ) , attrs . fontSize ) ;
119+ representation = svgLayer . drawAnnotationText ( attrs . x , attrs . y , attrs . text , this . getColor ( ) , attrs . fontSize ) ;
122120 break ;
123121 case this . self ( ) . TYPES . CONVERSATION : {
124- representation = this . __svgLayer . drawAnnotationConversation ( attrs . x , attrs . y , attrs . text ) ;
122+ representation = svgLayer . drawAnnotationConversation ( attrs . x , attrs . y , attrs . text ) ;
125123 const conversationId = attrs . conversationId ;
126124 if ( conversationId ) {
127125 osparc . store . Conversations . getInstance ( ) . addListener ( "conversationRenamed" , e => {
@@ -244,14 +242,19 @@ qx.Class.define("osparc.workbench.Annotation", {
244242 } ,
245243
246244 setSelected : function ( selected ) {
245+ const svgCanvas = this . getSvgCanvas ( ) ;
246+ if ( svgCanvas === null ) {
247+ return ;
248+ } ;
249+
247250 const representation = this . getRepresentation ( ) ;
248251 if ( representation ) {
249252 switch ( this . getType ( ) ) {
250253 case this . self ( ) . TYPES . RECT :
251254 case this . self ( ) . TYPES . TEXT : {
252255 if ( selected ) {
253256 if ( ! ( "bBox" in representation . node ) ) {
254- const bBox = this . __svgLayer . drawBoundingBox ( this ) ;
257+ const bBox = svgCanvas . drawBoundingBox ( this ) ;
255258 representation . node [ "bBox" ] = bBox ;
256259 }
257260 } else if ( "bBox" in representation . node ) {
@@ -265,11 +268,18 @@ qx.Class.define("osparc.workbench.Annotation", {
265268 } ,
266269
267270 serialize : function ( ) {
268- return {
271+ const serializeData = {
269272 type : this . getType ( ) ,
270273 attributes : this . getAttributes ( ) ,
271- color : this . getColor ( ) ,
272274 } ;
275+ if ( [
276+ this . self ( ) . TYPES . RECT ,
277+ this . self ( ) . TYPES . TEXT ,
278+ this . self ( ) . TYPES . NOTE ,
279+ ] . includes ( this . getType ( ) ) ) {
280+ serializeData . color = this . getColor ( ) ;
281+ }
282+ return serializeData ;
273283 }
274284 }
275285} ) ;
0 commit comments