11import { Component } from '../../core' ;
2- import type { Group } from '../../shapes' ;
2+ import { HTML , type Group } from '../../shapes' ;
33import { BBox , select , Selection , splitStyle , subStyleProps } from '../../util' ;
44import type { TitleStyleProps } from './title' ;
55import { getBBox , Title } from './title' ;
@@ -9,6 +9,12 @@ import type { CategoryOptions, CategoryStyleProps } from './types';
99
1010export type { CategoryOptions , CategoryStyleProps } ;
1111
12+ class HtmlLegend extends HTML {
13+ update ( options : any ) {
14+ this . attr ( options ) ;
15+ }
16+ }
17+
1218export class Category extends Component < CategoryStyleProps > {
1319 constructor ( options : CategoryOptions ) {
1420 super ( options , CATEGORY_DEFAULT_OPTIONS ) ;
@@ -35,6 +41,26 @@ export class Category extends Component<CategoryStyleProps> {
3541 . update ( finalTitleStyle ) as Selection < Title > ;
3642 }
3743
44+ private renderCustom ( container : Selection ) {
45+ const { data } = this . attributes ;
46+
47+ const style = {
48+ innerHTML : this . attributes . render ( data ) ,
49+ pointerEvents : 'auto' as const ,
50+ } ;
51+
52+ container
53+ . maybeAppendByClassName (
54+ CLASS_NAMES . html ,
55+ ( ) =>
56+ new HtmlLegend ( {
57+ className : CLASS_NAMES . html . name ,
58+ style,
59+ } )
60+ )
61+ . update ( style ) ;
62+ }
63+
3864 private renderItems ( container : Selection , bbox : DOMRect ) {
3965 const { x, y, width, height } = bbox ;
4066 const style = subStyleProps ( this . attributes , 'title' , true ) ;
@@ -84,7 +110,7 @@ export class Category extends Component<CategoryStyleProps> {
84110 }
85111
86112 render ( attributes : Required < CategoryStyleProps > , container : Group ) {
87- const { width, height, x = 0 , y = 0 , classNamePrefix } = this . attributes ;
113+ const { width, height, x = 0 , y = 0 , classNamePrefix, render } = this . attributes ;
88114 const ctn = select ( container ) ;
89115
90116 // Set root container className
@@ -97,10 +123,14 @@ export class Category extends Component<CategoryStyleProps> {
97123
98124 container . style . transform = `translate(${ x } , ${ y } )` ;
99125
100- this . renderTitle ( ctn , width ! , height ! ) ;
126+ if ( render as CategoryStyleProps [ 'render' ] ) {
127+ this . renderCustom ( ctn ) ;
128+ } else {
129+ this . renderTitle ( ctn , width ! , height ! ) ;
101130
102- this . renderItems ( ctn , this . availableSpace ) ;
131+ this . renderItems ( ctn , this . availableSpace ) ;
103132
104- this . adjustLayout ( ) ;
133+ this . adjustLayout ( ) ;
134+ }
105135 }
106136}
0 commit comments