11import type { ColorDecoratorResult } from '../etoile/native/runtime'
22import { Box , Rect , Text , etoile } from '../etoile'
33import type { EventMethods } from './event'
4- import { bindParentForModule } from './struct'
4+ import { bindParentForModule , findRelativeNodeById } from './struct'
55import type { Module , NativeModule } from './struct'
66import { squarify } from './squarify'
77import type { LayoutModule } from './squarify'
@@ -22,6 +22,7 @@ export interface App {
2222 resize : ( ) => void
2323 // eslint-disable-next-line no-use-before-define
2424 use : ( using: Using , register : ( app : TreemapLayout ) => void ) => void
25+ zoom : ( id : string ) => void
2526}
2627
2728const defaultRegistries = [
@@ -212,14 +213,16 @@ export class TreemapLayout extends Schedule {
212213export function createTreemap ( ) {
213214 let treemap : TreemapLayout | null = null
214215 let root : Element | null = null
216+ let installed = false
215217 const uses : any [ ] = [ ]
216218
217219 const context = {
218220 init,
219221 dispose,
220222 setOptions,
221223 resize,
222- use
224+ use,
225+ zoom
223226 }
224227
225228 function init ( el : Element ) {
@@ -249,9 +252,14 @@ export function createTreemap() {
249252 throw new Error ( 'Treemap not initialized' )
250253 }
251254 treemap . data = bindParentForModule ( options . data || [ ] )
252- for ( const registry of defaultRegistries ) {
253- registry ( context , treemap , treemap . render )
255+
256+ if ( ! installed ) {
257+ for ( const registry of defaultRegistries ) {
258+ registry ( context , treemap , treemap . render )
259+ }
260+ installed = true
254261 }
262+
255263 for ( const use of uses ) {
256264 use ( treemap )
257265 }
@@ -266,6 +274,14 @@ export function createTreemap() {
266274 }
267275 }
268276
277+ function zoom ( id : string ) {
278+ if ( ! treemap ) {
279+ throw new Error ( "treemap don't init." )
280+ }
281+ const node = findRelativeNodeById ( id , treemap . layoutNodes )
282+ node && treemap . api . zoom ( node )
283+ }
284+
269285 return context as App & EventMethods
270286}
271287
0 commit comments