Skip to content

Commit 892d73e

Browse files
committed
feat(book): add packages readme
1 parent 11d4ff2 commit 892d73e

File tree

4 files changed

+263
-39
lines changed

4 files changed

+263
-39
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# hedgehog Canvas Components
2+
3+
This package can be used to render the output of the hedgehog compiler result easily.
4+
5+
## Installation
6+
7+
```bash
8+
yarn install @hedgehogcomputing/canvas
9+
# or
10+
npm install @hedgehogcomputing/canvas
11+
```
12+
13+
## Usage
14+
15+
> `outputItem` is the output of the hedgehog compiler(hedgehog-core)
16+
17+
```jsx
18+
import Output from "@hedgehogcomputing/canvas/src/Output";
19+
20+
const Results = () => {
21+
return (
22+
<>
23+
<Output outputItemList={outputItem}/>
24+
</>
25+
)
26+
}
27+
```
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Hedgehog Core components
2+
3+
This package provides a simple way to run Hedgehog compiler in your application.
4+
5+
> We recommend to use hedgehog-canvas, the canvas package provides a one component to render the core result.
6+
7+
## Installation
8+
9+
```bash
10+
yarn install @hedgehogcomputing/core
11+
# or
12+
npm install @hedgehogcomputing/core
13+
```
14+
15+
## Full example
16+
17+
```tsx
18+
import React from 'react';
19+
import ReactECharts from 'echarts-for-react';
20+
import Plot from 'react-plotly.js';
21+
import MathJax from 'react-mathjax';
22+
import Markdown from 'react-markdown';
23+
import {
24+
isDrawingItem,
25+
isEChartItem,
26+
isFormulaItem,
27+
isMarkdownItem,
28+
isTableItem,
29+
isTeXItem,
30+
isTextItem,
31+
OutputItem
32+
} from '@hedgehogcomputing/core';
33+
import type {CodeComponent} from 'react-markdown/src/ast-to-react'
34+
import {Prism as SyntaxHighlighter} from 'react-syntax-highlighter'
35+
import TableComponent from "@hedgehogcomputing/website/src/components/Results/OutputItemCompoments/TableComponent";
36+
37+
type CodeProps = Parameters<CodeComponent>[0]
38+
39+
const Output = ({outputItemList}: { outputItemList: OutputItem[] }): React.ReactElement => {
40+
41+
const items = outputItemList.map((item) => {
42+
if (isDrawingItem(item)) {
43+
const actualLayout = item.layout === undefined ? {} : item.layout;
44+
//@ts-ignore
45+
return <Plot
46+
data={JSON.parse(JSON.stringify(item.data))}
47+
layout={JSON.parse(JSON.stringify(actualLayout))}
48+
/>
49+
} else if (isTeXItem(item)) {
50+
return (
51+
//@ts-ignore
52+
<MathJax.Provider>
53+
<div>
54+
<MathJax.Node inline formula={item.text}/>
55+
</div>
56+
</MathJax.Provider>
57+
);
58+
} else if (isFormulaItem(item)) {
59+
return (
60+
//@ts-ignore
61+
<MathJax.Provider>
62+
<div>
63+
<MathJax.Node formula={item.text}/>
64+
</div>
65+
</MathJax.Provider>
66+
);
67+
} else if (isMarkdownItem(item)) {
68+
return <Markdown components={{
69+
code({node, inline, className, children, ...props}: CodeProps): React.ReactElement {
70+
const match = /language-(\w+)/.exec(className || '')
71+
return !inline && match ? (
72+
//@ts-ignore
73+
<SyntaxHighlighter
74+
language={match[1]}
75+
customStyle={{backgroundColor: 'transparent'}}
76+
PreTag="div" {...props as any} >
77+
{String(children).replace(/\n$/, '')}
78+
</SyntaxHighlighter>
79+
) : (
80+
<code className={className} {...props}>
81+
{children}
82+
</code>
83+
)
84+
}
85+
}}>{item.text}</Markdown>;
86+
} else if (isTableItem(item)) {
87+
return <TableComponent tableItem={item}/>;
88+
} else if (isEChartItem(item)) {
89+
//@ts-ignore
90+
return <ReactECharts option={item.option}/>
91+
} else if (isTextItem(item)) {
92+
return <div>{item.text}</div>;
93+
} else {
94+
return <React.Fragment/>;
95+
}
96+
});
97+
98+
return (
99+
<>
100+
{items.map((item, index) => (
101+
<React.Fragment key={index}>{item}</React.Fragment>
102+
))}
103+
</>
104+
);
105+
};
106+
107+
export default Output;
108+
```

packages/hedgehog-canvas/README.md

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,27 @@
1-
# Getting Started with Create React App
1+
# hedgehog Canvas Components
22

3-
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
3+
This package can be used to render the output of the hedgehog compiler result easily.
44

5-
## Available Scripts
5+
## Installation
66

7-
In the project directory, you can run:
7+
```bash
8+
yarn install @hedgehogcomputing/canvas
9+
# or
10+
npm install @hedgehogcomputing/canvas
11+
```
812

