@@ -3,6 +3,7 @@ import ReactDOM from 'react-dom';
33import { withStyles } from '@material-ui/core' ;
44import Canvas from '@metacell/geppetto-meta-ui/3d-canvas/Canvas' ;
55import CameraControls from '@metacell/geppetto-meta-ui/camera-controls/CameraControls' ;
6+ import { applySelection , mapToCanvasData } from '@metacell/geppetto-meta-ui/3d-canvas/showcase/utils/SelectionUtils' ;
67// TODO: replace this with the list viewer during refactoring
78// import ControlPanel from 'geppetto-client/js/components/interface/controlPanel/controlpanel';
89
@@ -15,10 +16,10 @@ import { THEMES } from '../../constants';
1516const CANVAS_LIGHT = 'canvas-toolbar-btns-light' ;
1617const CANVAS_DARK = 'canvas-toolbar-btns-dark' ;
1718const SELECTION_COLOR = {
18- r : 0.8 , g : 0.8 , b : 0 , a : 1 ,
19+ r : 0 , g : 0.8 , b : 0.8 , a : 1 ,
1920} ;
2021const DEFAULT_COLOR = {
21- r : 1 , g : 0 , b : 0 , a : 0.5 ,
22+ g : 0.50 , b : 0.60 , r : 1 , a : 0.80 ,
2223} ;
2324
2425const styles = ( ) => ( {
@@ -38,14 +39,6 @@ class NetPyNEInstantiated extends React.Component {
3839 hasModelLoaded : false ,
3940 intersected : [ ] ,
4041 tooltipVisible : false ,
41- data : [
42- {
43- instancePath : 'network' ,
44- color : {
45- g : 0.50 , b : 0.60 , r : 1 , a : 0.80 ,
46- } ,
47- } ,
48- ] ,
4942 selected : { } ,
5043 cameraOptions : {
5144 angle : 60 ,
@@ -66,11 +59,26 @@ class NetPyNEInstantiated extends React.Component {
6659 } ,
6760 } ;
6861 this . dimensions = {
69- width : '1980px ' ,
70- height : '1900px ' ,
62+ width : '100% ' ,
63+ height : '100% ' ,
7164 } ;
7265 this . canvasRef = React . createRef ( ) ;
73- this . controlPanelToggle = this . controlPanelToggle . bind ( this ) ;
66+
67+ this . onSelection = this . onSelection . bind ( this ) ;
68+ }
69+
70+ onSelection ( selectedInstances ) {
71+ const { selectInstances, data } = this . props ;
72+ selectInstances ( applySelection ( data , selectedInstances ) ) ;
73+ }
74+
75+ getParentSize ( ) {
76+ if ( this . canvasRef . current === null ) {
77+ return false ;
78+ }
79+ // eslint-disable-next-line react/no-find-dom-node
80+ const node = ReactDOM . findDOMNode ( this ) ;
81+ return node . parentNode . getBoundingClientRect ( ) ;
7482 }
7583
7684 updateBtnsWithTheme = ( removeClass , addClass ) => {
@@ -102,46 +110,11 @@ class NetPyNEInstantiated extends React.Component {
102110 this . timer = setTimeout ( ( ) => this . resizeIfNeeded ( ) , 100 ) ;
103111 }
104112
105- getParentSize ( ) {
106- if ( this . canvasRef . current === null ) {
107- return false ;
108- }
109- // eslint-disable-next-line react/no-find-dom-node
110- const node = ReactDOM . findDOMNode ( this ) ;
111- return node . parentNode . getBoundingClientRect ( ) ;
112- }
113-
114- controlPanelToggle ( ) {
115- if ( ! this . state . controlPanelInitialized ) {
116- this . setState ( { controlPanelInitialized : true } ) ;
117- } else {
118- $ ( '#controlpanel' )
119- . show ( ) ;
120- }
121- }
122-
123- mapToCanvasData ( data ) {
124- return data . map ( ( item ) => (
125- {
126- color : item . selected ? SELECTION_COLOR : item . color ,
127- instancePath : item . instancePath ,
128- }
129- ) ) ;
130- }
131-
132113 render ( ) {
133- const {
134- update,
135- canvasBtnCls,
136- controlPanelInitialized,
137- } = this . state ;
138- const { theme } = this . props ;
139- const { controlPanelToggle } = this ;
140- const bgColor = theme === THEMES . LIGHT ? canvasBgLight : theme === THEMES . BLACK ? canvasBgDark : 'transparent' ;
141-
142- const { data, cameraOptions } = this . state ;
114+ const { cameraOptions } = this . state ;
115+ const { data } = this . props ;
143116
144- const canvasData = this . mapToCanvasData ( data ) ;
117+ const canvasData = mapToCanvasData ( data ) ;
145118
146119 let camOptions = cameraOptions ;
147120 if ( this . lastCameraUpdate ) {
@@ -155,7 +128,6 @@ class NetPyNEInstantiated extends React.Component {
155128 } ;
156129 }
157130
158-
159131 return (
160132 < div className = "instantiatedContainer" >
161133 < Canvas
@@ -164,6 +136,7 @@ class NetPyNEInstantiated extends React.Component {
164136 key = "CanvasContainer"
165137 data = { canvasData }
166138 backgroundColor = { bgRegular }
139+ onSelection = { this . onSelection }
167140 />
168141 </ div >
169142 ) ;
0 commit comments