Skip to content

Commit d4dc873

Browse files
committed
doc init
1 parent abec2c7 commit d4dc873

File tree

20 files changed

+7931
-701
lines changed

20 files changed

+7931
-701
lines changed

.github/workflows/my-pipeline.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: my-pipeline
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
branches:
8+
- main
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
build:
16+
name: Deploy to GitHub Pages
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: checkout
21+
uses: actions/checkout@v3
22+
#with:
23+
# submodules: true # Fetch Hugo themes (true OR recursive)
24+
# fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
25+
26+
- uses: actions/setup-node@v3
27+
with:
28+
node-version: 18
29+
cache: yarn
30+
- name: Install dependencies
31+
run: yarn install --frozen-lockfile
32+
33+
- name: build
34+
run: yarn build
35+
36+
- name: deploy
37+
uses: peaceiris/actions-gh-pages@v3
38+
with:
39+
github_token: ${{ secrets.GITHUB_TOKEN }}
40+
publish_dir: ./build
41+
# cname: wolanx.com

README.md

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,45 @@
11
# react-netron
22

3-
> Inspired by netron. In the react project and need to load the onnx file for display. So this project was created.
3+
> netron via react
44
5+
- Demo https://wolanx.github.io/react-netron
6+
- Docs https://wolanx.github.io/react-netron/docs/intro
57

6-
# Install
8+
# Intro
79

8-
`npm i @wolanx/react-netron`
10+
View Neural Network model with graphs.
911

10-
# Demo
11-
12-
- Homepage https://wolanx.github.io/react-netron/
12+
## Install
13+
14+
```shell
15+
# https://www.npmjs.com/package/@wolanx/react-netron
16+
npm i @wolanx/react-netron
17+
```
18+
19+
## Prepare file
20+
21+
- download https://github.com/onnx/models/blob/main/vision/classification/mnist/model/mnist-12.onnx
22+
23+
## Demo - open with button
1324

1425
```jsx
15-
// open with button
1626
export default function Demo1 () {
17-
return <ReactOnnx width={1000} height={400} openSlot={<Button>Open Model...</Button>}/>
27+
const ref = useRef(null)
28+
29+
return (
30+
<div>
31+
<button onClick={() => ref.current?.open()}>Open Model...</button>
32+
<ReactOnnx ref={ref} width={'100%'} height={600} file={null}/>
33+
</div>
34+
)
1835
}
36+
```
1937
20-
// open with link
38+
## Demo - open with link
39+
40+
```jsx
2141
export default function Demo2 () {
22-
const file = useOnnx('/model/ann.onnx')
23-
return <ReactOnnx width={1000} height={400} file={file}/>
42+
const file = useOnnx('./model/demo.onnx')
43+
return <ReactOnnx width={'100%'} height={600} file={file}/>
2444
}
2545
```

core/README.md

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,45 @@
11
# react-netron
22

3-
> Inspired by netron. In the react project and need to load the onnx file for display. So this project was created.
3+
> netron via react
4+
5+
- Demo https://wolanx.github.io/react-netron
6+
- Docs https://wolanx.github.io/react-netron/docs/intro
7+
8+
# Intro
9+
10+
View Neural Network model with graphs.
11+
12+
## Install
13+
14+
```shell
15+
# https://www.npmjs.com/package/@wolanx/react-netron
16+
npm i @wolanx/react-netron
17+
```
18+
19+
## Prepare file
20+
21+
- download https://github.com/onnx/models/blob/main/vision/classification/mnist/model/mnist-12.onnx
22+
23+
## Demo - open with button
424

