Skip to content

Commit 39d7035

Browse files
committed
chore: release v0.1.1
1 parent fb298ea commit 39d7035

File tree

5 files changed

+46
-10
lines changed

5 files changed

+46
-10
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 0.1.1
2+
3+
- Fix error `zooming` logic.
4+
- Expose more friednly tool.
5+
16
# 0.1.0
27

38
First version.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "squarified",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "squarified tree map",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",

src/index.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
export { createTreemap } from './primitives/component'
2-
export type { App, TreemapInstanceAPI } from './primitives/component'
2+
export type { App, TreemapInstanceAPI, TreemapOptions } from './primitives/component'
3+
export { TreemapLayout } from './primitives/component'
34
export * from './primitives/decorator'
4-
export { c2m, flatten as flattenModule, sortChildrenByKey } from './primitives/struct'
5+
export type {
6+
EventMethods,
7+
PrimitiveEvent,
8+
PrimitiveEventCallback,
9+
PrimitiveEventDefinition,
10+
PrimitiveEventMetadata
11+
} from './primitives/event'
12+
export type { LayoutModule } from './primitives/squarify'
13+
export {
14+
c2m,
15+
findRelativeNode,
16+
findRelativeNodeById,
17+
flatten as flattenModule,
18+
getNodeDepth,
19+
sortChildrenByKey,
20+
visit
21+
} from './primitives/struct'
22+
export type { Module, NativeModule } from './primitives/struct'

src/primitives/component.ts

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ColorDecoratorResult } from '../etoile/native/runtime'
22
import { Box, Rect, Text, etoile } from '../etoile'
33
import type { EventMethods } from './event'
4-
import { bindParentForModule } from './struct'
4+
import { bindParentForModule, findRelativeNodeById } from './struct'
55
import type { Module, NativeModule } from './struct'
66
import { squarify } from './squarify'
77
import 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

2728
const defaultRegistries = [
@@ -212,14 +213,16 @@ export class TreemapLayout extends Schedule {
212213
export 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

src/primitives/event.ts

-3
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,6 @@ function onZoom(ctx: SelfEventContenxt, node: LayoutModule, root: LayoutModule |
418418
const startTime = Date.now()
419419
const animationDuration = 300
420420
const draw = () => {
421-
if (self.forceDestroy) {
422-
return
423-
}
424421
const elapsed = Date.now() - startTime
425422
const progress = Math.min(elapsed / animationDuration, 1)
426423
const easedProgress = easing.cubicInOut(progress)

0 commit comments

Comments
 (0)