diff --git a/CHANGELOG.md b/CHANGELOG.md index d9bb616..0f41725 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 0.1.1 + +- Fix error `zooming` logic. +- Expose more friednly tool. + # 0.1.0 First version. diff --git a/package.json b/package.json index ea85933..814da16 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "squarified", - "version": "0.1.0", + "version": "0.1.1", "description": "squarified tree map", "main": "dist/index.js", "module": "dist/index.mjs", diff --git a/src/index.ts b/src/index.ts index aca0d31..48f9e21 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,22 @@ export { createTreemap } from './primitives/component' -export type { App, TreemapInstanceAPI } from './primitives/component' +export type { App, TreemapInstanceAPI, TreemapOptions } from './primitives/component' +export { TreemapLayout } from './primitives/component' export * from './primitives/decorator' -export { c2m, flatten as flattenModule, sortChildrenByKey } from './primitives/struct' +export type { + EventMethods, + PrimitiveEvent, + PrimitiveEventCallback, + PrimitiveEventDefinition, + PrimitiveEventMetadata +} from './primitives/event' +export type { LayoutModule } from './primitives/squarify' +export { + c2m, + findRelativeNode, + findRelativeNodeById, + flatten as flattenModule, + getNodeDepth, + sortChildrenByKey, + visit +} from './primitives/struct' +export type { Module, NativeModule } from './primitives/struct' diff --git a/src/primitives/component.ts b/src/primitives/component.ts index e76875d..1801972 100644 --- a/src/primitives/component.ts +++ b/src/primitives/component.ts @@ -1,7 +1,7 @@ import type { ColorDecoratorResult } from '../etoile/native/runtime' import { Box, Rect, Text, etoile } from '../etoile' import type { EventMethods } from './event' -import { bindParentForModule } from './struct' +import { bindParentForModule, findRelativeNodeById } from './struct' import type { Module, NativeModule } from './struct' import { squarify } from './squarify' import type { LayoutModule } from './squarify' @@ -22,6 +22,7 @@ export interface App { resize: () => void // eslint-disable-next-line no-use-before-define use: (using: Using, register: (app: TreemapLayout) => void) => void + zoom: (id: string) => void } const defaultRegistries = [ @@ -212,6 +213,7 @@ export class TreemapLayout extends Schedule { export function createTreemap() { let treemap: TreemapLayout | null = null let root: Element | null = null + let installed = false const uses: any[] = [] const context = { @@ -219,7 +221,8 @@ export function createTreemap() { dispose, setOptions, resize, - use + use, + zoom } function init(el: Element) { @@ -249,9 +252,14 @@ export function createTreemap() { throw new Error('Treemap not initialized') } treemap.data = bindParentForModule(options.data || []) - for (const registry of defaultRegistries) { - registry(context, treemap, treemap.render) + + if (!installed) { + for (const registry of defaultRegistries) { + registry(context, treemap, treemap.render) + } + installed = true } + for (const use of uses) { use(treemap) } @@ -266,6 +274,14 @@ export function createTreemap() { } } + function zoom(id: string) { + if (!treemap) { + throw new Error("treemap don't init.") + } + const node = findRelativeNodeById(id, treemap.layoutNodes) + node && treemap.api.zoom(node) + } + return context as App & EventMethods } diff --git a/src/primitives/event.ts b/src/primitives/event.ts index cd3421c..ec8842f 100644 --- a/src/primitives/event.ts +++ b/src/primitives/event.ts @@ -418,9 +418,6 @@ function onZoom(ctx: SelfEventContenxt, node: LayoutModule, root: LayoutModule | const startTime = Date.now() const animationDuration = 300 const draw = () => { - if (self.forceDestroy) { - return - } const elapsed = Date.now() - startTime const progress = Math.min(elapsed / animationDuration, 1) const easedProgress = easing.cubicInOut(progress)