(elOption: CustomElementOption)
| 331 | |
| 332 | |
| 333 | function createEl(elOption: CustomElementOption): Element { |
| 334 | const graphicType = elOption.type; |
| 335 | let el; |
| 336 | |
| 337 | // Those graphic elements are not shapes. They should not be |
| 338 | // overwritten by users, so do them first. |
| 339 | if (graphicType === 'path') { |
| 340 | const shape = (elOption as CustomSVGPathOption).shape; |
| 341 | // Using pathRect brings convenience to users sacle svg path. |
| 342 | const pathRect = (shape.width != null && shape.height != null) |
| 343 | ? { |
| 344 | x: shape.x || 0, |
| 345 | y: shape.y || 0, |
| 346 | width: shape.width, |
| 347 | height: shape.height |
| 348 | } as RectLike |
| 349 | : null; |
| 350 | const pathData = getPathData(shape); |
| 351 | // Path is also used for icon, so layout 'center' by default. |
| 352 | el = graphicUtil.makePath(pathData, null, pathRect, shape.layout || 'center'); |
| 353 | customInnerStore(el).customPathData = pathData; |
| 354 | } |
| 355 | else if (graphicType === 'image') { |
| 356 | el = new graphicUtil.Image({}); |
| 357 | customInnerStore(el).customImagePath = (elOption as CustomImageOption).style.image; |
| 358 | } |
| 359 | else if (graphicType === 'text') { |
| 360 | el = new graphicUtil.Text({}); |
| 361 | // customInnerStore(el).customText = (elOption.style as TextStyleProps).text; |
| 362 | } |
| 363 | else if (graphicType === 'group') { |
| 364 | el = new graphicUtil.Group(); |
| 365 | } |
| 366 | else if (graphicType === 'compoundPath') { |
| 367 | const shape = (elOption as CustomCompoundPathOption).shape; |
| 368 | if (!shape || !shape.paths) { |
| 369 | let errMsg = ''; |
| 370 | if (__DEV__) { |
| 371 | errMsg = 'shape.paths must be specified in compoundPath'; |
| 372 | } |
| 373 | throwError(errMsg); |
| 374 | } |
| 375 | const paths = map(shape.paths as Path[], function (path) { |
| 376 | if (path.type === 'path') { |
| 377 | return graphicUtil.makePath(path.shape.pathData, path, null); |
| 378 | } |
| 379 | const Clz = graphicUtil.getShapeClass(path.type); |
| 380 | if (!Clz) { |
| 381 | let errMsg = ''; |
| 382 | if (__DEV__) { |
| 383 | errMsg = 'graphic type "' + graphicType + '" can not be found.'; |
| 384 | } |
| 385 | throwError(errMsg); |
| 386 | } |
| 387 | return new Clz(); |
| 388 | }); |
| 389 | el = new graphicUtil.CompoundPath({ |
| 390 | shape: { |
no test coverage detected
searching dependent graphs…