525
```jsx
6-
// open with button
7-
export default function Demo1() {
8-
return <ReactOnnx width={1000} height={400} openSlot={<Button>Open Model...</Button>}/>
26+
export default function Demo1 () {
27+
const ref = useRef(null)
28+
29+
return (
30+
<div>
31+
<button onClick={() => ref.current?.open()}>Open Model...</button>
32+
<ReactOnnx ref={ref} width={'100%'} height={600} file={null}/>
33+
</div>
34+
)
935
}
36+
```
37+
38+
## Demo - open with link
1039
11-
// open with link
12-
export default function Demo2() {
13-
const file = useOnnx('/model/ann.onnx')
14-
return <ReactOnnx width={1000} height={400} file={file}/>
40+
```jsx
41+
export default function Demo2 () {
42+
const file = useOnnx('./model/demo.onnx')
43+
return <ReactOnnx width={'100%'} height={600} file={file}/>
1544
}
1645
```

core/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "@wolanx/react-netron",
3-
"version": "1.0.3",
3+
"version": "1.0.5",
44
"keywords": [
55
"netron",
6-
"onnx"
6+
"onnx",
7+
"react"
78
],
8-
"description": "view onnx file",
9+
"description": "View Neural Network model with graphs.",
910
"main": "dist/index.js",
1011
"files": [
1112
"README.md",
@@ -14,7 +15,7 @@
1415
"scripts": {
1516
"build": "node esbuild.mjs",
1617
"publish": "npm publish --access public",
17-
"unpublish": "npm unpublish @wolanx/[email protected].2"
18+
"unpublish": "npm unpublish @wolanx/[email protected].1"
1819
},
1920
"dependencies": {
2021
},

core/src/browser.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ export class BrowserHost {
77
this._navigator = window.navigator
88
this._document = window.document
99
this._telemetry = new base.Telemetry(this._window)
10-
this._window.eval = () => {
11-
throw new Error('window.eval() not supported.')
12-
}
10+
1311
this._meta = {}
1412
for (const element of Array.from(this._document.getElementsByTagName('meta'))) {
1513
if (element.name !== undefined && element.content !== undefined) {
@@ -84,10 +82,6 @@ export class BrowserHost {
8482
}
8583
const telemetry = async () => {
8684
if (this._environment.packaged) {
87-
this._window.addEventListener('error', (event) => {
88-
const error = event instanceof ErrorEvent && event.error && event.error instanceof Error ? event.error : new Error(event && event.message ? event.message : JSON.stringify(event))
89-
this.exception(error, true)
90-
})
9185
const ga4 = async () => {
9286
const measurement_id = '848W2NVWVH'
9387
const user = this._getCookie('_ga').replace(/^(GA1\.\d\.)*/, '')

core/src/index.jsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import React, { useEffect, useRef, useState } from 'react'
1+
import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react'
22
import { BrowserHost } from './browser'
33
import { View } from './view'
44
import css from './index.module.scss'
55
import { SvgMenu, SvgZoomIn, SvgZoomOut } from './icon'
66

7-
8-
export function useOnnx(url) {
7+
export function useOnnx (url) {
98
const [data, setData] = useState(null)
109
useEffect(() => {
1110
console.log(url)
@@ -18,7 +17,7 @@ export function useOnnx(url) {
1817
return data
1918
}
2019

21-
export default function ReactOnnx({ width, height, file, openSlot }) {
20+
const ReactOnnx = forwardRef(({ width, height, file }, ref) => {
2221
const refIns = useRef(null)
2322
const refFile = useRef(null)
2423

@@ -34,11 +33,17 @@ export default function ReactOnnx({ width, height, file, openSlot }) {
3433
}
3534
}, [file])
3635

37-
function doOpen() {
36+
useImperativeHandle(ref, () => {
37+
return {
38+
open: doOpen,
39+
}
40+
}, [])
41+
42+
function doOpen () {
3843
refFile.current?.click()
3944
}
4045

41-
function doLoadByFile({ target }) {
46+
function doLoadByFile ({ target }) {
4247
const files = Array.from(target.files)
4348
const file = files[0]
4449
refIns.current?.openByFile(file, files)
@@ -47,7 +52,6 @@ export default function ReactOnnx({ width, height, file, openSlot }) {
4752
// onClick={doOpen}
4853
return (
4954
<>
50-
{openSlot && React.cloneElement(openSlot, { onClick: doOpen })}
5155
<input ref={refFile} type="file" multiple={false} accept=".onnx" onChange={doLoadByFile}
5256
style={{ display: 'none' }}/>
5357
<section className={css.onnxGraph} style={{ width: width || '100%', height: height || 400 }}>
@@ -80,4 +84,6 @@ export default function ReactOnnx({ width, height, file, openSlot }) {
8084
</section>
8185
</>
8286
)
83-
}
87+
})
88+
89+
export default ReactOnnx

core/src/view.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class View {
2020
weights: true,
2121
attributes: false,
2222
names: false,
23-
direction: 'vertical',
23+
direction: 'horizontal',
2424
mousewheel: 'scroll',
2525
}
2626
this._options = Object.assign({}, this._defaultOptions)
@@ -209,7 +209,7 @@ export class View {
209209
}
210210

211211
let buffer = await blob.arrayBuffer()
212-
console.log(buffer)
212+
// console.log(buffer)
213213
this.open(new _BlobCtn(buffer))
214214
}
215215

docs/intro.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,46 @@
22
sidebar_position: 1
33
---
44

5-
# Tutorial Intro
5+
# react-netron
66

7-
Let's discover **Docusaurus in less than 5 minutes**.
7+
> netron via react
88
9-
## Getting Started
9+
- Demo https://wolanx.github.io/react-netron
10+
- Docs https://wolanx.github.io/react-netron/docs/intro
1011

11-
Get started by **creating a new site**.
12+
# Intro
1213

13-
Or **try Docusaurus immediately** with **[docusaurus.new](https://docusaurus.new)**.
14+
## Install
1415

15-
### What you'll need
16-
17-
- [Node.js](https://nodejs.org/en/download/) version 16.14 or above:
18-
- When installing Node.js, you are recommended to check all checkboxes related to dependencies.
19-
20-
## Generate a new site
21-
22-
Generate a new Docusaurus site using the **classic template**.
23-
24-
The classic template will automatically be added to your project after you run the command:
25-
26-
```bash
27-
npm init docusaurus@latest my-website classic
16+
```shell
17+
# https://www.npmjs.com/package/@wolanx/react-netron
18+
npm i @wolanx/react-netron
2819
```
2920

30-
You can type this command into Command Prompt, Powershell, Terminal, or any other integrated terminal of your code editor.
21+
## Prepare file
3122

32-
The command also installs all necessary dependencies you need to run Docusaurus.
23+
- download https://github.com/onnx/models/blob/main/vision/classification/mnist/model/mnist-12.onnx
3324

34-
## Start your site
25+
## Demo - open with button
3526

36-
Run the development server:
27+
```jsx
28+
export default function Demo1 () {
29+
const ref = useRef(null)
3730

38-
```bash
39-
cd my-website
40-
npm run start
31+
return (
32+
<div>
33+
<button onClick={() => ref.current?.open()}>Open Model...</button>
34+
<ReactOnnx ref={ref} width={'100%'} height={600} file={null}/>
35+
</div>
36+
)
37+
}
4138
```
4239
43-
The `cd` command changes the directory you're working with. In order to work with your newly created Docusaurus site, you'll need to navigate the terminal there.
44-
45-
The `npm run start` command builds your website locally and serves it through a development server, ready for you to view at http://localhost:3000/.
40+
## Demo - open with link
4641
47-
Open `docs/intro.md` (this page) and edit some lines: the site **reloads automatically** and displays your changes.
42+
```jsx
43+
export default function Demo2 () {
44+
const file = useOnnx('./model/demo.onnx')
45+
return <ReactOnnx width={'100%'} height={600} file={file}/>
46+
}
47+
```

0 commit comments

Comments
 (0)