Skip to content

Commit 80cd889

Browse files
committed
feat(wind-layer): refactor lineWidth to support min-max range
BREAKING CHANGE: lineWidth option now requires min-max range object instead of single number - Change lineWidth type from number to { min: number, max: number } - Set default lineWidth range to { min: 1, max: 2 } - Update shader to support dynamic line width based on particle speed - Update types and documentation - Update example to demonstrate new lineWidth configuration - Add lineWidth range control in ControlPanel component This change allows for more dynamic and visually appealing particle trails by varying the line width based on wind speed, similar to how line length works.
1 parent 24a56b8 commit 80cd889

File tree

13 files changed

+235
-107
lines changed

13 files changed

+235
-107
lines changed

example/CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
# example
22

3+
## 0.7.0
4+
5+
### Minor Changes
6+
7+
- feat(wind-layer): refactor lineWidth to support min-max range
8+
9+
BREAKING CHANGE: lineWidth option now requires min-max range object instead of single number
10+
11+
- Change lineWidth type from number to { min: number, max: number }
12+
- Set default lineWidth range to { min: 1, max: 2 }
13+
- Update shader to support dynamic line width based on particle speed
14+
- Update types and documentation
15+
- Update example to demonstrate new lineWidth configuration
16+
- Add lineWidth range control in ControlPanel component
17+
18+
This change allows for more dynamic and visually appealing particle trails by varying
19+
the line width based on wind speed, similar to how line length works.
20+
21+
### Patch Changes
22+
23+
- Updated dependencies
24+
25+
326
## 0.6.0
427

528
### Minor Changes

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "example",
33
"private": true,
4-
"version": "0.6.0",
4+
"version": "0.7.0",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

example/src/components/ColorTableInput.tsx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ import {
1515
interpolateOranges,
1616
interpolateReds,
1717
interpolatePurples,
18+
interpolateBuGn,
19+
interpolateBuPu,
20+
interpolateCividis,
21+
interpolateCubehelixDefault,
22+
interpolateGnBu,
23+
interpolateGreys,
24+
interpolateOrRd,
25+
interpolatePuBu,
26+
interpolatePuBuGn,
27+
interpolatePuRd,
28+
interpolateRdPu,
29+
interpolateSinebow,
30+
interpolateTurbo,
31+
interpolateYlGn,
32+
interpolateYlGnBu,
33+
interpolateYlOrBr,
34+
interpolateYlOrRd,
1835
} from 'd3-scale-chromatic';
1936
import styled from 'styled-components';
2037

