@kanaries/graphic-walker 0.2.15 → 0.2.17
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 +4 -3
- package/dist/assets/transform.worker-5d54ff09.js.map +1 -0
- package/dist/assets/viewQuery.worker-ffefc111.js.map +1 -0
- package/dist/components/codeExport/index.d.ts +3 -0
- package/dist/components/loadingLayer.d.ts +2 -0
- package/dist/components/tabs/defaultTab.d.ts +1 -0
- package/dist/components/tabs/editableTab.d.ts +1 -2
- package/dist/dataSource/dataSelection/config.d.ts +1 -0
- package/dist/dataSource/dataSelection/utils.d.ts +2 -0
- package/dist/dataSource/index.d.ts +0 -1
- package/dist/datasets/tmp/test.json +1 -0
- package/dist/fields/encodeFields/singleEncodeEditor.d.ts +4 -4
- package/dist/graphic-walker.es.js +29228 -33650
- package/dist/graphic-walker.es.js.map +1 -1
- package/dist/graphic-walker.umd.js +218 -256
- package/dist/graphic-walker.umd.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/interfaces.d.ts +52 -17
- package/dist/lib/execExp.d.ts +8 -0
- package/dist/lib/inferMeta.d.ts +2 -9
- package/dist/lib/insights/explainByChildren.d.ts +16 -0
- package/dist/lib/insights/explainBySelection.d.ts +5 -0
- package/dist/lib/insights/explainValue.d.ts +2 -0
- package/dist/lib/insights/utils.d.ts +11 -0
- package/dist/lib/interfaces.d.ts +23 -0
- package/dist/lib/op/aggregate.d.ts +3 -0
- package/dist/lib/op/bin.d.ts +3 -0
- package/dist/lib/op/fold.d.ts +3 -0
- package/dist/lib/op/stat.d.ts +8 -0
- package/dist/lib/viewQuery.d.ts +4 -0
- package/dist/models/visSpecHistory.d.ts +2 -0
- package/dist/renderer/index.d.ts +8 -7
- package/dist/renderer/specRenderer.d.ts +13 -0
- package/dist/services.d.ts +5 -31
- package/dist/store/commonStore.d.ts +6 -0
- package/dist/store/index.d.ts +3 -2
- package/dist/store/visualSpecStore.d.ts +11 -5
- package/dist/utils/autoMark.d.ts +1 -1
- package/dist/utils/dataPrep.d.ts +3 -2
- package/dist/utils/index.d.ts +3 -5
- package/dist/utils/save.d.ts +1 -2
- package/dist/vis/react-vega.d.ts +2 -22
- package/dist/vis/spec/aggregate.d.ts +4 -0
- package/dist/vis/spec/encode.d.ts +20 -0
- package/dist/vis/spec/field.d.ts +2 -0
- package/dist/vis/spec/mark.d.ts +7 -0
- package/dist/vis/spec/stack.d.ts +4 -0
- package/dist/vis/spec/tooltip.d.ts +4 -0
- package/dist/vis/spec/view.d.ts +73 -0
- package/dist/workers/transform.d.ts +2 -0
- package/package.json +5 -6
- package/src/App.tsx +56 -66
- package/src/components/codeExport/index.tsx +114 -0
- package/src/components/dataTable/index.tsx +10 -10
- package/src/components/loadingLayer.tsx +7 -0
- package/src/components/tabs/defaultTab.tsx +4 -2
- package/src/components/tabs/editableTab.tsx +74 -39
- package/src/dataSource/dataSelection/config.ts +11 -0
- package/src/dataSource/dataSelection/csvData.tsx +71 -39
- package/src/dataSource/dataSelection/gwFile.tsx +2 -2
- package/src/dataSource/dataSelection/utils.ts +28 -0
- package/src/dataSource/index.tsx +0 -17
- package/src/dataSource/utils.ts +8 -3
- package/src/fields/aestheticFields.tsx +1 -2
- package/src/fields/datasetFields/meaFields.tsx +12 -4
- package/src/fields/encodeFields/singleEncodeEditor.tsx +11 -12
- package/src/fields/fieldsContext.tsx +1 -0
- package/src/index.css +4 -4
- package/src/index.tsx +22 -22
- package/src/interfaces.ts +85 -49
- package/src/lib/execExp.ts +147 -0
- package/src/lib/inferMeta.ts +26 -29
- package/src/lib/insights/explainByChildren.ts +50 -0
- package/src/lib/insights/explainBySelection.ts +47 -0
- package/src/lib/insights/explainValue.ts +30 -0
- package/src/lib/insights/utils.ts +21 -0
- package/src/lib/interfaces.ts +33 -0
- package/src/lib/op/aggregate.ts +49 -0
- package/src/lib/op/bin.ts +25 -0
- package/src/lib/op/fold.ts +17 -0
- package/src/lib/op/stat.ts +46 -0
- package/src/lib/viewQuery.ts +22 -0
- package/src/locales/en-US.json +6 -3
- package/src/locales/i18n.ts +0 -1
- package/src/locales/ja-JP.json +4 -2
- package/src/locales/zh-CN.json +6 -3
- package/src/main.tsx +1 -1
- package/src/models/visSpecHistory.ts +14 -0
- package/src/renderer/index.tsx +58 -126
- package/src/renderer/specRenderer.tsx +121 -0
- package/src/segments/segmentNav.tsx +3 -16
- package/src/segments/visNav.tsx +17 -6
- package/src/services.ts +101 -67
- package/src/store/commonStore.ts +14 -9
- package/src/store/index.tsx +11 -4
- package/src/store/visualSpecStore.ts +89 -52
- package/src/utils/autoMark.ts +1 -1
- package/src/utils/dataPrep.ts +25 -2
- package/src/utils/index.ts +16 -17
- package/src/utils/normalization.ts +3 -1
- package/src/utils/save.ts +1 -2
- package/src/vis/react-vega.tsx +9 -340
- package/src/vis/spec/aggregate.ts +13 -0
- package/src/vis/spec/encode.ts +70 -0
- package/src/vis/spec/field.ts +10 -0
- package/src/vis/spec/mark.ts +30 -0
- package/src/vis/spec/stack.ts +11 -0
- package/src/vis/spec/tooltip.ts +16 -0
- package/src/vis/spec/view.ts +136 -0
- package/src/vis/theme.ts +12 -0
- package/src/visualSettings/index.tsx +10 -1
- package/src/workers/transform.ts +12 -0
- package/src/workers/transform.worker.js +13 -0
- package/src/workers/viewQuery.worker.js +16 -0
- package/dist/assets/explainer.worker-8428eb12.js.map +0 -1
- package/dist/dataSource/pannel.d.ts +0 -5
- package/dist/insightBoard/index.d.ts +0 -3
- package/dist/insightBoard/mainBoard.d.ts +0 -11
- package/dist/insightBoard/radioGroupButtons.d.ts +0 -12
- package/dist/insightBoard/selectionSpec.d.ts +0 -13
- package/dist/insightBoard/std2vegaSpec.d.ts +0 -12
- package/dist/insightBoard/utils.d.ts +0 -8
- package/dist/insights.d.ts +0 -61
- package/src/dataSource/pannel.tsx +0 -71
- package/src/insightBoard/index.tsx +0 -31
- package/src/insightBoard/mainBoard.tsx +0 -224
- package/src/insightBoard/radioGroupButtons.tsx +0 -57
- package/src/insightBoard/selectionSpec.ts +0 -113
- package/src/insightBoard/std2vegaSpec.ts +0 -184
- package/src/insightBoard/utils.ts +0 -32
- package/src/insights.ts +0 -408
- package/src/workers/explainer.worker.js +0 -76
package/src/store/commonStore.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DataSet, Filters, IDataSet, IDataSetInfo, IDataSource, IMutField, IRow, ISegmentKey } from '../interfaces';
|
|
2
2
|
import { makeAutoObservable, observable, toJS } from 'mobx';
|
|
3
3
|
import { transData } from '../dataSource/utils';
|
|
4
|
-
import { extendCountField } from '../utils';
|
|
5
4
|
|
|
6
5
|
export class CommonStore {
|
|
7
6
|
public datasets: IDataSet[] = [];
|
|
@@ -14,6 +13,7 @@ export class CommonStore {
|
|
|
14
13
|
public showInsightBoard: boolean = false;
|
|
15
14
|
public vizEmbededMenu: { show: boolean; position: [number, number] } = { show: false, position: [0, 0] };
|
|
16
15
|
public showDataConfig: boolean = false;
|
|
16
|
+
public showCodeExportPanel: boolean = false;
|
|
17
17
|
public filters: Filters = {};
|
|
18
18
|
public segmentKey: ISegmentKey = ISegmentKey.vis;
|
|
19
19
|
constructor () {
|
|
@@ -30,12 +30,12 @@ export class CommonStore {
|
|
|
30
30
|
if (this.datasets.length > 0) {
|
|
31
31
|
const dataSourceId = this.datasets[datasetIndex].dsId;
|
|
32
32
|
const dataSource = this.dataSources.find(d => d.id === dataSourceId);
|
|
33
|
-
const rawFields = toJS(this.datasets[datasetIndex].rawFields)
|
|
34
|
-
const base = extendCountField((dataSource ? dataSource.data : []), rawFields)
|
|
33
|
+
const rawFields = toJS(this.datasets[datasetIndex].rawFields)//.concat(createCountField())
|
|
34
|
+
// const base = extendCountField((dataSource ? dataSource.data : []), rawFields)
|
|
35
35
|
return {
|
|
36
36
|
...this.datasets[datasetIndex],
|
|
37
|
-
dataSource:
|
|
38
|
-
rawFields
|
|
37
|
+
dataSource: dataSource?.data ?? [],
|
|
38
|
+
rawFields
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
return {
|
|
@@ -61,6 +61,9 @@ export class CommonStore {
|
|
|
61
61
|
this.vizEmbededMenu.show = true;
|
|
62
62
|
this.vizEmbededMenu.position = position;
|
|
63
63
|
}
|
|
64
|
+
public setShowCodeExportPanel (show: boolean) {
|
|
65
|
+
this.showCodeExportPanel = show;
|
|
66
|
+
}
|
|
64
67
|
public closeEmbededMenu () {
|
|
65
68
|
this.vizEmbededMenu.show = false;
|
|
66
69
|
}
|
|
@@ -112,11 +115,13 @@ export class CommonStore {
|
|
|
112
115
|
|
|
113
116
|
public updateTempDS (rawData: IRow[]) {
|
|
114
117
|
const result = transData(rawData);
|
|
115
|
-
|
|
116
|
-
this.tmpDataSource = result.dataSource.slice(0, -1);
|
|
118
|
+
this.tmpDataSource = result.dataSource;
|
|
117
119
|
this.tmpDSRawFields = result.fields;
|
|
118
120
|
}
|
|
119
|
-
|
|
121
|
+
/**
|
|
122
|
+
* update temp dataset (standard) with dataset info
|
|
123
|
+
* @param dataset
|
|
124
|
+
*/
|
|
120
125
|
public updateTempSTDDS (dataset: IDataSetInfo) {
|
|
121
126
|
this.tmpDataSource = dataset.dataSource;
|
|
122
127
|
this.tmpDSRawFields = dataset.rawFields;
|
|
@@ -176,7 +181,7 @@ export class CommonStore {
|
|
|
176
181
|
}
|
|
177
182
|
public createPlaceholderDS() {
|
|
178
183
|
this.addDS({
|
|
179
|
-
name: '
|
|
184
|
+
name: 'new dataset',
|
|
180
185
|
dataSource: [],
|
|
181
186
|
rawFields: []
|
|
182
187
|
})
|
package/src/store/index.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { useContext
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
2
|
import { CommonStore } from './commonStore'
|
|
3
3
|
import { VizSpecStore } from './visualSpecStore'
|
|
4
4
|
|
|
5
|
-
interface
|
|
5
|
+
export interface IGlobalStore {
|
|
6
6
|
commonStore: CommonStore;
|
|
7
7
|
vizStore: VizSpecStore;
|
|
8
8
|
}
|
|
@@ -10,12 +10,12 @@ interface GlobalStore {
|
|
|
10
10
|
const commonStore = new CommonStore();
|
|
11
11
|
const vizStore = new VizSpecStore(commonStore);
|
|
12
12
|
|
|
13
|
-
const initStore:
|
|
13
|
+
const initStore: IGlobalStore = {
|
|
14
14
|
commonStore,
|
|
15
15
|
vizStore
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const StoreContext = React.createContext<
|
|
18
|
+
const StoreContext = React.createContext<IGlobalStore>(null!);
|
|
19
19
|
|
|
20
20
|
export function destroyGWStore() {
|
|
21
21
|
initStore.commonStore.destroy();
|
|
@@ -31,16 +31,23 @@ export function rebootGWStore() {
|
|
|
31
31
|
|
|
32
32
|
interface StoreWrapperProps {
|
|
33
33
|
keepAlive?: boolean;
|
|
34
|
+
storeRef?: React.MutableRefObject<IGlobalStore | null>;
|
|
34
35
|
}
|
|
35
36
|
export class StoreWrapper extends React.Component<StoreWrapperProps> {
|
|
36
37
|
constructor(props: StoreWrapperProps) {
|
|
37
38
|
super(props)
|
|
39
|
+
if (props.storeRef) {
|
|
40
|
+
props.storeRef.current = initStore;
|
|
41
|
+
}
|
|
38
42
|
if (props.keepAlive) {
|
|
39
43
|
rebootGWStore();
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
componentWillUnmount() {
|
|
43
47
|
if (!this.props.keepAlive) {
|
|
48
|
+
if (this.props.storeRef) {
|
|
49
|
+
this.props.storeRef.current = null;
|
|
50
|
+
}
|
|
44
51
|
destroyGWStore();
|
|
45
52
|
}
|
|
46
53
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { IReactionDisposer, makeAutoObservable, observable, reaction, toJS } from "mobx";
|
|
2
2
|
import produce from "immer";
|
|
3
3
|
import { v4 as uuidv4 } from "uuid";
|
|
4
|
-
import { Specification } from "
|
|
5
|
-
import { DataSet, DraggableFieldState, IFilterRule, IViewField, IVisSpec, IVisualConfig } from "../interfaces";
|
|
4
|
+
import { DataSet, DraggableFieldState, IFilterRule, IViewField, IVisSpec, IVisualConfig, Specification } from "../interfaces";
|
|
6
5
|
import { CHANNEL_LIMIT, GEMO_TYPES, MetaFieldKeys } from "../config";
|
|
7
|
-
import { makeBinField, makeLogField } from "../utils/normalization";
|
|
8
6
|
import { VisSpecWithHistory } from "../models/visSpecHistory";
|
|
9
|
-
import { dumpsGWPureSpec, parseGWContent, parseGWPureSpec, stringifyGWContent } from "../utils/save";
|
|
7
|
+
import { IStoInfo, dumpsGWPureSpec, parseGWContent, parseGWPureSpec, stringifyGWContent } from "../utils/save";
|
|
10
8
|
import { CommonStore } from "./commonStore";
|
|
9
|
+
import { createCountField } from "../utils";
|
|
11
10
|
|
|
12
11
|
function getChannelSizeLimit(channel: string): number {
|
|
13
12
|
if (typeof CHANNEL_LIMIT[channel] === "undefined") return Infinity;
|
|
@@ -40,7 +39,7 @@ function geomAdapter(geom: string) {
|
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
function initEncoding(): DraggableFieldState {
|
|
42
|
+
export function initEncoding(): DraggableFieldState {
|
|
44
43
|
return {
|
|
45
44
|
dimensions: [],
|
|
46
45
|
measures: [],
|
|
@@ -58,7 +57,7 @@ function initEncoding(): DraggableFieldState {
|
|
|
58
57
|
};
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
function initVisualConfig(): IVisualConfig {
|
|
60
|
+
export function initVisualConfig(): IVisualConfig {
|
|
62
61
|
return {
|
|
63
62
|
defaultAggregated: true,
|
|
64
63
|
geoms: [GEMO_TYPES[0]!],
|
|
@@ -92,6 +91,10 @@ const forwardVisualConfigs = (backwards: ReturnType<typeof parseGWContent>["spec
|
|
|
92
91
|
}));
|
|
93
92
|
};
|
|
94
93
|
|
|
94
|
+
function isDraggableStateEmpty(state: DeepReadonly<DraggableFieldState>): boolean {
|
|
95
|
+
return Object.values(state).every((value) => value.length === 0);
|
|
96
|
+
}
|
|
97
|
+
|
|
95
98
|
export class VizSpecStore {
|
|
96
99
|
// public fields: IViewField[] = [];
|
|
97
100
|
private commonStore: CommonStore;
|
|
@@ -139,7 +142,7 @@ export class VizSpecStore {
|
|
|
139
142
|
this.visualConfig = initVisualConfig();
|
|
140
143
|
this.visList.push(
|
|
141
144
|
new VisSpecWithHistory({
|
|
142
|
-
name:
|
|
145
|
+
name: 'Chart 1',
|
|
143
146
|
visId: uuidv4(),
|
|
144
147
|
config: this.visualConfig,
|
|
145
148
|
encodings: this.draggableFieldState,
|
|
@@ -151,13 +154,6 @@ export class VizSpecStore {
|
|
|
151
154
|
reactions: false,
|
|
152
155
|
});
|
|
153
156
|
this.reactions.push(
|
|
154
|
-
reaction(
|
|
155
|
-
() => commonStore.currentDataset,
|
|
156
|
-
(dataset) => {
|
|
157
|
-
// this.initState();
|
|
158
|
-
this.initMetaState(dataset);
|
|
159
|
-
}
|
|
160
|
-
),
|
|
161
157
|
reaction(
|
|
162
158
|
() => this.visList[this.visIndex],
|
|
163
159
|
(frame) => {
|
|
@@ -168,6 +164,15 @@ export class VizSpecStore {
|
|
|
168
164
|
this.canUndo = frame.canUndo;
|
|
169
165
|
this.canRedo = frame.canRedo;
|
|
170
166
|
}
|
|
167
|
+
),
|
|
168
|
+
reaction(
|
|
169
|
+
() => commonStore.currentDataset,
|
|
170
|
+
(dataset) => {
|
|
171
|
+
// this.initState();
|
|
172
|
+
if (isDraggableStateEmpty(this.draggableFieldState) && dataset.dataSource.length > 0 && dataset.rawFields.length > 0) {
|
|
173
|
+
this.initMetaState(dataset);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
171
176
|
)
|
|
172
177
|
);
|
|
173
178
|
}
|
|
@@ -275,10 +280,24 @@ export class VizSpecStore {
|
|
|
275
280
|
});
|
|
276
281
|
return fields;
|
|
277
282
|
}
|
|
278
|
-
public
|
|
283
|
+
public get allFields(): IViewField[] {
|
|
284
|
+
const { draggableFieldState } = this;
|
|
285
|
+
const dimensions = toJS(draggableFieldState.dimensions);
|
|
286
|
+
const measures = toJS(draggableFieldState.measures);
|
|
287
|
+
return [...dimensions, ...measures];
|
|
288
|
+
}
|
|
289
|
+
public get viewFilters() {
|
|
290
|
+
const { draggableFieldState } = this;
|
|
291
|
+
const state = toJS(draggableFieldState);
|
|
292
|
+
return state.filters;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
public addVisualization(defaultName?: string) {
|
|
297
|
+
const name = defaultName || 'Chart ' + (this.visList.length + 1);
|
|
279
298
|
this.visList.push(
|
|
280
299
|
new VisSpecWithHistory({
|
|
281
|
-
name
|
|
300
|
+
name,
|
|
282
301
|
visId: uuidv4(),
|
|
283
302
|
config: initVisualConfig(),
|
|
284
303
|
encodings: initEncoding(),
|
|
@@ -290,9 +309,10 @@ export class VizSpecStore {
|
|
|
290
309
|
this.visIndex = visIndex;
|
|
291
310
|
}
|
|
292
311
|
public setVisName(visIndex: number, name: string) {
|
|
293
|
-
this.
|
|
294
|
-
|
|
295
|
-
|
|
312
|
+
this.visList[visIndex] = this.visList[visIndex].clone();
|
|
313
|
+
this.visList[visIndex].updateLatest({
|
|
314
|
+
name
|
|
315
|
+
})
|
|
296
316
|
}
|
|
297
317
|
public initState() {
|
|
298
318
|
this.useMutable((tab) => {
|
|
@@ -301,6 +321,7 @@ export class VizSpecStore {
|
|
|
301
321
|
});
|
|
302
322
|
}
|
|
303
323
|
public initMetaState(dataset: DataSet) {
|
|
324
|
+
const countField = createCountField();
|
|
304
325
|
this.useMutable(({ encodings }) => {
|
|
305
326
|
encodings.fields = dataset.rawFields.map((f) => ({
|
|
306
327
|
dragId: uuidv4(),
|
|
@@ -309,7 +330,8 @@ export class VizSpecStore {
|
|
|
309
330
|
aggName: f.analyticType === "measure" ? "sum" : undefined,
|
|
310
331
|
analyticType: f.analyticType,
|
|
311
332
|
semanticType: f.semanticType,
|
|
312
|
-
}));
|
|
333
|
+
}))//.concat(countField);
|
|
334
|
+
encodings.fields.push(countField);
|
|
313
335
|
encodings.dimensions = dataset.rawFields
|
|
314
336
|
.filter((f) => f.analyticType === "dimension")
|
|
315
337
|
.map((f) => ({
|
|
@@ -329,17 +351,10 @@ export class VizSpecStore {
|
|
|
329
351
|
semanticType: f.semanticType,
|
|
330
352
|
aggName: "sum",
|
|
331
353
|
}));
|
|
354
|
+
encodings.measures.push(countField);
|
|
332
355
|
});
|
|
333
356
|
|
|
334
357
|
this.freezeHistory();
|
|
335
|
-
// this.draggableFieldState.measures.push({
|
|
336
|
-
// dragId: uuidv4(),
|
|
337
|
-
// fid: COUNT_FIELD_ID,
|
|
338
|
-
// name: '记录数',
|
|
339
|
-
// analyticType: 'measure',
|
|
340
|
-
// semanticType: 'quantitative',
|
|
341
|
-
// aggName: 'count'
|
|
342
|
-
// })
|
|
343
358
|
}
|
|
344
359
|
public clearState() {
|
|
345
360
|
this.useMutable(({ encodings }) => {
|
|
@@ -489,44 +504,59 @@ export class VizSpecStore {
|
|
|
489
504
|
encodings.rows = fieldsInCup as typeof encodings.rows; // assume this as writable
|
|
490
505
|
});
|
|
491
506
|
}
|
|
492
|
-
public createBinField(stateKey: keyof DraggableFieldState, index: number) {
|
|
507
|
+
public createBinField(stateKey: keyof DraggableFieldState, index: number, binType: 'bin' | 'binCount') {
|
|
493
508
|
this.useMutable(({ encodings }) => {
|
|
494
509
|
const originField = encodings[stateKey][index];
|
|
510
|
+
const newVarKey = uuidv4();
|
|
495
511
|
const binField: IViewField = {
|
|
496
|
-
fid:
|
|
497
|
-
dragId:
|
|
498
|
-
name:
|
|
512
|
+
fid: newVarKey,
|
|
513
|
+
dragId: newVarKey,
|
|
514
|
+
name: `${binType}(${originField.name})`,
|
|
499
515
|
semanticType: "ordinal",
|
|
500
516
|
analyticType: "dimension",
|
|
517
|
+
computed: true,
|
|
518
|
+
expressoion: {
|
|
519
|
+
op: binType,
|
|
520
|
+
as: newVarKey,
|
|
521
|
+
params: [
|
|
522
|
+
{
|
|
523
|
+
type: 'field',
|
|
524
|
+
value: originField.fid
|
|
525
|
+
}
|
|
526
|
+
]
|
|
527
|
+
}
|
|
501
528
|
};
|
|
502
529
|
encodings.dimensions.push(binField);
|
|
503
|
-
this.commonStore.currentDataset.dataSource = makeBinField(
|
|
504
|
-
this.commonStore.currentDataset.dataSource,
|
|
505
|
-
originField.fid,
|
|
506
|
-
binField.fid
|
|
507
|
-
);
|
|
508
530
|
});
|
|
509
531
|
}
|
|
510
|
-
public createLogField(stateKey: keyof DraggableFieldState, index: number) {
|
|
532
|
+
public createLogField(stateKey: keyof DraggableFieldState, index: number, scaleType: 'log10' | 'log2') {
|
|
511
533
|
if (stateKey === "filters") {
|
|
512
534
|
return;
|
|
513
535
|
}
|
|
514
536
|
|
|
515
537
|
this.useMutable(({ encodings }) => {
|
|
516
538
|
const originField = encodings[stateKey][index];
|
|
539
|
+
const newVarKey = uuidv4();
|
|
517
540
|
const logField: IViewField = {
|
|
518
|
-
fid:
|
|
519
|
-
dragId:
|
|
520
|
-
name:
|
|
541
|
+
fid: newVarKey,
|
|
542
|
+
dragId: newVarKey,
|
|
543
|
+
name: `${scaleType}(${originField.name})`,
|
|
521
544
|
semanticType: "quantitative",
|
|
522
545
|
analyticType: originField.analyticType,
|
|
546
|
+
aggName: 'sum',
|
|
547
|
+
computed: true,
|
|
548
|
+
expressoion: {
|
|
549
|
+
op: scaleType,
|
|
550
|
+
as: newVarKey,
|
|
551
|
+
params: [
|
|
552
|
+
{
|
|
553
|
+
type: 'field',
|
|
554
|
+
value: originField.fid
|
|
555
|
+
}
|
|
556
|
+
]
|
|
557
|
+
}
|
|
523
558
|
};
|
|
524
559
|
encodings[stateKey].push(logField);
|
|
525
|
-
this.commonStore.currentDataset.dataSource = makeLogField(
|
|
526
|
-
this.commonStore.currentDataset.dataSource,
|
|
527
|
-
originField.fid,
|
|
528
|
-
logField.fid
|
|
529
|
-
);
|
|
530
560
|
});
|
|
531
561
|
}
|
|
532
562
|
public setFieldAggregator(stateKey: keyof DraggableFieldState, index: number, aggName: string) {
|
|
@@ -616,6 +646,7 @@ export class VizSpecStore {
|
|
|
616
646
|
// thi
|
|
617
647
|
// const [xField, yField, ] = spec.position;
|
|
618
648
|
this.clearState();
|
|
649
|
+
this.setVisualConfig('defaultAggregated', Boolean(spec.aggregate));
|
|
619
650
|
if ((spec.geomType?.length ?? 0) > 0) {
|
|
620
651
|
this.setVisualConfig(
|
|
621
652
|
"geoms",
|
|
@@ -677,13 +708,19 @@ export class VizSpecStore {
|
|
|
677
708
|
specList: pureVisList,
|
|
678
709
|
});
|
|
679
710
|
}
|
|
711
|
+
public exportViewSpec() {
|
|
712
|
+
const pureVisList = dumpsGWPureSpec(this.visList);
|
|
713
|
+
return pureVisList
|
|
714
|
+
}
|
|
715
|
+
public importStoInfo (stoInfo: IStoInfo) {
|
|
716
|
+
this.visList = parseGWPureSpec(forwardVisualConfigs(stoInfo.specList));
|
|
717
|
+
this.visIndex = 0;
|
|
718
|
+
this.commonStore.datasets = stoInfo.datasets;
|
|
719
|
+
this.commonStore.dataSources = stoInfo.dataSources;
|
|
720
|
+
this.commonStore.dsIndex = Math.max(stoInfo.datasets.length - 1, 0);
|
|
721
|
+
}
|
|
680
722
|
public importRaw(raw: string) {
|
|
681
723
|
const content = parseGWContent(raw);
|
|
682
|
-
this.
|
|
683
|
-
this.commonStore.dataSources = content.dataSources;
|
|
684
|
-
this.commonStore.dsIndex = Math.max(content.datasets.length - 1, 0);
|
|
685
|
-
// 补上初始化新版本特性
|
|
686
|
-
this.visList = parseGWPureSpec(forwardVisualConfigs(content.specList));
|
|
687
|
-
this.visIndex = 0;
|
|
724
|
+
this.importStoInfo(content);
|
|
688
725
|
}
|
|
689
726
|
}
|
package/src/utils/autoMark.ts
CHANGED
package/src/utils/dataPrep.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { IRow } from "
|
|
2
|
-
import { IMutField } from "../interfaces";
|
|
1
|
+
import { IMutField, IRow } from "../interfaces";
|
|
3
2
|
|
|
4
3
|
function updateRowKeys(data: IRow[], keyEncodeList: {from: string; to: string}[]): IRow[] {
|
|
5
4
|
return data.map((row) => {
|
|
@@ -41,4 +40,28 @@ export function guardDataKeys (data: IRow[], metas: IMutField[]): {
|
|
|
41
40
|
safeData,
|
|
42
41
|
safeMetas
|
|
43
42
|
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const SPLITOR = '__'
|
|
46
|
+
export function flatNestKeys (object: any): string[] {
|
|
47
|
+
const keys = Object.keys(object);
|
|
48
|
+
let flatColKeys: string[] = [];
|
|
49
|
+
for (let key of keys) {
|
|
50
|
+
if (typeof object[key] === 'object') {
|
|
51
|
+
const subKeys = flatNestKeys(object[key]);
|
|
52
|
+
flatColKeys = flatColKeys.concat(subKeys.map(k => `${key}${SPLITOR}${k}`));
|
|
53
|
+
} else {
|
|
54
|
+
flatColKeys.push(key)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return flatColKeys;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function getValueByKeyPath (object: any, keyPath: string): any {
|
|
61
|
+
const keys = keyPath.split(SPLITOR);
|
|
62
|
+
let value = object;
|
|
63
|
+
for (let key of keys) {
|
|
64
|
+
value = value[key];
|
|
65
|
+
}
|
|
66
|
+
return value;
|
|
44
67
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import i18next from "i18next";
|
|
2
2
|
import { COUNT_FIELD_ID } from "../constants";
|
|
3
|
-
import { IRow, Filters, IMutField } from "../interfaces";
|
|
3
|
+
import { IRow, Filters, IMutField, IViewField } from "../interfaces";
|
|
4
4
|
interface NRReturns {
|
|
5
5
|
normalizedData: IRow[];
|
|
6
6
|
maxMeasures: IRow;
|
|
@@ -236,26 +236,21 @@ export function applyFilters(dataSource: IRow[], filters: Filters): IRow[] {
|
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
export function
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
dataSource: IRow[];
|
|
244
|
-
fields: IMutField[];
|
|
245
|
-
} {
|
|
246
|
-
const nextData = dataSource.map((r) => ({
|
|
247
|
-
...r,
|
|
248
|
-
[COUNT_FIELD_ID]: 1,
|
|
249
|
-
}));
|
|
250
|
-
const nextFields = fields.concat({
|
|
239
|
+
export function createCountField(): IViewField {
|
|
240
|
+
return {
|
|
241
|
+
// viewId: "",
|
|
242
|
+
dragId: COUNT_FIELD_ID,
|
|
251
243
|
fid: COUNT_FIELD_ID,
|
|
252
244
|
name: i18next.t("constant.row_count"),
|
|
253
245
|
analyticType: "measure",
|
|
254
246
|
semanticType: "quantitative",
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
247
|
+
aggName: 'sum',
|
|
248
|
+
computed: true,
|
|
249
|
+
expressoion: {
|
|
250
|
+
op: 'one',
|
|
251
|
+
params: [],
|
|
252
|
+
as: COUNT_FIELD_ID,
|
|
253
|
+
}
|
|
259
254
|
};
|
|
260
255
|
}
|
|
261
256
|
|
|
@@ -276,4 +271,8 @@ export function makeNumbersBeautiful (nums: number[]): number[] {
|
|
|
276
271
|
return nums.map((num) => {
|
|
277
272
|
return Math.round(num / step) * step;
|
|
278
273
|
})
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export function classNames(...classes: string[]) {
|
|
277
|
+
return classes.filter(Boolean).join(' ')
|
|
279
278
|
}
|
|
@@ -146,7 +146,9 @@ export function makeBinField(dataSource: IRow[], fid: string, binFid: string, bi
|
|
|
146
146
|
if (bIndex === binSize) bIndex = binSize - 1;
|
|
147
147
|
return {
|
|
148
148
|
...r,
|
|
149
|
-
[binFid]:
|
|
149
|
+
[binFid]: [bIndex * step + _min, (bIndex + 1) * step + _min],
|
|
150
|
+
|
|
151
|
+
// [binFid]: Number(((bIndex * step + _min)).toFixed(beaStep)),
|
|
150
152
|
};
|
|
151
153
|
});
|
|
152
154
|
}
|
package/src/utils/save.ts
CHANGED
|
@@ -9,10 +9,9 @@ export function parseGWPureSpec(list: IVisSpec[]): VisSpecWithHistory[] {
|
|
|
9
9
|
return list.map((l) => new VisSpecWithHistory(l));
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
interface IStoInfo {
|
|
12
|
+
export interface IStoInfo {
|
|
13
13
|
datasets: IDataSet[];
|
|
14
14
|
specList: {
|
|
15
|
-
/** 由于 gw 内部实现暂时未锁版本,这里获取到的信息可能会与当前实例内容有偏差,需要用初始值合入 */
|
|
16
15
|
[K in keyof IVisSpec]: K extends "config" ? Partial<IVisSpec[K]> : IVisSpec[K];
|
|
17
16
|
}[];
|
|
18
17
|
dataSources: IDataSource[];
|