11export interface DatasetTypeInfo {
22 name : string ;
3+ type ?: string ; // Data type like 'string', 'boolean', etc.
34 style : {
45 backgroundColor : string ;
56 borderColor : string ;
@@ -12,45 +13,79 @@ export function hashString(str: string): number {
1213 let hash = 0 ;
1314 for ( let i = 0 ; i < str . length ; i ++ ) {
1415 const char = str . charCodeAt ( i ) ;
15- hash = ( ( hash << 5 ) - hash ) + char ;
16+ hash = ( hash << 5 ) - hash + char ;
1617 hash = hash & hash ; // Convert to 32bit integer
1718 }
1819 return Math . abs ( hash ) ;
1920}
2021
2122// Function to create a dynamic type for any path
22- export function createDynamicType ( path : string ) : DatasetTypeInfo {
23+ export function createDynamicType (
24+ path : string ,
25+ type ?: string
26+ ) : DatasetTypeInfo {
2327 const hash = hashString ( path ) ;
24- const hue = hash % 360 ;
25-
28+
29+ // Create a more varied hash by combining multiple factors
30+ const pathLength = path . length ;
31+ const firstChar = path . charCodeAt ( 0 ) ;
32+ const lastChar = path . charCodeAt ( path . length - 1 ) ;
33+ const complexHash =
34+ ( hash + pathLength * 17 + firstChar * 31 + lastChar * 13 ) % 360 ;
35+
36+ // Define distinct color palette with good separation
37+ const distinctColors = [
38+ 20 , // Orange-red
39+ 45 , // Orange
40+ 70 , // Yellow-orange
41+ 95 , // Yellow-green
42+ 120 , // Green
43+ 145 , // Blue-green
44+ 170 , // Cyan
45+ 195 , // Light blue (but shifted to avoid dark blue)
46+ 280 , // Purple
47+ 305 , // Magenta
48+ 330 , // Pink-red
49+ 350 , // Red-orange
50+ ] ;
51+
52+ // Use modulo to select from our distinct color palette
53+ const colorIndex = complexHash % distinctColors . length ;
54+ const selectedHue = distinctColors [ colorIndex ] ;
55+
56+ // Add slight variation based on the original hash to avoid exact duplicates
57+ const hueVariation = ( hash % 20 ) - 10 ; // -10 to +10 degrees variation
58+ const finalHue = ( selectedHue + hueVariation + 360 ) % 360 ;
59+
2660 // Convert path to a readable name (e.g., "targetPrivacyPassV2_prod" -> "Target Privacy Pass V2 Prod")
2761 const name = path
2862 . replace ( / ( [ A - Z ] ) / g, ' $1' ) // Add space before capital letters
2963 . replace ( / _ / g, ' ' ) // Replace underscores with spaces
30- . replace ( / ^ ./ , str => str . toUpperCase ( ) ) // Capitalize first letter
31- . replace ( / \s + ./ g, str => str . toUpperCase ( ) ) // Capitalize first letter of each word
64+ . replace ( / ^ ./ , ( str ) => str . toUpperCase ( ) ) // Capitalize first letter
65+ . replace ( / \s + ./ g, ( str ) => str . toUpperCase ( ) ) // Capitalize first letter of each word
3266 . trim ( ) ;
3367
3468 return {
3569 name,
70+ type,
3671 style : {
37- backgroundColor : `hsla(${ hue } , 60 %, 50 %, 0.08 )` ,
38- borderColor : `hsla(${ hue } , 60 %, 50 %, 0.2 )` ,
39- color : `hsl(${ hue } , 60 %, 40 %)`
40- }
72+ backgroundColor : `hsla(${ finalHue } , 80 %, 60 %, 0.15 )` ,
73+ borderColor : `hsla(${ finalHue } , 80 %, 60 %, 0.4 )` ,
74+ color : `hsl(${ finalHue } , 80 %, 65 %)` ,
75+ } ,
4176 } ;
42- }
43-
44- // Function to process schema paths into types
45- export function processSchemaPathsToTypes ( schemaPaths ?: Array < { path ?: string | null } > ) : DatasetTypeInfo [ ] {
77+ } // Function to process schema paths into types
78+ export function processSchemaPathsToTypes (
79+ schemaPaths ?: Array < { path ?: string | null ; type ?: string | null } >
80+ ) : DatasetTypeInfo [ ] {
4681 if ( ! schemaPaths || schemaPaths . length === 0 ) {
4782 return [ ] ;
4883 }
4984
5085 return schemaPaths
5186 . map ( ( item ) => {
5287 if ( ! item . path ) return null ;
53- return createDynamicType ( item . path ) ;
88+ return createDynamicType ( item . path , item . type || undefined ) ;
5489 } )
5590 . filter ( Boolean ) as DatasetTypeInfo [ ] ;
5691}
0 commit comments