Skip to content

Commit ad258bb

Browse files
committed
#417 finished sorting issues geppetto related for the selection, visibility, changing color through the new control panel + fixed source maps for the geppetto packages
1 parent 9d94bf2 commit ad258bb

5 files changed

Lines changed: 126 additions & 19 deletions

File tree

webapp/components/general/ControlPanelTreeItem.js

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Box from '@material-ui/core/Box';
66
import IconButton from '@material-ui/core/IconButton';
77
import TreeItem from '@material-ui/lab/TreeItem';
88
import Visibility from '@material-ui/icons/Visibility';
9+
import VisibilityOff from '@material-ui/icons/VisibilityOff';
910
import ColorLens from '@material-ui/icons/ColorLens';
1011
import Shuffle from '@material-ui/icons/Shuffle';
1112
import { ChromePicker } from 'react-color';
@@ -40,35 +41,84 @@ const ControlPanelTreeItem = (props) => {
4041
const dispatch = useDispatch();
4142
const [showColorPicker, setShowColorPicker] = React.useState(false);
4243
const [isHoveredOver, setIsHoveredOver] = React.useState(false);
43-
const [color, setColor] = React.useState('#ff0000');
44+
const [color, setColor] = React.useState({
45+
g: 0.50, b: 0.60, r: 1, a: 1,
46+
});
47+
const [visibility, setVisibility] = React.useState(true);
4448
const instances = useSelector((state) => state.general.instances);
4549

46-
const handleColorSelection = (color, event, nodeId) => {
50+
const handleColorSelection = (_color, event, nodeId) => {
4751
const newInstances = instances.filter((instance) => !(instance.instancePath.startsWith(nodeId)));
4852
newInstances.push({
4953
instancePath: nodeId,
5054
color: {
51-
r: color.rgb.r / 255,
52-
g: color.rgb.g / 255,
53-
b: color.rgb.b / 255,
54-
a: color.rgb.a,
55+
r: _color.rgb.r / 255,
56+
g: _color.rgb.g / 255,
57+
b: _color.rgb.b / 255,
58+
a: _color.rgb.a,
5559
},
5660
});
5761
dispatch(changeInstanceColor(newInstances));
58-
console.log(color);
59-
setColor(color.hex);
62+
setColor(_color.rgb);
6063
};
6164

62-
const generateRandomColor = () => {
65+
const generateRandomColor = (event, nodeId) => {
66+
const newInstances = instances.filter((instance) => !(instance.instancePath.startsWith(nodeId)));
6367
const randomColor = {
64-
r: parseFloat((Math.random() * 1.00).toFixed(2)),
65-
g: parseFloat((Math.random() * 1.00).toFixed(2)),
66-
b: parseFloat((Math.random() * 1.00).toFixed(2)),
68+
r: parseFloat((Math.random() * 255).toFixed(2)),
69+
g: parseFloat((Math.random() * 255).toFixed(2)),
70+
b: parseFloat((Math.random() * 255).toFixed(2)),
6771
a: 1,
6872
};
73+
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+
},
82+
});
83+
dispatch(changeInstanceColor(newInstances));
6984
setColor(randomColor);
7085
};
7186

