Skip to content

Commit

Permalink
Revert "Don't use async import"
Browse files Browse the repository at this point in the history
This reverts commit 4d8e3a0.
  • Loading branch information
kitsuyui committed May 4, 2024
1 parent fa1e5c1 commit 24e4d6d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/treemap/src/treemap.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useState } from 'react'
import { useMeasure } from 'react-use'
import { dividing } from '@kitsuyui/rectangle-dividing'

interface Rect {
x: number
Expand Down Expand Up @@ -114,11 +113,26 @@ export const Treemap = (props: {
const aspectRatio = props.aspectRatio ?? DEFAULT_ASPECT_RATIO
const boustrophedon = props.boustrophedon ?? false
const [inAreas, setInAreas] = useState<Rect[]>([])
const [dividing, setDividing] = useState<
typeof import('@kitsuyui/rectangle-dividing') | null
>(null)

useEffect(() => {
; (async () => {
if (dividing) return
const d = await import('@kitsuyui/rectangle-dividing')
setDividing(d)
})()
})

useEffect(() => {
if (!dividing) {
setInAreas([])
return
}
const rect: Rect = { x: 0, y: 0, w: width, h: height }
const weights = new Float32Array(weightedItems.map(({ weight }) => weight))
const ia: Rect[] = dividing(
const ia: Rect[] = dividing.dividing(
rect,
weights,
aspectRatio,
Expand All @@ -135,6 +149,7 @@ export const Treemap = (props: {
aspectRatio,
verticalFirst,
boustrophedon,
dividing,
])

const rectInfos = rectsToRectInfos(inAreas)
Expand Down

0 comments on commit 24e4d6d

Please sign in to comment.