Skip to content

Commit a5ec4b0

Browse files
committed
chore: release v0.17.1
1 parent d5ea783 commit a5ec4b0

File tree

6 files changed

+345
-249
lines changed

6 files changed

+345
-249
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 0.17.1
2+
3+
- Fixed warning not showing as expected. #58
4+
- Non-js files no need to record child nodes.
5+
6+
### credits
7+
8+
@urbnjamesmi1
9+
110
## 0.17.0
211

312
- `Cli` add default config path (`vite.config.ts`)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-bundle-analyzer",
3-
"version": "0.17.0",
3+
"version": "0.17.1",
44
"description": "a modern vite bundle analyzer tool",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",

src/client/components/treemap/component.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { inline } from '@stylex-extend/core'
22
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef } from 'react'
33
import type { Ref } from 'react'
4-
import { c2m, createTreemap, presetDecorator, sortChildrenByKey } from 'squarified'
4+
import { c2m, createTreemap, sortChildrenByKey } from 'squarified'
55
import type { ExposedEventCallback } from 'squarified'
66
import { useQueryParams, useResize } from '../../composables'
77
import { useApplicationContext, useToggleSize } from '../../context'
88
import { createMagicEvent } from '../../special'
99
import type { QueryKind } from '../../special'
10+
import { presetDecorator } from './preset'
1011

1112
export type TreemapComponentInstance = ReturnType<typeof createTreemap>
1213

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import type { ColorMappings, NativeModule, TreemapLayout } from 'squarified'
2+
import { hashCode } from '../../shared'
3+
4+
export function presetDecorator(app: TreemapLayout) {
5+
Object.assign(app.decorator, {
6+
layout: {
7+
titleAreaHeight: {
8+
max: 60,
9+
min: 30
10+
},
11+
rectGap: 5
12+
},
13+
font: {
14+
color: '#000',
15+
fontSize: {
16+
max: 70,
17+
min: 0
18+
},
19+
fontFamily: 'sans-serif'
20+
},
21+
color: { mappings: evaluateColorMappings(app.data) }
22+
})
23+
}
24+
25+
function evaluateColorMappings(data: NativeModule[]): ColorMappings {
26+
const colorMappings: ColorMappings = {}
27+
28+
const hashToHue = (id: string): number => {
29+
const hash = Math.abs(hashCode(id))
30+
return hash % 360
31+
}
32+
33+
const lightScale = (depth: number) => 70 - depth * 5
34+
const baseSaturation = 40
35+
const siblingHueShift = 20
36+
37+
const rc = 0.2126
38+
const gc = 0.7152
39+
const bc = 0.0722
40+
41+
const hslToRgb = (h: number, s: number, l: number): { r: number, g: number, b: number } => {
42+
const a = s * Math.min(l, 1 - l)
43+
const f = (n: number) => {
44+
const k = (n + h / 30) % 12
45+
return l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1)
46+
}
47+
return { r: f(0), g: f(8), b: f(4) }
48+
}
49+
50+
const calculateLuminance = (r: number, g: number, b: number): number => {
51+
return rc * r + gc * g + bc * b
52+
}
53+
54+
const calculateColor = (
55+
module: NativeModule,
56+
depth: number,
57+
parentHue: number | null,
58+
siblingIndex: number,
59+
totalSiblings: number
60+
) => {
61+
const nodeHue = hashToHue(module.id)
62+
const hue = parentHue !== null
63+
? (parentHue + siblingHueShift * siblingIndex / totalSiblings) % 360
64+
: nodeHue
65+
const lightness = lightScale(depth)
66+
67+
const hslColor = {
68+
h: hue,
69+
s: baseSaturation,
70+
l: lightness / 100
71+
}
72+
const { r, g, b } = hslToRgb(hslColor.h, hslColor.s / 100, hslColor.l)
73+
const luminance = calculateLuminance(r, g, b)
74+
75+
if (luminance < 0.6) {
76+
hslColor.l += 0.2
77+
} else if (luminance > 0.8) {
78+
hslColor.l -= 0.1
79+
}
80+
81+
hslColor.l *= 100
82+
83+
colorMappings[module.id] = {
84+
mode: 'hsl',
85+
desc: hslColor
86+
}
87+
88+
if (module.groups && Array.isArray(module.groups)) {
89+
const totalChildren = module.groups.length
90+
for (let i = 0; i < totalChildren; i++) {
91+
const child = module.groups[i]
92+
calculateColor(child, depth + 1, hue, i, totalChildren)
93+
}
94+
}
95+
}
96+
97+
for (let i = 0; i < data.length; i++) {
98+
const module = data[i]
99+
calculateColor(module, 0, null, i, data.length)
100+
}
101+
102+
return colorMappings
103+
}

0 commit comments

Comments
 (0)