87+
const changeVisibility = (event, nodeId) => {
88+
const copiedInstances = instances.slice();
89+
let oldIndex = null;
90+
let oldInstance = copiedInstances.find((pInstance, index) => {
91+
if (pInstance.instancePath === nodeId) {
92+
oldIndex = index;
93+
return true;
94+
}
95+
return false;
96+
});
97+
if (!oldInstance) {
98+
oldInstance = {
99+
instancePath: nodeId,
100+
visibility: false,
101+
};
102+
} else {
103+
copiedInstances.splice(oldIndex, 1);
104+
oldInstance.visibility = (oldInstance?.visibility !== undefined) ? !oldInstance.visibility : false;
105+
}
106+
107+
const newInstances = instances.map((instance) => {
108+
if (!(instance.instancePath.startsWith(nodeId))) {
109+
return instance;
110+
}
111+
const newInstance = instance;
112+
newInstance.visibility = oldInstance.visibility;
113+
return newInstance;
114+
});
115+
116+
newInstances.push(oldInstance);
117+
118+
dispatch(changeInstanceColor(newInstances));
119+
setVisibility(oldInstance.visibility);
120+
};
121+
72122
const {
73123
label,
74124
type,
@@ -100,8 +150,10 @@ const ControlPanelTreeItem = (props) => {
100150
? (
101151
<>
102152

103-
<IconButton onClick={(event) => onVisibilityClick(event, nodeId)}><Visibility /></IconButton>
104-
<IconButton onClick={generateRandomColor}><Shuffle /></IconButton>
153+
<IconButton onClick={(event) => changeVisibility(event, nodeId)}>
154+
{ visibility ? <Visibility /> : <VisibilityOff /> }
155+
</IconButton>
156+
<IconButton onClick={(event) => generateRandomColor(event, nodeId)}><Shuffle /></IconButton>
105157
<IconButton onClick={() => setShowColorPicker(true)}><ColorLens /></IconButton>
106158
{
107159
showColorPicker

webapp/components/general/ExperimentControlPanel.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-nested-ternary */
12
import * as React from 'react';
23
import { makeStyles } from '@material-ui/core/styles';
34
import Box from '@material-ui/core/Box';

webapp/components/instantiation/NetPyNEInstantiated.js

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import React from 'react';
22
import { withStyles } from '@material-ui/core';
33
import Canvas from '@metacell/geppetto-meta-ui/3d-canvas/Canvas';
44
import CameraControls from '@metacell/geppetto-meta-ui/camera-controls/CameraControls';
5-
import { applySelection, mapToCanvasData } from '@metacell/geppetto-meta-ui/3d-canvas/showcase/utils/SelectionUtils';
65
import {
76
primaryColor, canvasBgDark, canvasBgLight, bgRegular,
87
} from '../../theme';
98
import { THEMES } from '../../constants';
109

10+
require('source-map-support').install();
11+
1112
const CANVAS_LIGHT = 'canvas-toolbar-btns-light';
1213
const CANVAS_DARK = 'canvas-toolbar-btns-dark';
1314
const SELECTION_COLOR = {
@@ -51,11 +52,13 @@ class NetPyNEInstantiated extends React.Component {
5152
this.canvasRef = React.createRef();
5253

5354
this.onSelection = this.onSelection.bind(this);
55+
this.applySelection = this.applySelection.bind(this);
56+
this.mapToCanvasData = this.mapToCanvasData.bind(this);
5457
}
5558

5659
onSelection (selectedInstances) {
5760
const { selectInstances, data } = this.props;
58-
selectInstances(applySelection(data, selectedInstances));
61+
selectInstances(this.applySelection(data, selectedInstances));
5962
}
6063

6164
updateBtnsWithTheme = (removeClass, addClass) => {
@@ -67,11 +70,46 @@ class NetPyNEInstantiated extends React.Component {
6770
this.setState({ canvasBtnCls: addClass });
6871
};
6972

73+
mapToCanvasData (data) {
74+
return data.map((item) => (
75+
{
76+
visibility: item?.visibility !== undefined ? item.visibility : true,
77+
color: item.selected ? SELECTION_COLOR : item.color,
78+
instancePath: item.instancePath,
79+
}
80+
));
81+
}
82+
83+
applySelection (data, selectedInstances) {
84+
const smap = new Map(selectedInstances.map((i) => [i, true]))
85+
const newData = data.map((item) => {
86+
if (smap.get(item.instancePath)) {
87+
return {
88+
...item,
89+
selected: !item.selected,
90+
};
91+
}
92+
return { ...item };
93+
});
94+
const dmap = new Map(newData.map((i) => [i.instancePath, true]));
95+
96+
smap.forEach((value, key) => {
97+
if (!dmap.get(key)) {
98+
newData.push({
99+
instancePath: key,
100+
color: undefined,
101+
selected: true,
102+
});
103+
}
104+
});
105+
return newData;
106+
}
107+
70108
render () {
71109
const { cameraOptions } = this.state;
72110
const { data } = this.props;
73111

74-
const canvasData = mapToCanvasData(data);
112+
const canvasData = this.mapToCanvasData(data);
75113

76114
let camOptions = cameraOptions;
77115
if (this.lastCameraUpdate) {

webapp/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"react-dom": "^16.4.0",
3737
"react-json-view": "^1.21.3",
3838
"react-redux": "^7.2.0",
39-
"react-resize-detector": "^6.7.4",
4039
"react-sortable-tree": "^2.8.0",
4140
"redux": "^4.1.0",
4241
"sass": "^1.49.0",

webapp/webpack.config.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ try {
1616
console.error('\nFailed to load Geppetto Configuration');
1717
}
1818
const geppettoClientPath = 'node_modules/@metacell/geppetto-meta-client';
19+
const geppettoCorePath = 'node_modules/@metacell/geppetto-meta-core';
20+
const geppettoUIPath = 'node_modules/@metacell/geppetto-meta-ui';
1921

2022
const publicPath = path.join('/', geppettoConfig.contextPath, 'geppetto/build/');
2123
console.log(`\nThe public path (used by the main bundle when including split bundles) is: ${publicPath}`);
@@ -37,6 +39,16 @@ const availableExtensions = [
3739
to: 'static',
3840
flatten: true,
3941
},
42+
{
43+
from: path.resolve(__dirname, geppettoCorePath, 'static/*'),
44+
to: 'static',
45+
flatten: true,
46+
},
47+
{
48+
from: path.resolve(__dirname, geppettoUIPath, 'static/*'),
49+
to: 'static',
50+
flatten: true,
51+
},
4052
{
4153
from: path.resolve(__dirname, 'images/*'),
4254
to: '',
@@ -128,6 +140,8 @@ module.exports = function (env) {
128140
alias: {
129141
root: path.resolve(__dirname),
130142
'geppetto-client': path.resolve(__dirname, geppettoClientPath),
143+
'geppetto-core': path.resolve(__dirname, geppettoCorePath),
144+
'geppetto-ui': path.resolve(__dirname, geppettoUIPath),
131145
geppetto: path.resolve(__dirname, geppettoClientPath, 'pages/geppetto/GEPPETTO.js'),
132146
'geppetto-client-initialization': path.resolve(__dirname, geppettoClientPath, 'pages/geppetto/main.js'),
133147
handlebars: 'handlebars/dist/handlebars.js',
@@ -140,7 +154,10 @@ module.exports = function (env) {
140154
rules: [
141155
{
142156
test: /\.(js|jsx|ts|tsx)$/,
143-
exclude: [/ami.min.js/, /node_modules\/(?!(@metacell\/geppetto-meta-client)\/).*/],
157+
exclude: [
158+
/ami.min.js/,
159+
/node_modules\/(?!(@metacell\/geppetto-meta-client)|(@metacell\/geppetto-meta-core)|(@metacell\/geppetto-meta-ui)\/).*/,
160+
],
144161
use: {
145162
loader: 'babel-loader',
146163
options: {

0 commit comments

Comments
 (0)