@kanaries/graphic-walker 0.3.15 → 0.4.0
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/App.d.ts +9 -2
- package/dist/assets/filter.worker-f09fcd6f.js.map +1 -1
- package/dist/assets/sort.worker-f77540ac.js.map +1 -0
- package/dist/assets/transform.worker-bae8e910.js.map +1 -0
- package/dist/assets/{viewQuery.worker-03404216.js.map → viewQuery.worker-bdb6477c.js.map} +1 -1
- package/dist/components/askViz/index.d.ts +6 -0
- package/dist/components/askViz/schemaTransform.d.ts +2 -0
- package/dist/components/dataTable/index.d.ts +8 -5
- package/dist/components/limitSetting.d.ts +5 -0
- package/dist/components/pivotTable/store.d.ts +0 -2
- package/dist/components/spinner.d.ts +2 -0
- package/dist/computation/clientComputation.d.ts +3 -0
- package/dist/computation/serverComputation.d.ts +8 -0
- package/dist/config.d.ts +3 -1
- package/dist/fields/filterField/tabs.d.ts +2 -1
- package/dist/graphic-walker.es.js +16181 -15523
- package/dist/graphic-walker.es.js.map +1 -1
- package/dist/graphic-walker.umd.js +144 -144
- package/dist/graphic-walker.umd.js.map +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/interfaces.d.ts +93 -4
- package/dist/lib/execExp.d.ts +4 -4
- package/dist/lib/interfaces.d.ts +1 -0
- package/dist/lib/viewQuery.d.ts +2 -2
- package/dist/renderer/hooks.d.ts +10 -4
- package/dist/renderer/index.d.ts +2 -1
- package/dist/renderer/pureRenderer.d.ts +17 -1
- package/dist/renderer/specRenderer.d.ts +1 -0
- package/dist/services.d.ts +8 -4
- package/dist/store/commonStore.d.ts +2 -2
- package/dist/store/visualSpecStore.d.ts +58 -40
- package/dist/utils/save.d.ts +10 -2
- package/dist/utils/workflow.d.ts +3 -0
- package/dist/vis/react-vega.d.ts +3 -1
- package/dist/workers/sort.d.ts +2 -0
- package/dist/workers/sort.worker.d.ts +1 -0
- package/dist/workers/transform.d.ts +5 -2
- package/package.json +2 -2
- package/src/App.tsx +46 -7
- package/src/components/askViz/index.tsx +92 -0
- package/src/components/askViz/schemaTransform.ts +38 -0
- package/src/components/dataTable/index.tsx +51 -11
- package/src/components/limitSetting.tsx +38 -0
- package/src/components/pivotTable/index.tsx +0 -1
- package/src/components/pivotTable/store.tsx +0 -16
- package/src/components/spinner.tsx +14 -0
- package/src/components/toggle.tsx +2 -2
- package/src/components/visualConfig/index.tsx +78 -8
- package/src/computation/clientComputation.ts +55 -0
- package/src/computation/serverComputation.ts +153 -0
- package/src/config.ts +15 -2
- package/src/dataSource/datasetConfig/index.tsx +38 -6
- package/src/dataSource/table.tsx +11 -2
- package/src/fields/filterField/filterEditDialog.tsx +11 -10
- package/src/fields/filterField/tabs.tsx +178 -77
- package/src/hooks/index.ts +10 -0
- package/src/index.tsx +2 -0
- package/src/interfaces.ts +108 -5
- package/src/lib/execExp.ts +20 -11
- package/src/lib/interfaces.ts +1 -0
- package/src/lib/op/aggregate.ts +1 -1
- package/src/lib/viewQuery.ts +2 -2
- package/src/locales/en-US.json +12 -2
- package/src/locales/ja-JP.json +12 -2
- package/src/locales/zh-CN.json +12 -2
- package/src/main.tsx +1 -1
- package/src/renderer/hooks.ts +113 -49
- package/src/renderer/index.tsx +32 -18
- package/src/renderer/pureRenderer.tsx +44 -22
- package/src/renderer/specRenderer.tsx +24 -7
- package/src/services.ts +30 -9
- package/src/store/commonStore.ts +7 -7
- package/src/store/visualSpecStore.ts +300 -193
- package/src/utils/save.ts +81 -3
- package/src/utils/workflow.ts +148 -0
- package/src/vis/react-vega.tsx +21 -6
- package/src/vis/spec/aggregate.ts +3 -2
- package/src/vis/spec/stack.ts +7 -6
- package/src/visualSettings/index.tsx +22 -1
- package/src/workers/filter.worker.js +1 -1
- package/src/workers/sort.ts +22 -0
- package/src/workers/sort.worker.ts +21 -0
- package/src/workers/transform.ts +7 -8
- package/src/workers/transform.worker.js +2 -2
- package/src/workers/viewQuery.worker.js +2 -2
- package/dist/assets/transform.worker-a12fb3d8.js.map +0 -1
|
@@ -19,17 +19,18 @@ interface SpecRendererProps {
|
|
|
19
19
|
visualConfig: DeepReadonly<IVisualConfig>;
|
|
20
20
|
onGeomClick?: ((values: any, e: any) => void) | undefined;
|
|
21
21
|
onChartResize?: ((width: number, height: number) => void) | undefined;
|
|
22
|
+
locale?: string;
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* Sans-store renderer of GraphicWalker.
|
|
25
26
|
* This is a pure component, which means it will not depend on any global state.
|
|
26
27
|
*/
|
|
27
28
|
const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (
|
|
28
|
-
{ name, themeKey, dark, data, loading, draggableFieldState, visualConfig, onGeomClick, onChartResize },
|
|
29
|
+
{ name, themeKey, dark, data, loading, draggableFieldState, visualConfig, onGeomClick, onChartResize, locale },
|
|
29
30
|
ref
|
|
30
31
|
) {
|
|
31
32
|
// const { draggableFieldState, visualConfig } = vizStore;
|
|
32
|
-
const { geoms, interactiveScale, defaultAggregated, stack, showActions, size, format: _format, zeroScale } = visualConfig;
|
|
33
|
+
const { geoms, interactiveScale, defaultAggregated, stack, showActions, size, format: _format, background, zeroScale, resolve } = visualConfig;
|
|
33
34
|
|
|
34
35
|
const rows = draggableFieldState.rows;
|
|
35
36
|
const columns = draggableFieldState.columns;
|
|
@@ -41,7 +42,7 @@ const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (
|
|
|
41
42
|
const sizeChannel = draggableFieldState.size;
|
|
42
43
|
const details = draggableFieldState.details;
|
|
43
44
|
const text = draggableFieldState.text;
|
|
44
|
-
const format = toJS(_format)
|
|
45
|
+
const format = toJS(_format);
|
|
45
46
|
|
|
46
47
|
const rowLeftFacetFields = useMemo(() => rows.slice(0, -1).filter((f) => f.analyticType === 'dimension'), [rows]);
|
|
47
48
|
const colLeftFacetFields = useMemo(
|
|
@@ -59,8 +60,9 @@ const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (
|
|
|
59
60
|
|
|
60
61
|
const vegaConfig = useMemo<VegaGlobalConfig>(() => {
|
|
61
62
|
const config: VegaGlobalConfig = {
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
...themeConfig,
|
|
64
|
+
background: mediaTheme === 'dark' ? '#18181f' : '#ffffff',
|
|
65
|
+
};
|
|
64
66
|
if (format.normalizedNumberFormat && format.normalizedNumberFormat.length > 0) {
|
|
65
67
|
// @ts-ignore
|
|
66
68
|
config.normalizedNumberFormat = format.normalizedNumberFormat;
|
|
@@ -79,9 +81,23 @@ const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (
|
|
|
79
81
|
config.scale = {};
|
|
80
82
|
}
|
|
81
83
|
// @ts-ignore
|
|
82
|
-
config.scale.zero = Boolean(zeroScale)
|
|
84
|
+
config.scale.zero = Boolean(zeroScale);
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
config.resolve = resolve;
|
|
87
|
+
if (background) {
|
|
88
|
+
config.background = background;
|
|
89
|
+
}
|
|
90
|
+
|
|
83
91
|
return config;
|
|
84
|
-
|
|
92
|
+
}, [
|
|
93
|
+
themeConfig,
|
|
94
|
+
zeroScale,
|
|
95
|
+
resolve,
|
|
96
|
+
background,
|
|
97
|
+
format.normalizedNumberFormat,
|
|
98
|
+
format.numberFormat,
|
|
99
|
+
format.timeFormat,
|
|
100
|
+
]);
|
|
85
101
|
|
|
86
102
|
if (isPivotTable) {
|
|
87
103
|
return (
|
|
@@ -148,6 +164,7 @@ const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (
|
|
|
148
164
|
height={size.height - 12 * 4}
|
|
149
165
|
ref={ref}
|
|
150
166
|
onGeomClick={onGeomClick}
|
|
167
|
+
locale={locale}
|
|
151
168
|
/>
|
|
152
169
|
</Resizable>
|
|
153
170
|
);
|
package/src/services.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toJS } from 'mobx';
|
|
2
|
-
import { IRow, IMutField,
|
|
2
|
+
import { IRow, IMutField, Specification, IFilterFiledSimple, IExpression } from './interfaces';
|
|
3
3
|
/* eslint import/no-webpack-loader-syntax:0 */
|
|
4
4
|
// @ts-ignore
|
|
5
5
|
// eslint-disable-next-line
|
|
@@ -11,6 +11,8 @@ import { IRow, IMutField, IField, IFilterField, Specification } from './interfac
|
|
|
11
11
|
import FilterWorker from './workers/filter.worker?worker&inline';
|
|
12
12
|
import TransformDataWorker from './workers/transform.worker?worker&inline';
|
|
13
13
|
import ViewQueryWorker from './workers/viewQuery.worker?worker&inline';
|
|
14
|
+
import SortWorker from './workers/sort.worker?worker&inline';
|
|
15
|
+
|
|
14
16
|
import { IViewQuery } from './lib/viewQuery';
|
|
15
17
|
|
|
16
18
|
// interface WorkerState {
|
|
@@ -106,7 +108,7 @@ interface PreAnalysisParams {
|
|
|
106
108
|
let filterWorker: Worker | null = null;
|
|
107
109
|
let filterWorkerAutoTerminator: NodeJS.Timeout | null = null;
|
|
108
110
|
|
|
109
|
-
export const applyFilter = async (data: IRow[], filters: readonly
|
|
111
|
+
export const applyFilter = async (data: IRow[], filters: readonly IFilterFiledSimple[]): Promise<IRow[]> => {
|
|
110
112
|
if (filters.length === 0) return data;
|
|
111
113
|
if (filterWorkerAutoTerminator !== null) {
|
|
112
114
|
clearTimeout(filterWorkerAutoTerminator);
|
|
@@ -140,13 +142,13 @@ export const applyFilter = async (data: IRow[], filters: readonly IFilterField[]
|
|
|
140
142
|
}
|
|
141
143
|
};
|
|
142
144
|
|
|
143
|
-
export const transformDataService = async (data: IRow[],
|
|
144
|
-
if (
|
|
145
|
+
export const transformDataService = async (data: IRow[], trans: { key: string, expression: IExpression }[]): Promise<IRow[]> => {
|
|
146
|
+
if (data.length === 0) return data;
|
|
145
147
|
const worker = new TransformDataWorker();
|
|
146
148
|
try {
|
|
147
149
|
const res: IRow[] = await workerService(worker, {
|
|
148
150
|
dataSource: data,
|
|
149
|
-
|
|
151
|
+
trans,
|
|
150
152
|
});
|
|
151
153
|
return res;
|
|
152
154
|
} catch (error) {
|
|
@@ -154,14 +156,13 @@ export const transformDataService = async (data: IRow[], columns: IField[]): Pro
|
|
|
154
156
|
} finally {
|
|
155
157
|
worker.terminate();
|
|
156
158
|
}
|
|
157
|
-
}
|
|
159
|
+
};
|
|
158
160
|
|
|
159
|
-
export const applyViewQuery = async (data: IRow[],
|
|
161
|
+
export const applyViewQuery = async (data: IRow[], query: IViewQuery): Promise<IRow[]> => {
|
|
160
162
|
const worker = new ViewQueryWorker();
|
|
161
163
|
try {
|
|
162
164
|
const res: IRow[] = await workerService(worker, {
|
|
163
165
|
dataSource: data,
|
|
164
|
-
metas: toJS(metas),
|
|
165
166
|
query: toJS(query),
|
|
166
167
|
});
|
|
167
168
|
return res;
|
|
@@ -170,4 +171,24 @@ export const applyViewQuery = async (data: IRow[], metas: IField[], query: IView
|
|
|
170
171
|
} finally {
|
|
171
172
|
worker.terminate();
|
|
172
173
|
}
|
|
173
|
-
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export const applySort = async (
|
|
177
|
+
data: IRow[],
|
|
178
|
+
viewMeasures: string[],
|
|
179
|
+
sort: 'ascending' | 'descending'
|
|
180
|
+
): Promise<IRow[]> => {
|
|
181
|
+
const worker = new SortWorker();
|
|
182
|
+
try {
|
|
183
|
+
const res: IRow[] = await workerService(worker, {
|
|
184
|
+
data,
|
|
185
|
+
viewMeasures: viewMeasures.map((x) => toJS(x)),
|
|
186
|
+
sort,
|
|
187
|
+
});
|
|
188
|
+
return res;
|
|
189
|
+
} catch (err) {
|
|
190
|
+
throw new Error('Uncaught error in ViewQueryWorker', { cause: err });
|
|
191
|
+
} finally {
|
|
192
|
+
worker.terminate();
|
|
193
|
+
}
|
|
194
|
+
};
|
package/src/store/commonStore.ts
CHANGED
|
@@ -147,14 +147,14 @@ export class CommonStore {
|
|
|
147
147
|
this.initTempDS();
|
|
148
148
|
this.showDSPanel = true;
|
|
149
149
|
}
|
|
150
|
-
public addAndUseDS(dataset: IDataSetInfo) {
|
|
151
|
-
const
|
|
150
|
+
public addAndUseDS(dataset: IDataSetInfo, datasetId?: string | undefined) {
|
|
151
|
+
const id = this.addDS(dataset, datasetId);
|
|
152
152
|
this.dsIndex = this.datasets.length - 1;
|
|
153
|
-
return
|
|
153
|
+
return id
|
|
154
154
|
}
|
|
155
|
-
public addDS(dataset: IDataSetInfo) {
|
|
155
|
+
public addDS(dataset: IDataSetInfo, datasetId?: string | undefined) {
|
|
156
156
|
const timestamp = new Date().getTime();
|
|
157
|
-
const dataSetId = `dst-${timestamp}`
|
|
157
|
+
const dataSetId = datasetId || `dst-${timestamp}`
|
|
158
158
|
const dataSourceId = `dse-${timestamp}`;
|
|
159
159
|
this.dataSources.push({
|
|
160
160
|
id: dataSourceId,
|
|
@@ -166,12 +166,12 @@ export class CommonStore {
|
|
|
166
166
|
rawFields: dataset.rawFields,
|
|
167
167
|
dsId: dataSourceId
|
|
168
168
|
})
|
|
169
|
-
return
|
|
169
|
+
return dataSourceId;
|
|
170
170
|
}
|
|
171
171
|
public removeDS(datasetId: string) {
|
|
172
172
|
const datasetIndex = this.datasets.findIndex(d => d.id === datasetId);
|
|
173
173
|
if (datasetIndex > -1) {
|
|
174
|
-
const dataSourceId = this.datasets[datasetIndex].
|
|
174
|
+
const dataSourceId = this.datasets[datasetIndex].id;
|
|
175
175
|
const dataSourceIndex = this.dataSources.findIndex(d => d.id === dataSourceId);
|
|
176
176
|
this.dataSources.splice(dataSourceIndex, 1);
|
|
177
177
|
this.datasets.splice(datasetIndex, 1);
|