9-
### `npm start`
13+
## Usage
1014

11-
Runs the app in the development mode.\
12-
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
15+
> `outputItem` is the output of the hedgehog compiler(hedgehog-core)
1316
14-
The page will reload if you make edits.\
15-
You will also see any lint errors in the console.
17+
```jsx
18+
import Output from "@hedgehogcomputing/canvas/src/Output";
1619

17-
### `npm test`
18-
19-
Launches the test runner in the interactive watch mode.\
20-
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21-
22-
### `npm run build`
23-
24-
Builds the app for production to the `build` folder.\
25-
It correctly bundles React in production mode and optimizes the build for the best performance.
26-
27-
The build is minified and the filenames include the hashes.\
28-
Your app is ready to be deployed!
29-
30-
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31-
32-
### `npm run eject`
33-
34-
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
35-
36-
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37-
38-
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
39-
40-
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
41-
42-
## Learn More
43-
44-
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45-
46-
To learn React, check out the [React documentation](https://reactjs.org/).
20+
const Results = () => {
21+
return (
22+
<>
23+
<Output outputItemList={outputItem}/>
24+
</>
25+
)
26+
}
27+
```

packages/hedgehog-core/readme.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Hedgehog Core package
2+
3+
This package provides a simple way to run Hedgehog compiler in your application.
4+
5+
> We recommend to use hedgehog-canvas, the canvas package provides a one component to render the core result.
6+
>
7+
## Installation
8+
9+
```bash
10+
yarn install @hedgehogcomputing/core
11+
# or
12+
npm install @hedgehogcomputing/core
13+
```
14+
15+
## Full example
16+
17+
```tsx
18+
import React from 'react';
19+
import ReactECharts from 'echarts-for-react';
20+
import Plot from 'react-plotly.js';
21+
import MathJax from 'react-mathjax';
22+
import Markdown from 'react-markdown';
23+
import {
24+
isDrawingItem,
25+
isEChartItem,
26+
isFormulaItem,
27+
isMarkdownItem,
28+
isTableItem,
29+
isTeXItem,
30+
isTextItem,
31+
OutputItem
32+
} from '@hedgehogcomputing/core';
33+
import type {CodeComponent} from 'react-markdown/src/ast-to-react'
34+
import {Prism as SyntaxHighlighter} from 'react-syntax-highlighter'
35+
import TableComponent from "@hedgehogcomputing/website/src/components/Results/OutputItemCompoments/TableComponent";
36+
37+
type CodeProps = Parameters<CodeComponent>[0]
38+
39+
const Output = ({outputItemList}: { outputItemList: OutputItem[] }): React.ReactElement => {
40+
41+
const items = outputItemList.map((item) => {
42+
if (isDrawingItem(item)) {
43+
const actualLayout = item.layout === undefined ? {} : item.layout;
44+
//@ts-ignore
45+
return <Plot
46+
data={JSON.parse(JSON.stringify(item.data))}
47+
layout={JSON.parse(JSON.stringify(actualLayout))}
48+
/>
49+
} else if (isTeXItem(item)) {
50+
return (
51+
//@ts-ignore
52+
<MathJax.Provider>
53+
<div>
54+
<MathJax.Node inline formula={item.text}/>
55+
</div>
56+
</MathJax.Provider>
57+
);
58+
} else if (isFormulaItem(item)) {
59+
return (
60+
//@ts-ignore
61+
<MathJax.Provider>
62+
<div>
63+
<MathJax.Node formula={item.text}/>
64+
</div>
65+
</MathJax.Provider>
66+
);
67+
} else if (isMarkdownItem(item)) {
68+
return <Markdown components={{
69+
code({node, inline, className, children, ...props}: CodeProps): React.ReactElement {
70+
const match = /language-(\w+)/.exec(className || '')
71+
return !inline && match ? (
72+
//@ts-ignore
73+
<SyntaxHighlighter
74+
language={match[1]}
75+
customStyle={{backgroundColor: 'transparent'}}
76+
PreTag="div" {...props as any} >
77+
{String(children).replace(/\n$/, '')}
78+
</SyntaxHighlighter>
79+
) : (
80+
<code className={className} {...props}>
81+
{children}
82+
</code>
83+
)
84+
}
85+
}}>{item.text}</Markdown>;
86+
} else if (isTableItem(item)) {
87+
return <TableComponent tableItem={item}/>;
88+
} else if (isEChartItem(item)) {
89+
//@ts-ignore
90+
return <ReactECharts option={item.option}/>
91+
} else if (isTextItem(item)) {
92+
return <div>{item.text}</div>;
93+
} else {
94+
return <React.Fragment/>;
95+
}
96+
});
97+
98+
return (
99+
<>
100+
{items.map((item, index) => (
101+
<React.Fragment key={index}>{item}</React.Fragment>
102+
))}
103+
</>
104+
);
105+
};
106+
107+
export default Output;
108+
```

0 commit comments

Comments
 (0)