Skip to content

Commit

Permalink
Don't use async import
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsuyui committed May 4, 2024
1 parent a51ffee commit 4d8e3a0
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions packages/treemap/src/treemap.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 @@ -113,26 +114,11 @@ 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.dividing(
const ia: Rect[] = dividing(
rect,
weights,
aspectRatio,
Expand All @@ -149,7 +135,6 @@ export const Treemap = (props: {
aspectRatio,
verticalFirst,
boustrophedon,
dividing,
])

const rectInfos = rectsToRectInfos(inAreas)
Expand Down

0 comments on commit 4d8e3a0

Please sign in to comment.