Skip to content

Commit

Permalink
chore: release v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz committed Nov 7, 2024
1 parent fb298ea commit 39d7035
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.1.1

- Fix error `zooming` logic.
- Expose more friednly tool.

# 0.1.0

First version.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
22 changes: 20 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
24 changes: 20 additions & 4 deletions src/primitives/component.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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 = [
Expand Down Expand Up @@ -212,14 +213,16 @@ 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 = {
init,
dispose,
setOptions,
resize,
use
use,
zoom
}

function init(el: Element) {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}

Expand Down
3 changes: 0 additions & 3 deletions src/primitives/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 39d7035

Please sign in to comment.