@kanaries/graphic-walker 0.3.1 → 0.3.2

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.
@@ -1,65 +0,0 @@
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
- }
@@ -1,11 +0,0 @@
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;
@@ -1,37 +0,0 @@
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
- }