@@ -11,21 +11,28 @@ import {
1111 getAttributes ,
1212 getOrCreateDefs ,
1313 removeAttributes ,
14+ setAttributes ,
1415 uuid ,
1516} from '../../utils' ;
1617import { ElementTypeEnum } from '../constants' ;
1718
19+ type IllusRenderAttributes = IllusAttributes & Record < string , any > ;
20+
1821export function renderIllus (
1922 svg : SVGSVGElement ,
2023 node : SVGElement ,
2124 value : string | ResourceConfig | undefined ,
2225 datum ?: ItemDatum ,
26+ attrs : Record < string , any > = { } ,
2327) : IllusElement | null {
2428 if ( ! value ) return null ;
2529 const config = parseResourceConfig ( value ) ;
2630 if ( ! config ) return null ;
2731
2832 const id = getResourceId ( config ) ! ;
33+ if ( attrs && Object . keys ( attrs ) . length > 0 ) {
34+ setAttributes ( node , attrs ) ;
35+ }
2936 const clipPathId = createClipPath ( svg , node , id ) ;
3037
3138 loadResource ( svg , 'illus' , config , datum ) ;
@@ -35,8 +42,9 @@ export function renderIllus(
3542 id ,
3643 {
3744 ...parseIllusBounds ( node ) ,
38- 'clip-path' : `url(#${ clipPathId } )` ,
3945 ...( color ? { color } : { } ) ,
46+ ...attrs ,
47+ 'clip-path' : `url(#${ clipPathId } )` ,
4048 } ,
4149 data ,
4250 ) ;
@@ -48,7 +56,8 @@ export function renderItemIllus(
4856 datum : ItemDatum ,
4957) {
5058 const value = datum . illus ;
51- return renderIllus ( svg , node , value , datum ) ;
59+ const attrs = datum . attributes ?. illus as Record < string , any > | undefined ;
60+ return renderIllus ( svg , node , value , datum , attrs ) ;
5261}
5362
5463function createClipPath (
@@ -79,7 +88,11 @@ function createClipPath(
7988 return clipPathId ;
8089}
8190
82- function createIllusElement ( id : string , attrs : IllusAttributes , value : string ) {
91+ function createIllusElement (
92+ id : string ,
93+ attrs : IllusRenderAttributes ,
94+ value : string ,
95+ ) {
8396 const { 'clip-path' : clipPath , ...restAttrs } = attrs ;
8497
8598 const { x = '0' , y = '0' , width = '0' , height = '0' } = restAttrs ;
0 commit comments