-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
bindings/streamlit-gpt-vis/streamlit_gpt_vis/frontend/src/Render.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from "react" | ||
import { | ||
Streamlit, | ||
withStreamlitConnection, | ||
ComponentProps, | ||
Theme, | ||
} from "streamlit-component-lib" | ||
import { | ||
ConfigProvider, | ||
GPTVis, | ||
VisText, | ||
withDefaultChartCode, | ||
ChartType, | ||
DualAxes, | ||
Radar, | ||
Histogram, | ||
Treemap, | ||
WordCloud, | ||
} from "@antv/gpt-vis" | ||
|
||
const components = { | ||
"vis-text": VisText, | ||
code: withDefaultChartCode({ | ||
components: { | ||
[ChartType.DualAxes]: DualAxes, | ||
[ChartType.Radar]: Radar, | ||
[ChartType.Histogram]: Histogram, | ||
[ChartType.Treemap]: Treemap, | ||
[ChartType.WordCloud]: WordCloud, | ||
}, | ||
loadingTimeout: 5, | ||
debug: false, | ||
}), | ||
} | ||
|
||
const GPTVisRender: React.FC<ComponentProps> = (props) => { | ||
const { theme, args } = props | ||
const { config, content } = args | ||
|
||
const style: React.CSSProperties = {} | ||
|
||
if (theme) { | ||
// Use the theme object to style our button border. Alternatively, the | ||
// theme style is defined in CSS vars. | ||
style.color = theme.textColor | ||
style.font = theme.font | ||
style.backgroundColor = theme.backgroundColor | ||
} | ||
|
||
return ( | ||
<div style={style}> | ||
<ConfigProvider {...config}> | ||
<GPTVis components={components}>{content}</GPTVis> | ||
</ConfigProvider> | ||
</div> | ||
) | ||
} | ||
|
||
export const GPTVisRenderWrapper = withStreamlitConnection(GPTVisRender) |
5 changes: 3 additions & 2 deletions
5
bindings/streamlit-gpt-vis/streamlit_gpt_vis/frontend/src/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import React from "react" | ||
import ReactDOM from "react-dom" | ||
import MyComponent from "./MyComponent" | ||
// import MyComponent from "./MyComponent" | ||
import { GPTVisRenderWrapper } from "./Render" | ||
|
||
ReactDOM.render( | ||
<React.StrictMode> | ||
<MyComponent /> | ||
<GPTVisRenderWrapper /> | ||
</React.StrictMode>, | ||
document.getElementById("root") | ||
) |