11import React , { useState , useEffect } from 'react' ;
22import type { ActiveConfig , LayerSchema , SelectConfig , LayerEventPayload } from '../../schema/types' ;
33import { PointLayer } from '../Layer/PointLayer' ;
4+ import { getColorPalette , type ColorScheme } from '../../constants/colorPalettes' ;
45
56export const BUBBLE_SIZE_LEVELS = [ 8 , 16 , 32 , 48 , 64 ] as const ;
67
@@ -36,6 +37,8 @@ export interface BubbleLayerProps extends Omit<LayerSchema, 'type' | 'source' |
3637 labelOffset ?: [ number , number ] ;
3738 /** sizeField 为离散值时,对应每个 sizeValues 的域值顺序(默认 1..N) */
3839 sizeDomain ?: Array < string | number > ;
40+ /** 连续数值尺寸范围 [min, max],与 sizeField 配合使用。提供时自动线性映射 */
41+ sizeRange ?: [ number , number ] ;
3942 /** 气泡锚点,决定标签相对气泡的连接参考点 */
4043 bubbleAnchor ?: BubbleAnchor ;
4144 /** 文本锚点,映射到 textAnchor */
@@ -55,6 +58,9 @@ export interface BubbleLayerProps extends Omit<LayerSchema, 'type' | 'source' |
5558 /** 语义色板映射字段,例如 status: primary|warning|error|success */
5659 semanticColorField ?: string ;
5760
61+ /** 色板预设,默认 'categorical'。当无 semanticColorField 且无 colorValues 时使用 */
62+ colorScheme ?: ColorScheme ;
63+
5864 // ===== 事件回调 =====
5965 /** 点击事件 */
6066 onClick ?: ( payload : LayerEventPayload ) => void ;
@@ -88,14 +94,16 @@ export function BubbleLayer({
8894 showLabel = true ,
8995 labelOffset,
9096 sizeDomain,
97+ sizeRange,
9198 bubbleAnchor = 'bottom' ,
9299 labelAnchor = 'top' ,
93- hoverEffect = true ,
94- clickEffect = true ,
95- tooltipEffect = true ,
100+ hoverEffect = false ,
101+ clickEffect = false ,
102+ tooltipEffect = false ,
96103 tooltipFields,
97104 tooltipTemplate,
98105 semanticColorField,
106+ colorScheme = 'categorical' ,
99107 color = '#2563eb' ,
100108 size = 16 ,
101109 sizeField,
@@ -119,14 +127,16 @@ export function BubbleLayer({
119127 BUBBLE_QUALITATIVE_COLORS . error ,
120128 BUBBLE_QUALITATIVE_COLORS . success ,
121129 ]
122- : undefined ) ;
130+ : mappedColorField
131+ ? [ ...getColorPalette ( colorScheme ) ]
132+ : undefined ) ;
123133
124134 const mappedSizeValues = sizeField
125- ? ( sizeValues ?? [ ...BUBBLE_SIZE_LEVELS ] )
135+ ? ( sizeValues ?? ( sizeRange ? undefined : [ ...BUBBLE_SIZE_LEVELS ] ) )
126136 : sizeValues ;
127137
128- const defaultActive : ActiveConfig = { color : '#60a5fa' } ;
129- const defaultSelect : SelectConfig = { color : '#1d4ed8' } ;
138+ const defaultActive : ActiveConfig = { color : '#60a5fa' , duration : 150 } ;
139+ const defaultSelect : SelectConfig = { color : '#1d4ed8' , duration : 150 } ;
130140
131141 const resolvedEvents = ( ( ) => {
132142 const origin = rest . events ;
@@ -150,7 +160,7 @@ export function BubbleLayer({
150160
151161 // 气泡圆图层的 size 配置:当有 sizeField 时不传固定 size 避免冲突
152162 const bubbleSizeProps = sizeField
153- ? { sizeField, sizeValues : mappedSizeValues }
163+ ? { sizeField, sizeValues : mappedSizeValues , ... ( sizeRange ? { sizeRange } : { } ) }
154164 : { size } ;
155165
156166 return (
@@ -195,7 +205,7 @@ export function BubbleLayer({
195205 shapeValues = "text"
196206 color = { labelColor }
197207 size = { labelSize }
198- zIndex = { ( rest . zIndex ?? 0 ) + 1 }
208+ zIndex = { ( rest . zIndex ?? 0 ) + 10 }
199209 style = { {
200210 textAnchor : labelAnchor ,
201211 textOffset : labelOffset ?? [ 0 , 0 ] ,
0 commit comments