Skip to content

Commit

Permalink
feat: add table walker example
Browse files Browse the repository at this point in the history
  • Loading branch information
islxyqwe committed Feb 27, 2024
1 parent 2d34aa1 commit 28a10e2
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 4 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ If you want to use Graphic Walker as a data exploration tool without thinking ab

Use it here: [Graphic Walker Online](https://graphic-walker.kanaries.net)

Examples here: [Graphic Walker Examples](https://graphic-walker.kanaries.net/examples)
Examples here: [Graphic Walker Examples](https://graphic-walker.kanaries.net/examples/)

### Method 1: use as an independent app.
```bash
Expand Down Expand Up @@ -156,6 +156,23 @@ const YourChart: React.FC<IYourChartProps> = props => {
export default YourChart;
```

You can use `TableWalker` component to make a single table view with your data. it accepts same props as `GraphicWalker`, but you don't need to pass the chart prop, and you can control the page size by pageSize prop(default value is 20).

```typescript
import { TableWalker } from '@kanaries/graphic-walker';

const YourChart: React.FC<IYourChartProps> = props => {
const { dataSource, fields, spec } = props;
return <TableWalker
dataSource={dataSource}
rawFields={fields}
pageSize={50}
/>;
}

export default YourChart;
```

### try local (dev mode)
```bash
# packages/graphic-walker
Expand Down
4 changes: 4 additions & 0 deletions packages/playground/src/examples/nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export const pages = [
comp: () => import('./pages/cc'),
name: 'CustomColor',
},
{
comp: () => import('./pages/table'),
name: 'TableWalker',
},
].map((Component) => ({
name: Component.name,
path: Component.name.replace(/\s/g, '_'),
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/src/examples/pages/cc.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const colorConfig: IColorConfig = {

export default function GraphicWalkerComponent() {
const { theme } = useContext(themeContext);
const { dataSource, fields } = useFetch<IDataSource>('https://chspace.oss-cn-hongkong.aliyuncs.com/api/ds-students-service.json');
const { dataSource, fields } = useFetch<IDataSource>('https://pub-2422ed4100b443659f588f2382cfc7b1.r2.dev/datasets/ds-students-service.json');
return (
<div className="bg-amber-100 dark:bg-amber-900 p-4">
<GraphicWalker rawFields={fields} dataSource={dataSource} dark={theme} colorConfig={colorConfig} />
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/src/examples/pages/ds.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function DataSourceSegment() {
const { theme } = useContext(themeContext);
const provider = getProvider();
return (
<DataSourceSegmentComponent provider={provider}>
<DataSourceSegmentComponent dark={theme} provider={provider}>
{(p) => {
return (
<GraphicWalker
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/src/examples/pages/inModal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useFetch, IDataSource } from '../util';
export default function GraphicWalkerInModal() {
const ref = useRef<VizSpecStore>(null);
const { theme } = useContext(themeContext);
const { dataSource, fields } = useFetch<IDataSource>('https://chspace.oss-cn-hongkong.aliyuncs.com/api/ds-students-service.json');
const { dataSource, fields } = useFetch<IDataSource>('https://pub-2422ed4100b443659f588f2382cfc7b1.r2.dev/datasets/ds-students-service.json');

useEffect(() => {
setTimeout(() => {
Expand Down
11 changes: 11 additions & 0 deletions packages/playground/src/examples/pages/table.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useContext } from 'react';
import { TableWalker } from '@kanaries/graphic-walker';
import { themeContext } from '../context';
import { useFetch, IDataSource } from '../util';

export default function GraphicWalkerComponent() {
const { theme } = useContext(themeContext);
const { dataSource, fields } = useFetch<IDataSource>('https://pub-2422ed4100b443659f588f2382cfc7b1.r2.dev/datasets/ds-students-service.json');

return <TableWalker rawFields={fields} dataSource={dataSource} dark={theme} pageSize={50} />;
}
11 changes: 11 additions & 0 deletions packages/playground/src/examples/pages/table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Example from '../components/examplePage';
import code from './table.stories?raw';
import Comp from './table.stories';

export default function GraphicWalkerComponent() {
return (
<Example name="TableWalker" code={code}>
<Comp />
</Example>
);
}

0 comments on commit 28a10e2

Please sign in to comment.