@@ -12,7 +12,7 @@ import Shuffle from '@material-ui/icons/Shuffle';
1212import { ChromePicker } from 'react-color' ;
1313import { useDispatch , useSelector } from 'react-redux' ;
1414import { experimentLabelColor } from '../../theme' ;
15- import { changeInstanceColor } from '../../redux/actions/general' ;
15+ import { changeInstanceColor , selectInstances } from '../../redux/actions/general' ;
1616
1717const useStyles = makeStyles ( ( theme ) => ( {
1818 networkItem : {
@@ -62,26 +62,39 @@ const ControlPanelTreeItem = (props) => {
6262 setColor ( _color . rgb ) ;
6363 } ;
6464
65+ const getRandomColor = ( ) => ( {
66+ r : parseFloat ( ( Math . random ( ) * 255 ) . toFixed ( 2 ) ) ,
67+ g : parseFloat ( ( Math . random ( ) * 255 ) . toFixed ( 2 ) ) ,
68+ b : parseFloat ( ( Math . random ( ) * 255 ) . toFixed ( 2 ) ) ,
69+ a : 1 ,
70+ } ) ;
71+
6572 const generateRandomColor = ( event , nodeId ) => {
66- const newInstances = instances . filter ( ( instance ) => ! ( instance . instancePath . startsWith ( nodeId ) ) ) ;
67- const randomColor = {
68- r : parseFloat ( ( Math . random ( ) * 255 ) . toFixed ( 2 ) ) ,
69- g : parseFloat ( ( Math . random ( ) * 255 ) . toFixed ( 2 ) ) ,
70- b : parseFloat ( ( Math . random ( ) * 255 ) . toFixed ( 2 ) ) ,
71- a : 1 ,
72- } ;
73+ const children = window . Instances . getInstance ( nodeId ) . getChildren ( ) . map ( ( instance ) => instance . getInstancePath ( ) ) ;
74+ // const newInstances = instances.filter((instance) => !(instance.instancePath.startsWith(nodeId)));
75+ const newInstances = instances . filter ( ( instance ) => {
76+ let condition = true ;
77+ children . forEach ( ( child ) => {
78+ if ( instance . instancePath . startsWith ( child ) ) {
79+ condition = false ;
80+ }
81+ } ) ;
82+ return condition ;
83+ } ) ;
7384
74- newInstances . push ( {
75- instancePath : nodeId ,
76- color : {
77- r : randomColor . r / 255 ,
78- g : randomColor . g / 255 ,
79- b : randomColor . b / 255 ,
80- a : randomColor . a ,
81- } ,
85+ children . forEach ( ( child ) => {
86+ const randomColor = getRandomColor ( ) ;
87+ newInstances . push ( {
88+ instancePath : child ,
89+ color : {
90+ r : randomColor . r / 255 ,
91+ g : randomColor . g / 255 ,
92+ b : randomColor . b / 255 ,
93+ a : randomColor . a ,
94+ } ,
95+ } ) ;
8296 } ) ;
8397 dispatch ( changeInstanceColor ( newInstances ) ) ;
84- setColor ( randomColor ) ;
8598 } ;
8699
87100 const changeVisibility = ( event , nodeId ) => {
@@ -126,6 +139,7 @@ const ControlPanelTreeItem = (props) => {
126139 onNodeSelect,
127140 onVisibilityClick,
128141 children,
142+ disableRandom,
129143 ...other
130144 } = props ;
131145
@@ -153,7 +167,7 @@ const ControlPanelTreeItem = (props) => {
153167 < IconButton onClick = { ( event ) => changeVisibility ( event , nodeId ) } >
154168 { visibility ? < Visibility /> : < VisibilityOff /> }
155169 </ IconButton >
156- < IconButton onClick = { ( event ) => generateRandomColor ( event , nodeId ) } > < Shuffle /> </ IconButton >
170+ < IconButton disabled = { disableRandom } onClick = { ( event ) => generateRandomColor ( event , nodeId ) } > < Shuffle /> </ IconButton >
157171 < IconButton onClick = { ( ) => setShowColorPicker ( true ) } > < ColorLens /> </ IconButton >
158172 {
159173 showColorPicker
0 commit comments