Skip to content

Commit ab3067e

Browse files
authored
Merge pull request #1 from ducfilan/main
Add options for direction
2 parents 5a5c668 + 951306b commit ab3067e

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

core/src/index.jsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { View } from './view'
44
import css from './index.module.scss'
55
import { SvgMenu, SvgZoomIn, SvgZoomOut } from './icon'
66

7-
export function useOnnx (url) {
7+
export function useOnnx(url) {
88
const [data, setData] = useState(null)
99
useEffect(() => {
1010
console.log(url)
@@ -17,7 +17,7 @@ export function useOnnx (url) {
1717
return data
1818
}
1919

20-
const ReactOnnx = forwardRef(({ width, height, file }, ref) => {
20+
const ReactOnnx = forwardRef(({ width, height, file, direction }, ref) => {
2121
const refIns = useRef(null)
2222
const refFile = useRef(null)
2323

@@ -27,6 +27,13 @@ const ReactOnnx = forwardRef(({ width, height, file }, ref) => {
2727
refIns.current?.start()
2828
}, [])
2929

30+
useEffect(() => {
31+
if (refIns.current && direction) {
32+
refIns.current.setDirection(direction);
33+
}
34+
}, [direction]);
35+
36+
3037
useEffect(() => {
3138
if (file) {
3239
refIns.current?.openByBlob(file)
@@ -39,11 +46,11 @@ const ReactOnnx = forwardRef(({ width, height, file }, ref) => {
3946
}
4047
}, [])
4148

42-
function doOpen () {
49+
function doOpen() {
4350
refFile.current?.click()
4451
}
4552

46-
function doLoadByFile ({ target }) {
53+
function doLoadByFile({ target }) {
4754
const files = Array.from(target.files)
4855
const file = files[0]
4956
refIns.current?.openByFile(file, files)
@@ -53,11 +60,11 @@ const ReactOnnx = forwardRef(({ width, height, file }, ref) => {
5360
return (
5461
<>
5562
<input ref={refFile} type="file" multiple={false} accept=".onnx" onChange={doLoadByFile}
56-
style={{ display: 'none' }}/>
63+
style={{ display: 'none' }} />
5764
<section className={css.onnxGraph} style={{ width: width || '100%', height: height || 400 }}>
5865
<div id="graph" className="graph" tabIndex="0">
5966
<svg id="canvas" className="canvas" preserveAspectRatio="xMidYMid meet" width="100%"
60-
height="100%"></svg>
67+
height="100%"></svg>
6168
</div>
6269
<div id="sidebar" className="sidebar">
6370
<h1 id="sidebar-title" className="sidebar-title"></h1>
@@ -66,20 +73,20 @@ const ReactOnnx = forwardRef(({ width, height, file }, ref) => {
6673
</div>
6774
<div id="toolbar" className="toolbar">
6875
<button id="sidebar-button" className="toolbar-button" title="Model Properties">
69-
<SvgMenu/>
76+
<SvgMenu />
7077
</button>
7178
<button id="zoom-in-button" className="toolbar-button" title="Zoom In">
72-
<SvgZoomIn/>
79+
<SvgZoomIn />
7380
</button>
7481
<button id="zoom-out-button" className="toolbar-button" title="Zoom Out">
75-
<SvgZoomOut/>
82+
<SvgZoomOut />
7683
</button>
7784
<button id="back-button" className="toolbar-back-button" title="Back">
7885
&#x276E;
7986
</button>
80-
<button id="name-button" className="toolbar-name-button" title="Name"/>
87+
<button id="name-button" className="toolbar-name-button" title="Name" />
8188
</div>
82-
<div id="menu" className="menu"/>
89+
<div id="menu" className="menu" />
8390
<div id="menu-button" className="menu-button">&#9776;</div>
8491
</section>
8592
</>

core/src/view.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,29 @@ export class View {
189189
}
190190
}
191191

192+
setDirection(direction) {
193+
if (direction !== 'vertical' && direction !== 'horizontal') {
194+
throw new view.Error('Invalid direction. Must be "vertical" or "horizontal".')
195+
}
196+
if (this._options.direction !== direction) {
197+
this._options.direction = direction
198+
this._reload()
199+
// Persist the setting
200+
const options = {}
201+
for (const entry of Object.entries(this._options)) {
202+
const name = entry[0]
203+
if (this._defaultOptions[name] !== entry[1]) {
204+
options[name] = entry[1]
205+
}
206+
}
207+
if (Object.entries(options).length == 0) {
208+
this._host.delete('configuration', 'options')
209+
} else {
210+
this._host.set('configuration', 'options', options)
211+
}
212+
}
213+
}
214+
192215
openByFile(file, files) {
193216
this._host._open(file, files)
194217
}
@@ -748,9 +771,9 @@ export class View {
748771
if (nodes.length > 2048) {
749772
if (!this._host.confirm('Large model detected.', 'This graph contains a large number of nodes and might take a long time to render. Do you want to continue?')) {
750773
this._host.event('graph_view', {
751-
graph_node_count: nodes.length,
752-
graph_skip: 1,
753-
},
774+
graph_node_count: nodes.length,
775+
graph_skip: 1,
776+
},
754777
)
755778
this.show(null)
756779
return null

0 commit comments

Comments
 (0)