44
55import React , { useCallback , useEffect , useMemo , useState } from 'react' ;
66import type { ReactNode } from 'react' ;
7- import type { GraphLayerProps } from '@deck.gl-community/graph-layers' ;
8-
9- export type LayoutType =
10- | 'd3-force-layout'
11- | 'gpu-force-layout'
12- | 'simple-layout'
13- | 'radial-layout'
14- | 'hive-plot-layout'
15- | 'force-multi-graph-layout'
16- | 'd3-dag-layout' ;
17-
18- export type ExampleStyles = NonNullable < GraphLayerProps [ 'stylesheet' ] > ;
19-
20- export type ExampleDefinition = {
21- name : string ;
22- description : string ;
23- data : ( ) => { nodes : unknown [ ] ; edges : unknown [ ] } ;
24- /** First listed layout is the default */
25- layouts : LayoutType [ ] ;
26- layoutDescriptions : Record < LayoutType , string > ;
27- style : ExampleStyles ;
28- getLayoutOptions ?: (
29- layout : LayoutType ,
30- data : { nodes : unknown [ ] ; edges : unknown [ ] }
31- ) => Record < string , unknown > | undefined ;
32- } ;
7+ import type { ExampleDefinition , LayoutType } from './layout-options' ;
8+ import { LAYOUT_LABELS } from './layout-options' ;
9+ import { LayoutOptionsPanel } from './layout-options-panel' ;
3310
3411type ControlPanelProps = {
3512 examples : ExampleDefinition [ ] ;
3613 defaultExample ?: ExampleDefinition ;
3714 onExampleChange : ( example : ExampleDefinition , layout : LayoutType ) => void ;
3815 children ?: ReactNode ;
39- } ;
40-
41- const LAYOUT_LABELS : Record < LayoutType , string > = {
42- 'd3-force-layout' : 'D3 Force Layout' ,
43- 'gpu-force-layout' : 'GPU Force Layout' ,
44- 'simple-layout' : 'Simple Layout' ,
45- 'radial-layout' : 'Radial Layout' ,
46- 'hive-plot-layout' : 'Hive Plot Layout' ,
47- 'force-multi-graph-layout' : 'Force Multi-Graph Layout' ,
48- 'd3-dag-layout' : 'D3 DAG Layout' ,
16+ layoutOptions ?: Record < string , unknown > ;
17+ onLayoutOptionsApply ?: ( layout : LayoutType , options : Record < string , unknown > ) => void ;
4918} ;
5019
5120export function ControlPanel ( {
5221 examples,
5322 defaultExample,
5423 onExampleChange,
24+ layoutOptions,
25+ onLayoutOptionsApply,
5526 children
5627} : ControlPanelProps ) {
5728 const resolveExampleIndex = useCallback (
@@ -74,6 +45,7 @@ export function ControlPanel({
7445 const [ selectedLayout , setSelectedLayout ] = useState < LayoutType | undefined > (
7546 availableLayouts [ 0 ]
7647 ) ;
48+
7749 useEffect ( ( ) => {
7850 if ( ! availableLayouts . length ) {
7951 setSelectedLayout ( undefined ) ;
@@ -122,6 +94,19 @@ export function ControlPanel({
12294 return selectedExample . layoutDescriptions [ selectedLayout ] ;
12395 } , [ selectedExample , selectedLayout ] ) ;
12496
97+ const styleJson = useMemo ( ( ) => {
98+ const styles = selectedExample ?. style ;
99+ if ( ! styles ) {
100+ return '' ;
101+ }
102+
103+ return JSON . stringify (
104+ styles ,
105+ ( _key , value ) => ( typeof value === 'function' ? value . toString ( ) : value ) ,
106+ 2
107+ ) ;
108+ } , [ selectedExample ] ) ;
109+
125110 if ( ! examples . length ) {
126111 return null ;
127112 }
@@ -172,6 +157,25 @@ export function ControlPanel({
172157 </ option >
173158 ) ) }
174159 </ select >
160+ </ div >
161+ { datasetDescription ? (
162+ < section style = { { fontSize : '0.875rem' , lineHeight : 1.5 , color : '#334155' } } >
163+ < h3 style = { { margin : '0 0 0.25rem' , fontSize : '0.875rem' , fontWeight : 600 , color : '#0f172a' } } >
164+ Dataset overview
165+ </ h3 >
166+ < p style = { { margin : 0 } } > { datasetDescription } </ p >
167+ </ section >
168+ ) : null }
169+ < div
170+ style = { {
171+ display : 'grid' ,
172+ gridTemplateColumns : 'auto 1fr' ,
173+ gridAutoRows : 'auto' ,
174+ columnGap : '0.75rem' ,
175+ rowGap : '0.75rem' ,
176+ alignItems : 'center'
177+ } }
178+ >
175179 < label htmlFor = "graph-viewer-layout" style = { { fontSize : '0.875rem' , fontWeight : 600 , color : '#0f172a' } } >
176180 Layout
177181 </ label >
@@ -197,14 +201,11 @@ export function ControlPanel({
197201 ) ) }
198202 </ select >
199203 </ div >
200- { datasetDescription ? (
201- < section style = { { fontSize : '0.875rem' , lineHeight : 1.5 , color : '#334155' } } >
202- < h3 style = { { margin : '0 0 0.25rem' , fontSize : '0.875rem' , fontWeight : 600 , color : '#0f172a' } } >
203- Dataset overview
204- </ h3 >
205- < p style = { { margin : 0 } } > { datasetDescription } </ p >
206- </ section >
207- ) : null }
204+ < LayoutOptionsPanel
205+ layout = { selectedLayout }
206+ appliedOptions = { layoutOptions }
207+ onApply = { onLayoutOptionsApply }
208+ />
208209 { children ? (
209210 < section
210211 style = { {
0 commit comments