@@ -114,23 +131,40 @@ const generateSingleColorTable = (color: string): string[] => {
114131

115132
export const colorSchemes = [
116133
{ label: 'Single Color', value: 'single', interpolator: () => '#FFFFFF', isSingleColor: true },
117-
{ label: 'Rainbow', value: 'rainbow', interpolator: interpolateRainbow, reverse: true },
134+
{ label: 'Rainbow', value: 'rainbow', interpolator: interpolateRainbow },
135+
{ label: 'Turbo', value: 'turbo', interpolator: interpolateTurbo },
118136
{ label: 'Viridis', value: 'viridis', interpolator: interpolateViridis },
119137
{ label: 'Cool', value: 'cool', interpolator: interpolateCool },
120138
{ label: 'Warm', value: 'warm', interpolator: interpolateWarm },
121139
{ label: 'Inferno', value: 'inferno', interpolator: interpolateInferno },
122140
{ label: 'Magma', value: 'magma', interpolator: interpolateMagma },
123141
{ label: 'Plasma', value: 'plasma', interpolator: interpolatePlasma },
142+
{ label: 'Cividis', value: 'cividis', interpolator: interpolateCividis },
143+
{ label: 'Cubehelix', value: 'cubehelix', interpolator: interpolateCubehelixDefault },
144+
{ label: 'Sinebow', value: 'sinebow', interpolator: interpolateSinebow },
124145
{ label: 'Blues', value: 'blues', interpolator: interpolateBlues },
125146
{ label: 'Greens', value: 'greens', interpolator: interpolateGreens },
147+
{ label: 'Greys', value: 'greys', interpolator: interpolateGreys },
126148
{ label: 'Oranges', value: 'oranges', interpolator: interpolateOranges },
127-
{ label: 'Reds', value: 'reds', interpolator: interpolateReds },
128149
{ label: 'Purples', value: 'purples', interpolator: interpolatePurples },
150+
{ label: 'Reds', value: 'reds', interpolator: interpolateReds },
151+
{ label: 'BuGn', value: 'bugn', interpolator: interpolateBuGn },
152+
{ label: 'BuPu', value: 'bupu', interpolator: interpolateBuPu },
153+
{ label: 'GnBu', value: 'gnbu', interpolator: interpolateGnBu },
154+
{ label: 'OrRd', value: 'orrd', interpolator: interpolateOrRd },
155+
{ label: 'PuBuGn', value: 'pubugn', interpolator: interpolatePuBuGn },
156+
{ label: 'PuBu', value: 'pubu', interpolator: interpolatePuBu },
157+
{ label: 'PuRd', value: 'purd', interpolator: interpolatePuRd },
158+
{ label: 'RdPu', value: 'rdpu', interpolator: interpolateRdPu },
159+
{ label: 'YlGnBu', value: 'ylgnbu', interpolator: interpolateYlGnBu },
160+
{ label: 'YlGn', value: 'ylgn', interpolator: interpolateYlGn },
161+
{ label: 'YlOrBr', value: 'ylorbr', interpolator: interpolateYlOrBr },
162+
{ label: 'YlOrRd', value: 'ylorrd', interpolator: interpolateYlOrRd }
129163
].map((item) => ({
130164
...item,
131165
colors: item.isSingleColor
132166
? generateSingleColorTable(item.interpolator())
133-
: generateColorTable(item.interpolator, item.reverse),
167+
: generateColorTable(item.interpolator),
134168
}));
135169

136170
const ColorTableInput: React.FC<ColorTableInputProps> = ({

example/src/components/ControlPanel.tsx

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,53 @@ export const ControlPanel: React.FC<ControlPanelProps> = ({
316316
</CompactFormItem>
317317

318318
<CompactFormItem
319-
name="lineWidth"
320319
label={renderLabel(
321-
'Line Width',
322-
'Width of particle trails in pixels. Controls the width of the particles.'
320+
'Line Width Range',
321+
'Width range of particle trails in pixels. Lower values for thinner lines, higher values for thicker ones.'
323322
)}
324323
>
325-
<NumberInput min={0.1} max={100} step={0.1} precision={1} />
324+
<Space direction="vertical" style={{ width: '100%' }} size={8}>
325+
<div style={{ display: 'flex', gap: '8px' }}>
326+
<div style={{ flex: 1 }}>
327+
<CompactFormItem
328+
name={['lineWidth', 'min']}
329+
label={
330+
<Text type="secondary" style={{ fontSize: '12px' }}>
331+
Min Width
332+
</Text>
333+
}
334+
style={{ marginBottom: 0 }}
335+
>
336+
<InputNumber
337+
min={0.1}
338+
max={10}
339+
step={0.1}
340+
precision={1}
341+
placeholder='Min Width'
342+
/>
343+
</CompactFormItem>
344+
</div>
345+
<div style={{ flex: 1 }}>
346+
<CompactFormItem
347+
name={['lineWidth', 'max']}
348+
label={
349+
<Text type="secondary" style={{ fontSize: '12px' }}>
350+
Max Width
351+
</Text>
352+
}
353+
style={{ marginBottom: 0 }}
354+
>
355+
<InputNumber
356+
min={0.1}
357+
max={10}
358+
step={0.1}
359+
precision={1}
360+
placeholder='Max Width'
361+
/>
362+
</CompactFormItem>
363+
</div>
364+
</div>
365+
</Space>
326366
</CompactFormItem>
327367

328368
<CompactFormItem

example/src/pages/earth.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ const dataConfigs = {
4747
max: 8,
4848
},
4949
speedFactor: 0.8,
50-
lineWidth: 5.0,
51-
lineLength: { min: 20, max: 100 },
50+
lineWidth: { min: 1, max: 2 },
51+
lineLength: { min: 50, max: 100 },
52+
particleHeight: 100,
5253
},
5354
file: '/wind.json'
5455
},
@@ -59,25 +60,21 @@ const dataConfigs = {
5960
max: 1,
6061
},
6162
speedFactor: 8,
62-
lineWidth: 10.0,
63+
lineWidth: { min: 1, max: 4 },
6364
lineLength: { min: 20, max: 50 },
65+
particleHeight: 10,
6466
},
6567
file: '/ocean.json'
6668
}
6769
};
6870

