Skip to content

Commit 1eb0ca7

Browse files
fix: update app and e2e
1 parent 6559f10 commit 1eb0ca7

File tree

1 file changed

+19
-8
lines changed
  • runtime-plugins/control-sharing/app1/src

1 file changed

+19
-8
lines changed

runtime-plugins/control-sharing/app1/src/App.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,28 @@ const styles = {
6060
};
6161

6262
const getColorFromString = str => {
63-
let primes = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23];
63+
const colors = [
64+
'#F44336', // red
65+
'#2196F3', // blue
66+
'#4CAF50', // green
67+
'#9C27B0', // purple
68+
'#E91E63', // pink
69+
'#FF9800', // orange
70+
'#03A9F4', // light blue
71+
'#009688', // teal
72+
'#8BC34A', // light green
73+
'#AB47BC' // medium purple
74+
];
75+
6476
let hash = 0;
6577
for (let i = 0; i < str.length; i++) {
66-
hash += str.charCodeAt(i) * primes[i % primes.length];
67-
}
68-
let color = '#';
69-
for (let i = 0; i < 3; i++) {
70-
const value = (hash >> (i * 8)) & 0xff;
71-
color += ('00' + value.toString(16)).substr(-2);
78+
hash = ((hash << 5) - hash) + str.charCodeAt(i);
79+
hash = hash & hash; // Convert to 32-bit integer
7280
}
73-
return color;
81+
82+
hash = Math.abs(hash);
83+
84+
return colors[hash % colors.length];
7485
};
7586

7687
const App = () => {

0 commit comments

Comments
 (0)