Skip to content

Commit

Permalink
Merge pull request #429 from kitsuyui/simplify-treemap-import
Browse files Browse the repository at this point in the history
Simplify treemap import
  • Loading branch information
kitsuyui authored May 21, 2024
2 parents e7c708a + a832b3d commit e0c8d8d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
20 changes: 2 additions & 18 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 @@ -100,7 +101,6 @@ const rectsToRectInfos = (rects: Rect[]): RectInfo[] => {

const DEFAULT_ASPECT_RATIO = 16 / 9


export const Treemap = (props: {
weightedItems: WeightedItem[]
verticalFirst?: boolean
Expand All @@ -113,26 +113,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 +134,6 @@ export const Treemap = (props: {
aspectRatio,
verticalFirst,
boustrophedon,
dividing,
])

const rectInfos = rectsToRectInfos(inAreas)
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"target": "esnext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
Expand Down

0 comments on commit e0c8d8d

Please sign in to comment.