6971
const defaultOptions: Partial<WindLayerOptions> = {
72+
...WindLayer.defaultOptions,
7073
particlesTextureSize: 200,
71-
dropRate: 0.003,
72-
particleHeight: 1000,
73-
dropRateBump: 0.01,
74-
lineWidth: 5.0,
75-
lineLength: { min: 20, max: 100 },
76-
colors: colorSchemes[3].colors.reverse(),
74+
colors: colorSchemes.find(item => item.value === 'cool')?.colors.reverse(),
7775
flipY: true,
7876
useViewerBounds: true,
7977
dynamic: true,
80-
// Remove domain and speedFactor from here since they will be set dynamically
8178
};
8279

8380
export function Earth() {
@@ -124,7 +121,7 @@ export function Earth() {
124121

125122
viewerRef.current.scene.globe.depthTestAgainstTerrain = true;
126123
// Optional: Add exaggeration to make terrain features more visible
127-
viewerRef.current.scene.verticalExaggeration = 2;
124+
// viewerRef.current.scene.verticalExaggeration = 2;
128125
// viewerRef.current.sceneModePicker.viewModel.duration = 0;
129126

130127
const initWindLayer = async () => {

packages/cesium-wind-layer/CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# cesium-wind-layer
22

3+
## 0.10.0
4+
5+
### Minor Changes
6+
7+
- feat(wind-layer): refactor lineWidth to support min-max range
8+
9+
BREAKING CHANGE: lineWidth option now requires min-max range object instead of single number
10+
11+
- Change lineWidth type from number to { min: number, max: number }
12+
- Set default lineWidth range to { min: 1, max: 2 }
13+
- Update shader to support dynamic line width based on particle speed
14+
- Update types and documentation
15+
- Update example to demonstrate new lineWidth configuration
16+
- Add lineWidth range control in ControlPanel component
17+
18+
This change allows for more dynamic and visually appealing particle trails by varying
19+
the line width based on wind speed, similar to how line length works.
20+
321
## 0.9.0
422

523
### Minor Changes

packages/cesium-wind-layer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cesium-wind-layer",
3-
"version": "0.9.0",
3+
"version": "0.10.0",
44
"publishConfig": {
55
"access": "public"
66
},

packages/cesium-wind-layer/readme.md

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,18 @@ const windData = {
6767

6868
// Create wind layer with options
6969
const windLayer = new WindLayer(viewer, windData, {
70-
particlesTextureSize: 100, // Size of the particle texture. Determines the maximum number of particles (size squared).
71-
particleHeight: 1000, // Height of particles above ground
72-
lineWidth: 10.0, // Width of particle trails
73-
speedFactor: 1.0, // Speed multiplier
74-
dropRate: 0.003, // Rate at which particles are dropped
75-
dropRateBump: 0.001, // Additional drop rate for slow particles
76-
colors: ['white'], // Colors for particles
77-
flipY: false, // Flip Y coordinates if needed
78-
domain: undefined, // Optional: domain for speed
79-
displayRange: undefined, // Optional: display range for speed
80-
dynamic: true, // Whether to enable dynamic particle animation
70+
particlesTextureSize: 100, // Size of the particle texture. Determines the maximum number of particles (size squared).
71+
particleHeight: 1000, // Height of particles above ground
72+
lineWidth: { min: 1, max: 2 }, // Width of particle trails
73+
lineLength: { min: 20, max: 100 }, // Length range of particle trails
74+
speedFactor: 1.0, // Speed multiplier
75+
dropRate: 0.003, // Rate at which particles are dropped
76+
dropRateBump: 0.001, // Additional drop rate for slow particles
77+
colors: ['white'], // Colors for particles
78+
flipY: false, // Flip Y coordinates if needed
79+
domain: undefined, // Optional: domain for speed
80+
displayRange: undefined, // Optional: display range for speed
81+
dynamic: true, // Whether to enable dynamic particle animation
8182
});
8283
```
8384

@@ -91,25 +92,25 @@ Main class for wind visualization.
9192

9293
```typescript
9394
interface WindLayerOptions {
94-
particlesTextureSize: number; // Size of the particle texture. Determines the maximum number of particles (size squared). Default is 100.
95-
particleHeight: number; // Height of particles above the ground in meters. Default is 0.
96-
lineWidth: number; // Width of particle trails in pixels. Default is 5.0.
97-
lineLength: { min: number; max: number }; // Length range of particle trails. Default is { min: 20, max: 100 }.
98-
speedFactor: number; // Factor to adjust the speed of particles. Default is 1.0.
99-
dropRate: number; // Rate at which particles are dropped (reset). Default is 0.003.
100-
dropRateBump: number; // Additional drop rate for slow-moving particles. Default is 0.001.
101-
colors: string[]; // Array of colors for particles. Can be used to create color gradients. Default is ['white'].
102-
flipY: boolean; // Whether to flip the Y-axis of the wind data. Default is false.
103-
useViewerBounds: boolean; // Whether to use the viewer bounds to generate particles. Default is false.
104-
domain?: { // Controls the speed rendering range. Default is undefined.
105-
min?: number; // Minimum speed value for rendering
106-
max?: number; // Maximum speed value for rendering
95+
particlesTextureSize: number; // Size of the particle texture. Determines the maximum number of particles (size squared). Default is 100.
96+
particleHeight: number; // Height of particles above the ground in meters. Default is 0.
97+
lineWidth: { min: number; max: number }; // Width range of particle trails in pixels. Default is { min: 1, max: 2 }.
98+
lineLength: { min: number; max: number }; // Length range of particle trails. Default is { min: 20, max: 100 }.
99+
speedFactor: number; // Factor to adjust the speed of particles. Default is 1.0.
100+
dropRate: number; // Rate at which particles are dropped (reset). Default is 0.003.
101+
dropRateBump: number; // Additional drop rate for slow-moving particles. Default is 0.001.
102+
colors: string[]; // Array of colors for particles. Can be used to create color gradients. Default is ['white'].
103+
flipY: boolean; // Whether to flip the Y-axis of the wind data. Default is false.
104+
useViewerBounds: boolean; // Whether to use the viewer bounds to generate particles. Default is false.
105+
domain?: { // Controls the speed rendering range. Default is undefined.
106+
min?: number; // Minimum speed value for rendering
107+
max?: number; // Maximum speed value for rendering
107108
};
108-
displayRange?: { // Controls the speed display range for visualization. Default is undefined.
109-
min?: number; // Minimum speed value for display
110-
max?: number; // Maximum speed value for display
109+
displayRange?: { // Controls the speed display range for visualization. Default is undefined.
110+
min?: number; // Minimum speed value for display
111+
max?: number; // Maximum speed value for display
111112
};
112-
dynamic: boolean; // Whether to enable dynamic particle animation. Default is true.
113+
dynamic: boolean; // Whether to enable dynamic particle animation. Default is true.
113114
}
114115
```
115116

packages/cesium-wind-layer/readme.zh-CN.md

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,18 @@ const windData = {
6767

6868
// 使用配置创建风场图层
6969
const windLayer = new WindLayer(viewer, windData, {
70-
particlesTextureSize: 100, // 粒子系统的纹理大小
71-
particleHeight: 1000, // 粒子距地面高度
72-
lineWidth: 10.0, // 粒子轨迹宽度
73-
speedFactor: 1.0, // 速度倍数
74-
dropRate: 0.003, // 粒子消失率
75-
dropRateBump: 0.001, // 慢速粒子的额外消失率
76-
colors: ['white'], // 粒子颜色
77-
flipY: false, // 是否翻转 Y 坐标
78-
domain: undefined, // 速度渲染范围
79-
displayRange: undefined, // 速度显示范围
80-
dynamic: true // 是否启用动态粒子动画
70+
particlesTextureSize: 100, // 粒子系统的纹理大小
71+
particleHeight: 1000, // 粒子距地面高度
72+
lineWidth: { min: 1, max: 2 }, // 粒子轨迹宽度范围
73+
lineLength: { min: 20, max: 100 }, // 粒子轨迹长度范围
74+
speedFactor: 1.0, // 速度倍数
75+
dropRate: 0.003, // 粒子消失率
76+
dropRateBump: 0.001, // 慢速粒子的额外消失率
77+
colors: ['white'], // 粒子颜色
78+
flipY: false, // 是否翻转 Y 坐标
79+
domain: undefined, // 速度渲染范围
80+
displayRange: undefined, // 速度显示范围
81+
dynamic: true // 是否启用动态粒子动画
8182
});
8283
```
8384

@@ -91,25 +92,25 @@ const windLayer = new WindLayer(viewer, windData, {
9192

9293
```typescript
9394
interface WindLayerOptions {
94-
particlesTextureSize: number; // 粒子纹理大小,决定粒子最大数量(size * size)(默认:100)
95-
particleHeight: number; // 粒子距地面高度(默认:0)
96-
lineWidth: number; // 粒子线宽(默认:5.0
97-
lineLength: { min: number; max: number }; // 粒子轨迹长度范围(默认:{ min: 20, max: 100 })
98-
speedFactor: number; // 速度倍数(默认:1.0)
99-
dropRate: number; // 粒子消失率(默认:0.003)
100-
dropRateBump: number; // 额外消失率(默认:0.01)
101-
colors: string[]; // 粒子颜色数组(默认:['white'])
102-
flipY: boolean; // 是否翻转 Y 坐标(默认:false)
103-
useViewerBounds: boolean; // 是否使用视域范围生成粒子(默认:false)
104-
domain?: { // 速度渲染范围(默认:undefined)
105-
min?: number; // 最小速度值
106-
max?: number; // 最大速度值
95+
particlesTextureSize: number; // 粒子纹理大小,决定粒子最大数量(size * size)(默认:100)
96+
particleHeight: number; // 粒子距地面高度(默认:0)
97+
lineWidth: { min: number; max: number }; // 粒子轨迹宽度范围(默认:{ min: 1, max: 5 }
98+
lineLength: { min: number; max: number }; // 粒子轨迹长度范围(默认:{ min: 20, max: 100 })
99+
speedFactor: number; // 速度倍数(默认:1.0)
100+
dropRate: number; // 粒子消失率(默认:0.003)
101+
dropRateBump: number; // 额外消失率(默认:0.01)
102+
colors: string[]; // 粒子颜色数组(默认:['white'])
103+
flipY: boolean; // 是否翻转 Y 坐标(默认:false)
104+
useViewerBounds: boolean; // 是否使用视域范围生成粒子(默认:false)
105+
domain?: { // 速度渲染范围(默认:undefined)
106+
min?: number; // 最小速度值
107+
max?: number; // 最大速度值
107108
};
108-
displayRange?: { // 速度显示范围(默认:undefined)
109-
min?: number; // 最小速度值
110-
max?: number; // 最大速度值
111-
};
112-
dynamic: boolean; // 是否启用动态粒子动画(默认:true)
109+
displayRange?: { // 速度显示范围(默认:undefined)
110+
min?: number; // 最小速度值
111+
max?: number; // 最大速度值
112+
};
113+
dynamic: boolean; // 是否启用动态粒子动画(默认:true)
113114
}
114115
```
115116

0 commit comments

Comments
 (0)