@kanaries/graphic-walker 0.2.19 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/pivotTable/index.d.ts +1 -0
- package/dist/components/pivotTable/inteface.d.ts +13 -0
- package/dist/components/pivotTable/leftTree.d.ts +7 -0
- package/dist/components/pivotTable/store.d.ts +24 -0
- package/dist/components/pivotTable/topTree.d.ts +7 -0
- package/dist/components/pivotTable/utils.d.ts +4 -0
- package/dist/graphic-walker.es.js +1 -1
- package/dist/graphic-walker.es.js.map +1 -1
- package/dist/graphic-walker.umd.js +1 -1
- package/dist/graphic-walker.umd.js.map +1 -1
- package/dist/main.d.ts +1 -1
- package/package.json +3 -3
- package/src/components/pivotTable/index.tsx +40 -0
- package/src/components/pivotTable/inteface.ts +12 -0
- package/src/components/pivotTable/leftTree.tsx +11 -0
- package/src/components/pivotTable/store.tsx +65 -0
- package/src/components/pivotTable/topTree.tsx +11 -0
- package/src/components/pivotTable/utils.ts +37 -0
- package/src/main.tsx +24 -11
- package/src/models/visSpecHistory.ts +1 -0
package/dist/main.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import './index.css';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanaries/graphic-walker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev:front_end": "vite --host",
|
|
6
6
|
"dev": "npm run dev:front_end",
|
|
@@ -70,8 +70,8 @@
|
|
|
70
70
|
"vite": "^4.1.1"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
|
-
"react": "
|
|
74
|
-
"react-dom": "
|
|
73
|
+
"react": ">=17.0.0 <19.0.0",
|
|
74
|
+
"react-dom": ">=17.0.0 <19.0.0",
|
|
75
75
|
"styled-components": "^5.3.6"
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StoreWrapper, useGlobalStore } from '../../store';
|
|
3
|
+
import { PivotTableDataProps, PivotTableStoreWrapper, usePivotTableStore } from './store';
|
|
4
|
+
import { observer } from 'mobx-react-lite';
|
|
5
|
+
import LeftTree from './leftTree';
|
|
6
|
+
import TopTree from './topTree';
|
|
7
|
+
|
|
8
|
+
interface PivotTableProps extends PivotTableDataProps {}
|
|
9
|
+
const PivotTable: React.FC = observer((props) => {
|
|
10
|
+
const store = usePivotTableStore();
|
|
11
|
+
const { vizStore } = useGlobalStore();
|
|
12
|
+
const { draggableFieldState } = vizStore;
|
|
13
|
+
const { rows, columns } = draggableFieldState;
|
|
14
|
+
|
|
15
|
+
const { leftTree, topTree, metricTable } = store;
|
|
16
|
+
return (
|
|
17
|
+
<div>
|
|
18
|
+
<div>
|
|
19
|
+
<h1>left</h1>
|
|
20
|
+
{leftTree && <LeftTree data={leftTree} />}
|
|
21
|
+
</div>
|
|
22
|
+
<div>
|
|
23
|
+
<h1>top</h1>
|
|
24
|
+
{topTree && <TopTree data={topTree} />}
|
|
25
|
+
</div>
|
|
26
|
+
<div>
|
|
27
|
+
<h1>metric</h1>
|
|
28
|
+
<code>{JSON.stringify(metricTable, null, 2)}</code>
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const PivotTableApp: React.FC<PivotTableProps> = (props) => {
|
|
35
|
+
return (
|
|
36
|
+
<PivotTableStoreWrapper {...props}>
|
|
37
|
+
<PivotTable />
|
|
38
|
+
</PivotTableStoreWrapper>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IAggregator } from "../../interfaces";
|
|
2
|
+
|
|
3
|
+
export interface INestNode {
|
|
4
|
+
key: string;
|
|
5
|
+
value: string;
|
|
6
|
+
children: INestNode[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface IGroupByQuery {
|
|
10
|
+
groupBy: string[];
|
|
11
|
+
measures: { field: string; agg: IAggregator }[];
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { INestNode } from './inteface';
|
|
3
|
+
|
|
4
|
+
export interface TreeProps {
|
|
5
|
+
data: INestNode;
|
|
6
|
+
}
|
|
7
|
+
const LeftTree: React.FC<TreeProps> = (props) => {
|
|
8
|
+
return <div>{JSON.stringify(props.data)}</div>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default LeftTree;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { makeAutoObservable, observable } from 'mobx';
|
|
2
|
+
import { IGroupByQuery, INestNode } from './inteface';
|
|
3
|
+
import { IAggQuery } from '../../lib/interfaces';
|
|
4
|
+
import { queryView } from '../../lib/viewQuery';
|
|
5
|
+
import { IField, IRow } from '../../interfaces';
|
|
6
|
+
import React, { createContext, useContext, useEffect } from 'react';
|
|
7
|
+
|
|
8
|
+
class PivotTableStore {
|
|
9
|
+
public leftTree: INestNode | null = null;
|
|
10
|
+
public topTree: INestNode | null = null;
|
|
11
|
+
public metricTable: any[][] = [];
|
|
12
|
+
public dataSource: IRow[] = [];
|
|
13
|
+
public metas: IField[] = [];
|
|
14
|
+
public viewData: IRow[] = [];
|
|
15
|
+
constructor() {
|
|
16
|
+
makeAutoObservable(this, {
|
|
17
|
+
leftTree: observable.ref,
|
|
18
|
+
topTree: observable.ref,
|
|
19
|
+
metricTable: observable.ref,
|
|
20
|
+
dataSource: observable.ref,
|
|
21
|
+
metas: observable.ref,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
public init(dataSource: IRow[], metas: IField[]) {
|
|
25
|
+
this.dataSource = dataSource ?? [];
|
|
26
|
+
this.metas = metas ?? [];
|
|
27
|
+
this.leftTree = null;
|
|
28
|
+
this.metricTable = [];
|
|
29
|
+
this.topTree = null;
|
|
30
|
+
this.viewData = [];
|
|
31
|
+
}
|
|
32
|
+
public createTree(query: IGroupByQuery, viewData: IRow[]) {}
|
|
33
|
+
|
|
34
|
+
public createTopTree(query: IGroupByQuery, viewData) {}
|
|
35
|
+
public createLeftTree(query: IGroupByQuery, viewData) {}
|
|
36
|
+
public async queryData(leftQuery: IGroupByQuery, topQuery: IGroupByQuery) {
|
|
37
|
+
const viewQuery: IAggQuery = {
|
|
38
|
+
op: 'aggregate',
|
|
39
|
+
groupBy: leftQuery.groupBy.concat(topQuery.groupBy),
|
|
40
|
+
agg: Object.fromEntries(leftQuery.measures.concat(topQuery.measures).map((mea) => [mea.field, mea.agg])),
|
|
41
|
+
};
|
|
42
|
+
const viewData = queryView(this.dataSource, this.metas, viewQuery);
|
|
43
|
+
this.viewData = viewData;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const initStore = new PivotTableStore();
|
|
48
|
+
const PTContext = createContext<PivotTableStore>(initStore);
|
|
49
|
+
|
|
50
|
+
export interface PivotTableDataProps {
|
|
51
|
+
data: IRow[];
|
|
52
|
+
metas: IField[];
|
|
53
|
+
}
|
|
54
|
+
export const PivotTableStoreWrapper: React.FC<PivotTableDataProps> = (props) => {
|
|
55
|
+
const { data, metas } = props;
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
initStore.init(data, metas);
|
|
58
|
+
}, [data, metas]);
|
|
59
|
+
return <PTContext.Provider value={initStore}>{props.children}</PTContext.Provider>;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
export function usePivotTableStore () {
|
|
64
|
+
return useContext(PTContext)
|
|
65
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { INestNode } from './inteface';
|
|
3
|
+
|
|
4
|
+
export interface TreeProps {
|
|
5
|
+
data: INestNode;
|
|
6
|
+
}
|
|
7
|
+
const TopTree: React.FC<TreeProps> = (props) => {
|
|
8
|
+
return <div>{JSON.stringify(props.data)}</div>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default TopTree;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { IRow } from "../../interfaces";
|
|
2
|
+
import { INestNode } from "./inteface";
|
|
3
|
+
|
|
4
|
+
const key_prefix = 'nk_';
|
|
5
|
+
|
|
6
|
+
export function insertNode (tree: INestNode, layerKeys: string[], nodeData: IRow, depth: number) {
|
|
7
|
+
if (depth === layerKeys.length - 1) {
|
|
8
|
+
// tree.key = nodeData[layerKeys[depth]];
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const key = nodeData[layerKeys[depth]];
|
|
12
|
+
let child = tree.children.find((c) => c.key === key);
|
|
13
|
+
if (!child) {
|
|
14
|
+
// insertNode(child, layerKeys, nodeData, depth + 1);
|
|
15
|
+
// return;
|
|
16
|
+
child = {
|
|
17
|
+
key: `${key_prefix}${key}`,
|
|
18
|
+
value: key,
|
|
19
|
+
children: [],
|
|
20
|
+
}
|
|
21
|
+
tree.children.push(child);
|
|
22
|
+
}
|
|
23
|
+
insertNode(child, layerKeys, nodeData, depth + 1);
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function buildNestTree (layerKeys: string[], data: IRow[]): INestNode {
|
|
28
|
+
const tree: INestNode = {
|
|
29
|
+
key: 'root',
|
|
30
|
+
value: 'root',
|
|
31
|
+
children: [],
|
|
32
|
+
};
|
|
33
|
+
for (let row of data) {
|
|
34
|
+
insertNode(tree, layerKeys, row, 0);
|
|
35
|
+
}
|
|
36
|
+
return tree;
|
|
37
|
+
}
|
package/src/main.tsx
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import ReactDOM from
|
|
3
|
-
import { GraphicWalker } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import { GraphicWalker } from './index';
|
|
4
4
|
|
|
5
|
-
import { inject } from
|
|
6
|
-
import
|
|
5
|
+
import { inject } from '@vercel/analytics';
|
|
6
|
+
import './index.css';
|
|
7
7
|
|
|
8
8
|
if (!import.meta.env.DEV) {
|
|
9
9
|
inject();
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
)
|
|
12
|
+
// Example: Detect if Concurrent Mode is available
|
|
13
|
+
const isConcurrentModeAvailable = 'createRoot' in ReactDOM;
|
|
14
|
+
|
|
15
|
+
// Use the new ReactDOM.createRoot API if available, otherwise fall back to the old ReactDOM.render API
|
|
16
|
+
if (isConcurrentModeAvailable) {
|
|
17
|
+
if (import.meta.env.DEV) {
|
|
18
|
+
console.warn('React 18+ detected, remove strict mode if you meet drag and drop issue. more info at https://docs.kanaries.net/graphic-walker/faq/graphic-walker-react-18')
|
|
19
|
+
}
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
|
|
22
|
+
root.render(<GraphicWalker themeKey="g2" />);
|
|
23
|
+
} else {
|
|
24
|
+
ReactDOM.render(
|
|
25
|
+
<React.StrictMode>
|
|
26
|
+
<GraphicWalker themeKey="g2" />
|
|
27
|
+
</React.StrictMode>,
|
|
28
|
+
document.getElementById('root') as HTMLElement
|
|
29
|
+
);
|
|
30
|
+
}
|