(
symbolType: string,
x: number,
y: number,
w: number,
h: number,
color?: ZRColor,
// whether to keep the ratio of w/h,
keepAspect?: boolean
)
| 331 | * Create a symbol element with given symbol configuration: shape, x, y, width, height, color |
| 332 | */ |
| 333 | export function createSymbol( |
| 334 | symbolType: string, |
| 335 | x: number, |
| 336 | y: number, |
| 337 | w: number, |
| 338 | h: number, |
| 339 | color?: ZRColor, |
| 340 | // whether to keep the ratio of w/h, |
| 341 | keepAspect?: boolean |
| 342 | ) { |
| 343 | // TODO Support image object, DynamicImage. |
| 344 | |
| 345 | const isEmpty = symbolType.indexOf('empty') === 0; |
| 346 | if (isEmpty) { |
| 347 | symbolType = symbolType.substr(5, 1).toLowerCase() + symbolType.substr(6); |
| 348 | } |
| 349 | let symbolPath: ECSymbol | graphic.Image; |
| 350 | |
| 351 | if (symbolType.indexOf('image://') === 0) { |
| 352 | symbolPath = graphic.makeImage( |
| 353 | symbolType.slice(8), |
| 354 | new BoundingRect(x, y, w, h), |
| 355 | keepAspect ? 'center' : 'cover' |
| 356 | ); |
| 357 | } |
| 358 | else if (symbolType.indexOf('path://') === 0) { |
| 359 | symbolPath = graphic.makePath( |
| 360 | symbolType.slice(7), |
| 361 | {}, |
| 362 | new BoundingRect(x, y, w, h), |
| 363 | keepAspect ? 'center' : 'cover' |
| 364 | ) as unknown as ECSymbol; |
| 365 | } |
| 366 | else { |
| 367 | symbolPath = new SymbolClz({ |
| 368 | shape: { |
| 369 | symbolType: symbolType, |
| 370 | x: x, |
| 371 | y: y, |
| 372 | width: w, |
| 373 | height: h |
| 374 | } |
| 375 | }) as unknown as ECSymbol; |
| 376 | } |
| 377 | |
| 378 | (symbolPath as ECSymbol).__isEmptyBrush = isEmpty; |
| 379 | |
| 380 | // TODO Should deprecate setColor |
| 381 | (symbolPath as ECSymbol).setColor = symbolPathSetColor; |
| 382 | |
| 383 | if (color) { |
| 384 | (symbolPath as ECSymbol).setColor(color); |
| 385 | } |
| 386 | |
| 387 | return symbolPath as ECSymbol; |
| 388 | } |
| 389 | |
| 390 | export function normalizeSymbolSize(symbolSize: number | number[]): [number, number] { |
no outgoing calls
no test coverage detected
searching dependent graphs…