diff --git a/core/src/index.jsx b/core/src/index.jsx
index 237fa67..6ffc960 100644
--- a/core/src/index.jsx
+++ b/core/src/index.jsx
@@ -4,7 +4,7 @@ import { View } from './view'
import css from './index.module.scss'
import { SvgMenu, SvgZoomIn, SvgZoomOut } from './icon'
-export function useOnnx (url) {
+export function useOnnx(url) {
const [data, setData] = useState(null)
useEffect(() => {
console.log(url)
@@ -17,7 +17,7 @@ export function useOnnx (url) {
return data
}
-const ReactOnnx = forwardRef(({ width, height, file }, ref) => {
+const ReactOnnx = forwardRef(({ width, height, file, direction }, ref) => {
const refIns = useRef(null)
const refFile = useRef(null)
@@ -27,6 +27,13 @@ const ReactOnnx = forwardRef(({ width, height, file }, ref) => {
refIns.current?.start()
}, [])
+ useEffect(() => {
+ if (refIns.current && direction) {
+ refIns.current.setDirection(direction);
+ }
+ }, [direction]);
+
+
useEffect(() => {
if (file) {
refIns.current?.openByBlob(file)
@@ -39,11 +46,11 @@ const ReactOnnx = forwardRef(({ width, height, file }, ref) => {
}
}, [])
- function doOpen () {
+ function doOpen() {
refFile.current?.click()
}
- function doLoadByFile ({ target }) {
+ function doLoadByFile({ target }) {
const files = Array.from(target.files)
const file = files[0]
refIns.current?.openByFile(file, files)
@@ -53,11 +60,11 @@ const ReactOnnx = forwardRef(({ width, height, file }, ref) => {
return (
<>
+ style={{ display: 'none' }} />
+ height="100%">
-
+
-
+
>
diff --git a/core/src/view.js b/core/src/view.js
index c86d4a9..cfeacc2 100644
--- a/core/src/view.js
+++ b/core/src/view.js
@@ -189,6 +189,29 @@ export class View {
}
}
+ setDirection(direction) {
+ if (direction !== 'vertical' && direction !== 'horizontal') {
+ throw new view.Error('Invalid direction. Must be "vertical" or "horizontal".')
+ }
+ if (this._options.direction !== direction) {
+ this._options.direction = direction
+ this._reload()
+ // Persist the setting
+ const options = {}
+ for (const entry of Object.entries(this._options)) {
+ const name = entry[0]
+ if (this._defaultOptions[name] !== entry[1]) {
+ options[name] = entry[1]
+ }
+ }
+ if (Object.entries(options).length == 0) {
+ this._host.delete('configuration', 'options')
+ } else {
+ this._host.set('configuration', 'options', options)
+ }
+ }
+ }
+
openByFile(file, files) {
this._host._open(file, files)
}
@@ -748,9 +771,9 @@ export class View {
if (nodes.length > 2048) {
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?')) {
this._host.event('graph_view', {
- graph_node_count: nodes.length,
- graph_skip: 1,
- },
+ graph_node_count: nodes.length,
+ graph_skip: 1,
+ },
)
this.show(null)
return null